From 86b2938879a061ded0d3756559007ea66c419804 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 13 Nov 2018 21:59:51 +0000 Subject: [PATCH] --- app/ayanova/src/api/apiutil.js | 2 +- app/ayanova/src/api/locale.js | 6 +++--- app/ayanova/src/store.js | 8 ++++++-- app/ayanova/src/utils/authUtil.js | 4 ++-- app/ayanova/src/utils/initialize.js | 26 ++++++++++++-------------- devdocs/coding-standards.txt | 6 ++++-- devdocs/todo.txt | 1 - 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/app/ayanova/src/api/apiutil.js b/app/ayanova/src/api/apiutil.js index 1b30dde1..8376fd1e 100644 --- a/app/ayanova/src/api/apiutil.js +++ b/app/ayanova/src/api/apiutil.js @@ -1,5 +1,5 @@ import logger from "../utils/logit"; -import { getToken } from "../utils/authUtil"; +import { getToken } from "../utils/authutil"; export default { status(response) { diff --git a/app/ayanova/src/api/locale.js b/app/ayanova/src/api/locale.js index 59d8ece9..03efcab5 100644 --- a/app/ayanova/src/api/locale.js +++ b/app/ayanova/src/api/locale.js @@ -24,13 +24,13 @@ Methods var lt = {}; export default { - Get(key) { + get(key) { if (!_.has(lt, key)) { return "?" + key + "?"; } return lt[key]; }, - Fetch(keys) { + fetch(keys) { return new Promise(function(resolve, reject) { //step 1: build an array of keys that we don't have already var NeedIt = []; @@ -67,7 +67,7 @@ export default { }); }); }, - ClearCache() { + clearCache() { lt = {}; } }; diff --git a/app/ayanova/src/store.js b/app/ayanova/src/store.js index a12b3908..de84d19b 100644 --- a/app/ayanova/src/store.js +++ b/app/ayanova/src/store.js @@ -12,16 +12,20 @@ export default new Vuex.Store({ navItems: [] }, mutations: { - authenticated(state, data) { + setAuthentication(state, data) { // mutate state state.authenticated = data.authenticated; state.userId = data.userId; state.roles = data.roles; }, - notAuthenticated(state) { + clearAuthentication(state) { state.authenticated = false; state.userId = 0; state.roles = 0; + state.navItems = []; + }, + addNavItem(state, data) { + state.navItems.push(data); } }, actions: {} diff --git a/app/ayanova/src/utils/authUtil.js b/app/ayanova/src/utils/authUtil.js index 87a988c5..4f5045e0 100644 --- a/app/ayanova/src/utils/authUtil.js +++ b/app/ayanova/src/utils/authUtil.js @@ -32,7 +32,7 @@ export function processLogin(response) { setToken(response.data.token); //Put app relevant items into vuex store so app can use them - store.commit("authenticated", { + store.commit("setAuthentication", { authenticated: true, userId: Number(token.id), roles: token["ayanova/roles"] @@ -47,7 +47,7 @@ export function processLogin(response) { export function processLogout() { logger.log("Logout"); - store.commit("notAuthenticated"); + store.commit("clearAuthentication"); clearToken(); //router.go('/'); } diff --git a/app/ayanova/src/utils/initialize.js b/app/ayanova/src/utils/initialize.js index 8d4fe05b..98557e06 100644 --- a/app/ayanova/src/utils/initialize.js +++ b/app/ayanova/src/utils/initialize.js @@ -5,7 +5,7 @@ import roles from "./roles"; import lt from "../api/locale"; function addNavItem(title, icon, route) { - store.state.navItems.push({ + store.commit("addNavItem", { title, icon, route @@ -16,13 +16,11 @@ function addNavItem(title, icon, route) { // Initialize the app // on change of authentication status export default function initialize() { - //clear the nav items either way - store.state.navItems = []; //clear the locale text cache - lt.ClearCache(); + lt.clearCache(); if (store.state.authenticated) { //fetch the required localized text keys into the cache - lt.Fetch([ + lt.fetch([ "Home", "Service", "Dispatch", @@ -36,7 +34,7 @@ export default function initialize() { .then(function() { //put nav items into store //Everyone has a home - addNavItem(lt.Get("Home"), "home", "/"); + addNavItem(lt.get("Home"), "home", "/"); if ( roles.hasRole(roles.AuthorizationRoles.TechLimited) || @@ -44,26 +42,26 @@ export default function initialize() { roles.hasRole(roles.AuthorizationRoles.SubContractorLimited) || roles.hasRole(roles.AuthorizationRoles.SubContractorFull) ) { - addNavItem(lt.Get("Service"), "toolbox", "/service"); + addNavItem(lt.get("Service"), "toolbox", "/service"); } if ( roles.hasRole(roles.AuthorizationRoles.DispatchLimited) || roles.hasRole(roles.AuthorizationRoles.DispatchFull) ) { - addNavItem(lt.Get("Dispatch"), "shipping-fast", "/dispatch"); + addNavItem(lt.get("Dispatch"), "shipping-fast", "/dispatch"); } if ( roles.hasRole(roles.AuthorizationRoles.InventoryLimited) || roles.hasRole(roles.AuthorizationRoles.InventoryFull) ) { - addNavItem(lt.Get("Inventory"), "dolly", "/inventory"); + addNavItem(lt.get("Inventory"), "dolly", "/inventory"); } if (roles.hasRole(roles.AuthorizationRoles.AccountingFull)) { addNavItem( - lt.Get("Accounting"), + lt.get("Accounting"), "file-invoice-dollar", "/accounting" ); @@ -73,19 +71,19 @@ export default function initialize() { roles.hasRole(roles.AuthorizationRoles.BizAdminLimited) || roles.hasRole(roles.AuthorizationRoles.BizAdminFull) ) { - addNavItem(lt.Get("Administration"), "user-tie", "/admin"); + addNavItem(lt.get("Administration"), "user-tie", "/admin"); } if ( roles.hasRole(roles.AuthorizationRoles.OpsAdminFull) || roles.hasRole(roles.AuthorizationRoles.OpsAdminLimited) ) { - addNavItem(lt.Get("Operations"), "cogs", "ops"); + addNavItem(lt.get("Operations"), "cogs", "ops"); } //Everyone can see about and logout - addNavItem(lt.Get("HelpAboutAyaNova"), "info-circle", "/about"); - addNavItem(lt.Get("Logout"), "sign-out-alt", "/login"); + addNavItem(lt.get("HelpAboutAyaNova"), "info-circle", "/about"); + addNavItem(lt.get("Logout"), "sign-out-alt", "/login"); }) .catch(function(error) { logger.log("Initialize::() -> error", error); diff --git a/devdocs/coding-standards.txt b/devdocs/coding-standards.txt index 3c238a9a..0ed58c95 100644 --- a/devdocs/coding-standards.txt +++ b/devdocs/coding-standards.txt @@ -28,8 +28,10 @@ Localized text - All text prsented by the server will be a locale key only and i - Ops logs, Metrics, event logs: these items and any other future pre-generated text items will be localized at the server according to the logged in users' locale - - +JAVASCRIPT +(mostly using AirBNB standard but using Google standard for naming things) +https://google.github.io/styleguide/javascriptguide.xml?showone=Naming#Naming +In general, use functionNamesLikeThis, variableNamesLikeThis, ClassNamesLikeThis, EnumNamesLikeThis, methodNamesLikeThis, CONSTANT_VALUES_LIKE_THIS, foo.namespaceNamesLikeThis.bar, and filenameslikethis.js. OLDER STUFF =-=-=-=-=-= diff --git a/devdocs/todo.txt b/devdocs/todo.txt index 4d6781f1..4b1651d3 100644 --- a/devdocs/todo.txt +++ b/devdocs/todo.txt @@ -32,7 +32,6 @@ WEEK OF 2018-11-12 - RAVEN shell start work. YAY! NEXT UP / CURRENTLY WORKING ON: - - Clean up the login form to use graphics and no text - lookup naming guidelines for javascript functions (capitalized?) and fixup the code and stick to it. - Look over the (now two) api calls and look for optimization and code shrinkage / de-duplication - Move on to the next thing (build and post?)