On 06/29/2011 12:52 PM, Endi Sukma Dewata wrote:
On 6/29/2011 11:30 AM, Adam Young wrote:
On 06/29/2011 10:34 AM, Adam Young wrote:
On 06/29/2011 09:37 AM, Adam Young wrote:
Better solution than the algorithm in 256 for nested entities.
Changes for Hyphen and pkey names

Some issues:

1. This statement will store undefined values into url_state:

       url_state[key_name] = state[key_name];

   We need to check whether the state[key_name] is undefined.
   To test, open the UI, click the 'User Group' tab.

2. The following line should be located outside the for loop that
   iterates through the key names for that entity:

       current_entity = current_entity.containing_entity;

   This will cause a problem when there are more than 1 key name.

3. Optionally, the get_key_names() could just return 'pkey' instead
   of the full '<entity name>-pkey'. The navigation code can add the
   prefix.


From ed527d9a3c933e43fe009f811d35b8d682b461f4 Mon Sep 17 00:00:00 2001
From: Adam Young <[email protected]>
Date: Wed, 29 Jun 2011 09:26:49 -0400
Subject: [PATCH] containing entity pkeys

Instead of looking for a match on the entity name, use the nesting structure
of containing entites to grab their pkeys.

Code review fixes

https://fedorahosted.org/freeipa/ticket/674
---
 install/ui/entity.js     |    7 ++++++-
 install/ui/navigation.js |   30 ++++++++++++++++++++++++------
 2 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/install/ui/entity.js b/install/ui/entity.js
index c04f85d6de4815c9707513d787cadc85e361ce23..2188e041765479e0b7078e2eb6a2295983be84cc 100644
--- a/install/ui/entity.js
+++ b/install/ui/entity.js
@@ -597,7 +597,12 @@ IPA.entity = function (spec) {
         pkey.unshift(IPA.nav.get_state(current_entity.name+'-pkey'));
         return pkey;
     };
-
+    /* most entites only require -pkey for their primary keys, but some
+       are more specific.  This call allows those entites a place
+       to override the other parameters. */
+    that.get_key_names = function() {
+        return [that.name + '-pkey'];
+    }
 
     that.entity_init = that.init;
 
diff --git a/install/ui/navigation.js b/install/ui/navigation.js
index d0b45cc3ca285d9715c919d3060736c614dd8e03..9bcb20f057606f57a95528642bdb79b0de640959 100644
--- a/install/ui/navigation.js
+++ b/install/ui/navigation.js
@@ -115,14 +115,32 @@ IPA.navigation = function(spec) {
         while(state[key]){
             var value = state[key];
             url_state[key] = value;
-            var entity = value;
-            for (var key2 in state){
-                if ((key2 === entity) || (key2.search('^'+entity) > -1)){
-                    url_state[key2] = state[key2];
-                }
-            }
             key = value;
         }
+
+        /*We are at the leaf node, which is the sleected entity.*/
+        var entity = value;
+        for (var key2 in state){
+            if ((key2 === entity) || (key2.search('^'+entity +'-') > -1)){
+                url_state[key2] = state[key2];
+            }
+        }
+
+        /*
+           Trace back up the nested entities for their pkeys as well
+        */
+        var current_entity = IPA.get_entity(entity);
+        while(current_entity !== null){
+            var key_names = current_entity.get_key_names();
+            for (var j = 0; j < key_names.length; j+= 1){
+                var key_name = key_names[j];
+                if (state[key_name]){
+                    url_state[key_name] = state[key_name];
+                }
+            }
+            current_entity = current_entity.containing_entity;
+        }
+
         $.bbq.pushState(url_state,2);
         return true;
     };
-- 
1.7.5.2

_______________________________________________
Freeipa-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to