# -*- coding: utf-8 -*- """User Interface for selectors """ from gluon.html import URL from gluon.storage import Storage from plugin_dbui import (FieldsModifier, FieldSet, map_tabpanel, PanelWithUrlSelector, to_fields) class SelectorUi(object): @staticmethod def configure(virtdb, db, T): """Configure the user interface for selectors. Args: virtdb (pyDAL.DAL): connection to the virtual database db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator """ SelectorUi.selector_list(virtdb, db, T) SelectorUi.selector_metric2d(virtdb, db, T) SelectorUi.selector_source(virtdb, db, T) @staticmethod def selector_list(virtdb, db, T): """UI for the selector table list Args: virtdb (pyDAL.DAL): connection to the virtual database db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: gluon.storage.Storage: the configuration of the PanelWithUrlSelector. """ # .................................................................... # # Fields # mdf = FieldsModifier("selector_list") mytype = "xcomboboxuserreset" text = T("select...") mdf.configure_field("id_categories", emptyText=text, xtype=mytype) mdf.configure_field("id_domains", emptyText=text, xtype=mytype) mdf.configure_field("id_fundings", emptyText=text, xtype=mytype) mdf.configure_field("id_objects", emptyText=text, xtype=mytype) # combobox for object categories li = [el.category for el in db(db.object_categories.id > 0).select()] categories = sorted(set(li)) mdf.configure_field("object_categories_category", allowBlank=True, emptyText=T("select..."), store=categories, xtype="combobox") # to have an unique key use xcomboboxmaster instead of userreset mdf.configure_field("id_object_code", emptyText=text, xtype=mytype) mdf.configure_field("id_people", emptyText=text, xtype=mytype) # combobox for people categories li = [el.category for el in db(db.people_categories.id > 0).select()] categories = sorted(set(li)) mdf.configure_field("people_categories_category", allowBlank=True, emptyText=T("select..."), store=categories, xtype="combobox") # to have an unique key use xcomboboxmaster instead of userreset mdf.configure_field("id_people_code", emptyText=text, xtype=mytype) mdf.configure_field("id_teams", emptyText=text, xtype=mytype) mdf.configure_field("id_projects", emptyText=text, xtype=mytype) mdf.configure_field("query", hideLabel=True, emptyText="variable are column names while " "operators are in, not in, and, or, " "&, |, ...") # .................................................................... # # PanelWithUrlSelector # - configure it once since it is used many times (lists, ...) # - organise the field in tabs # - Use an accordion layout for the first tab # # SELECT TAB ......................................................... # # map between field name and field configuration # keys are the field name or field label for merge fields mapfields = Storage() for cfgfield in to_fields(virtdb.selector_list): key = (cfgfield.name if cfgfield.name else cfgfield.fieldLabel) mapfields[key] = cfgfield # Organise fields within different panels # and replace field name by their configuration items = [ { "title": T("Period"), "collapsible": True, "items": [mapfields["Selector_listYear_start"], mapfields["Selector_listYear_end"]], "xtype": "fieldset" }, { "title": T("Metadata"), "collapsible": True, "items": [mapfields["Selector_listId_domains"], mapfields["Selector_listId_teams"], mapfields["Selector_listId_projects"]], "xtype": "fieldset" }, { "title": T("People"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_listId_people"], mapfields["Selector_listPeople_categories_category"], mapfields["Selector_listId_people_code"]], "xtype": "fieldset" }, { "title": T("Object"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_listId_objects"], mapfields["Selector_listId_object_categories"], mapfields["Selector_listId_object_code"]], "xtype": "fieldset" }, { "title": T("Fundings"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_listId_fundings"]], "xtype": "fieldset" }, { "title": T("Query"), "collapsible": True, "collapsed": False, "items": [mapfields["Selector_listQuery"]], "xtype": "fieldset" } ] # wrap fields within a FieldSet fieldset1 = FieldSet( defaults=dict(frame=True, layout="form"), items=items, layout="anchor", plugins=["pFormToolTip"], title=T("Select")) # configure the PanelWithUrlSelector selector_panel = PanelWithUrlSelector( baseUrl=URL("report", "grid"), selectorItems=map_tabpanel([fieldset1])) return selector_panel @staticmethod def selector_metric2d(virtdb, db, T): """UI for the selector table metric2d Args: virtdb (pyDAL.DAL): connection to the virtual database db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: gluon.storage.Storage: the configuration of the PanelWithUrlSelector. """ # .................................................................... # # Fields # mdf = FieldsModifier("selector_metric2d") mytype = "xcomboboxuserreset" text = T("select...") mdf.configure_field("id_categories", emptyText=text, xtype=mytype) mdf.configure_field("id_domains", emptyText=text, xtype=mytype) mdf.configure_field("id_fundings", emptyText=text, xtype=mytype) mdf.configure_field("id_objects", emptyText=text, xtype=mytype) # combobox for object categories li = [el.category for el in db(db.object_categories.id > 0).select()] categories = sorted(set(li)) mdf.configure_field("object_categories_category", allowBlank=True, emptyText=T("select..."), store=categories, xtype="combobox") # to have an unique key use xcomboboxmaster instead of userreset mdf.configure_field("id_object_code", emptyText=text, xtype=mytype) mdf.configure_field("id_people", emptyText=text, xtype=mytype) # combobox for people categories li = [el.category for el in db(db.people_categories.id > 0).select()] categories = sorted(set(li)) mdf.configure_field("people_categories_category", allowBlank=True, emptyText=T("select..."), store=categories, xtype="combobox") # to have an unique key use xcomboboxmaster instead of userreset mdf.configure_field("id_people_code", emptyText=text, xtype=mytype) mdf.configure_field("id_teams", emptyText=text, xtype=mytype) mdf.configure_field("id_projects", emptyText=text, xtype=mytype) mdf.configure_field("query", hideLabel=True, emptyText="variable are column names while " "operators are in, not in, and, or, " "&, |, ...") mdf.configure_field("summary_x", hideLabel=True, xtype="xsummaryfield") mdf.configure_field("summary_y", hideLabel=True, xtype="xsummaryfield") mdf.configure_field("graph", hideLabel=True, xtype="xgraphfield") # .................................................................... # # PanelWithUrlSelector # - configure it once since it is used many times (lists, ...) # - organise the field in tabs # - Use an accordion layout for the first tab # # SELECT TAB ......................................................... # # map between field name and field configuration # keys are the field name or field label for merge fields mapfields = Storage() for cfgfield in to_fields(virtdb.selector_metric2d): key = (cfgfield.name if cfgfield.name else cfgfield.fieldLabel) mapfields[key] = cfgfield # Organise fields within different panels # and replace field name by their configuration items = [ { "title": T("Period"), "collapsible": True, "items": [mapfields["Selector_metric2dYear_start"], mapfields["Selector_metric2dYear_end"]], "xtype": "fieldset" }, { "title": T("Metadata"), "collapsible": True, "items": [mapfields["Selector_metric2dId_domains"], mapfields["Selector_metric2dId_teams"], mapfields["Selector_metric2dId_projects"]], "xtype": "fieldset" }, { "title": T("People"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_metric2dId_people"], mapfields["Selector_metric2dPeople_categories_category"], mapfields["Selector_metric2dId_people_code"]], "xtype": "fieldset" }, { "title": T("Object"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_metric2dId_objects"], mapfields["Selector_metric2dId_object_categories"], mapfields["Selector_metric2dId_object_code"]], "xtype": "fieldset" }, { "title": T("Fundings"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_metric2dId_fundings"]], "xtype": "fieldset" }, { "title": T("Query"), "collapsible": True, "collapsed": False, "items": [mapfields["Selector_metric2dQuery"]], "xtype": "fieldset" } ] # wrap fields within a FieldSet fieldset1 = FieldSet( defaults=dict(frame=True, layout="form"), items=items, layout="anchor", plugins=["pFormToolTip"], title=T("Select")) # SUMMARY TAB ........................................................ items = [ { "checkbox": { "name": "Selector_metric2dIs_summary_x" }, "checkboxToggle": True, "collapsed": True, "items": mapfields["Selector_metric2dSummary_x"], "title": "summary per row", "xtype": "fieldset" }, { "checkbox": { "name": "Selector_metric2dIs_summary_y" }, "checkboxToggle": True, "collapsed": True, "items": mapfields["Selector_metric2dSummary_y"], "title": "summary per column", "xtype": "fieldset" } ] fieldset2 = FieldSet( defaults=dict(frame=True), items=items, layout="anchor", plugins=["pFormToolTip"], title=T("Metric2D")) # GRAPH TAB .......................................................... items = [ { "checkbox": { "name": "Selector_metric2dIs_graph" }, "checkboxToggle": True, "collapsed": True, "items": [mapfields["Selector_metric2dGraph"]], "title": "tune graph", "xtype": "fieldset" } ] fieldset3 = FieldSet( defaults=dict(frame=True), items=items, layout="anchor", plugins=["pFormToolTip"], title=T("Graph")) # configure the PanelWithUrlSelector selector_panel = PanelWithUrlSelector( baseUrl=URL("report", "grid"), selectorItems=map_tabpanel([fieldset1, fieldset2, fieldset3])) return selector_panel @staticmethod def selector_source(virtdb, db, T): """UI for the selector table source Args: virtdb (pyDAL.DAL): connection to the virtual database db (pyDAL.DAL): database connection T (gluon.languages.translator): language translator Returns: gluon.storage.Storage: the configuration of the PanelWithUrlSelector. """ # .................................................................... # # Fields # mdf = FieldsModifier("selector_source") mytype = "xcomboboxuserreset" text = T("select...") mdf.configure_field("id_categories", emptyText=text, xtype=mytype) mdf.configure_field("id_domains", emptyText=text, xtype=mytype) mdf.configure_field("id_events", emptyText=text, xtype=mytype) mdf.configure_field("id_fundings", emptyText=text, xtype=mytype) mdf.configure_field("id_objects", emptyText=text, xtype=mytype) # combobox for object categories li = [el.category for el in db(db.object_categories.id > 0).select()] categories = sorted(set(li)) mdf.configure_field("object_categories_category", allowBlank=True, emptyText=T("select..."), store=categories, xtype="combobox") # to have an unique key use xcomboboxmaster instead of userreset mdf.configure_field("id_object_code", emptyText=text, xtype=mytype) mdf.configure_field("id_people", emptyText=text, xtype=mytype) # combobox for people categories li = [el.category for el in db(db.people_categories.id > 0).select()] categories = sorted(set(li)) mdf.configure_field("people_categories_category", allowBlank=True, emptyText=T("select..."), store=categories, xtype="combobox") # to have an unique key use xcomboboxmaster instead of userreset mdf.configure_field("id_people_code", emptyText=text, xtype=mytype) mdf.configure_field("id_teams", emptyText=text, xtype=mytype) mdf.configure_field("id_projects", emptyText=text, xtype=mytype) mdf.configure_field("query", hideLabel=True, emptyText="variable are column names while " "operators are in, not in, and, or, " "&, |, ...") # .................................................................... # # PanelWithUrlSelector # - configure it once since it is used many times (lists, ...) # - organise the field in tabs # - Use an accordion layout for the first tab # # SELECT TAB ......................................................... # # map between field name and field configuration # keys are the field name or field label for merge fields mapfields = Storage() for cfgfield in to_fields(virtdb.selector_source): key = (cfgfield.name if cfgfield.name else cfgfield.fieldLabel) mapfields[key] = cfgfield # Organise fields within different panels # and replace field name by their configuration items = [ { "title": T("Period"), "collapsible": True, "items": [mapfields["Selector_sourceYear_start"], mapfields["Selector_sourceYear_end"]], "xtype": "fieldset" }, { "title": T("Metadata"), "collapsible": True, "items": [mapfields["Selector_sourceId_events"], mapfields["Selector_sourceId_domains"], mapfields["Selector_sourceId_teams"], mapfields["Selector_sourceId_projects"]], "xtype": "fieldset" }, { "title": T("People"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_sourceId_people"], mapfields["Selector_sourcePeople_categories_category"], mapfields["Selector_sourceId_people_code"]], "xtype": "fieldset" }, { "title": T("Object"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_sourceId_objects"], mapfields["Selector_sourceId_object_categories"], mapfields["Selector_sourceId_object_code"]], "xtype": "fieldset" }, { "title": T("Fundings"), "collapsible": True, "collapsed": True, "items": [mapfields["Selector_sourceId_fundings"]], "xtype": "fieldset" }, { "title": T("Query"), "collapsible": True, "collapsed": False, "items": [mapfields["Selector_sourceQuery"]], "xtype": "fieldset" } ] # wrap fields within a FieldSet fieldset1 = FieldSet( defaults=dict(frame=True, layout="form"), items=items, layout="anchor", plugins=["pFormToolTip"], title=T("Select")) # configure the PanelWithUrlSelector selector_panel = PanelWithUrlSelector( baseUrl=URL("report", "grid"), selectorItems=map_tabpanel([fieldset1])) return selector_panel