From 2be73df1f6fa5250fc781904f59dfec3b7709d09 Mon Sep 17 00:00:00 2001
From: Renaud Le Gac <legac@cppm.in2p3.fr>
Date: Sat, 22 Mar 2014 15:17:43 +0100
Subject: [PATCH] Add actions and views to display about, documentations and
 versions information.

---
 controllers/plugin_dbui.py                |  30 +++-
 languages/fr-fr.py                        |   8 +-
 models/plugin_dbui.py                     |   3 +-
 models/widgets_viewport.py                |  92 +++++++----
 modules/plugin_dbui/helper.py             |  15 +-
 static/ABOUT.html                         |   8 +
 static/plugin_dbui/TODO                   |   1 +
 static/plugin_dbui/resources/css/dbui.css |  62 ++++++++
 views/plugin_dbui/documentations.html     | 179 ++++++++++++++++++++++
 views/plugin_dbui/versions.html           |  14 ++
 10 files changed, 371 insertions(+), 41 deletions(-)
 create mode 100644 static/ABOUT.html
 create mode 100644 static/plugin_dbui/resources/css/dbui.css
 create mode 100644 views/plugin_dbui/documentations.html
 create mode 100644 views/plugin_dbui/versions.html

diff --git a/controllers/plugin_dbui.py b/controllers/plugin_dbui.py
index d367aa83..38f8cd2a 100644
--- a/controllers/plugin_dbui.py
+++ b/controllers/plugin_dbui.py
@@ -24,6 +24,14 @@ App.REMOTE_API = {
 };"""
 
 
+def about():
+    fn = os.path.join("applications", 
+                      request.application, 
+                      "static", 
+                      "ABOUT.html")
+    return open(fn, 'rb').read()
+
+
 def call():
     """Action to handle the Ext.Direct protocol.
     
@@ -191,6 +199,19 @@ def debug():
     return dict(plugin=plugin)
     
 
+def documentations():
+    di = {}
+    
+    di["app"] = request.application
+    di["app_name"] = request.application.replace('_', ' ')
+    di["epydoc_dbui"] = URL('static', 'plugin_dbui/docs/epydoc/index.html')
+    di["epydoc_application"] = URL('static', 'docs/epydoc/index.html')
+    di["jsduck_dbui"] = URL('static', 'plugin_dbui/docs/jsduck/index.html')
+    di["png_db"] = URL('static', 'docs/database.png')
+    
+    return di 
+
+
 def index():
     """Default Action to run the plugin
     Load compressed version of all libraries.
@@ -253,11 +274,4 @@ def versions():
     """Return the versions of the different part of the code.
     
     """
-    import plugin_dbui as dbui
-    
-    my_style = \
-    """
-        margin-left: 20px; 
-        font-size: 10px;
-    """
-    return BEAUTIFY(dbui.get_versions(), _style=my_style)
+    return dbui.get_versions()
diff --git a/languages/fr-fr.py b/languages/fr-fr.py
index 506ab8e8..e5fcf5c7 100644
--- a/languages/fr-fr.py
+++ b/languages/fr-fr.py
@@ -1,7 +1,8 @@
-# -*- coding: utf-8 -*-
+# coding: utf8
 {
 '%Y-%m-%d': '%Y-%m-%d',
 'Abbreviation': 'Abréviation',
+'about': 'à propos',
 'AERES': 'AERES',
 'agency': 'agence',
 'Authors': 'Auteurs',
@@ -22,13 +23,17 @@
 'Definition': 'Définition',
 'dev': 'dev',
 'Dictionary': 'Dictionary',
+'documentations': 'documentations',
 'Doi': 'Doi',
 'domain': 'domaine',
 'E Print': 'E Print',
 'End date': 'Date de fin',
+'enter a number between %(min)g and %(max)g': 'enter a number between %(min)g and %(max)g',
 'Enter a number between %(min)g and %(max)g': 'Enter a number between %(min)g and %(max)g',
 'enter a value': 'entré une valeur',
 'Enter an integer between %(min)g and %(max)g': 'Enter an integer between %(min)g and %(max)g',
+'enter an integer between %(min)g and %(max)g': 'enter an integer between %(min)g and %(max)g',
+'enter an integer greater than or equal to %(min)g': 'enter an integer greater than or equal to %(min)g',
 'Enter an integer greater than or equal to %(min)g': 'Enter an integer greater than or equal to %(min)g',
 'Filter categories': 'Filter categories',
 'Filter collaborations': 'Filter collaborations',
@@ -49,6 +54,7 @@
 'Help': 'Help',
 'Host': 'Host',
 'Id': 'Id',
+'install': 'installé',
 'invalid json': 'invalid json',
 'Json': 'Json',
 'Last Page': 'Dernière Page',
diff --git a/models/plugin_dbui.py b/models/plugin_dbui.py
index 3fccbf04..dff3576e 100644
--- a/models/plugin_dbui.py
+++ b/models/plugin_dbui.py
@@ -36,7 +36,8 @@ plugins = PluginManager('dbui',
                         app_script_dir=None,    # relative directory static/scripts
 
                         dbui_conf=URL(c='plugin_dbui', f='dbui_conf'),
-                        dbui_css='static/plugin_dbui/resources/css/kde-oxygen.css',
+                        dbui_css=['static/plugin_dbui/resources/css/kde-oxygen.css',
+                                  'static/plugin_dbui/resources/css/dbui.css'],
                         dbui_js='static/plugin_dbui/src',
                         dbui_lg='static/plugin_dbui/locale/dbui-lang-%s.js' % lg,
                         dbui_libmin='static/plugin_dbui/dbui-min.js',
diff --git a/models/widgets_viewport.py b/models/widgets_viewport.py
index f5d1af81..929d74eb 100644
--- a/models/widgets_viewport.py
+++ b/models/widgets_viewport.py
@@ -2,73 +2,105 @@
 """ 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
