# -*- coding: utf-8 -*- """Main user interface the viewport """ import plugin_dbui as dbui from event import Event from gluon import current from gluon.html import URL from ui_selector import SelectorUi Node = dbui.Node Panel = dbui.Panel to_grid = dbui.to_gridPanel class ViewportUi(object): @staticmethod def configure(db, T, virtdb): """Configure the viewport. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator virtdb (pyDAL.DAL): virtual database with the definiton of selectors """ selector_list = SelectorUi.selector_list(virtdb, db, T) selector_metric2d = SelectorUi.selector_metric2d(virtdb, db, T) selector_source = SelectorUi.selector_source(virtdb, db, T) nodes = [ ViewportUi.help_node(db, T), ViewportUi.app_node(db, T), ViewportUi.event_node(db, T), ViewportUi.meta_node(db, T), ViewportUi.people_object_node(db, T), ViewportUi.configure_node(db, T), ViewportUi.source_node(db, T, selector_source), ViewportUi.list_node(db, T, selector_list), ViewportUi.metric2d_node(db, T, selector_metric2d)] modifier = dbui.ViewportModifier() modifier.add_node(*nodes) modifier.configure(tabTitleTpl="{1}") if current.session.auth: modifier.configure(logged=True, plugins=["pViewportLogin"]) modifier.default_node(T("Events"), T("history")) @staticmethod def app_node(db, T): """To deal with authentication and preferences. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: dbui.Node: the configuration of a tree node. """ node = None if "auth" in current.globalenv: node = Node(T("Application")) add_child = node.add_child add_child(T("users"), to_grid(db.auth_user)) add_child(T("groups"), to_grid(db.auth_group)) add_child(T("relation user / groups"), to_grid(db.auth_membership)) return node @staticmethod def help_node(db, T): """To deal with documentation and version. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: dbui.Node: the configuration of a tree node. """ loader = dict(autoLoad=True, renderer="html", url=URL("plugin_dbui", "about")) about_panel = Panel(loader=loader, autoScroll=True) loader = dict(autoLoad=True, renderer="html", url=URL("plugin_dbui", "documentations_list")) doc_panel = Panel(loader=loader, plugins=["pPanelLoaderException"]) loader = dict(autoLoad=True, renderer="html", scripts=True, url=URL("plugin_dbui", "versions")) version_panel = Panel(loader=loader, plugins=["pPanelLoaderException"]) node = Node(T("Help")) # NOTE # Immediate translation is required by node.short_children add_child = node.add_child add_child(T("about", lazy=False), about_panel) add_child(T("documentations", lazy=False), doc_panel) add_child(T("versions", lazy=False), version_panel) node.sort_children() return node @staticmethod def configure_node(db, T): """To configure lists and metrics. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("Configure lists and metrics")) add_child = node.add_child add_child(T("the lists"), to_grid(db.lists2)) add_child(T("the metrics 2d"), to_grid(db.metrics2d2)) return node @staticmethod def event_node(db, T): """To deal with event. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("Events")) add_child = node.add_child add_child(T("definitions"), to_grid(db.events)) add_child(T("history"), to_grid(db.history)) return node @staticmethod def meta_node(db, T): """To deal with meta data. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("Metadata")) # NOTE # Immediate translation is required by node.short_children add_child = node.add_child add_child(T("domains", lazy=False), to_grid(db.domains)) add_child(T("fundings", lazy=False), to_grid(db.fundings)) add_child(T("teams", lazy=False), to_grid(db.teams)) add_child(T("projects", lazy=False), to_grid(db.projects)) node.sort_children() return node @staticmethod def list_node(db, T, selector_panel): """To deal with lists. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator selector_panel (gluon.storage.Storage): configuration of the selector panel. Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("The lists")) add_child = node.add_child for row in db(db.lists2.id > 0).select(orderby=db.lists2.name): panel = selector_panel panel.baseUrl = URL("plugin_event", "grid") panel.baseParams = {"id_list": row.id} add_child(row.name, panel) return node @staticmethod def metric2d_node(db, T, selector_panel): """To deal with two-dimension metrics. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator selector_panel (gluon.storage.Storage): configuration of the selector panel. Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("The metrics 2d")) add_child = node.add_child for row in db(db.metrics2d2.id > 0).select(orderby=db.metrics2d2.name): panel = selector_panel panel.baseUrl = URL("plugin_event", "metric2d") panel.baseParams = {"id_metric2d": row.id} add_child(row.name, panel) return node @staticmethod def people_object_node(db, T): """To deal with people and objects. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("People and objects")) # NOTE # Immediate translation is required by node.short_children add_child = node.add_child add_child(T("people", lazy=False), to_grid(db.people)) add_child(T("people_categories", lazy=False), to_grid(db.people_categories)) add_child(T("objects", lazy=False), to_grid(db.objects)) add_child(T("object_categories", lazy=False), to_grid(db.object_categories)) node.sort_children() return node @staticmethod def source_node(db, T, selector_panel): """To deal with sources. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator selector_panel (gluon.storage.Storage): configuration of the selector panel. Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("The sources")) add_child = node.add_child for source in sorted(Event.get_sources()): panel = selector_panel panel.baseUrl = URL("plugin_event", "source") panel.baseParams = {"source": source} add_child(source, panel) return node