From f10cf8ec48b341ca25b2dfe89cdb810dd1470623 Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Thu, 14 Nov 2013 15:39:03 +0100 Subject: [PATCH] SliceList and TestbedList are specialized versions of SimpleList with related css --- plugins/lists/simplelist.py | 7 ++-- plugins/lists/slicelist.py | 7 +++- plugins/lists/static/css/simplelist.css | 13 +++---- plugins/lists/static/css/slicelist.css | 23 ++++++++++++ plugins/lists/static/css/testbedlist.css | 23 ++++++++++++ plugins/lists/static/js/simplelist.js | 45 +++++++++++++----------- plugins/lists/staticlist.py | 6 ++++ plugins/lists/templates/simplelist.html | 6 ++-- plugins/lists/testbedlist.py | 15 ++++++++ portal/dashboardview.py | 22 ++++++------ portal/platformview.py | 3 -- portal/static/css/onelab_marko.css | 5 --- portal/templates/dashboard.html | 2 +- 13 files changed, 120 insertions(+), 57 deletions(-) create mode 100644 plugins/lists/static/css/slicelist.css create mode 100644 plugins/lists/static/css/testbedlist.css create mode 100644 plugins/lists/testbedlist.py diff --git a/plugins/lists/simplelist.py b/plugins/lists/simplelist.py index 69e47aa5..26510303 100644 --- a/plugins/lists/simplelist.py +++ b/plugins/lists/simplelist.py @@ -3,10 +3,12 @@ from unfold.plugin import Plugin class SimpleList (Plugin) : # only deal with our own stuff here and let Plugin handle the rest - def __init__ (self, key, with_datatables=False, **settings): + def __init__ (self, key, with_datatables=False, classname=None, **settings): Plugin.__init__ (self, **settings) self.key=key self.with_datatables = with_datatables + # the DOM classname + self.classname = classname if classname is not None else "simplelist" # SimpleList is useless per se anyways def template_file (self): @@ -18,6 +20,7 @@ class SimpleList (Plugin) : header=getattr(self,'header',None) if header: env['header']=header env['with_datatables']= "yes" if self.with_datatables else "" + env['classname']=self.classname return env def requirements (self): @@ -34,5 +37,5 @@ class SimpleList (Plugin) : reqs['js_files'].append ("js/with-datatables.js") return reqs - def json_settings_list (self): return ['plugin_uuid','query_uuid','key'] + def json_settings_list (self): return ['plugin_uuid','query_uuid','key','classname'] diff --git a/plugins/lists/slicelist.py b/plugins/lists/slicelist.py index b9220db9..adfb9bf8 100644 --- a/plugins/lists/slicelist.py +++ b/plugins/lists/slicelist.py @@ -5,8 +5,13 @@ from plugins.lists.simplelist import SimpleList class SliceList (SimpleList): def __init__ (self, **settings): - SimpleList.__init__(self, key='slice_hrn', **settings) + SimpleList.__init__(self, key='slice.slice_hrn', classname='slicelist', **settings) # writing a js plugin for that would be overkill, just use SimpleList def plugin_classname (self): return 'SimpleList' + + def requirements (self): + req = SimpleList.requirements(self) + req['css_files'] += [ 'css/slicelist.css' ] + return req diff --git a/plugins/lists/static/css/simplelist.css b/plugins/lists/static/css/simplelist.css index bbf537e7..77f80ce4 100644 --- a/plugins/lists/static/css/simplelist.css +++ b/plugins/lists/static/css/simplelist.css @@ -15,14 +15,9 @@ thead.simplelist>tr>th { tbody.simplelist i { padding-right: 8px; } -/* make previous next buttons a bit nicer */ -div.paging_two_button>a { padding: 0px 4px 0px 4px; } -/* ---------- */ -/* xxx this probably should be separated in something related to datatables */ -select { - width: auto; -} -div.dataTables_filter input[type=text] { - width: 60; +.simplelist { + font-size: 100%; + text-align: center !important; + margin: 0 auto; } diff --git a/plugins/lists/static/css/slicelist.css b/plugins/lists/static/css/slicelist.css new file mode 100644 index 00000000..34a427c0 --- /dev/null +++ b/plugins/lists/static/css/slicelist.css @@ -0,0 +1,23 @@ +/* font size for regular (non datatable'd) slicelists */ +tbody.slicelist { + font-size: 150%; +} +/* datatable'd tables behave differently */ +table.with-datatables>tbody.slicelist { + font-size: 80%; +} +/* larger headers */ +thead.slicelist>tr>th { + font-size: 150%; + padding: 10px 10px 20px 10px; +} +/* some space after the arrow */ +tbody.slicelist i { + padding-right: 8px; +} + +.slicelist { + font-size: 100%; + text-align: center !important; + margin: 0 auto; +} diff --git a/plugins/lists/static/css/testbedlist.css b/plugins/lists/static/css/testbedlist.css new file mode 100644 index 00000000..fd312bab --- /dev/null +++ b/plugins/lists/static/css/testbedlist.css @@ -0,0 +1,23 @@ +/* font size for regular (non datatable'd) testbedlists */ +tbody.testbedlist { + font-size: 300%; +} +/* datatable'd tables behave differently */ +table.with-datatables>tbody.testbedlist { + font-size: 80%; +} +/* larger headers */ +thead.testbedlist>tr>th { + font-size: 150%; + padding: 10px 10px 20px 10px; +} +/* some space after the arrow */ +tbody.testbedlist i { + padding-right: 8px; +} + +.testbedlist { + font-size: 100%; + text-align: center !important; + margin: 0 auto; +} diff --git a/plugins/lists/static/js/simplelist.js b/plugins/lists/static/js/simplelist.js index 6a61ca53..ad6985c2 100644 --- a/plugins/lists/static/js/simplelist.js +++ b/plugins/lists/static/js/simplelist.js @@ -7,7 +7,7 @@ (function($){ var debug=false; - // debug=true + debug=true $.fn.SimpleList = function( method ) { /* Method calling logic */ @@ -53,14 +53,16 @@ // e.data is what we passed in second argument to subscribe // so here it is the jquery object attached to the plugin
var $plugindiv = e.data; + var options = $plugindiv.data().SimpleList; + var classname=options.classname; // locate the element; with datatables in the way, // this might not be a direct son of the div-plugin - var $table = $plugindiv.find("table.simplelist").first(); + var $table = $plugindiv.find("table."+classname).first(); // also we may or may not have a header - var $tbody = $table.find("tbody.simplelist").first(); + var $tbody = $table.find("tbody."+classname).first(); var use_datatables = $table.hasClass("with-datatables"); if (debug) - messages.debug($plugindiv.attr('id') + " udt= " + use_datatables); + messages.debug($plugindiv.attr('id') + " udt= " + use_datatables + " rows="+rows.length); // clear the spinning wheel: look up an ancestor that has the need-spin class // do this before we might return @@ -75,21 +77,20 @@ } if (typeof rows[0].error != 'undefined') { - var error="ERROR: " + rows[0].error; - if (use_datatables) + var error="ERROR: " + rows[0].error; + if (use_datatables) datatables_set_message ($table, $tbody, unfold.error(error)); - else - regular_set_message ($table, $tbody, unfold.error(error)); + else + regular_set_message ($table, $tbody, unfold.error(error)); return; } - var options = $plugindiv.data().SimpleList; - if (use_datatables) + if (use_datatables) datatables_update_table($table, $tbody, rows, options.key); - else - regular_update_table($table, $tbody, rows, options.key); + else + regular_update_table($table, $tbody, rows, options.key, classname); - } + } // hard-wire a separate presentation depending on the key being used.... function cell(key, value) { @@ -106,10 +107,10 @@ $tbody.html(""); } - function regular_update_table ($table, $tbody, rows, key) { + function regular_update_table ($table, $tbody, rows, key, classname) { if (debug) - messages.debug('regular_update_table ' + rows.length + " rows"); - var html=$.map(rows, function (row) { + messages.debug('regular_update_table ' + rows.length + " rows" + " key=" + key + " classname=" + classname); + var html=$.map(rows, function (row) { value = row; $.each(key.split('.'), function(i, k) { if ($.isArray(value)) { @@ -118,11 +119,13 @@ value = value[k]; } }); - if ($.isArray(value)) { - x = $.map(value, function(val, i) { return html_row ( cell (key, val)); }); + if ($.isArray(value)) { + x = $.map(value, function(val, i) { + messages.debug("loop.loop val="+val+" i="+i); + return html_row ( cell (key, val), classname); }); return x; } else { - return html_row ( cell (key, value)); + return html_row ( cell (key, value), classname); } }).join(); $tbody.html(html); @@ -144,8 +147,8 @@ $table.dataTable().fnDraw(); } - function html_row (cell) { - return ""; + function html_row (cell, classname) { + return ""; } })( jQuery ); diff --git a/plugins/lists/staticlist.py b/plugins/lists/staticlist.py index c5a254ac..f53a2acb 100644 --- a/plugins/lists/staticlist.py +++ b/plugins/lists/staticlist.py @@ -2,6 +2,12 @@ from unfold.plugin import Plugin class StaticList (Plugin) : + """ StaticList allows you to display an html list + that you provide the contents for in the 'list' input argument + It is static in the sense that no query is going to be used to + manage this contents + """ + # only deal with our own stuff here and let Plugin handle the rest def __init__ (self, list=[], with_datatables=False, **settings): Plugin.__init__ (self, **settings) diff --git a/plugins/lists/templates/simplelist.html b/plugins/lists/templates/simplelist.html index e34d087e..c3e2954d 100644 --- a/plugins/lists/templates/simplelist.html +++ b/plugins/lists/templates/simplelist.html @@ -1,4 +1,4 @@ -
"+message+"
"+cell+"
"+cell+"
-{% if header %} {% endif %} - +
{{ header }}
+{% if header %} {% endif %} +
{{ header }}
diff --git a/plugins/lists/testbedlist.py b/plugins/lists/testbedlist.py new file mode 100644 index 00000000..6496d909 --- /dev/null +++ b/plugins/lists/testbedlist.py @@ -0,0 +1,15 @@ +from plugins.lists.simplelist import SimpleList + +class TestbedList (SimpleList): + + def __init__ (self, **settings): + SimpleList.__init__(self, key='platform', classname='testbedlist', **settings) + + # writing a js plugin for that would be overkill, just use SimpleList + def plugin_classname (self): + return 'SimpleList' + + def requirements (self): + req = SimpleList.requirements(self) + req['css_files'] += [ 'css/testbedlist.css' ] + return req diff --git a/portal/dashboardview.py b/portal/dashboardview.py index 1cc12e0e..44a3ea91 100644 --- a/portal/dashboardview.py +++ b/portal/dashboardview.py @@ -1,7 +1,8 @@ from manifold.core.query import Query from unfold.page import Page -from plugins.lists.simplelist import SimpleList +from plugins.lists.testbedlist import TestbedList +from plugins.lists.slicelist import SliceList from unfold.loginrequired import LoginRequiredAutoLogoutView @@ -22,32 +23,29 @@ class DashboardView (LoginRequiredAutoLogoutView): # Slow... #slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn') - auth_query = Query().get('network').select('network_hrn','platform') + testbed_query = Query().get('network').select('network_hrn','platform') # DEMO GEC18 Query only PLE slice_query = Query().get('user').filter_by('user_hrn', '==', '$user_hrn').select('user_hrn', 'slice.slice_hrn') page.enqueue_query(slice_query) - page.enqueue_query(auth_query) + page.enqueue_query(testbed_query) page.expose_js_metadata() page.expose_queries() - slicelist = SimpleList( - title = None, + slicelist = SliceList( page = page, - key = 'slice.slice_hrn', + title = "slices", query = slice_query, ) - # XXX TODO: plugins/lists/static/js/simplelist.js => hardcoded keys that give links : slice_hrn & platform - authlist = SimpleList( - title = None, + testbedlist = TestbedList( page = page, - key = 'platform', - query = auth_query, + title = "testbeds", + query = testbed_query, ) context = super(DashboardView, self).get_context_data(**kwargs) context['person'] = self.request.user - context['networks'] = authlist.render(self.request) + context['testbeds'] = testbedlist.render(self.request) context['slices'] = slicelist.render(self.request) # XXX This is repeated in all pages diff --git a/portal/platformview.py b/portal/platformview.py index a81ba871..f3ea7f7a 100644 --- a/portal/platformview.py +++ b/portal/platformview.py @@ -61,6 +61,3 @@ class PlatformView(FreeAccessView): context.update(page.prelude_env()) return context - - - diff --git a/portal/static/css/onelab_marko.css b/portal/static/css/onelab_marko.css index 0201e8b5..a7b256c6 100644 --- a/portal/static/css/onelab_marko.css +++ b/portal/static/css/onelab_marko.css @@ -419,8 +419,3 @@ table.query-editor td { padding-left: 0 !important; } -.simplelist { - font-size: 100%; - text-align: center !important; - margin: 0 auto; -} diff --git a/portal/templates/dashboard.html b/portal/templates/dashboard.html index cd136088..e4c61b42 100644 --- a/portal/templates/dashboard.html +++ b/portal/templates/dashboard.html @@ -28,7 +28,7 @@

Testbeds

- {{networks}} + {{testbeds}}
-- 2.43.0