+
+#-------------------------------------------------------------------------------
 #
-# the CAS node
+# CAS 
 #
+#-------------------------------------------------------------------------------
 casNode = None
 
+#-------------------------------------------------------------------------------
 #
-# The form node
+# FORM 
 #
-formNode = dbui.Node(T('Forms'))
+#-------------------------------------------------------------------------------
+formNode = Node(T('Forms'))
 for tablename in ('categories', 'harvesters', 'publications', 'new_fields'):
 
-    leaf = dbui.Window(closable=True,
-                       items=[dbui.to_formPanel(db[tablename])],
-                       layout='fit',
-                       title="Add %s ..." % tablename,
-                       modal=True)
+    leaf = Window(closable=True,
+                  items=[dbui.to_formPanel(db[tablename])],
+                  layout='fit',
+                  title="Add %s ..." % tablename,
+                  modal=True)
 
     formNode.add_child(T(tablename), leaf)
 
+#-------------------------------------------------------------------------------
 #
-# the grid node
+# GRID 
 #
-gridNode = dbui.Node(T('Tables'))
-configurator = lambda tablename: dbui.to_gridPanel(db[tablename]) 
-gridNode.add_children(db.tables, func=configurator) 
+#-------------------------------------------------------------------------------
+gridNode = Node(T('Tables'))
+gridNode.add_children(db.tables, func=to_grid) 
 
+#-------------------------------------------------------------------------------
 #
-# The helper node
+# HELP 
 #
+#-------------------------------------------------------------------------------
 loader = dict(ajaxOptions=dict(disableCaching=False),
               autoLoad=True,
               renderer='html',
               url=URL('plugin_dbui', 'versions'))
 
-versionLeaf = dbui.Panel(loader=loader,
-                         plugins=['pPanelLoaderException'])
+aboutLeaf = Panel(autoLoad=URL('plugin_dbui', 'about'), autoScroll=True)
+docLeaf = Panel(autoLoad=URL('plugin_dbui', 'documentations'), autoScroll=True)
+versionLeaf = Panel(loader=loader, plugins=['pPanelLoaderException'])
 
-helpNode = dbui.Node(T('Help'))
+helpNode = Node(T('Help'))
+helpNode.add_child(T('about'), aboutLeaf)
+helpNode.add_child(T('documentations'), docLeaf)
 helpNode.add_child(T('versions'), versionLeaf)
 
+#-------------------------------------------------------------------------------
 #
-# the report node
+# REPORT
 #
