Created
March 8, 2018 16:59
-
-
Save godmar/cbab07e718784643f1e7d5edf0006dd8 to your computer and use it in GitHub Desktop.
This patch would link menu items to navigation states. If a state is already defined, the menu item would be { state: "nameofstate", label: "Menu Label" } and then the state would be looked up and the item's path set. Otherwise, it's backwards compatible with what you had before.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/app/app.js b/src/app/app.js | |
index 160ad4a..62e6e13 100644 | |
--- a/src/app/app.js | |
+++ b/src/app/app.js | |
@@ -359,25 +359,29 @@ import login_template from '../templates/login.html'; | |
}); | |
} | |
- config.nav_targets.topbar.forEach(function (item) { | |
- // add the routes from config. | |
- let state_body = {name: item.label.toLowerCase(), url: item.path, templateUrl: item.templateUrl}; | |
- if (item.needauthentication) { | |
- state_body.parent = 'authentication'; | |
- state_body.needsAuth = true; | |
- } | |
- if (!$stateRegistry.get(state_body.name)) | |
+ function addStateFromMenuItem(item, needsAuthentication) { | |
+ let state_name = item.state || item.label.toLowerCase(); // fall back to Eric's hack | |
+ let state = $stateRegistry.get(state_name); | |
+ if (!state) { | |
+ let state_body = {name: state_name, url: item.path, templateUrl: item.templateUrl}; | |
+ if (needsAuthentication) { | |
+ state_body.parent = 'authentication'; | |
+ state_body.needsAuth = true; | |
+ } | |
$stateRegistry.register(state_body); | |
+ } else { | |
+ // if state is already registered, place the URL in the path attribute of the item | |
+ item.path = state.url.replace(/\?.*/, ""); // trim query part of URL | |
+ } | |
+ } | |
+ | |
+ // add the routes for the menu items listed in config. | |
+ config.nav_targets.topbar.forEach(function (item) { | |
+ addStateFromMenuItem(item, item.needauthentication); | |
}); | |
config.nav_targets.dropdowns.forEach(function (dropdownmenu) { | |
dropdownmenu.entries.forEach(function (item) { | |
- let state_body = {name: item.label.toLowerCase(), url: item.path, templateUrl: item.templateUrl}; | |
- if (dropdownmenu.needauthentication || item.needauthentication) { | |
- state_body.parent = 'authentication'; | |
- state_body.needsAuth = true; | |
- } | |
- if (!$stateRegistry.get(state_body.name)) | |
- $stateRegistry.register(state_body); | |
+ addStateFromMenuItem(item, dropdownmenu.needauthentication || item.needauthentication); | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am also willing to break with backward compatibility if it makes it more readable in the future.
One method is to always force the state to be specified in these navbar targets, this would force us to be explicit with all of the states and not have the label.toLowerCase() hack.