The details and association facets have been modified to show the number of records in each association in the corresponding facet tab.

Ticket #1386

--
Endi S. Dewata
From 3e6f3e2ce48b4405369006c101c0eda8b8f17b9b Mon Sep 17 00:00:00 2001
From: Endi S. Dewata <edew...@redhat.com>
Date: Thu, 23 Jun 2011 11:44:44 -0500
Subject: [PATCH] Added record count into association facet tabs.

The details and association facets have been modified to show the number of records in each association in the corresponding facet tab.

Ticket #1386
---
 install/ui/association.js |   50 +++++++++++++++++++++----------------
 install/ui/details.js     |   36 ++++++++++++---------------
 install/ui/entity.js      |   59 +++++++++++++++++++++++++++++++-------------
 install/ui/ipa.css        |    4 +-
 install/ui/search.js      |   10 +-------
 5 files changed, 88 insertions(+), 71 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index ad8d84795c0c7ea1ebcb74a71c31dc9233b612b8..54a8f6ae2031988b37286d32ad0c5e1b92443b1e 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -1011,7 +1011,7 @@ IPA.association_facet = function (spec) {
         that.table.current_page_input.val(that.table.current_page);
         that.table.total_pages_span.text(that.table.total_pages);
 
-        var pkeys = that.record[that.get_attribute_name()];
+        var pkeys = that.data[that.get_attribute_name()];
         if (!pkeys || !pkeys.length) {
             that.table.empty();
             that.table.summary.text('No entries.');
@@ -1087,6 +1087,22 @@ IPA.association_facet = function (spec) {
         batch.execute();
     };
 
+    that.load = function(data) {
+        that.facet_load(data);
+
+        var pkeys = that.data[that.get_attribute_name()];
+        if (pkeys) {
+            that.table.total_pages =
+                Math.ceil(pkeys.length / that.table.page_length);
+        } else {
+            that.table.total_pages = 1;
+        }
+
+        that.table.current_page = 1;
+
+        that.table.refresh();
+    };
+
     that.refresh = function() {
 
         if (that.association_type == 'direct') {
@@ -1099,31 +1115,21 @@ IPA.association_facet = function (spec) {
             if (that.remove_button) that.remove_button.css('display', 'none');
         }
 
-        function on_success(data, text_status, xhr) {
-            that.record = data.result.result;
-
-            that.table.current_page = 1;
-
-            var pkeys = that.record[that.get_attribute_name()];
-            if (pkeys) {
-                that.table.total_pages =
-                    Math.ceil(pkeys.length / that.table.page_length);
-            } else {
-                that.table.total_pages = 1;
-            }
-
-            that.table.refresh();
-        }
-
         var pkey = IPA.get_entity(that.entity_name).get_primary_key();
 
-        IPA.command({
+        var command = IPA.command({
             entity: that.entity_name,
             method: 'show',
-            args: pkey,
-            on_success: on_success,
-            on_error: that.on_error
-        }).execute();
+            args: pkey
+        });
+
+        command.on_success = function(data, text_status, xhr) {
+            that.load(data.result.result);
+        };
+
+        command.on_error = that.on_error;
+
+        command.execute();
     };
 
     that.association_facet_init = that.init;
diff --git a/install/ui/details.js b/install/ui/details.js
index 8a43818b5984e1fd88c8487542b166384410961f..45ba121aea94512f876d0609300c2b2f016287d5 100644
--- a/install/ui/details.js
+++ b/install/ui/details.js
@@ -321,14 +321,14 @@ IPA.details_facet = function(spec) {
 
         var pkey = IPA.get_entity(that.entity_name).get_primary_key_prefix();
 
-        if (from_url){
+        if (from_url) {
             pkey.push(that.pkey);
-        }else{
+        } else {
             var pkey_name = IPA.metadata.objects[that.entity_name].primary_key;
-            var pkey_val = that.record[pkey_name];
-            if (pkey_val instanceof Array){
-                pkey.push( pkey_val[0]);
-            }else{
+            var pkey_val = that.data[pkey_name];
+            if (pkey_val instanceof Array) {
+                pkey.push(pkey_val[0]);
+            } else {
                 pkey.push(pkey_val);
             }
         }
@@ -524,12 +524,13 @@ IPA.details_facet = function(spec) {
         return false;
     };
 
-    that.load = function(record) {
-        that.record = record;
+    that.load = function(data) {
+        that.facet_load(data);
+
         var sections = that.sections.values;
         for (var i=0; i<sections.length; i++) {
             var section = sections[i];
-            section.load(record);
+            section.load(data);
         }
     };
 
@@ -636,20 +637,15 @@ IPA.details_facet = function(spec) {
             options: { all: true, rights: true }
         });
 
-        if (IPA.details_refresh_devel_hook){
-            IPA.details_refresh_devel_hook(that.entity_name,command,that.pkey);
+        if (IPA.details_refresh_devel_hook) {
+            IPA.details_refresh_devel_hook(that.entity_name, command, that.pkey);
         }
 
-        if (that.pkey){
+        if (that.pkey) {
             command.args = that.get_primary_key(true);
-        }else if (that.entity.redirect_facet) {
-            var current_entity = that.entity;
-            while (current_entity.containing_entity){
-                current_entity = current_entity.containing_entity;
-            }
-            IPA.nav.show_page(
-                current_entity.name,
-                that.entity.redirect_facet);
+
+        } else if (that.entity.redirect_facet) {
+            that.redirect();
             return;
         }
 
diff --git a/install/ui/entity.js b/install/ui/entity.js
index 6a1cde38d05721b1ee79765ad5900a282042d74d..b24a874e6a93f027a644bc4c80c70f5a9a0fdbad 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -123,7 +123,9 @@ IPA.facet = function (spec) {
         that.container.css('display', 'none');
     };
 
-    that.load = function() {
+    that.load = function(data) {
+        that.data = data;
+        that.header.load(data);
     };
 
     that.is_dirty = function() {
@@ -140,13 +142,14 @@ IPA.facet = function (spec) {
         details.append('<p>'+error_thrown.message+'</p>');
     };
 
-    that.redirect_on_error = function(){
-        var current_entity = that.entity;
-        while (current_entity.containing_entity){
-            current_entity = current_entity.containing_entity;
+    that.redirect = function() {
+        var entity = that.entity;
+        while (entity.containing_entity) {
+            entity = entity.containing_entity;
         }
+
         IPA.nav.show_page(
-            current_entity.name,
+            entity.name,
             that.entity.redirect_facet);
     };
 
@@ -157,11 +160,10 @@ IPA.facet = function (spec) {
 
         /*If the error is in talking to the server, don't attempt to redirect,
           as there is nothing any other facet can do either. */
-        if (that.entity.redirect_facet )
-        {
-            for (var i =0; i <  redirect_errors.length; i += 1){
-                if (error_thrown.name ===  redirect_errors[i]){
-                    that.redirect_on_error();
+        if (that.entity.redirect_facet) {
+            for (var i=0; i<redirect_errors.length; i++) {
+                if (error_thrown.name ===  redirect_errors[i]) {
+                    that.redirect();
                     return;
                 }
             }
@@ -178,6 +180,7 @@ IPA.facet = function (spec) {
     that.facet_setup = that.setup;
     that.facet_show = that.show;
     that.facet_hide = that.hide;
+    that.facet_load = that.load;
 
     return that;
 };
@@ -251,6 +254,7 @@ IPA.facet_header = function(spec) {
     that.create_facet_link = function(container, other_facet) {
 
         var li = $('<li/>', {
+            name: other_facet.name,
             title: other_facet.name,
             click: function() {
                 if (li.hasClass('entity-facet-disabled')) {
@@ -273,11 +277,12 @@ IPA.facet_header = function(spec) {
     that.create_facet_group = function(container, facet_group) {
 
         var section = $('<span/>', {
+            name: facet_group.name,
             'class': 'facet-group'
         }).appendTo(container);
 
         $('<div/>', {
-            'class': 'facet-group-name',
+            'class': 'facet-group-label',
             text: facet_group.label
         }).appendTo(section);
 
@@ -308,12 +313,7 @@ IPA.facet_header = function(spec) {
             $('<a/>', {
                 text: that.facet.back_link_text,
                 click: function() {
-                    var current_entity = that.facet.entity;
-                    while(current_entity.containing_entity){
-                        current_entity = current_entity.containing_entity;
-                    }
-
-                    IPA.nav.show_page(current_entity.name, 'search');
+                    that.facet.redirect();
                     return false;
                 }
             }).appendTo(that.back_link);
@@ -347,6 +347,29 @@ IPA.facet_header = function(spec) {
         }
     };
 
+    that.load = function(data) {
+        if (!that.facet.disable_facet_tabs) {
+            var facet_groups = that.facet.entity.facet_groups.values;
+            for (var i=0; i<facet_groups.length; i++) {
+                var facet_group = facet_groups[i];
+                var span = $('.facet-group[name='+facet_group.name+']', that.facet_tabs);
+
+                var facets = facet_group.facets.values;
+                for (var j=0; j<facets.length; j++) {
+                    var facet = facets[j];
+                    var link = $('li[name='+facet.name+'] a', span);
+
+                    var values = data[facet.name];
+                    if (values) {
+                        link.text(facet.label+' ('+values.length+')');
+                    } else {
+                        link.text(facet.label);
+                    }
+                }
+            }
+        }
+    };
+
     return that;
 };
 
diff --git a/install/ui/ipa.css b/install/ui/ipa.css
index b9801b8c9185fafaa3ce2cd7acb7f3f7bd8ee3fc..b2a9ffe0ca287ea1a914b9cb7efe4f09404465ff 100644
--- a/install/ui/ipa.css
+++ b/install/ui/ipa.css
@@ -489,7 +489,7 @@ div.tabs {
     height: 100%;
 }
 
-.facet-group-name {
+.facet-group-label {
     height: 20px;
 }
 
@@ -504,7 +504,7 @@ div.tabs {
 .facet-tab li {
     display: inline-block;
     position: relative;
-	padding-right: 5px;
+	padding-right: 1px;
 }
 
 .facet-tab li a {
diff --git a/install/ui/search.js b/install/ui/search.js
index 33f6b8bb65eaaa1a10104a109ca4dc7c326f506f..382e26bc57aaf9f062c732d61cf1631513bcc013 100644
--- a/install/ui/search.js
+++ b/install/ui/search.js
@@ -361,15 +361,7 @@ IPA.nested_search_facet = function(spec) {
         var pkey = $.bbq.getState(that.entity.name+'-pkey');
 
         if ((!pkey) && (that.entity.redirect_facet)) {
-
-            var current_entity = that.entity;
-            while (current_entity.containing_entity){
-                current_entity = current_entity.containing_entity;
-            }
-
-            IPA.nav.show_page(
-                current_entity.name,
-                that.entity.redirect_facet);
+            that.redirect();
             return;
         }
 
-- 
1.7.5.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to