-leaf_1 = dbui.Panel(html="salut ma poule")
+#-------------------------------------------------------------------------------
+leaf_1 = Panel(html="salut ma poule")
 
-leaf_2 = dbui.to_panelWithUrlSelector(virtdb.foo1, 
-                                      baseUrl=URL('reports', 'report_2'),
-                                      baseParams={'hello': 3},
-                                      extField='my_format',
-                                      plugins=['pMathJax'])
+leaf_2 = PanelWithUrlSelector(virtdb.foo1, 
+                              baseUrl=URL('reports', 'report_2'),
+                              baseParams={'hello': 3},
+                              extField='my_format',
+                              plugins=['pMathJax'])
 
-leaf_3 = dbui.to_panelWithUrlSelector(virtdb.harvester_selector,
-                                      baseUrl=URL('reports', 'report_3'),
-                                      selectorRegion='east',
-                                      selectorTitle='Select a project')
+leaf_3 = PanelWithUrlSelector(virtdb.harvester_selector,
+                              baseUrl=URL('reports', 'report_3'),
+                              selectorRegion='east',
+                              selectorTitle='Select a project')
 
-reportNode = dbui.Node(T('Reports'))
+reportNode = Node(T('Reports'))
 reportNode.add_child(T('report_1'), leaf_1)
 reportNode.add_child(T('report_2'), leaf_2)
 reportNode.add_child(T('report_3'), leaf_3)
 
+#-------------------------------------------------------------------------------
 #
-# The viewport with its navigation tree
+# VIEWPORT
 #
+#-------------------------------------------------------------------------------
+nodes = [helpNode, 
+         casNode, 
+         formNode, 
+         gridNode,
+         reportNode]
+
 viewportModifier = dbui.ViewportModifier()
+viewportModifier.configure(tabTitleTpl="{1}")
+
+viewportModifier.add_node(*nodes)
+
 viewportModifier.configure(plugins=['pViewportLogin'], logged=True);
-viewportModifier.add_node(helpNode, casNode, formNode, gridNode, reportNode)
 
 viewportModifier.default_node(T('Tables'), T('categories'))
 # viewportModifier.default_node(T('Tables'), T('new_fields'))
diff --git a/modules/plugin_dbui/helper.py b/modules/plugin_dbui/helper.py
index 9bcc4b89..537dafc8 100644
--- a/modules/plugin_dbui/helper.py
+++ b/modules/plugin_dbui/helper.py
@@ -547,6 +547,7 @@ def get_versions():
     
     @rtype: dict
     @return:
+        - C{ace} the version of the plugin ace
         - C{dbui} the version of the plugin  dbui
         - C{extjs} the version of the plugin extjs
         - C{mathjax} the version of the plugin mathjax
