From a73d8ce5a1ee807a3afd80010bab0ff11a7c367a Mon Sep 17 00:00:00 2001
From: legac <renaud.legac@free.fr>
Date: Sat, 5 Jul 2014 16:24:52 +0200
Subject: [PATCH] Improved code for the documentations and version view.

---
 controllers/reports.py                | 18 +++++++++-
 languages/fr-fr.py                    |  3 ++
 views/plugin_dbui/documentations.html | 52 +++++++++++----------------
 views/plugin_dbui/versions.html       | 34 +++++-------------
 views/reports/report_4.html           | 48 ++++++++++++++++++++++---
 5 files changed, 94 insertions(+), 61 deletions(-)

diff --git a/controllers/reports.py b/controllers/reports.py
index 76f03ed4..c441a5b3 100644
--- a/controllers/reports.py
+++ b/controllers/reports.py
@@ -46,4 +46,20 @@ def report_4():
     """Execute a javascript in the view using python information
     
     """
-    return dict(msg="Hello world")
\ No newline at end of file
+    import json
+    
+    cfg = dict()
+
+    cfg['fields'] = [{'name': 'controller', 'type': 'string'},
+                     {'name': 'host', 'type': 'string'},
+                     {'name': 'collections', 'type': 'string'},
+                     {'name': 'ratio', 'type': 'number'}]
+
+    cfg['data'] = []
+    for row in db().select(db.harvesters.ALL):
+        cfg['data'].append([row.controller,
+                            row.host,
+                            row.collections,
+                            row.ratio])
+        
+    return dict(msg="Hello world", cfg_store=json.dumps(cfg))
diff --git a/languages/fr-fr.py b/languages/fr-fr.py
index 573df569..d58f7b13 100644
--- a/languages/fr-fr.py
+++ b/languages/fr-fr.py
@@ -7,6 +7,7 @@
 'agency': 'agence',
 'Authors': 'Auteurs',
 'Authors Cppm': 'Auteurs Cppm',
+'Binary files': 'Fichiers binaires',
 'bla bla...': 'bla bla...',
 'blab blab ....': 'blab blab ....',
 'categories': 'catégories',
@@ -26,6 +27,7 @@
 'Dictionary': 'Dictionary',
 'Documentation for developers': 'Documentation pour développeurs',
 'documentations': 'documentations',
+'Documentations': 'Documentations',
 'Doi': 'Doi',
 'domain': 'domaine',
 'E Print': 'E Print',
@@ -74,6 +76,7 @@
 'My String': 'My String',
 'My_Merge': 'My_Merge',
 'new_fields': 'new_fields',
+'Open source': 'Code open source',
 'Pages': 'Pages',
 'plugin not install': 'plugin not install',
 'Project': 'Projet',
diff --git a/views/plugin_dbui/documentations.html b/views/plugin_dbui/documentations.html
index de14e2cf..1e8c9b14 100644
--- a/views/plugin_dbui/documentations.html
+++ b/views/plugin_dbui/documentations.html
@@ -4,26 +4,35 @@
     # The python controller return cfg_doc, and cfg_src the configuration for
     # the Ext.data.Array
     #
-    #    - build unique DIV identifier
-    #
     #--------------------------------------------------------------------------
 
+    #
+    # Export python variables to the javascript
+    #
+    jsvars = ["cfgDoc = %s" % cfg_doc,
+              "cfgSrc = %s" % cfg_src]
+
+    jsvars = "    var %s;" % ',\n'.join(jsvars)
+    response.write(SCRIPT(jsvars), escape=False)
+
     #
     # unique identifier for the DIV block associated to the grid
     #
     divdoc = id(cfg_doc)
     divsrc = id(cfg_src)
 
-}}
-<h2 class="dbui-h2 dbui-small-cap">Documentations</h2>
-<div id="grid-{{=divdoc}}"></div>
-
-<h2 class="dbui-h2 dbui-small-cap">Code source</h2>
-<div id="grid-{{=divsrc}}"></div>
+    #
+    # The DIV blocks
+    #
+    response.write(H2(T("Documentations"), _class="dbui-h2 dbui-small-cap"))
+    response.write(DIV(_id="grid-%s" % divdoc))
 
+    response.write(H2(T("Open source"), _class="dbui-h2 dbui-small-cap"))
+    response.write(DIV(_id="grid-%s" % divsrc))
 
-<h2 class="dbui-h2 dbui-small-cap">Binnaires pour web2py</h2>
+    response.write(H2(T("Binary files"), _class="dbui-h2 dbui-small-cap"))
 
+}}
 <div style="width: 570px; padding: 0 20 0 20;">
     <p class="dbui-p">
     Les logiciels tierce
@@ -41,27 +50,8 @@
 </div>
 <script>
 
