Slice Resources View: fixed view, default fields are setup in the view, fields of...
authorLoic Baron <loic.baron@lip6.fr>
Fri, 19 Dec 2014 17:40:45 +0000 (18:40 +0100)
committerLoic Baron <loic.baron@lip6.fr>
Fri, 19 Dec 2014 17:40:45 +0000 (18:40 +0100)
plugins/columns_editor/__init__.py
plugins/querytable/__init__.py
plugins/querytable/static/js/querytable.js
portal/sliceresourceview.py
unfold/page.py

index 3cc48a9..a58d412 100644 (file)
@@ -33,12 +33,16 @@ class ColumnsEditor(Plugin):
 
     def template_env(self, request):
         fields = []
+        if self.default_fields is not None:
+            default_fields = self.default_fields
+        else:
+            default_fields = self.query.fields
         #hidden_columns = self.hidden_columns
         metadata = self.page.get_metadata()
         md_fields = metadata.details_by_object('resource')
 
         # XXX use django templating system here
-        for md_field in md_fields['column']:
+        for md_field in sorted(md_fields['column']):
             if md_field['type'] == 'string':
                 if 'allowed_values' in md_field:
                     allowed_values = md_field['allowed_values'].split(',')
@@ -82,7 +86,7 @@ class ColumnsEditor(Plugin):
                 'resource_type': 'N/A',
                 'filter_input':  filter_input,
                 'header':        None,
-                'checked':       md_field['name'] in self.query.get_select()
+                'checked':       md_field['name'] in default_fields
             })
         #return { 'fields': fields, 'hidden_columns': hidden_columns }
         #return { 'fields': fields , 'query_uuid': self.query_uuid, 'query_all_uuid': self.query_all_uuid }
