code refactor
This commit is contained in:
@@ -4,6 +4,7 @@ import { defaultLanguage, allLanguages } from '@/locales/index.js';
|
|||||||
import datetime from '@/consts/datetime.js';
|
import datetime from '@/consts/datetime.js';
|
||||||
import timezone from '@/consts/timezone.js';
|
import timezone from '@/consts/timezone.js';
|
||||||
import currency from '@/consts/currency.js';
|
import currency from '@/consts/currency.js';
|
||||||
|
import statistics from '@/consts/statistics.js';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isString,
|
isString,
|
||||||
@@ -541,6 +542,66 @@ function getAllWeekDays(translateFn) {
|
|||||||
return allWeekDays;
|
return allWeekDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAllDateRanges(includeCustom, translateFn) {
|
||||||
|
const allDateRanges = [];
|
||||||
|
|
||||||
|
for (let dateRangeField in datetime.allDateRanges) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(datetime.allDateRanges, dateRangeField)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dateRangeType = datetime.allDateRanges[dateRangeField];
|
||||||
|
|
||||||
|
if (includeCustom || dateRangeType.type !== datetime.allDateRanges.Custom.type) {
|
||||||
|
allDateRanges.push({
|
||||||
|
type: dateRangeType.type,
|
||||||
|
displayName: translateFn(dateRangeType.name)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return allDateRanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllStatisticsChartDataTypes(translateFn) {
|
||||||
|
const allChartDataTypes = [];
|
||||||
|
|
||||||
|
for (const dataTypeField in statistics.allChartDataTypes) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(statistics.allChartDataTypes, dataTypeField)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chartDataType = statistics.allChartDataTypes[dataTypeField];
|
||||||
|
|
||||||
|
allChartDataTypes.push({
|
||||||
|
type: chartDataType.type,
|
||||||
|
displayName: translateFn(chartDataType.name)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return allChartDataTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAllStatisticsSortingTypes(translateFn) {
|
||||||
|
const allSortingTypes = [];
|
||||||
|
|
||||||
|
for (const sortingTypeField in statistics.allSortingTypes) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(statistics.allSortingTypes, sortingTypeField)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortingType = statistics.allSortingTypes[sortingTypeField];
|
||||||
|
|
||||||
|
allSortingTypes.push({
|
||||||
|
type: sortingType.type,
|
||||||
|
displayName: translateFn(sortingType.name),
|
||||||
|
displayFullName: translateFn(sortingType.fullName)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return allSortingTypes;
|
||||||
|
}
|
||||||
|
|
||||||
function getDisplayCurrency(value, currencyCode, options, translateFn) {
|
function getDisplayCurrency(value, currencyCode, options, translateFn) {
|
||||||
if (!isNumber(value) && !isString(value)) {
|
if (!isNumber(value) && !isString(value)) {
|
||||||
return value;
|
return value;
|
||||||
@@ -806,6 +867,9 @@ export function i18nFunctions(i18nGlobal) {
|
|||||||
getAllTimezones: (includeSystemDefault) => getAllTimezones(includeSystemDefault, i18nGlobal.t),
|
getAllTimezones: (includeSystemDefault) => getAllTimezones(includeSystemDefault, i18nGlobal.t),
|
||||||
getAllCurrencies: () => getAllCurrencies(i18nGlobal.t),
|
getAllCurrencies: () => getAllCurrencies(i18nGlobal.t),
|
||||||
getAllWeekDays: () => getAllWeekDays(i18nGlobal.t),
|
getAllWeekDays: () => getAllWeekDays(i18nGlobal.t),
|
||||||
|
getAllDateRanges: (includeCustom) => getAllDateRanges(includeCustom, i18nGlobal.t),
|
||||||
|
getAllStatisticsChartDataTypes: () => getAllStatisticsChartDataTypes(i18nGlobal.t),
|
||||||
|
getAllStatisticsSortingTypes: () => getAllStatisticsSortingTypes(i18nGlobal.t),
|
||||||
getDisplayCurrency: (value, currencyCode, options) => getDisplayCurrency(value, currencyCode, options, i18nGlobal.t),
|
getDisplayCurrency: (value, currencyCode, options) => getDisplayCurrency(value, currencyCode, options, i18nGlobal.t),
|
||||||
setLanguage: (locale, force) => setLanguage(i18nGlobal, locale, force),
|
setLanguage: (locale, force) => setLanguage(i18nGlobal, locale, force),
|
||||||
initLocale: (lastUserLanguage, timezone) => initLocale(i18nGlobal, lastUserLanguage, timezone)
|
initLocale: (lastUserLanguage, timezone) => initLocale(i18nGlobal, lastUserLanguage, timezone)
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
<select v-model="defaultChartDataType">
|
<select v-model="defaultChartDataType">
|
||||||
<option :value="chartDataType.type"
|
<option :value="chartDataType.type"
|
||||||
:key="chartDataType.type"
|
:key="chartDataType.type"
|
||||||
v-for="chartDataType in allChartDataTypes">{{ $t(chartDataType.name) }}</option>
|
v-for="chartDataType in allChartDataTypes">{{ chartDataType.displayName }}</option>
|
||||||
</select>
|
</select>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@
|
|||||||
<select v-model="defaultDateRange">
|
<select v-model="defaultDateRange">
|
||||||
<option :value="dateRange.type"
|
<option :value="dateRange.type"
|
||||||
:key="dateRange.type"
|
:key="dateRange.type"
|
||||||
v-for="dateRange in allDateRanges">{{ $t(dateRange.name) }}</option>
|
v-for="dateRange in allDateRanges">{{ dateRange.displayName }}</option>
|
||||||
</select>
|
</select>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
<select v-model="defaultSortingType">
|
<select v-model="defaultSortingType">
|
||||||
<option :value="sortingType.type"
|
<option :value="sortingType.type"
|
||||||
:key="sortingType.type"
|
:key="sortingType.type"
|
||||||
v-for="sortingType in allSortingTypes">{{ $t(sortingType.name) }}</option>
|
v-for="sortingType in allSortingTypes">{{ sortingType.displayName }}</option>
|
||||||
</select>
|
</select>
|
||||||
</f7-list-item>
|
</f7-list-item>
|
||||||
</f7-list>
|
</f7-list>
|
||||||
@@ -53,7 +53,6 @@
|
|||||||
import { mapStores } from 'pinia';
|
import { mapStores } from 'pinia';
|
||||||
import { useSettingsStore } from '@/stores/setting.js';
|
import { useSettingsStore } from '@/stores/setting.js';
|
||||||
|
|
||||||
import datetimeConstants from '@/consts/datetime.js';
|
|
||||||
import statisticsConstants from '@/consts/statistics.js';
|
import statisticsConstants from '@/consts/statistics.js';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@@ -63,27 +62,13 @@ export default {
|
|||||||
return statisticsConstants.allChartTypes;
|
return statisticsConstants.allChartTypes;
|
||||||
},
|
},
|
||||||
allChartDataTypes() {
|
allChartDataTypes() {
|
||||||
return statisticsConstants.allChartDataTypes;
|
return this.$locale.getAllStatisticsChartDataTypes();
|
||||||
},
|
},
|
||||||
allSortingTypes() {
|
allSortingTypes() {
|
||||||
return statisticsConstants.allSortingTypes;
|
return this.$locale.getAllStatisticsSortingTypes();
|
||||||
},
|
},
|
||||||
allDateRanges() {
|
allDateRanges() {
|
||||||
const allDateRanges = [];
|
return this.$locale.getAllDateRanges(false);
|
||||||
|
|
||||||
for (let dateRangeField in datetimeConstants.allDateRanges) {
|
|
||||||
if (!Object.prototype.hasOwnProperty.call(datetimeConstants.allDateRanges, dateRangeField)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const dateRangeType = datetimeConstants.allDateRanges[dateRangeField];
|
|
||||||
|
|
||||||
if (dateRangeType.type !== datetimeConstants.allDateRanges.Custom.type) {
|
|
||||||
allDateRanges.push(dateRangeType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allDateRanges;
|
|
||||||
},
|
},
|
||||||
defaultChartType: {
|
defaultChartType: {
|
||||||
get: function () {
|
get: function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user