-    /**
-     * Inline javascript to instantiate and render the Ext JS grids
-     *
-     */
-
-    //
-    // bind the python and javascript variables
-    // use the internationalization of web2py to translate grid header
-    // MANDATORY: escape false to convert properly the quotes
-    //
-    {{
-        def write(value):
-            return response.write("\n%s" % value, escape=False)
-
-        write("var cfgDoc = %s," % cfg_doc)
-        write("    cfgSrc = %s;" % cfg_src)
-
-    }}
-
     //
-    // instantiate the grids for the documentation
+    // instantiate the grid for the documentation
     //
     var grid = Ext.create('Ext.grid.Panel', {
         store: Ext.create('Ext.data.ArrayStore', cfgDoc),
@@ -79,7 +69,7 @@
     });
 
     //
-    // instantiate the grids for source code
+    // instantiate the grid for source code
     //
     var grid = Ext.create('Ext.grid.Panel', {
         store: Ext.create('Ext.data.ArrayStore', cfgSrc),
@@ -94,4 +84,4 @@
         renderTo: 'grid-{{=divsrc}}'
     });
 
-</script>
+</script>
\ No newline at end of file
diff --git a/views/plugin_dbui/versions.html b/views/plugin_dbui/versions.html
index 8a61bb61..7f091682 100644
--- a/views/plugin_dbui/versions.html
+++ b/views/plugin_dbui/versions.html
@@ -13,43 +13,27 @@
     #
     # unique identifier for the DIV block associated to the grid
     #
-    divgrid = abs(hash(cfg_store))
+    divgrid = id(cfg_store)
 
     #
     # The title and the DIV block
     #
-    style = ["font-size: 12px;",
-             "font-variant: small-caps;",
-             "margin-left: 20px;",
-             "margin-bottom: 1ex;",
-             "margin-top: 2ex;"]
-
-    response.write(P(T("Software versions"), _style="".join(style)))
+    response.write(H2(T("Software versions"), _class="dbui-h2 dbui-small-cap"))
     response.write(DIV(_id="grid-%s" % divgrid))
 
+    #
+    # Export python variables to the javascript
+    #
+    jsvars = "var cfgStore = %s;" % cfg_store
+    response.write(SCRIPT(jsvars), escape=False)
+
 }}
 <script>
 
-    /**
-     * Inline javascript to instantiate and render the Ext JS grid
-     *
-     */
-
     //
-    // bind the python and javascript variables
-    // use the internationalization of web2py to translate grid header
-    // MANDATORY: escape false to convert properly the quotes
+    // instantiate the grid showing version numbers
     //
-    {{
-        def write(value):
-            return response.write("\n%s" % value, escape=False)
-
-        write("var cfgStore = %s;" % cfg_store)
-    }}
 
-    //
-    // instantiate the grids
-    //
     var grid = Ext.create('Ext.grid.Panel', {
         store: Ext.create('Ext.data.ArrayStore', cfgStore),
         columns: [
diff --git a/views/reports/report_4.html b/views/reports/report_4.html
index 5bc5e5bb..e8ea7dcc 100644
--- a/views/reports/report_4.html
+++ b/views/reports/report_4.html
@@ -1,5 +1,45 @@
-{{=msg}}
-<script type="text/javascript">
-    var v1 = "{{=msg}}";
-    Ext.Msg.alert("Execute inline script", v1);
+{{
+    #--------------------------------------------------------------------------
+    #
+    # The python controller return cfg_store, the configuration of
+    # the Ext.data.Array
+    #--------------------------------------------------------------------------
+
+    #
+    # unique identifier for the DIV block associated to the grid
+    #
+    divgrid = id(cfg_store)
+
+    #
+    # The DIV block
+    #
+    response.write(DIV(_id="grid-%s" % divgrid))
+
+    #
+    # Export python variables to the javascript
+    #
+    jsvars = "var cfgStore = %s;" % cfg_store
+    response.write(SCRIPT(jsvars), escape=False)
+
+}}
+<script>
+    /**
+     * Inline javascript to instantiate and render the Ext JS grid
+     *
+     */
+
+    var grid = Ext.create('Ext.grid.Panel', {
+        store: Ext.create('Ext.data.ArrayStore', cfgStore),
+        columns: [
+            {text: "Controller", dataIndex: 'controller', flex: 0.8},
+            {text: "Host", dataIndex: 'host', flex: 1},
+            {text: "Collections", dataIndex: 'collections', flex: 1.2},
+            {text: "Ratio", dataIndex: 'ratio', flex: 0.5}
+        ],
+        forceFit: true,
+        //hideHeaders: true,
+        padding: "10 40 20 60",
+        renderTo: 'grid-{{=divgrid}}'
+    });
+
 </script>
-- 
GitLab