@@ -556,6 +557,13 @@ def get_versions():
     """
     server_path, client_path = get_reference_paths()
 
+
+    # plugin ace
+    ace = current.T('plugin not install')
+    path = os.path.join(server_path, 'static', 'plugin_ace')
+    if os.path.exists(path):
+        ace = current.T('install')
+    
     # plugin dbui
     fn = os.path.join(server_path, 'static', 'plugin_dbui', 'src', 'App.js')
     
@@ -625,7 +633,12 @@ def get_versions():
         
         os.chdir(ref_path)
 
-    return dict(dbui=dbui, extjs=extjs, mathjax=mathjax, web2py=web2py, myapp=myapp)
+    return dict(ace=ace, 
+                dbui=dbui, 
+                extjs=extjs, 
+                mathjax=mathjax,
+                myapp=myapp, 
+                web2py=web2py)
 
 
 def get_where_query(table):
diff --git a/static/ABOUT.html b/static/ABOUT.html
new file mode 100644
index 00000000..a9dad9b1
--- /dev/null
+++ b/static/ABOUT.html
@@ -0,0 +1,8 @@
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<p class="dbui-p">the about file for the application ....</p>
+</body>
+</html>
\ No newline at end of file
diff --git a/static/plugin_dbui/TODO b/static/plugin_dbui/TODO
index 97f5cb94..924140ac 100644
--- a/static/plugin_dbui/TODO
+++ b/static/plugin_dbui/TODO
@@ -26,6 +26,7 @@
   - Take benefit of Ext JS 4.2 to deploy the dynamic loading when running
     in debug mode.
 
+0.6.0.19 (Mar 2014)
   - Take benefit of Ext JS 4.2 to user requires and use class parameters.
 
 0.6.0.7 (Feb 2014)
diff --git a/static/plugin_dbui/resources/css/dbui.css b/static/plugin_dbui/resources/css/dbui.css
new file mode 100644
index 00000000..2b285e10
--- /dev/null
+++ b/static/plugin_dbui/resources/css/dbui.css
@@ -0,0 +1,62 @@
+/*
+ * CSS Class definition for application reporting
+ */
+
+.dbui-h2,
+.dbui-h3,
+.dbui-li,
+.dbui-ol,
+.dbui-p,
+.dbui-table,
+.dbui-td,
+.dbui-th,
+.dbui-tr,
+.dbui-ul,
+.dbui-ul-none {font-family: Liberation Sherif, Sherif;
+               font-size: 11px;}
+
+/*
+ * Body
+ */
+.dbui-h2 {font-family: Liberation Sans, Sans;
+          margin-bottom: 2ex;
+          margin-left: 3%;
+          margin-top: 3ex;}
+
+.dbui-p {margin-left: 3%;
+         text-align: justify;}
+
+/*
+ * Font
+ */
+.dbui-large {font-size: 90%;}
+
+/*
+ * List
+ */
+.dbui-li {margin-bottom: 1ex;
+          margin-left: 9%;
+          margin-right: 9%;
+          text-align: justify;}
+
+.dbui-ol {list-style-type: decimal;}
+.dbui-ul {list-style-type: disc;}
+.dbui-ul-none {list-style-type: none;}
+
+/*
+ * Table
+ */
+.dbui-td,
+.dbui-th,
+.dbui-tr {outline-style: solid;
+          outline-width: 1px;
+          outline-color: LightGray;
+          padding-left: 5px;
+          padding-right: 5px;}
+
+/*
+ * Text
+ */
+.dbui-left {text-align: left;}
+.dbui-right {text-align: right;}
+.dbui-small-cap {font-variant: small-caps;}
diff --git a/views/plugin_dbui/documentations.html b/views/plugin_dbui/documentations.html
new file mode 100644
index 00000000..038eff8e
--- /dev/null
+++ b/views/plugin_dbui/documentations.html
@@ -0,0 +1,179 @@
+<html>
+<head>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+</head>
+<body>
+<h2 class="dbui-h2 dbui-small-cap">Documentations</h2>
+
+<table border="0" style="margin-left: 6%">
+    <tr>
+        <td class="dbui-td">
+            {{=app_name}}
+        </td>
+        <td class="dbui-td">
+            <a href="{{=png_db}}" target="_blank">
+                Schéma de la base de données
+            </a>
+        </td>
+        <td  class="dbui-td">
+            <a href="{{=epydoc_application}}" target="_blank">
+                python API
+            </a>
+        </td>
+        <td class="dbui-td"></td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            <a href="https://marprod.in2p3.fr/plugin_dbui_book" target="_blank">
+                plugin dbui
+            </a>
+        </td>
+        <td class="dbui-td">
+            <a href="https://marprod.in2p3.fr/plugin_dbui_book/default/chapter/29" target="_blank">
+                documentation développeurs
+            </a>
+        </td>
+        <td class="dbui-td">
+            <a href="{{=epydoc_dbui}}" target="_blank">
+                python API
+            </a>
+        </td>
+        <td class="dbui-td">
+            <a href="{{=jsduck_dbui}}" target="_blank">
+                javascript API
+            </a>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            <a href="http://web2py.com/" target="_blank">
+                Web2py
+            </a>
+        </td>
+        <td class="dbui-td">
+            <a href="http://web2py.com/book" target="_blank">
+                documentation développeurs
+            </a>
+        </td>
+        <td class="dbui-td">
+            <a href="http://www.web2py.com/examples/static/epydoc/index.html" target="_blank">
+                python API
+            </a>
+        </td>
+        <td class="dbui-td"></td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            <a href="http://www.sencha.com/products/extjs/" target="_blank">
+                Ext JS
+            </a>
+        </td>
+        <td class="dbui-td"></td>
+        <td class="dbui-td"></td>
+        <td class="dbui-td">
+            <a href="http://docs.sencha.com/extjs/4.2.1/" target="_blank">
+                javascript API
+            </a>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            <a href="http://www.mathjax.org/" target="_blank">
+                MathJax
+            </a>
+        </td>
+        <td class="dbui-td"></td>
+        <td class="dbui-td"></td>
+        <td class="dbui-td">
+            <a href="http://docs.mathjax.org/" target="_blank">
+                Javascript API
+            </a>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            <a href="http://ace.c9.io/#nav=about" target="_blank">
+                Ace
+            </a>
+        </td>
+        <td class="dbui-td"></td>
+        <td class="dbui-td"></td>
+        <td class="dbui-td">
+            <a href="http://ace.c9.io/#nav=api" target="_blank">
+                Javascript API
+            </a>
+        </td>
+    </tr>
+</table>
+
+<h2 class="dbui-h2 dbui-small-cap">Code source</h2>
+
+<table border="0" style="margin-left: 6%">
+    <tr>
+        <td class="dbui-td">
+            {{=app_name}}
+        </td>
+        <td class="dbui-td">
+            <em>git clone http://marwww.in2p3.fr/~legac/wap/git/{{=app}}.git</em>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            plugin dbui
+        </td>
+        <td class="dbui-td">
+            <em>git clone http://marwww.in2p3.fr/~legac/wap/git/web2py_plugin_dbui.git</em>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            Web2py
+        </td>
+        <td class="dbui-td">
+            <em>git clone git://github.com/web2py/web2py.git</em>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            Ext JS
+        </td>
+        <td class="dbui-td">
+            A télécharger à partir de leur site web.<br>
+            Disponible dans le répertoire
+            <em>{{=app}}/static/plugin_extjs/src</em>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            MathJax
+        </td>
+        <td class="dbui-td">
+            <em>git clone http://github.com/mathjax/MathJax</em>
+        </td>
+    </tr>
+    <tr>
+        <td class="dbui-td">
+            Ace
+        </td>
+        <td class="dbui-td">
+            <em>git clone git://github.com/ajaxorg/ace.git</em>
+        </td>
+    </tr>
+</table>
+
+<h2 class="dbui-h2 dbui-small-cap">Binnaires pour web2py</h2>
+<p class="dbui-p">
+Les logiciels tierce
+<span class="dbui-small-cap">ACE</span>,
+<span class="dbui-small-cap">Ext JS</span>,
+<span class="dbui-small-cap">MathJax</span>,
+<span class="dbui-small-cap">Plugin dbui</span>,
+sont construits sous la forme de plugins qui peuvent être chargés dans
+le serveur webpy.
+
+Des versions cohérentes sont disponible en utilisant
+le gestionnaire de version <a href="http://git-scm.com/" target="_blank">git</a> :
+<em>git clone http://marwww.in2p3.fr/~legac/wap/git/plugin_dbui_build.git</em>.
+</p>
+
+</body>
diff --git a/views/plugin_dbui/versions.html b/views/plugin_dbui/versions.html
new file mode 100644
index 00000000..e58be39b
--- /dev/null
+++ b/views/plugin_dbui/versions.html
@@ -0,0 +1,14 @@
+{{
+    title = 'Software versions'
+    response.write(P(title, _class="dbui-p dbui-small-cap dbui-large"))
+
+    table = TABLE(TR(TD("web2py",  _class="dbui-td"), TD(web2py,  _class="dbui-td")),
+                  TR(TD("dbui",    _class="dbui-td"), TD(dbui,    _class="dbui-td")),
+                  TR(TD("extjs",   _class="dbui-td"), TD(extjs,   _class="dbui-td")),
+                  TR(TD("mathjax", _class="dbui-td"), TD(mathjax, _class="dbui-td")),
+                  TR(TD("ace",     _class="dbui-td"), TD(ace,     _class="dbui-td")),
+                  TR(TD(request.application, _class="dbui-td"), TD(myapp, _class="dbui-td")),
+                  _style="margin-left:6%")
+
+    response.write(P(table))
+}}
\ No newline at end of file
-- 
GitLab