Commit 35799c60 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the modules/ui_viewport.py.

parent ecd4de91
......@@ -21,7 +21,6 @@ from _mydb import DBURIS
from auth import configure_auth, USER
from gluon import current
from gluon.tools import PluginManager
from model_app import App
from model_core import Core
from model_harvester import Harvester
......@@ -31,6 +30,15 @@ from plugin_dbui import (configure_forms,
configure_grids,
Dbui)
from ui_app import AppUI
from ui_auth import AuthUI
from ui_core import CoreUI
from ui_harvester import HarvesterUI
from ui_report import ReportUI
from ui_selector import SelectorUI
from ui_viewport import ViewportUi
# ............................................................................
#
# Connection to databases
......@@ -79,14 +87,6 @@ Dbui.define_paths(
app_libmin="static/limbra-min.js",
app_script="static/app.js")
# ............................................................................
#
# Constants
#
ONE_HOUR = 3600000
# ............................................................................
#
# Create the database models
......@@ -134,9 +134,25 @@ tables = ["application",
if session.role == USER:
tables.remove("categories")
configure_forms(tables, plugins=["pFormToolTip"], width=350)
configure_forms(
tables,
plugins=["pFormToolTip"],
width=350)
configure_grids(tables, plugins=["pGridRowEditorConfirmDelete",
configure_grids(
tables,
plugins=["pGridRowEditorConfirmDelete",
"pGridRowEditorContextMenu",
"pGridRowEditorDblClick",
"pGridToolbar"])
AppUI.configure(db, T)
AuthUI.configure(db, T)
CoreUI.configure(db, T)
HarvesterUI.configure(db, T)
ReportUI.configure(db, T)
SelectorUI.configure(virtdb, db, T)
ViewportUi.configure(db, T, virtdb)
# -*- coding: utf-8 -*-
""" widgets viewport
"""
# helper function translating a tablename into the grid configuration
to_grid = lambda tablename: dbui.to_gridPanel(db[tablename])
# short cuts
Node = dbui.Node
Panel = dbui.Panel
PanelWithUrlSelector = dbui.to_panelWithUrlSelector
Window = dbui.Window
#-------------------------------------------------------------------------------
#
# APPLICATION
#
#-------------------------------------------------------------------------------
appNode = None
if session.role == ADMIN:
appNode = Node(T('Application'))
prefLeaf = Window(closable=True,
items=[cfgPreferences],
layout='fit',
modal=True,
title=T('Preferences'))
appNode.add_child(T('preferences'), prefLeaf)
if "auth" in globals():
appNode.add_child(T('users'), to_grid('auth_user'))
appNode.add_child(T('groups'), to_grid('auth_group'))
appNode.add_child(T('relation user / groups'), to_grid('auth_membership'))
#-------------------------------------------------------------------------------
#
# CONFIGURE HARVESTERS
#
#-------------------------------------------------------------------------------
confHarvesterNode = None
if session.role in (ADMIN, USER):
confHarvesterNode = Node(T('Configure harvesters'))
confHarvesterNode.add_child(T('harvesters'), to_grid('harvesters'))
confHarvesterNode.add_child(T('relation harvesters / categories'), to_grid('controllers'))
confHarvesterNode.add_child(T("author's rescue list"), to_grid('my_authors'))
#-------------------------------------------------------------------------------
#
# CONFIGURE LISTS
#
#-------------------------------------------------------------------------------
confListNode = None
if session.role == ADMIN:
confListNode = Node(T('Configure lists'))
# NOTE: hide axes table which contains static data
# confListNode.add_child('axes', to_grid('axes'))
confListNode.add_child(T('renderers'), to_grid('renderers'))
confListNode.add_child(T('sections'), to_grid('sections'))
confListNode.add_child(T('lists'), to_grid('lists'))
#-------------------------------------------------------------------------------
#
# CONFIGURE METRICs
#
#-------------------------------------------------------------------------------
confMetricNode = None
if session.role == ADMIN:
confMetricNode = Node(T('Configure graphs and metrics'))
confMetricNode.add_child(T('graphs'), to_grid('graphs'))
confMetricNode.add_child(T('metrics'), to_grid('metrics'))
#-------------------------------------------------------------------------------
#
# DATA INSTITUT
#
#-------------------------------------------------------------------------------
dataInstituteNode = None
if session.role == ADMIN:
leaves = ('affiliation_keys', 'projects', 'teams')
dataInstituteNode = Node(T('Data institute'))
dataInstituteNode.add_children(leaves, func=to_grid)
dataInstituteNode.add_child(T('Relation team / projects'), to_grid('organisation'))
#-------------------------------------------------------------------------------
#
# DATA PUBLICATIONS
#
#-------------------------------------------------------------------------------
dataPublicationeNode = None
if session.role in (ADMIN, USER):
leaves = ('categories',
'collaborations',
'countries',
'publications',
'publishers',
'status')
if session.role == USER:
leaves = ('categories',
'publications')
dataPublicationeNode = Node(T('Data publications'))
dataPublicationeNode.add_children(leaves, func=to_grid)
#-------------------------------------------------------------------------------
#
# HARVESTER NODE
#
#-------------------------------------------------------------------------------
harvestNode = None
if session.role in (ADMIN, USER):
freeLeaf = PanelWithUrlSelector(virtdb.free_harvester_selector,
baseUrl=URL('harvest', 'free_run'),
selectorTitle='Fill all fields',
timeout=ONE_HOUR)
harvesterLeaf = PanelWithUrlSelector(virtdb.harvester_selector,
baseUrl=URL('harvest', 'run'),
extField='format',
timeout=ONE_HOUR)
runAllLeaf = PanelWithUrlSelector(virtdb.run_all_harvesters_selector,
baseUrl=URL('harvest', 'run_all'),
extField='format',
timeout=ONE_HOUR)
harvestNode = Node(T('Harvest'))
harvestNode.add_child(T('run a free harvester'), freeLeaf)
harvestNode.add_child(T('run a harvester'), harvesterLeaf)
harvestNode.add_child(T('run all harvesters'), runAllLeaf)
harvestNode.sort_children()
#-------------------------------------------------------------------------------
#
# HELP NODE
#
#-------------------------------------------------------------------------------
loader = dict(autoLoad=True,
renderer='html',
scripts=False,
url=URL('plugin_dbui', 'about'))
aboutLeaf = Panel(loader=loader, autoScroll=True)
loader = dict(autoLoad=True,
renderer='html',
scripts=True,
url=URL('plugin_dbui', 'documentations_table'))
docLeaf = Panel(loader=loader, plugins=['pPanelLoaderException'], autoScroll=True)
loader = dict(autoLoad=True,
renderer='html',
scripts=True,
url=URL('default', 'guides'))
guidesLeaf = Panel(loader=loader, plugins=['pPanelLoaderException'], autoScroll=True)
loader = dict(autoLoad=True,
renderer='html',
scripts=True,
url=URL('plugin_dbui', 'versions'))
versionLeaf = Panel(loader=loader, plugins=['pPanelLoaderException'])
helpNode = Node(T('Help'))
helpNode.add_child(T('about'), aboutLeaf)
helpNode.add_child(T('guides'), guidesLeaf)
helpNode.add_child(T('versions'), versionLeaf)
if session.role == ADMIN:
helpNode.add_child(T('documentations'), docLeaf)
helpNode.sort_children()
#-------------------------------------------------------------------------------
#
# REPORT NODE
#
#-------------------------------------------------------------------------------
loader = dict(autoLoad=True,
renderer='html',
scripts=True,
url=URL('graphs', 'dashboard'))
dashBoardLeaf = Panel(loader=loader,
plugins=['pPanelLoaderException'],
autoScroll=True)
graphLeaf = PanelWithUrlSelector(virtdb.graph_selector,
baseUrl=URL('graphs', 'index'),
extField='format')
listLeaf = PanelWithUrlSelector(virtdb.list_selector,
baseUrl=URL('lists', 'index'),
extField='format',
plugins=['pMathJax'])
metricLeaf = PanelWithUrlSelector(virtdb.metric_selector,
baseUrl=URL('metrics', 'index'),
extField='format')
reportNode = Node(T('Reports'))
reportNode.add_child(T('dashboard'), dashBoardLeaf)
reportNode.add_child(T('lists'), listLeaf)
reportNode.add_child(T('metrics'), metricLeaf)
reportNode.add_child(T('graphs'), graphLeaf)
#-------------------------------------------------------------------------------
#
# WIZARD NODE
#
#-------------------------------------------------------------------------------
wizardNode = None
if session.role in (ADMIN, USER):
authorLeaf = PanelWithUrlSelector(virtdb.authors_selector,
baseUrl=URL('wizards', 'extract_authors'))
checkLeaf = PanelWithUrlSelector(virtdb.check_selector,
baseUrl=URL('wizards', 'check_validate'),
extField='format',
timeout=ONE_HOUR)
editLeaf = PanelWithUrlSelector(virtdb.edit_insert_selector,
baseUrl=URL('harvest', 'edit_insert'),
selectorTitle='Fill all fields')
marc12Leaf = PanelWithUrlSelector(virtdb.marc12_selector,
selectorTitle='Fill all fields',
baseUrl=URL('harvest', 'insert_marcxml'))
wizardNode = Node(T('Wizards'))
wizardNode.add_child(T('extract authors'), authorLeaf)
if session.role == ADMIN:
wizardNode.add_child(T('check and validate'), checkLeaf)
else:
wizardNode.add_child(T('check'), checkLeaf)
wizardNode.add_child(T('edit and insert'), editLeaf)
wizardNode.add_child(T('insert MARCXML'), marc12Leaf)
wizardNode.sort_children()
#-------------------------------------------------------------------------------
#
# VIEWPORT
#
#-------------------------------------------------------------------------------
nodes = [helpNode,
appNode,
wizardNode,
confHarvesterNode,
confListNode,
confMetricNode,
dataInstituteNode,
dataPublicationeNode,
harvestNode,
reportNode]
viewportModifier = dbui.ViewportModifier()
viewportModifier.add_node(*nodes)
viewportModifier.configure(tabTitleTpl="{1}")
# NOTE the session.auth only exit when the user is logged
if "auth" in globals():
viewportModifier.configure(logged=False,
plugins=['pViewportLogin'])
if session.role in (ADMIN, USER):
viewportModifier.configure(logged=True)
viewportModifier.default_node(T('Data publications'), T('publications'))
else:
viewportModifier.default_node(T('Reports'), T('dashboard'))
# -*- 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,
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
"""
nodes = [
ViewportUi.help_node(db, T),
ViewportUi.app_node(db, T),
ViewportUi.wizard_node(db, T, virtdb),
ViewportUi.configure_harvester_node(db, T),
ViewportUi.configure_list_node(db, T),
ViewportUi.configure_metric_node(db, T),
ViewportUi.data_institute_node(db, T),
ViewportUi.data_publication_node(db, T),
ViewportUi.harvester_node(db, T, 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"])
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):
"""To deal with preferences for the application.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
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):
"""To configure harvesters.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
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):
"""To configure list.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
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):
"""To configure metrics.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
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):
"""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.
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):
"""To define data for publications.
Args:
db (pyDAL.DAL): database connection
T (gluon.languages.translator): language translator
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, virtdb):
"""To run harvester.
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.
"""