diff options
author | Petr Vobornik <pvoborni@redhat.com> | 2015-06-26 10:34:37 +0200 |
---|---|---|
committer | Tomas Babej <tbabej@redhat.com> | 2015-07-03 10:42:16 +0200 |
commit | 392809f9847eee21c8022f53153463033cd53966 (patch) | |
tree | fa7776613f442f203ae9e8200e35eb5340999085 | |
parent | 8d8aa60dbd5fe294e5beb4aa837cbf9b44457d09 (diff) | |
download | freeipa-392809f9847eee21c8022f53153463033cd53966.zip freeipa-392809f9847eee21c8022f53153463033cd53966.tar.gz freeipa-392809f9847eee21c8022f53153463033cd53966.tar.xz |
webui: menu and navigation fixes
fixes:
1. When navigation is initiated from clicking and a link with hash, update
of facet state causes that subsequent click on a link with hash will be
ignored. Caused by a code which prevents infinite loop because of facet
state update. Now hash update is done only if it was really changed.
2. registered correct handler for standalone pages
3. fix selection of menu item where the items differ only in args. Chooses
the item with the most similar state to current facet.
https://fedorahosted.org/freeipa/ticket/3129
Reviewed-By: Martin Kosek <mkosek@redhat.com>
Reviewed-By: Tomas Babej <tbabej@redhat.com>
-rw-r--r-- | install/ui/src/freeipa/Application_controller.js | 31 | ||||
-rw-r--r-- | install/ui/src/freeipa/navigation/Router.js | 2 | ||||
-rw-r--r-- | install/ui/src/freeipa/navigation/routing.js | 4 |
3 files changed, 32 insertions, 5 deletions
diff --git a/install/ui/src/freeipa/Application_controller.js b/install/ui/src/freeipa/Application_controller.js index ca08770..69b9cd1 100644 --- a/install/ui/src/freeipa/Application_controller.js +++ b/install/ui/src/freeipa/Application_controller.js @@ -379,9 +379,36 @@ define([ items = this.menu.query({ parent: null }); } - // select first if (items.total) { - return items[0]; + if (items.total === 1) return items[0]; + + // select the menu item with the most similar state as the facet + var best = items[0]; + var best_score = 0; + var item, i, j, l, score; + var state = facet.state; + for (i=0, l=items.total; i<l; i++) { + item = items[i]; + score = 0; + if (item.pkeys && facet.get_pkeys) { + var pkeys = facet.get_pkeys(); + for (j=0, j=item.pkeys.length; j<l; j++) { + if (pkeys.indexOf(item.pkeys[j]) > -1) score++; + } + } + if (item.args) { + for (var name in item.args) { + if (!item.args.hasOwnProperty(name)) continue; + if (state[name] == item.args[name]) score++; + } + } + if (score > best_score) { + best_score = score; + best = item; + } + } + + return best; } }, diff --git a/install/ui/src/freeipa/navigation/Router.js b/install/ui/src/freeipa/navigation/Router.js index a65c60f..5523993 100644 --- a/install/ui/src/freeipa/navigation/Router.js +++ b/install/ui/src/freeipa/navigation/Router.js @@ -66,7 +66,6 @@ define(['dojo/_base/declare', */ ignore_next: false, - /** * Register a route-handler pair to a dojo.router * Handler will be run in context of this object @@ -111,6 +110,7 @@ define(['dojo/_base/declare', * @param {boolean} Whether to suppress following hash change handler */ update_hash: function(hash, ignore_change) { + if (window.location.hash === "#" + hash) return; this.ignore_next = !!ignore_change; router.go(hash); }, diff --git a/install/ui/src/freeipa/navigation/routing.js b/install/ui/src/freeipa/navigation/routing.js index 6e18b02..89a323d 100644 --- a/install/ui/src/freeipa/navigation/routing.js +++ b/install/ui/src/freeipa/navigation/routing.js @@ -166,7 +166,7 @@ var routing = { */ navigate_to_facet: function(facet, options) { var hash = this.create_hash(facet, options); - return this.router.navigate_to_hash(hash); + return this.router.navigate_to_hash(hash, facet); }, update_hash: function(facet, options) { @@ -494,7 +494,7 @@ routing.init = function(router) { var entity_n = new routing.EntityNavigator(); this.add_hash_creator(generic_hc); this.add_hash_creator(entity_hc); - this.add_route(this.routes, generic_rh); + this.add_route(this.page_routes, generic_rh); this.add_route(this.entity_routes, entity_rh); this.add_navigator(generic_n); this.add_navigator(entity_n); |