From 162f542150a05edc90221677590fb6ad5ee09bb0 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 24 Jun 2020 21:12:48 +0000 Subject: [PATCH] --- ayanova/src/api/translation.js | 38 ++++++++++++++++++++++++++- ayanova/src/store.js | 2 +- ayanova/src/views/adm-translation.vue | 3 +++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ayanova/src/api/translation.js b/ayanova/src/api/translation.js index c1f7f0dd..bcd233dd 100644 --- a/ayanova/src/api/translation.js +++ b/ayanova/src/api/translation.js @@ -1,6 +1,42 @@ /* ZZeslint-disable */ //AyaNova Translation related utilities export default { + //////////////////////////////// + // Update the local cache + // + // + async updateCache(editedTranslation) { + //This function is only called if there is a requirement to refresh the local cache + //either they just changed translations and saved it in user settings + //or they just edited a translation and saved it in translation editor and it's also their own local translation + + if (editedTranslation) { + //iterate the keys that are cached and set them from whatever is in editedTranslation for that key + window.$gz._.forOwn(window.$gz.store.state.translationText, function( + cacheval, + cachekey + ) { + //find match + let display = window.$gz._.find(editedTranslation.translationItems, { + key: cachekey + }).display; + window.$gz.store.commit("setTranslationText", { + key: cachekey, + value: display + }); + }); + } else { + //gather up the keys that are cached and fetch the latest and then replace them + } + + //if editedTranslation is empty that means just fetch the existing ones freshly again + //refetch all the keys and update + //if edited translation is not empty that means update cache from the editedTranslation if it's the same one as is currently in use + //check if current translation is the same one passed in + //if it is, update all the currently cached local keys with the copy passed + + //TODO: call this from translation editor if same (add fetch for in use translation for editor initform) and from local settings on change of translation + }, get(key) { //no translation for Wiki if (key == "Wiki") { @@ -35,7 +71,7 @@ export default { transData.data.forEach(function commitFetchedTranslationItemToStore( item ) { - window.$gz.store.commit("addTranslationText", item); + window.$gz.store.commit("setTranslationText", item); }); return resolve(); }); diff --git a/ayanova/src/store.js b/ayanova/src/store.js index b793b6b2..3d1ec878 100644 --- a/ayanova/src/store.js +++ b/ayanova/src/store.js @@ -86,7 +86,7 @@ export default new Vuex.Store({ addNavItem(state, data) { state.navItems.push(data); }, - addTranslationText(state, data) { + setTranslationText(state, data) { state.translationText[data.key] = data.value; }, setFormCustomTemplateItem(state, data) { diff --git a/ayanova/src/views/adm-translation.vue b/ayanova/src/views/adm-translation.vue index 63dfeca4..be687def 100644 --- a/ayanova/src/views/adm-translation.vue +++ b/ayanova/src/views/adm-translation.vue @@ -333,6 +333,9 @@ export default { //PUT - only concurrency token is returned (**warning, if server changes object other fields then this needs to act more like POST above but is more efficient this way**) //Handle "put" of an existing record (UPDATE) vm.obj.concurrency = res.data.concurrency; + + //Update local copy of translations if that's the same one in use + await window.$gz.translation.updateCache(vm.obj); } //Update the form status