def __init__(self, name, options, dashboard): self.dashboard = dashboard self.name = name self.options = options if self.options.get("shared_card"): try: self.options = self.dashboard.dm.shared_cards[ options["shared_card"]] except KeyError: logging.error( f'Shared card {options["shared_card"]} not found, using defaults..' ) self.tags = self.options.get("tags", []) self.onpress = resolve_onpress_option(self.options.get("onpress", {})) self.card = self.options.get("card", {}) if not self.card.get("width"): self.card["width"] = "auto" if not self.card.get("alignment"): self.card["alignment"] = "center" if self.card.get("full-width") is True: self.card["width"] = "calc(100vw - 2rem)" self.icon = Icon(self.options) self.title = Title(self.options) self.description = Description(self.options) self.data_sources = DataSources(self.options) self.list = List(self.options) self.actionbar = ActionBar(self.options) self.content = Content(self.options, self)
def __init__(self, options): # apply user config dict for key, value in options.get("actionbar", {}).items(): setattr(self, key, value) if hasattr(self, "actions"): for action in self.actions: action["icon"] = resolve_image_option(action["icon"], default_height="24px") if action.get("onpress", None): action["onpress"] = resolve_onpress_option( action["onpress"])
def __init__(self, options): # parse string shorthand if isinstance(options.get("title"), str): self.text = options["title"] else: # apply user config dict for key, value in options.get("title", {}).items(): setattr(self, key, value) # set defaults if hasattr(self, "onpress"): self.onpress = resolve_onpress_option(self.onpress)
def __init__(self, options): self.items = [] # apply user config dict for key, value in options.get("list", {}).items(): setattr(self, key, value) if not hasattr(self, "alignment"): self.alignment = "left" for item in self.items: if item.get("icon"): item["icon"] = resolve_image_option(item["icon"], default_height="24px") if item.get("onpress"): item["onpress"] = resolve_onpress_option(item["onpress"])
def __init__(self, options): # parse string shorthand if isinstance(options.get("icon", None), str): self.image = resolve_image_option(options["icon"], default_height="64px") else: # apply user config dict for key, value in options.get("icon", {}).items(): setattr(self, key, value) if not hasattr(self, "height"): self.height = "64px" if hasattr(self, "image"): self.image = resolve_image_option(self.image, default_height=self.height) if hasattr(self, "onpress"): self.onpress = resolve_onpress_option(self.onpress)
def __init__(self, name, options, dashboard): """ The Card class. This class is responsible for storing the data from the parent dashboard's toml file. These configurations are applied in the html template rendered when the parent dashboard is sent to the ui. The ways in which these configurations effect the card's appearance can be found in /dashmachine/templates/main/dashboard-card.html :param name: (str) the searchable (not displayed) name of the card :param options: (dict) the key/value pairs of the card's options from the toml :param dashboard: (Dashboard Object) the parent Dashboard object. """ self.dashboard = dashboard self.name = name self.options = options if self.options.get("shared_card"): try: self.options = self.dashboard.dm.shared_cards[ options["shared_card"]] except KeyError: logging.error( f'Shared card {options["shared_card"]} not found, using defaults..' ) # SET CARD DEFAULTS self.tags = self.options.get("tags", []) self.onpress = resolve_onpress_option(self.options.get("onpress", {})) self.card = self.options.get("card", {}) if not self.card.get("width"): self.card["width"] = "auto" if not self.card.get("alignment"): self.card["alignment"] = "center" if self.card.get("full-width") is True: self.card["width"] = "calc(100vw - 2rem)" # INITIALIZE CHILD CLASSES (CARD BUILDING BLOCKS) USING CARD'S OPTIONS self.icon = Icon(self.options) self.title = Title(self.options) self.description = Description(self.options) self.data_sources = DataSources(self.options) self.list = List(self.options) self.actionbar = ActionBar(self.options) self.content = Content(self.options, self)
def __init__(self, options): """ The bar at the bottom of the card with configurable buttons. :param options: (dict) the key/value pairs from this section of the card's config toml """ # apply user config dict for key, value in options.get("actionbar", {}).items(): setattr(self, key, value) if hasattr(self, "actions"): for action in self.actions: action["icon"] = resolve_image_option(action["icon"], default_height="24px") if action.get("onpress", None): action["onpress"] = resolve_onpress_option( action["onpress"])
def __init__(self, options): """ This section contains text that is below the icon (if present) on the card. :param options: (dict) the key/value pairs from this section of the card's config toml """ # parse string shorthand if isinstance(options.get("title"), str): self.text = options["title"] else: # apply user config dict for key, value in options.get("title", {}).items(): setattr(self, key, value) # set defaults if hasattr(self, "onpress"): self.onpress = resolve_onpress_option(self.onpress)
def __init__(self, options): """ This section contains an image at the top of the card. :param options: (dict) the key/value pairs from this section of the card's config toml """ # parse string shorthand if isinstance(options.get("icon", None), str): self.image = resolve_image_option(options["icon"], default_height="64px") else: # apply user config dict for key, value in options.get("icon", {}).items(): setattr(self, key, value) if not hasattr(self, "height"): self.height = "64px" if hasattr(self, "image"): self.image = resolve_image_option( self.image, default_height=self.height ) if hasattr(self, "onpress"): self.onpress = resolve_onpress_option(self.onpress)
def __init__(self, options): """ This section is an area below the description (if present). In this section you can create a list of items with an icon, a title, and onpress action :param options: (dict) the key/value pairs from this section of the card's config toml """ self.items = [] # apply user config dict for key, value in options.get("list", {}).items(): setattr(self, key, value) if not hasattr(self, "alignment"): self.alignment = "left" for item in self.items: if item.get("icon"): item["icon"] = resolve_image_option(item["icon"], default_height="24px") if item.get("onpress"): item["onpress"] = resolve_onpress_option(item["onpress"])