From a31093d50df2952f666964e7aba5f83258933b04 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 13 Nov 2018 22:44:16 +0000 Subject: [PATCH] --- app/ayanova/src/api/locale.js | 21 +++++-------------- app/ayanova/src/store.js | 9 ++++++-- .../src/utils/{authUtil.js => authutil.js} | 0 app/ayanova/src/utils/initialize.js | 2 -- 4 files changed, 12 insertions(+), 20 deletions(-) rename app/ayanova/src/utils/{authUtil.js => authutil.js} (100%) diff --git a/app/ayanova/src/api/locale.js b/app/ayanova/src/api/locale.js index 2c771421..31efbde7 100644 --- a/app/ayanova/src/api/locale.js +++ b/app/ayanova/src/api/locale.js @@ -1,25 +1,22 @@ /* xeslint-disable */ +import store from "../store"; import config from "../utils/config"; import api from "./apiutil"; import _ from "../utils/libs/core.min.js"; -//Keep the localized text keys here temporarily -//TODO: rehydrate on page refresh / put in sessionstorage -var lt = {}; - export default { get(key) { - if (!_.has(lt, key)) { + if (!_.has(store.state.localeText, key)) { return "?" + key + "?"; } - return lt[key]; + return store.state.localeText[key]; }, fetch(keys) { return new Promise(function(resolve, reject) { //step 1: build an array of keys that we don't have already var NeedIt = []; for (var i = 0; i < keys.length; i++) { - if (!_.has(lt, keys[i])) { + if (!_.has(store.state.localeText, keys[i])) { NeedIt.push(keys[i]); } } @@ -31,18 +28,13 @@ export default { method: "post", mode: "cors", headers: api.AuthorizedHeaders(), - // headers: { - // Accept: "application/json, text/plain, */*", - // "Content-Type": "application/json", - // Authorization: "Bearer " + getToken() - // }, body: JSON.stringify(NeedIt) }) .then(api.status) .then(api.json) .then(response => { _.forEach(response.data, function(item) { - lt[item.key] = item.value; + store.commit("addLocaleText", item); }); resolve(); }) @@ -50,8 +42,5 @@ export default { reject(error); }); }); - }, - clearCache() { - lt = {}; } }; diff --git a/app/ayanova/src/store.js b/app/ayanova/src/store.js index a7ce28e8..41598fab 100644 --- a/app/ayanova/src/store.js +++ b/app/ayanova/src/store.js @@ -11,23 +11,28 @@ export default new Vuex.Store({ apiUrl: "http://localhost:7575/api/v8.0/", userId: 0, roles: 0, + localeText: {}, navItems: [] }, mutations: { - setAuthentication(state, data) { + login(state, data) { // mutate state state.authenticated = data.authenticated; state.userId = data.userId; state.roles = data.roles; }, - clearAuthentication(state) { + logout(state) { state.authenticated = false; state.userId = 0; state.roles = 0; state.navItems = []; + state.localeText = []; }, addNavItem(state, data) { state.navItems.push(data); + }, + addLocaleText(state, data) { + state.localeText[data.key] = data.value; } }, actions: {} diff --git a/app/ayanova/src/utils/authUtil.js b/app/ayanova/src/utils/authutil.js similarity index 100% rename from app/ayanova/src/utils/authUtil.js rename to app/ayanova/src/utils/authutil.js diff --git a/app/ayanova/src/utils/initialize.js b/app/ayanova/src/utils/initialize.js index 98557e06..1e65d421 100644 --- a/app/ayanova/src/utils/initialize.js +++ b/app/ayanova/src/utils/initialize.js @@ -16,8 +16,6 @@ function addNavItem(title, icon, route) { // Initialize the app // on change of authentication status export default function initialize() { - //clear the locale text cache - lt.clearCache(); if (store.state.authenticated) { //fetch the required localized text keys into the cache lt.fetch([