Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit fdc7543a authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Create 3 selectors instead of one: list, metric2d and source.

parent ce049b2e
......@@ -2,27 +2,17 @@
"""plugin_event controllers
"""
import json
import traceback
import urllib
from gluon.storage import Storage
from plugin_dbui import Selector, Store
from plugin_event import (Event,
Graph,
from plugin_event import (Graph,
List,
Metric2D,
ReportException,
Source)
FIELD_TYPES = {"gridcolumn": "string",
"booleancolumn": "boolean",
"datecolumn": "date",
"numbercolumn": "float"}
def grid():
"""The list is rendered such as an ``Ext.grid.Panel`` widget.
Its context menu allows to export the content of the table as a CSV, LaTeX
......
......@@ -107,8 +107,6 @@ if ctrl == "plugin_dbui" and fnct in ("call", "dbui_conf"):
event.CoreUi.define(db, T)
event.ReportUi.define(db, T)
selector_panel = event.SelectorUi.selector(virtdb, db, T)
# configure the main viewport
if fnct == "dbui_conf":
event.ViewportUi.define(db, T, selector_panel)
event.ViewportUi.define(db, T, virtdb)
......@@ -27,11 +27,13 @@ class Selector(object):
T (gluon.languages.translator): language translator
"""
Selector.selector(virtdb, db, T)
Selector.selector_list(virtdb, db, T)
Selector.selector_metric2d(virtdb, db, T)
Selector.selector_source(virtdb, db, T)
@staticmethod
def selector(virtdb, db, T):
"""selector table.
def selector_list(virtdb, db, T):
"""selector table for list report.
Note:
selector table are store in a virtual database.
......@@ -48,7 +50,63 @@ class Selector(object):
year = datetime.now().year
table = virtdb.define_table(
"selector",
"selector_list",
Field("year_start", "integer", default=year, label="Start"),
Field("year_end", "integer", label="End"),
Field("id_domains", "reference domains", label="Domain"),
Field("id_teams", "reference teams", label="Team"),
Field("id_projects", "reference projects", label="Project"),
Field("id_fundings", "reference fundings", label=""),
Field("id_people", "reference people", label="Last name"),
Field("people_categories_category", "string", label="Category"),
Field("id_people_code",
"reference people_categories",
label="Quality"),
Field("id_objects", "reference objects", label="Reference"),
Field("object_categories_category", "string", label="Category"),
Field("id_object_code",
"reference object_categories",
label="Code"),
Field("query", "text"))
table.id_domains.requires = IS_IN_DB(db, "domains.domain")
table.id_fundings.requires = IS_IN_DB(db, "fundings.agency")
table.id_objects.requires = IS_IN_DB(db, "objects.reference")
table.id_object_code.requires = IS_IN_DB(db, "object_categories.code")
table.id_people.requires = IS_IN_DB(db, "people.last_name")
table.id_people_code.requires = IS_IN_DB(db, "people_categories.code")
table.id_projects.requires = IS_IN_DB(db, "projects.project")
table.id_teams.requires = IS_IN_DB(db, "teams.team")
return table
@staticmethod
def selector_metric2d(virtdb, db, T):
"""selector table for metric2d report.
Note:
selector table are store in a virtual database.
Args:
virtdb (pyDAL.DAL): connection to the virtual database
db (pyDAL.DAL): connection to the database of the application
T (gluon.languages.translator): language translator
Returns:
pyDAL.Table
"""
year = datetime.now().year
table = virtdb.define_table(
"selector_metric2d",
Field("year_start", "integer", default=year, label="Start"),
Field("year_end", "integer", label="End"),
Field("id_domains", "reference domains", label="Domain"),
......@@ -93,3 +151,61 @@ class Selector(object):
table.id_teams.requires = IS_IN_DB(db, "teams.team")
return table
@staticmethod
def selector_source(virtdb, db, T):
"""selector table for source report.
Note:
selector table are store in a virtual database.
Args:
virtdb (pyDAL.DAL): connection to the virtual database
db (pyDAL.DAL): connection to the database of the application
T (gluon.languages.translator): language translator
Returns:
pyDAL.Table
"""
year = datetime.now().year
table = virtdb.define_table(
"selector_source",
Field("year_start", "integer", default=year, label="Start"),
Field("year_end", "integer", label="End"),
Field("id_events", "reference events", label="Event"),
Field("id_domains", "reference domains", label="Domain"),
Field("id_teams", "reference teams", label="Team"),
Field("id_projects", "reference projects", label="Project"),
Field("id_fundings", "reference fundings", label=""),
Field("id_people", "reference people", label="Last name"),
Field("people_categories_category", "string", label="Category"),
Field("id_people_code",
"reference people_categories",
label="Quality"),
Field("id_objects", "reference objects", label="Reference"),
Field("object_categories_category", "string", label="Category"),
Field("id_object_code",
"reference object_categories",
label="Code"),
Field("query", "text"))
table.id_domains.requires = IS_IN_DB(db, "domains.domain")
table.id_events.requires = IS_IN_DB(db, "events.event")
table.id_fundings.requires = IS_IN_DB(db, "fundings.agency")
table.id_objects.requires = IS_IN_DB(db, "objects.reference")
table.id_object_code.requires = IS_IN_DB(db, "object_categories.code")
table.id_people.requires = IS_IN_DB(db, "people.last_name")
table.id_people_code.requires = IS_IN_DB(db, "people_categories.code")
table.id_projects.requires = IS_IN_DB(db, "projects.project")
table.id_teams.requires = IS_IN_DB(db, "teams.team")
return table
......@@ -62,15 +62,13 @@ class BaseReport(object):
* **grid** (*dict*): configuration of the ``Ext.grid.Panel`` widget
"""
def __init__(self, config=Storage(), source_name=None):
virtdb = current.globalenv["virtdb"]
def __init__(self, config=Storage(), selector=Storage(), source_name=None):
# ....................................................................
#
# Get the user selection criteria
#
self.selector = selector = Selector(virtdb.selector)
self.selector = selector
# ....................................................................
#
......@@ -431,7 +429,12 @@ class List(BaseReport):
def __init__(self, id_list):
db = current.globalenv["db"]
BaseReport.__init__(self, config=db.lists2[id_list])
virtdb = current.globalenv["virtdb"]
BaseReport.__init__(
self,
config=db.lists2[id_list],
selector=Selector(virtdb.selector_list))
# ....................................................................
#
......@@ -556,7 +559,12 @@ class Metric2D(BaseReport):
def __init__(self, id_report):
db = current.globalenv["db"]
BaseReport.__init__(self, config=db.metrics2d2[id_report])
virtdb = current.globalenv["virtdb"]
BaseReport.__init__(
self,
config=db.metrics2d2[id_report],
selector=Selector(virtdb.selector_metric2d))
self.is_summary = False
......@@ -762,7 +770,12 @@ class Source(BaseReport):
"""
def __init__(self, name):
BaseReport.__init__(self, source_name=name)
virtdb = current.globalenv["virtdb"]
BaseReport.__init__(
self,
source_name=name,
selector=Selector(virtdb.selector_source))
df = self.df
self.source_name = name
......
......@@ -25,11 +25,13 @@ class SelectorUi(object):
T (gluon.languages.translator): language translator
"""
SelectorUi.selector(virtdb, db, T)
SelectorUi.selector_list(virtdb, db, T)
SelectorUi.selector_metric2d(virtdb, db, T)
SelectorUi.selector_source(virtdb, db, T)
@staticmethod
def selector(virtdb, db, T):
"""UI for the selector table
def selector_list(virtdb, db, T):
"""UI for the selector table list
Args:
virtdb (pyDAL.DAL): connection to the virtual database
......@@ -45,7 +47,149 @@ class SelectorUi(object):
#
# Fields
#
mdf = fieldsModifier("selector")
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 dbui.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 = dbui.FieldSet(
defaults=dict(frame=True, layout="form"),
items=items,
layout="anchor",
plugins=["pFormToolTip"],
title=T("Select"))
# configure the PanelWithUrlSelector
selector_panel = dbui.PanelWithUrlSelector(
baseUrl=URL("report", "grid"),
selectorItems=dbui.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...")
......@@ -107,7 +251,7 @@ class SelectorUi(object):
# map between field name and field configuration
# keys are the field name or field label for merge fields
mapfields = Storage()
for cfgfield in dbui.to_fields(virtdb.selector):
for cfgfield in dbui.to_fields(virtdb.selector_metric2d):
key = (cfgfield.name if cfgfield.name else cfgfield.fieldLabel)
mapfields[key] = cfgfield
......@@ -117,43 +261,43 @@ class SelectorUi(object):
{
"title": T("Period"),
"collapsible": True,
"items": [mapfields["SelectorYear_start"],
mapfields["SelectorYear_end"]],
"items": [mapfields["Selector_metric2dYear_start"],
mapfields["Selector_metric2dYear_end"]],
"xtype": "fieldset"
}, {
"title": T("Metadata"),
"collapsible": True,
"items": [mapfields["SelectorId_domains"],
mapfields["SelectorId_teams"],
mapfields["SelectorId_projects"]],
"items": [mapfields["Selector_metric2dId_domains"],
mapfields["Selector_metric2dId_teams"],
mapfields["Selector_metric2dId_projects"]],
"xtype": "fieldset"
}, {
"title": T("People"),
"collapsible": True,
"collapsed": True,
"items": [mapfields["SelectorId_people"],
mapfields["SelectorPeople_categories_category"],
mapfields["SelectorId_people_code"]],
"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["SelectorId_objects"],
mapfields["SelectorId_object_categories"],
mapfields["SelectorId_object_code"]],
"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["SelectorId_fundings"]],
"items": [mapfields["Selector_metric2dId_fundings"]],
"xtype": "fieldset"
}, {
"title": T("Query"),
"collapsible": True,
"collapsed": False,
"items": [mapfields["SelectorQuery"]],
"items": [mapfields["Selector_metric2dQuery"]],
"xtype": "fieldset"
}
]
......@@ -170,20 +314,20 @@ class SelectorUi(object):
items = [
{
"checkbox": {
"name": "SelectorIs_summary_x"
"name": "Selector_metric2dIs_summary_x"
},
"checkboxToggle": True,
"collapsed": True,
"items": mapfields["SelectorSummary_x"],
"items": mapfields["Selector_metric2dSummary_x"],
"title": "summary per row",
"xtype": "fieldset"
}, {
"checkbox": {
"name": "SelectorIs_summary_y"
"name": "Selector_metric2dIs_summary_y"
},
"checkboxToggle": True,
"collapsed": True,
"items": mapfields["SelectorSummary_y"],
"items": mapfields["Selector_metric2dSummary_y"],
"title": "summary per column",
"xtype": "fieldset"
}
......@@ -200,11 +344,11 @@ class SelectorUi(object):
items = [
{
"checkbox": {
"name": "SelectorIs_graph"
"name": "Selector_metric2dIs_graph"
},
"checkboxToggle": True,
"collapsed": True,
"items": [mapfields["SelectorGraph"]],
"items": [mapfields["Selector_metric2dGraph"]],
"title": "tune graph",
"xtype": "fieldset"
}
......@@ -223,3 +367,147 @@ class SelectorUi(object):
selectorItems=dbui.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 dbui.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"