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

Add the class Dbui to initialise the plugin_dbui.

parent d776c85e
......@@ -9,11 +9,13 @@
Author: R. Le Gac
"""
import json
import os
from gluon.tools import PluginManager
API = """
Dbui.csvUrl = '/%s/plugin_dbui/csv';
Dbui.config = %s;
......@@ -128,7 +130,7 @@ def dbui_conf():
# The only way to extract them is to scan the attributes list of
# the DAL since the method db.tables() or any variant return
# tables but not the alias one
config['stores'].update(plugins.dbui.static_stores)
config['stores'].update(PluginManager("dbui").dbui.static_stores)
for table in get_all_tables(db):
cfg = to_jsonstore(table)
config['stores'][cfg['storeId']] = cfg
......@@ -180,7 +182,7 @@ def debug():
"""
from plugin_dbui import get_file_paths, get_script_path
plugin = plugins.dbui
plugin = PluginManager("dbui").dbui
# css files
response.files.extend(get_file_paths(plugin.extjs_css, ext='.css'))
......@@ -225,7 +227,7 @@ def documentations():
"""
from plugin_dbui import get_reference_paths, Store
plugin = plugins.dbui
plugin = PluginManager("dbui").dbui
# alias
a = '<a href="%s" target="_blank">%s</a>'
......@@ -347,7 +349,7 @@ def index():
"""
from plugin_dbui import get_file_paths, get_script_path
plugin = plugins.dbui
plugin = PluginManager("dbui").dbui
# css files
response.files.extend(get_file_paths(plugin.extjs_css, ext='.css'))
......
......@@ -6,61 +6,60 @@ import plugin_dbui as dbui
from callbacks import country_delete, country_insert, country_update
from datetime import datetime
from gluon.tools import PluginManager
#-------------------------------------------------------------------------------
#.............................................................................
#
# PLUGIN DBUI
# LANGUAGE
#
#-------------------------------------------------------------------------------
plugins = PluginManager()
# plugins.dbui.app_css = None # relative path, i.e static/myapp.css or dir or list
# plugins.dbui.app_js = None # relative path static/src/my.js or dir or list
plugins.dbui.app_git = "https://gitlab.in2p3.fr/w2pext/%s.git" % request.application
# plugins.dbui.app_libmin = None # relative path static/myapp-min.js or dir or list
plugins.dbui.app_script = 'static/app.js' # relative path static/myapp.js
plugins.dbui.app_script_dir = 'static/scripts' # relative directory static/scripts
# plugins.dbui.dbui_libmin='static/plugin_dbui/dbui-debug.js'
T.set_current_languages("en", "en-gb", "en-us") # mother tongue
T.force("fr-fr") # user language
T.lazy = False # immediate translation
#-------------------------------------------------------------------------------
#.............................................................................
#
# LANGUAGE
# PLUGIN DBUI
#
#-------------------------------------------------------------------------------
T.set_current_languages('en', 'en-gb', 'en-us') # mother tongue
T.force('fr-fr') # user language
T.lazy = False # immediate translation
#-------------------------------------------------------------------------------
dbui.Dbui.initialise(
# app_css=None,
# app_js=None,
app_git="https://gitlab.in2p3.fr/w2pext/plugin_dbui.git",
# app_libmin=None,
app_script="static/app.js",
app_script_dir="static/scripts",
# dbui_libmin="static/plugin_dbui/dbui-debug.js"
)
#.............................................................................
#
# CONSTANTS
#
#-------------------------------------------------------------------------------
undef = T(dbui.UNDEF)
undef_id = dbui.UNDEF_ID
year = datetime.now().year
#-------------------------------------------------------------------------------
#.............................................................................
#
# COMMON CONFIGURATION FOR FORMS AND GRIDS
#
#-------------------------------------------------------------------------------
tables = ['categories',
'collaborations',
'countries',
'harvesters',
'new_fields',
'projects',
'publishers',
'publications',
'reports',
'teams']
dbui.configure_forms(tables, plugins=['pFormToolTip'],
tables = ["categories",
"collaborations",
"countries",
"harvesters",
"new_fields",
"projects",
"publishers",
"publications",
"reports",
"teams"]
dbui.configure_forms(tables, plugins=["pFormToolTip"],
width=300)
dbui.configure_grids(tables, plugins=['pGridRowEditorConfirmDelete',
'pGridRowEditorContextMenu',
'pGridRowEditorDblClick',
'pGridToolbar'])
\ No newline at end of file
dbui.configure_grids(tables, plugins=["pGridRowEditorConfirmDelete",
"pGridRowEditorContextMenu",
"pGridRowEditorDblClick",
"pGridToolbar"])
......@@ -8,66 +8,6 @@
import plugin_dbui as dbui
from gluon.storage import Storage
from gluon.tools import PluginManager
# NOTE:
# define default configuration parameters for the plugin,
# the application using it and the persistent storage used to tune the widgets.
# In most of the case configuration parameters are either a relative path
# to a file (static/myapp.css) or to a directory (static/css) except app_script
# and base_script which should point to a file.
#
# Default values for the plugin parameters
# All these parameters should be defined in the applications model.
# Applications value must be define in the application model
# Most of them can be either a relative path static/..., or a dir path
# or a list of paths
#
lg = dbui.get_language()
plugins = PluginManager('dbui',
app_css=None, # relative path static/myapp.css or dir or list
app_debug=None, # relative path static/src/my.js or dir or list
app_git=None,
app_lg=None, # relative path or dir or list
app_libmin=None, # relative path static/myapp-min.js or dir
app_script=None, # relative path static/myapp.js
app_script_dir=None, # relative directory static/scripts
dbui_conf=URL(c='plugin_dbui', f='dbui_conf'),
dbui_conf_debug=URL(c='plugin_dbui',
f='dbui_conf',
vars=dict(debug="")),
dbui_css=['static/plugin_dbui/resources/css/kde-oxygen.css',
'static/plugin_dbui/resources/css/dbui.css'],
dbui_debug='static/plugin_dbui/src/Dbui.js',
dbui_lg='static/plugin_dbui/locale/dbui-lang-%s.js' % lg,
dbui_libmin='static/plugin_dbui/dbui-min.js',
dbui_script='static/plugin_dbui/main.js',
ace_debug='static/plugin_ace/src-noconflict/ace.js',
ace_libmin='static/plugin_ace/src-min-noconflict/ace.js',
ace_css='static/plugin_ace/css/editor.css',
extjs_css='static/plugin_extjs/build/classic/theme-classic/resources/theme-classic-all.css',
extjs_debug=['static/plugin_extjs/build/ext-all-debug.js',
'static/plugin_extjs/build/classic/theme-classic/theme-classic-debug.js'],
extjs_libmin=['static/plugin_extjs/build/ext-all.js',
'static/plugin_extjs/build/classic/theme-classic/theme-classic.js'],
extjs_lg='static/plugin_extjs/build/classic/locale/locale-%s.js' % lg,
mathjax_libmin='static/plugin_mathjax/MathJax.js',
modifier_fields={},
modifier_forms={},
modifier_grids={},
modifier_stores={},
modifier_viewports=Storage(extjs={}),
static_stores={})
# Start common services
dbSvc = dbui.DbSvc()
......
......@@ -24,6 +24,7 @@ from converter import (to_field,
to_panelWithUrlSelector,
to_treeNodes,
to_viewport)
from dbui import Dbui
from dbsvc import CALLBACK_ERRORS, DbSvc
from directsvc import DBUI, DirectSvc
from extjs import (ArrayStore,
......
# -*- coding: utf-8 -*-
""" dbui
"""
import copy
from gluon.html import URL
from gluon.storage import Storage
from gluon.tools import PluginManager
from helper import get_language
defaults = Storage(
# application
app_css=None,
app_debug=None,
app_git=None,
app_lg=None,
app_libmin=None,
app_script=None,
app_script_dir=None,
# dbui library
dbui_conf=URL(c='plugin_dbui', f='dbui_conf'),
dbui_conf_debug=URL(c='plugin_dbui', f='dbui_conf', vars=dict(debug="")),
dbui_css=[
'static/plugin_dbui/resources/css/kde-oxygen.css',
'static/plugin_dbui/resources/css/dbui.css'],
dbui_debug='static/plugin_dbui/src/Dbui.js',
dbui_lg='static/plugin_dbui/locale/dbui-lang-%s.js',
dbui_libmin='static/plugin_dbui/dbui-min.js',
dbui_script='static/plugin_dbui/main.js',
# ACE library
ace_css='static/plugin_ace/css/editor.css',
ace_debug='static/plugin_ace/src-noconflict/ace.js',
ace_libmin='static/plugin_ace/src-min-noconflict/ace.js',
# EXT JS library
extjs_css='static/plugin_extjs/build/classic/theme-classic/resources/theme-classic-all.css',
extjs_debug=[
'static/plugin_extjs/build/ext-all-debug.js',
'static/plugin_extjs/build/classic/theme-classic/theme-classic-debug.js'],
extjs_libmin=[
'static/plugin_extjs/build/ext-all.js',
'static/plugin_extjs/build/classic/theme-classic/theme-classic.js'],
extjs_lg='static/plugin_extjs/build/classic/locale/locale-%s.js',
# MATHJAX library
mathjax_libmin='static/plugin_mathjax/MathJax.js')
class Dbui(object):
"""Set of tools to initialise the plugin Dbui.
"""
@staticmethod
def initialise(**kwargs):
"""Initialise the configuration of the the plugin dbui, namely paths
and a persistent storage.
Paths are relative to the main directory of the application.
They can target a file (static/myapp.css) or a directory (static/css).
The persistent storage contains the configuration of the widgets
used in the user interface.
Args:
app_css (str or list):
Relative path to CSS files for the application,
*e.g.* ``static/myapp/ressources/css``. Default is ``None``
app_debug (str or list):
Relative path to the debug version for the application library,
*e.g.* ``static/myapp/src`` or ``static/myapp/myapp-debug.js``.
Default is ``None``
app_git (str):
The URL of the git repository for the application,
*e.g.* https://gitlab.in2p3.fr/w2pext/plugin_dbui.git
Default is ``None``.
app_lg(str or list):
Relative path to languages files for the application,
*e.g.* static/myapp/locale/myapp-lang-fr.js.
Default is ``None``.
app_libmin (str or list):
Relative path to the minified version for the application
library, *e.g.* static/myapp-min.js.
app_script (str):
Relative path to the main script to run the application,
*e.g.* static/myapp.js
app_script_dir (str):
Relative path to a directory containing a collection
of JavaScript, *e.g* static/scripts.
The script named *foo* can be run via the URL:
``https://myverver/myapp?script=foo``. The default is ``None``.
dbui_conf (str):
The ULR returning the configuration for the User Interface.
The default is ``URL(c='plugin_dbui', f='dbui_conf')``,
dbui_conf_debug (str):
The URL returning the debug version of the configuration for
the User Interface. The default is
``URL(c='plugin_dbui', f='dbui_conf', vars=dict(debug=""))``.
dbui_css (str or list):
Relative path to CSS files for the dbui library:
``static/plugin_dbui/resources/css``.
dbui_debug (str of list)
Relative path to the debug version of the dbui library:
``static/plugin_dbui/dbui-debug.js``.
dbui_lg (str or list):
Relative path to languages files for the dbui library:
``static/plugin_dbui/locale/dbui-lang-fr.js``.
dbui_libmin (str of list):
Relative path to the minified version of the dbui library:
``static/plugin_dbui/dbui-min.js``
dbui_script (str):
Default script to run the application:
``static/plugin_dbui/main.js``. It is recommended to use
the option ``app_script``.
ace_css (str of list):
Relative path to the CSS file for the ACE library:
``static/plugin_ace/css/editor.css``,
ace_debug (str of list):
Relative path to the debug version of the ACE library:
``static/plugin_ace/src-noconflict/ace.js``.
ace_libmin (str of list):
Relative path to the minified version of the ACE library:
``static/plugin_ace/src-min-noconflict/ace.js``.
extjs_css (str of list):
Relative path to the CSS files for the Ext JS library.
extjs_debug (str of list):
Relative path to the debug version of the Ext JS library.
extjs_libmin (str of list):
Relative path to the minified version of the Ext JS library.
extjs_lg (str of list):
Relative path to the language files for the Ext JS library.
mathjax_libmin (str of list):
Relative path to the minified version of the MathJax library:
``static/plugin_mathjax/MathJax.js``.
Returns:
gluons.storage.Storage:
the configuration parameters for the plugin dbui.
The configuration is persistent across the application.
It can be accessed at any time using the syntax::
from gluon.tools import PluginManager
PluginManager("dbui").dbui
"""
plugin = PluginManager("dbui").dbui
# apply default values
plugin.update(copy.deepcopy(defaults))
plugin.update(kwargs)
# update values depending on language
lg = get_language()
plugin.dbui_lg = plugin.dbui_lg % lg
plugin.extjs_lg = plugin.extjs_lg % lg
# persistent storage for the UI (private)
plugin.modifier_fields={}
plugin.modifier_forms={}
plugin.modifier_grids={}
plugin.modifier_stores={}
plugin.modifier_viewports = Storage(extjs={})
plugin.static_stores={}
return plugin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment