update
This commit is contained in:
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
import Vue from 'vue';
|
||||
import VueResource from 'vue-resource';
|
||||
import * as types from '@app/pages/translations/store/mutation-types';
|
||||
import {showGrowl} from '@app/utils/growl';
|
||||
|
||||
Vue.use(VueResource);
|
||||
|
||||
export const getTranslations = ({commit}) => {
|
||||
const url = window.data.translationUrl;
|
||||
Vue.http.get(url).then(
|
||||
(response) => {
|
||||
commit(types.SET_TRANSLATIONS, response.body);
|
||||
commit(types.APP_IS_READY);
|
||||
},
|
||||
(error) => {
|
||||
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const getCatalog = ({commit}, payload) => {
|
||||
commit(types.PRINCIPAL_LOADING, true);
|
||||
Vue.http
|
||||
.get(payload.url, {
|
||||
params: {
|
||||
page_size: payload.page_size,
|
||||
page_index: payload.page_index,
|
||||
},
|
||||
})
|
||||
.then(
|
||||
(response) => {
|
||||
commit(types.SET_TOTAL_PAGES, response.headers.get('Total-Pages'));
|
||||
commit(types.SET_CATALOG, response.body);
|
||||
commit(types.PRINCIPAL_LOADING, false);
|
||||
},
|
||||
(error) => {
|
||||
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const getDomainsTree = ({commit}, payload) => {
|
||||
const url = window.data.domainsTreeUrl;
|
||||
const params = {};
|
||||
|
||||
commit(types.SIDEBAR_LOADING, true);
|
||||
commit(types.PRINCIPAL_LOADING, true);
|
||||
|
||||
if (payload.store.getters.searchTags.length) {
|
||||
params.search = payload.store.getters.searchTags;
|
||||
}
|
||||
|
||||
Vue.http
|
||||
.get(url, {
|
||||
params,
|
||||
})
|
||||
.then(
|
||||
(response) => {
|
||||
commit(types.SET_DOMAINS_TREE, response.body);
|
||||
commit(types.SIDEBAR_LOADING, false);
|
||||
commit(types.RESET_CURRENT_DOMAIN);
|
||||
},
|
||||
(error) => {
|
||||
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const refreshCounts = ({commit}, payload) => {
|
||||
const url = window.data.domainsTreeUrl;
|
||||
const params = {};
|
||||
|
||||
if (payload.store.getters.searchTags.length) {
|
||||
params.search = payload.store.getters.searchTags;
|
||||
}
|
||||
|
||||
Vue.http
|
||||
.get(url, {
|
||||
params,
|
||||
})
|
||||
.then(
|
||||
(response) => {
|
||||
commit(types.DECREASE_CURRENT_DOMAIN_TOTAL_MISSING_TRANSLATIONS, payload.successfullySaved);
|
||||
commit(types.SET_DOMAINS_TREE, response.body);
|
||||
},
|
||||
(error) => {
|
||||
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const saveTranslations = ({commit}, payload) => {
|
||||
const {url} = payload;
|
||||
const {translations} = payload;
|
||||
|
||||
Vue.http
|
||||
.post(url, {
|
||||
translations,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
payload.store.dispatch('refreshCounts', {
|
||||
successfullySaved: translations.length,
|
||||
store: payload.store,
|
||||
});
|
||||
commit(types.RESET_MODIFIED_TRANSLATIONS);
|
||||
return showGrowl('success', 'Translations successfully updated');
|
||||
},
|
||||
(error) => {
|
||||
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
/* eslint-disable-next-line no-unused-vars */
|
||||
export const resetTranslation = ({commit}, payload) => {
|
||||
const {url} = payload;
|
||||
const {translations} = payload;
|
||||
|
||||
Vue.http
|
||||
.post(url, {
|
||||
translations,
|
||||
})
|
||||
.then(
|
||||
() => {
|
||||
showGrowl('success', 'Translations successfully reset');
|
||||
},
|
||||
(error) => {
|
||||
showGrowl('error', error.bodyText ? JSON.parse(error.bodyText).error : error.statusText);
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const updatePageIndex = ({commit}, pageIndex) => {
|
||||
commit(types.SET_PAGE_INDEX, pageIndex);
|
||||
};
|
||||
|
||||
export const updateCurrentDomain = ({commit}, currentDomain) => {
|
||||
commit(types.SET_CURRENT_DOMAIN, currentDomain);
|
||||
};
|
||||
|
||||
export const updatePrincipalLoading = ({commit}, principalLoading) => {
|
||||
commit(types.PRINCIPAL_LOADING, principalLoading);
|
||||
};
|
||||
|
||||
export const updateSearch = ({commit}, searchTags) => {
|
||||
commit(types.SEARCH_TAGS, searchTags);
|
||||
};
|
||||
108
iadmin/themes/new-theme/js/app/pages/translations/store/index.js
Normal file
108
iadmin/themes/new-theme/js/app/pages/translations/store/index.js
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
import Vue from 'vue';
|
||||
import Vuex from 'vuex';
|
||||
import _ from 'lodash';
|
||||
import * as actions from './actions';
|
||||
import mutations from './mutations';
|
||||
|
||||
Vue.use(Vuex);
|
||||
|
||||
// root state object.
|
||||
|
||||
const state = {
|
||||
pageIndex: 1,
|
||||
totalPages: 0,
|
||||
translationsPerPage: 20,
|
||||
currentDomain: '',
|
||||
translations: {
|
||||
data: {},
|
||||
info: {},
|
||||
},
|
||||
catalog: {
|
||||
data: {},
|
||||
info: {},
|
||||
},
|
||||
domainsTree: [],
|
||||
totalMissingTranslations: 0,
|
||||
totalTranslations: 0,
|
||||
currentDomainTotalTranslations: 0,
|
||||
currentDomainTotalMissingTranslations: 0,
|
||||
isReady: false,
|
||||
sidebarLoading: true,
|
||||
principalLoading: true,
|
||||
searchTags: [],
|
||||
modifiedTranslations: [],
|
||||
};
|
||||
|
||||
// getters are functions
|
||||
const getters = {
|
||||
totalPages(rootState) {
|
||||
return rootState.totalPages;
|
||||
},
|
||||
pageIndex(rootState) {
|
||||
return rootState.pageIndex;
|
||||
},
|
||||
currentDomain(rootState) {
|
||||
return rootState.currentDomain;
|
||||
},
|
||||
translations(rootState) {
|
||||
return rootState.translations;
|
||||
},
|
||||
catalog(rootState) {
|
||||
return rootState.catalog;
|
||||
},
|
||||
domainsTree() {
|
||||
function convert(domains) {
|
||||
domains.forEach((domain) => {
|
||||
domain.children = _.values(domain.children);
|
||||
domain.extraLabel = domain.total_missing_translations;
|
||||
domain.dataValue = domain.domain_catalog_link;
|
||||
domain.warning = Boolean(domain.total_missing_translations);
|
||||
domain.disable = !domain.total_translations;
|
||||
domain.id = domain.full_name;
|
||||
convert(domain.children);
|
||||
});
|
||||
return domains;
|
||||
}
|
||||
|
||||
return convert(state.domainsTree);
|
||||
},
|
||||
isReady(rootState) {
|
||||
return rootState.isReady;
|
||||
},
|
||||
searchTags(rootState) {
|
||||
return rootState.searchTags;
|
||||
},
|
||||
};
|
||||
|
||||
// A Vuex instance is created by combining the state, mutations, actions,
|
||||
// and getters.
|
||||
export default new Vuex.Store({
|
||||
state,
|
||||
getters,
|
||||
actions,
|
||||
mutations,
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
export const SET_TRANSLATIONS = 'SET_TRANSLATIONS';
|
||||
export const SET_CATALOG = 'SET_CATALOG';
|
||||
export const SET_DOMAINS_TREE = 'SET_DOMAINS_TREE';
|
||||
export const APP_IS_READY = 'APP_IS_READY';
|
||||
export const SET_TOTAL_PAGES = 'SET_TOTAL_PAGES';
|
||||
export const SET_PAGE_INDEX = 'SET_PAGE_INDEX';
|
||||
export const SET_CURRENT_DOMAIN = 'SET_CURRENT_DOMAIN';
|
||||
export const RESET_CURRENT_DOMAIN = 'RESET_CURRENT_DOMAIN';
|
||||
export const SIDEBAR_LOADING = 'SIDEBAR_LOADING';
|
||||
export const PRINCIPAL_LOADING = 'PRINCIPAL_LOADING';
|
||||
export const SEARCH_TAGS = 'SEARCH_TAGS';
|
||||
export const DECREASE_CURRENT_DOMAIN_TOTAL_MISSING_TRANSLATIONS = 'DECREASE_CURRENT_DOMAIN_TOTAL_MISSING_TRANSLATIONS';
|
||||
export const RESET_MODIFIED_TRANSLATIONS = 'RESET_MODIFIED_TRANSLATIONS';
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* Copyright since 2007 PrestaShop SA and Contributors
|
||||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This source file is subject to the Open Software License (OSL 3.0)
|
||||
* that is bundled with this package in the file LICENSE.md.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* https://opensource.org/licenses/OSL-3.0
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@prestashop.com so we can send you a copy immediately.
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
||||
* versions in the future. If you wish to customize PrestaShop for your
|
||||
* needs please refer to https://devdocs.prestashop.com/ for more information.
|
||||
*
|
||||
* @author PrestaShop SA and Contributors <contact@prestashop.com>
|
||||
* @copyright Since 2007 PrestaShop SA and Contributors
|
||||
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
|
||||
*/
|
||||
|
||||
import * as types from './mutation-types';
|
||||
|
||||
export default {
|
||||
[types.SET_TRANSLATIONS](state, translations) {
|
||||
translations.data.forEach((t) => {
|
||||
state.translations[t.translation_id] = t.name;
|
||||
});
|
||||
},
|
||||
[types.SET_CATALOG](state, catalog) {
|
||||
state.catalog = catalog;
|
||||
},
|
||||
[types.SET_DOMAINS_TREE](state, domainsTree) {
|
||||
state.totalMissingTranslations = domainsTree.data.tree.total_missing_translations;
|
||||
state.totalTranslations = domainsTree.data.tree.total_translations;
|
||||
state.domainsTree = domainsTree.data.tree.children;
|
||||
},
|
||||
[types.APP_IS_READY](state) {
|
||||
state.isReady = true;
|
||||
},
|
||||
[types.SET_TOTAL_PAGES](state, totalPages) {
|
||||
state.totalPages = Number(totalPages);
|
||||
},
|
||||
[types.SET_PAGE_INDEX](state, pageIndex) {
|
||||
state.pageIndex = pageIndex;
|
||||
},
|
||||
[types.SET_CURRENT_DOMAIN](state, currentDomain) {
|
||||
state.currentDomain = currentDomain.full_name;
|
||||
state.currentDomainTotalTranslations = currentDomain.total_translations;
|
||||
state.currentDomainTotalMissingTranslations = currentDomain.total_missing_translations;
|
||||
},
|
||||
[types.RESET_CURRENT_DOMAIN](state) {
|
||||
state.currentDomain = '';
|
||||
state.currentDomainTotalTranslations = 0;
|
||||
state.currentDomainTotalMissingTranslations = 0;
|
||||
},
|
||||
[types.SIDEBAR_LOADING](state, isLoading) {
|
||||
state.sidebarLoading = isLoading;
|
||||
},
|
||||
[types.PRINCIPAL_LOADING](state, isLoading) {
|
||||
state.principalLoading = isLoading;
|
||||
},
|
||||
[types.SEARCH_TAGS](state, searchTags) {
|
||||
state.searchTags = searchTags;
|
||||
},
|
||||
[types.DECREASE_CURRENT_DOMAIN_TOTAL_MISSING_TRANSLATIONS](state, successfullySaved) {
|
||||
state.currentDomainTotalMissingTranslations -= successfullySaved;
|
||||
},
|
||||
[types.RESET_MODIFIED_TRANSLATIONS](state) {
|
||||
state.modifiedTranslations = [];
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user