From 392809f9847eee21c8022f53153463033cd53966 Mon Sep 17 00:00:00 2001 From: Petr Vobornik Date: Jul 03 2015 08:42:16 +0000 Subject: 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 Reviewed-By: Tomas Babej --- 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 -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);