index 995e935..fe486d5 100644 (file)
@@ -33,12 +33,6 @@ Current implementation makes the following assumptions
   as we use 'aoColumnDefs' instead.
 """
 
-    MAP = {
-        'facility_name' :   'Facility',
-        'testbed_name'  :   'Testbed',
-        'hostname'      :   'Resource name',
-        'type'          :   'Type',
-    }
 
     def __init__ (self, query=None, query_all=None, 
                   checkboxes=False, columns=None, 
@@ -56,10 +50,19 @@ Current implementation makes the following assumptions
             _columns = columns
             _hidden_columns = []
         elif self.query:
-            _columns = [field for field in self.query.fields if not field == 'urn']
+            print "self.query.fields = ", self.query_all.fields
+            # Columns displayed by default
+            if self.default_fields is not None:
+                _columns = [field for field in self.default_fields if not field == 'urn']
+            else:
+                _columns = [field for field in self.query.fields if not field == 'urn']
             if query_all:
                 # We need a list because sets are not JSON-serializable
-                _hidden_columns = list(self.query_all.fields - self.query.fields)
+                if self.default_fields is not None:
+                    print self.query_all.fields
+                    _hidden_columns = list(self.query_all.fields - set(self.default_fields))
+                else:
+                    _hidden_columns = list(self.query_all.fields - self.query.fields)
                 _hidden_columns.append('urn')
             else:
                 _hidden_columns = []
@@ -68,9 +71,10 @@ Current implementation makes the following assumptions
             _hidden_columns = []
 
         print "_columns=", _columns
-        self.columns = { self.MAP.get(c, c) : c for c in _columns }
-        self.hidden_columns = { self.MAP.get(c, c) : c for c in _hidden_columns }
+        self.columns = { self.mapping.get(c, c) : c for c in _columns }
+        self.hidden_columns = { self.mapping.get(c, c) : c for c in _hidden_columns }
         print "self.columns", self.columns
+        print "self.hidden_columns", self.hidden_columns
 
         self.init_key=init_key
         self.datatables_options=datatables_options
index 8d931d5..5fd2314 100644 (file)
@@ -10,14 +10,6 @@ QUERYTABLE_BGCOLOR_REMOVED = 2;
 
 (function($){
 
-    
-    var QUERYTABLE_MAP = {
-        'Facility': 'facility_name',
-        'Testbed': 'testbed_name',
-        'Resource name': 'hostname',
-        'Type': 'type',
-    };
-
     var debug=false;
 //    debug=true
 
@@ -158,13 +150,8 @@ QUERYTABLE_BGCOLOR_REMOVED = 2;
             });
 
             /* Processing hidden_columns */
-            arr = [];
-            arr = $.map(Object.keys(QUERYTABLE_MAP), function(x, i) { return QUERYTABLE_MAP[x]; });
             $.each(this.options.hidden_columns, function(i, field) {
-                is_inarray = $.inArray(field,arr);
-                if(is_inarray==-1){
-                    self.hide_column(field);
-                }
+                self.hide_column(field);
             });
             $(".dataTables_filter").append("<div style='display:inline-block;height:27px;width:27px;padding-left:6px;padding-top:4px;'><span class='glyphicon glyphicon-search'></span></div>");
             $(".dataTables_filter input").css("width","100%");
index 85bd368..3f0c3b4 100644 (file)
@@ -76,6 +76,22 @@ class SliceResourceView (LoginRequiredView, ThemeView):
         # Example: select slice_hrn, resource.urn, lease.resource, lease.start_time, lease.end_time from slice where slice_hrn == "ple.upmc.myslicedemo"
         main_query = Query.get('slice').filter_by('slice_hrn', '=', slicename)
         main_query.select(slice_fields)
+
+        # Columns shown by default in Query_table plugin
+        page.expose_js_var("QUERYTABLE_MAP","{'Resource name': 'hostname', 'Type': 'type', 'Facility': 'facility_name','Testbed': 'testbed_name', 'Status':'boot_state'}")
+       
+        # Columns checked by default in Columns_selector plugin
+        query_default_fields = ['hostname', 'type', 'facility_name', 'testbed_name', 'boot_state']
+
+        QUERYTABLE_MAP = { 
+            'hostname'      :   'Resource name',
+            'type'          :   'Type',
+            'facility_name' :   'Facility',
+            'testbed_name'  :   'Testbed',
+            'boot_state'    :   'Status',
+        }
+
+
         #        # SLICE
         #        'slice_hrn',
         #        # - The record key is needed otherwise the storage of records
@@ -121,14 +137,16 @@ class SliceResourceView (LoginRequiredView, ThemeView):
         # ALL RESOURCES LIST
         # resources as a list using datatable plugin
  
-        list_resources = QueryTable(
-            page       = page,
-            domid      = 'resources-list',
-            title      = 'List view',
-            query      = sq_resource,
-            query_all  = query_resource_all,
-            init_key   = "urn",
-            checkboxes = True,
+        list_resources     = QueryTable(
+            page           = page,
+            domid          = 'resources-list',
+            title          = 'List view',
+            query          = sq_resource,
+            query_all      = query_resource_all,
+            mapping        = QUERYTABLE_MAP,
+            default_fields = query_default_fields,
+            init_key       = "urn",
+            checkboxes     = True,
             datatables_options = {
                 'iDisplayLength': 25,
                 'bLengthChange' : True,
@@ -179,6 +197,7 @@ class SliceResourceView (LoginRequiredView, ThemeView):
             page  = page,
             query = sq_resource, 
             query_all = query_resource_all,
+            default_fields = query_default_fields,
             title = "Select Columns",
             domid = 'select-columns',
         )
index 42a3506..821c662 100644 (file)
@@ -123,6 +123,10 @@ class Page:
         # xxx this is fetched synchroneously..
         self.add_js_init_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";\n")
 
+    def expose_js_var(self, name, value):
+        # expose variable as a js value
+        self.add_js_init_chunks("var " + name + "=" + value + ";\n")
+
     def expose_js_manifold_config (self):
         self.add_js_init_chunks(ConfigEngine().manifold_js_export())