mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-26 00:54:27 +00:00
refactor fhcApi
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
console.warn('plugin/FhcAlert.js is DEPRECATED! Use plugins/FhcAlert.js instead.');
|
||||
/**
|
||||
* Copyright (C) 2022 fhcomplete.org
|
||||
*
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
console.warn('plugin/FhcApi.js is DEPRECATED! Use plugins/Api.js instead.');
|
||||
import FhcAlert from './FhcAlert.js';
|
||||
import FhcApiFactory from '../api/fhcapifactory.js';
|
||||
|
||||
@@ -5,9 +6,12 @@ import FhcApiFactory from '../api/fhcapifactory.js';
|
||||
export default {
|
||||
install: (app, options) => {
|
||||
if (app.config.globalProperties.$fhcApi) {
|
||||
/* Depricated Code start */
|
||||
if (options?.factory) {
|
||||
console.warn("$fhcApi is DEPRICATED!");
|
||||
app.config.globalProperties.$fhcApi.factory.addEndpoints(options.factory);
|
||||
}
|
||||
/* Depricated Code end */
|
||||
return;
|
||||
}
|
||||
app.use(FhcAlert);
|
||||
@@ -297,11 +301,31 @@ export default {
|
||||
}
|
||||
};
|
||||
|
||||
/* Depricated Code start */
|
||||
class FhcApiFactoryWrapper {
|
||||
constructor(factorypart, root) {
|
||||
if (root === undefined) {
|
||||
this.$fhcApi = app.config.globalProperties.$fhcApi;
|
||||
this.$fhcApi.factory = this;
|
||||
this.$fhcApi = {
|
||||
getUri(url) {
|
||||
console.warn('$fhcApi.factory is DEPRICATED!');
|
||||
return app.config.globalProperties.$fhcApi.getUri(url);
|
||||
},
|
||||
get(form, uri, params, config) {
|
||||
console.warn('$fhcApi.factory is DEPRICATED!');
|
||||
return app.config.globalProperties.$fhcApi.get(form, uri, params, config);
|
||||
},
|
||||
post(form, uri, data, config) {
|
||||
console.warn('$fhcApi.factory is DEPRICATED!');
|
||||
return app.config.globalProperties.$fhcApi.post(form, uri, data, config);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(this.$fhcApi, 'factory', {
|
||||
get() {
|
||||
console.warn('$fhcApi.factory is DEPRICATED!');
|
||||
return app.config.globalProperties.$fhcApi.factory;
|
||||
}
|
||||
});
|
||||
app.config.globalProperties.$fhcApi.factory = this;
|
||||
} else {
|
||||
Object.defineProperty(this, '$fhcApi', {
|
||||
get() {
|
||||
@@ -323,15 +347,19 @@ export default {
|
||||
}
|
||||
});
|
||||
});
|
||||
console.warn('$fhcApi.factory.addEndpoints() is DEPRICATED!');
|
||||
}
|
||||
}
|
||||
|
||||
const factory = new FhcApiFactoryWrapper(FhcApiFactory);
|
||||
if (options?.factory)
|
||||
if (options?.factory) {
|
||||
console.warn("$fhcApi is DEPRICATED!");
|
||||
factory.addEndpoints(options.factory);
|
||||
}
|
||||
|
||||
app.config.globalProperties.$fhcApi.factory = factory;
|
||||
|
||||
/* Depricated Code end */
|
||||
|
||||
app.provide('$fhcApi', app.config.globalProperties.$fhcApi);
|
||||
}
|
||||
};
|
||||
+23
-13
@@ -1,4 +1,7 @@
|
||||
console.warn('plugin/Phrasen.js is DEPRECATED! Use plugins/Phrasen.js instead.');
|
||||
import FhcApi from './FhcApi.js';
|
||||
import PluginsApi from '../plugins/Api.js';
|
||||
import ApiPhrasen from '../api/factory/phrasen.js';
|
||||
|
||||
const categories = Vue.reactive({});
|
||||
const loadingModules = {};
|
||||
@@ -27,26 +30,32 @@ function getValueForLoadedPhrase(category, phrase, params) {
|
||||
const phrasen = {
|
||||
user_language,
|
||||
user_locale,
|
||||
setLanguage(language, api) {
|
||||
setLanguage(language) {
|
||||
const catArray = Object.keys(categories)
|
||||
return api.factory.phrasen.setLanguage(catArray, language).then(res => {
|
||||
res.data.forEach(row => {
|
||||
categories[row.category][row.phrase] = row.text
|
||||
return this.config.globalProperties.$api
|
||||
.call(ApiPhrasen.setLanguage(catArray, language))
|
||||
.then(res => {
|
||||
res.data.forEach(row => {
|
||||
categories[row.category][row.phrase] = row.text
|
||||
})
|
||||
|
||||
// update the reactive data that holds the current active user_language
|
||||
user_language.value = language;
|
||||
|
||||
return res
|
||||
})
|
||||
|
||||
// update the reactive data that holds the current active user_language
|
||||
user_language.value = language;
|
||||
|
||||
return res
|
||||
})
|
||||
},
|
||||
loadCategory(category) {
|
||||
if (Array.isArray(category))
|
||||
return Promise.all(category.map(this.config.globalProperties
|
||||
.$p.loadCategory));
|
||||
const $fhcApi = this.config.globalProperties.$fhcApi;
|
||||
const $fhcApiFactory = this.config.globalProperties.$fhcApiFactory;
|
||||
if (!loadingModules[category])
|
||||
loadingModules[category] = this.config.globalProperties
|
||||
.$fhcApi.factory.phrasen.loadCategory(category)
|
||||
loadingModules[category] = this.config.globalProperties.$api
|
||||
.call(
|
||||
ApiPhrasen.loadCategory(category)
|
||||
)
|
||||
.then(res => res?.data ? extractCategory(res.data, category) : {})
|
||||
.then(res => {
|
||||
categories[category] = res;
|
||||
@@ -83,10 +92,11 @@ const phrasen = {
|
||||
export default {
|
||||
install(app, options) {
|
||||
app.use(FhcApi, options?.fhcApi || undefined);
|
||||
app.use(PluginsApi);
|
||||
app.config.globalProperties.$p = {
|
||||
t: phrasen.t,
|
||||
loadCategory: cat => phrasen.loadCategory.call(app, cat),
|
||||
setLanguage: phrasen.setLanguage,
|
||||
setLanguage: lang => phrasen.setLanguage.call(app, lang),
|
||||
user_language: user_language,
|
||||
user_locale,
|
||||
t_ref: phrasen.t_ref
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
console.warn('plugin/highchartsVue.js is DEPRECATED! Use plugins/highchartsVue.js instead.');
|
||||
function doCopy (copy, original, copyArray) {
|
||||
// Callback function to iterate on array or object elements
|
||||
function callback (value, key) {
|
||||
|
||||
Reference in New Issue
Block a user