# -*- coding: utf-8 -*- """Main user interface the viewport """ from auth import ADMIN, USER from gluon import current from gluon.html import URL from plugin_dbui import (Node, Panel, to_gridPanel, to_panelWithUrlSelector, ViewportModifier, Window) ONE_HOUR = 3600000 def to_grid(tablename): """helper function to translate a tablename into the grid configuration. Args: tablename (str) Return: dict """ return to_gridPanel(current.db[tablename]) 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 definition of selectors """ session = current.globalenv["session"] nodes = [ ViewportUi.help_node(db, T, session), ViewportUi.app_node(db, T, session), ViewportUi.wizard_node(db, T, session, virtdb), ViewportUi.configure_harvester_node(db, T, session), ViewportUi.configure_list_node(db, T, session), ViewportUi.configure_metric_node(db, T, session), ViewportUi.data_institute_node(db, T, session), ViewportUi.data_publication_node(db, T, session), ViewportUi.harvester_node(db, T, session, virtdb), ViewportUi.report_node(db, T, virtdb)] mdf = ViewportModifier() mdf.add_node(*nodes) mdf.configure(tabTitleTpl="{1}") # NOTE the session.auth only exit when the user is logged if current.auth is not None: mdf.configure(logged=False, plugins=["pViewportLogin"]) session = current.globalenv["session"] if session.role in (ADMIN, USER): mdf.configure(logged=True) mdf.default_node(T("Data publications"), T("publications")) else: mdf.default_node(T("Reports"), T("dashboard")) @staticmethod def app_node(db, T, session): """To deal with preferences for the application. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role == ADMIN: node = Node(T("Application")) add_child = node.add_child window = Window( closable=True, items=[current.app.cfgPreferences], layout="fit", modal=True, title=T("Preferences")) add_child(T("preferences"), window) if current.auth is not None: add_child(T("users"), to_grid("auth_user")) add_child(T("groups"), to_grid("auth_group")) add_child( T("relation user / groups"), to_grid("auth_membership")) return node @staticmethod def configure_harvester_node(db, T, session): """To configure harvesters. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role in (ADMIN, USER): node = Node(T("Configure harvesters")) add_child = node.add_child add_child(T("harvesters"), to_grid("harvesters")) add_child( T("relation harvesters / categories"), to_grid("controllers")) add_child(T("author's rescue list"), to_grid("my_authors")) return node @staticmethod def configure_list_node(db, T, session): """To configure list. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role == ADMIN: node = Node(T("Configure lists")) add_child = node.add_child # NOTE: hide axes table which contains static data # add_child("axes", to_grid("axes")) add_child(T("renderers"), to_grid("renderers")) add_child(T("sections"), to_grid("sections")) add_child(T("lists"), to_grid("lists")) return node @staticmethod def configure_metric_node(db, T, session): """To configure metrics. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role == ADMIN: node = Node(T("Configure graphs and metrics")) add_child = node.add_child add_child(T("graphs"), to_grid("graphs")) add_child(T("metrics"), to_grid("metrics")) return node @staticmethod def data_institute_node(db, T, session): """To define data for the institute, affiliation_keys, projects and teams. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator configuration of the selector panel. session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role == ADMIN: node = Node(T("Data institute")) leaves = ("affiliation_keys", "projects", "teams") node.add_children(leaves, func=to_grid) node.add_child( T("Relation team / projects"), to_grid("organisation")) return node @staticmethod def data_publication_node(db, T, session): """To define data for publications. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role in (ADMIN, USER): node = Node(T("Data publications")) leaves = ( "categories", "collaborations", "countries", "publications", "publishers", "status") if session.role == USER: leaves = ( "categories", "publications") node.add_children(leaves, func=to_grid) return node @staticmethod def harvester_node(db, T, session, virtdb): """To run harvester. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): virtdb (pyDAL.DAL): virtual database with the definition of selectors Returns: dbui.Node: the configuration of a tree node. """ node = None if session.role in (ADMIN, USER): node = Node(T("Harvest")) free_panel = to_panelWithUrlSelector( virtdb.free_harvester_selector, baseUrl=URL("harvest", "free_run"), selectorTitle="Fill all fields", timeout=ONE_HOUR) harvester_panel = to_panelWithUrlSelector( virtdb.harvester_selector, baseUrl=URL("harvest", "run"), extField="format", timeout=ONE_HOUR) run_all_panel = to_panelWithUrlSelector( virtdb.run_all_harvesters_selector, baseUrl=URL("harvest", "run_all"), extField="format", timeout=ONE_HOUR) add_child = node.add_child add_child(T("run a free harvester"), free_panel) add_child(T("run a harvester"), harvester_panel) add_child(T("run all harvesters"), run_all_panel) node.sort_children() return node @staticmethod def help_node(db, T, session): """To deal with documentation and version. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("Help")) 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_table")) doc_panel = Panel( loader=loader, plugins=["pPanelLoaderException"], autoScroll=True) loader = dict( autoLoad=True, renderer="html", scripts=True, url=URL("default", "guides")) guides_panel = Panel( loader=loader, plugins=["pPanelLoaderException"], autoScroll=True) loader = dict( autoLoad=True, renderer="html", scripts=True, url=URL("plugin_dbui", "versions")) version_panel = Panel(loader=loader, plugins=["pPanelLoaderException"]) # 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("guides", lazy=False), guides_panel) add_child(T("versions", lazy=False), version_panel) if session.role == ADMIN: node.add_child(T("documentations", lazy=False), doc_panel) node.sort_children() return node @staticmethod def report_node(db, T, virtdb): """To run report like lists or metrics. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator virtdb (pyDAL.DAL): virtual database with the definition of selectors Returns: dbui.Node: the configuration of a tree node. """ node = Node(T("Reports")) loader = dict( autoLoad=True, renderer="html", scripts=True, url=URL("graphs", "dashboard")) dashboard_panel = Panel( loader=loader, plugins=["pPanelLoaderException"], autoScroll=True) graph_panel = to_panelWithUrlSelector( virtdb.graph_selector, baseUrl=URL("graphs", "index"), extField="format") list_panel = to_panelWithUrlSelector( virtdb.list_selector, baseUrl=URL("lists", "index"), extField="format", plugins=["pMathJax"]) metric_panel = to_panelWithUrlSelector( virtdb.metric_selector, baseUrl=URL("metrics", "index"), extField="format") add_child = node.add_child add_child(T("dashboard"), dashboard_panel) add_child(T("lists"), list_panel) add_child(T("metrics"), metric_panel) add_child(T("graphs"), graph_panel) return node @staticmethod def wizard_node(db, T, session, virtdb): """To run wizards. Args: db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator session (gluon.storage.Storage): virtdb (pyDAL.DAL): virtual database with the definition of selectors Returns: dbui.Node: the configuration of a tree node. """ node = None session = current.globalenv["session"] if session.role in (ADMIN, USER): node = Node(T("Wizards")) author_panel = to_panelWithUrlSelector( virtdb.authors_selector, baseUrl=URL("wizards", "extract_authors")) check_panel = to_panelWithUrlSelector( virtdb.check_selector, baseUrl=URL("wizards", "check_validate"), extField="format", timeout=ONE_HOUR) edit_panel = to_panelWithUrlSelector( virtdb.edit_insert_selector, baseUrl=URL("harvest", "edit_insert"), selectorTitle="Fill all fields") marc12_panel = to_panelWithUrlSelector( virtdb.marc12_selector, selectorTitle="Fill all fields", baseUrl=URL("harvest", "insert_marcxml")) add_child = node.add_child add_child(T("extract authors"), author_panel) if session.role == ADMIN: add_child(T("check and validate"), check_panel) else: add_child(T("check"), check_panel) add_child(T("edit and insert"), edit_panel) add_child(T("insert MARCXML"), marc12_panel) node.sort_children() return node