diff options
-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 ca08770fe..69b9cd1c3 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 a65c60fd3..5523993f4 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 6e18b0228..89a323dd5 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); |