From adf922c0488c4d6fbb376af424d32dbcefc6e370 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 13 Mar 2022 21:31:52 +0100 Subject: [PATCH] feat: translate job status in history (#713) --- .../charts/HistoryAllPrintStatus.vue | 30 ++++++++++++++----- .../charts/HistoryFilamentUsage.vue | 15 ++++++---- src/components/charts/HistoryPrinttimeAvg.vue | 15 ++++++---- src/components/panels/.i18nignore | 7 +++++ src/components/panels/HistoryListPanel.vue | 20 +++++++++---- src/locales/de.json | 16 +++++++++- src/locales/en.json | 9 ++++++ src/store/server/history/getters.ts | 12 +++++++- src/store/server/history/types.ts | 1 + 9 files changed, 98 insertions(+), 27 deletions(-) create mode 100644 src/components/panels/.i18nignore diff --git a/src/components/charts/HistoryAllPrintStatus.vue b/src/components/charts/HistoryAllPrintStatus.vue index 6ca6c57e..d2e396f0 100644 --- a/src/components/charts/HistoryAllPrintStatus.vue +++ b/src/components/charts/HistoryAllPrintStatus.vue @@ -12,6 +12,8 @@ import Component from 'vue-class-component' import { Mixins, Watch } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import type { ECharts } from 'echarts/core' +import { ECBasicOption } from 'echarts/types/dist/shared' +import { ServerHistoryStateAllPrintStatusEntry } from '@/store/server/history/types' @Component({ components: {}, @@ -21,7 +23,7 @@ export default class HistoryAllPrintStatus extends Mixins(BaseMixin) { historyAllPrintStatus: any } - private chartOptions: any = { + private chartOptions: ECBasicOption = { darkMode: true, animation: false, grid: { @@ -64,12 +66,20 @@ export default class HistoryAllPrintStatus extends Mixins(BaseMixin) { } get printStatusArray() { - return this.selectedJobs.length ? this.selectedPrintStatusArray : this.allPrintStatusArray + const output: ServerHistoryStateAllPrintStatusEntry[] = [] + const orgArray = this.selectedJobs.length ? this.selectedPrintStatusArray : this.allPrintStatusArray + + orgArray.forEach((status: ServerHistoryStateAllPrintStatusEntry) => { + const tmp = { ...status } + tmp.name = status.displayName + output.push(tmp) + }) + + return output } get chart(): ECharts | null { - const historyAllPrintStatus = this.$refs.historyAllPrintStatus - return historyAllPrintStatus?.inst ?? null + return this.$refs.historyAllPrintStatus ?? null } mounted() { @@ -90,11 +100,15 @@ export default class HistoryAllPrintStatus extends Mixins(BaseMixin) { @Watch('printStatusArray') printStatusArrayChanged(newVal: any) { - this.chart?.setOption({ - series: { - data: newVal, + this.chart?.setOption( + { + series: { + data: newVal, + }, }, - }) + false, + true + ) } visibilityChanged(isVisible: boolean) { diff --git a/src/components/charts/HistoryFilamentUsage.vue b/src/components/charts/HistoryFilamentUsage.vue index 74711e0a..5b7b0c38 100644 --- a/src/components/charts/HistoryFilamentUsage.vue +++ b/src/components/charts/HistoryFilamentUsage.vue @@ -109,8 +109,7 @@ export default class HistoryPrinttimeAvg extends Mixins(BaseMixin) { } get chart(): ECharts | null { - const historyFilamentUsage = this.$refs.historyFilamentUsage - return historyFilamentUsage?.inst ?? null + return this.$refs.historyFilamentUsage ?? null } mounted() { @@ -131,11 +130,15 @@ export default class HistoryPrinttimeAvg extends Mixins(BaseMixin) { @Watch('filamentUsageArray') filamentUsageArrayChanged(newVal: any) { - this.chart?.setOption({ - series: { - data: newVal, + this.chart?.setOption( + { + series: { + data: newVal, + }, }, - }) + false, + true + ) } visibilityChanged(isVisible: boolean) { diff --git a/src/components/charts/HistoryPrinttimeAvg.vue b/src/components/charts/HistoryPrinttimeAvg.vue index fcdff4fb..776e54c5 100644 --- a/src/components/charts/HistoryPrinttimeAvg.vue +++ b/src/components/charts/HistoryPrinttimeAvg.vue @@ -95,8 +95,7 @@ export default class HistoryPrinttimeAvg extends Mixins(BaseMixin) { } get chart(): ECharts | null { - const historyPrinttimeAvg = this.$refs.historyPrinttimeAvg - return historyPrinttimeAvg?.inst ?? null + return this.$refs.historyPrinttimeAvg ?? null } mounted() { @@ -117,11 +116,15 @@ export default class HistoryPrinttimeAvg extends Mixins(BaseMixin) { @Watch('printtimeAvgArray') printtimeAvgArrayChanged(newVal: any) { - this.chart?.setOption({ - series: { - data: newVal, + this.chart?.setOption( + { + series: { + data: newVal, + }, }, - }) + false, + true + ) } visibilityChanged(isVisible: boolean) { diff --git a/src/components/panels/.i18nignore b/src/components/panels/.i18nignore new file mode 100644 index 00000000..6981c064 --- /dev/null +++ b/src/components/panels/.i18nignore @@ -0,0 +1,7 @@ +$t('History.StatusValues.cancelled') +$t('History.StatusValues.completed') +$t('History.StatusValues.error') +$t('History.StatusValues.in_progress') +$t('History.StatusValues.klippy_disconnect') +$t('History.StatusValues.klippy_shutdown') +$t('History.StatusValues.server_exit') \ No newline at end of file diff --git a/src/components/panels/HistoryListPanel.vue b/src/components/panels/HistoryListPanel.vue index a83ce464..a9fad7e7 100644 --- a/src/components/panels/HistoryListPanel.vue +++ b/src/components/panels/HistoryListPanel.vue @@ -69,9 +69,7 @@ class="mt-0" hide-details :input-value="status.showInTable" - :label=" - $t('History.ShowStatusName', { name: status.name, count: status.value }) - " + :label="`${status.displayName} (${status.value})`" @change="changeStatusVisible(status)"> @@ -183,7 +181,13 @@ - {{ item.status.replace(/_/g, ' ') }} + + {{ + $te(`History.StatusValues.${item.status}`, 'en') + ? $t(`History.StatusValues.${item.status}`) + : item.status.replace(/_/g, ' ') + }} + {{ $t('History.Status') }} - {{ detailsDialog.item.status }} + + {{ + $te(`History.StatusValues.${detailsDialog.item.status}`, 'en') + ? $t(`History.StatusValues.${detailsDialog.item.status}`) + : detailsDialog.item.status + }} + diff --git a/src/locales/de.json b/src/locales/de.json index abbb1352..ddce8393 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -251,7 +251,9 @@ "History": { "AllJobs": "Alle", "AvgPrinttime": "Druckzeit - Ø", + "Cancel": "abbrechen", "Delete": "Löschen", + "DeleteSelectedQuestion": "Sollen wirklich {count} ausgewählte Jobs gelöscht werden?", "Details": "Details", "Empty": "leer", "EndTime": "Endzeit", @@ -280,12 +282,24 @@ "PrinttimeAvg": "Druckzeit - Ø", "Reprint": "Erneut drucken", "Search": "Suchen", - "ShowStatusName": "Zeige \"{name}\" ({count})", + "SelectedFilamentUsed": "Ausg. Filamentverbrauch", + "SelectedJobs": "Ausg. Drucke", + "SelectedPrinttime": "Ausg. Druckzeit", "Slicer": "Slicer", "SlicerVersion": "Slicer Version", "StartTime": "Startzeit", "Statistics": "Statistik", "Status": "Status", + "StatusValues": { + "cancelled": "Abgebrochen", + "completed": "Abgeschlossen", + "error": "Fehler", + "in_progress": "In Arbeit", + "klippy_disconnect": "Klippy getrennt", + "klippy_shutdown": "Klippy heruntergefahren", + "server_exit": "Server-Exit" + }, + "TitleExportHistory": "Historie exportieren", "TitleRefreshHistory": "Historie aktualisieren", "TitleSettings": "Einstellungen", "TotalDuration": "Gesamtdauer", diff --git a/src/locales/en.json b/src/locales/en.json index 8e7259ab..15d3d4b9 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -287,6 +287,15 @@ "StartTime": "Start Time", "Statistics": "Statistics", "Status": "Status", + "StatusValues": { + "cancelled": "Cancelled", + "completed": "Completed", + "error": "Error", + "in_progress": "In progress", + "klippy_disconnect": "Klippy disconnect", + "klippy_shutdown": "Klippy shutdown", + "server_exit": "Server exit" + }, "TitleExportHistory": "Export History", "TitleRefreshHistory": "Refresh History", "TitleSettings": "Settings", diff --git a/src/store/server/history/getters.ts b/src/store/server/history/getters.ts index 89cea8c3..2ad656f4 100644 --- a/src/store/server/history/getters.ts +++ b/src/store/server/history/getters.ts @@ -11,6 +11,7 @@ import { mdiCloseCircleOutline, mdiProgressClock, } from '@mdi/js' +import i18n from '@/plugins/i18n' // eslint-disable-next-line export const getters: GetterTree = { @@ -78,6 +79,10 @@ export const getters: GetterTree = { const index = output.findIndex((element) => element.name === current.status) if (index !== -1) output[index].value += 1 else { + const displayName = i18n.te(`History.StatusValues.${current.status}`, 'en') + ? i18n.t(`History.StatusValues.${current.status}`).toString() + : current.status + const itemStyle = { opacity: 0.9, color: '#424242', @@ -102,8 +107,9 @@ export const getters: GetterTree = { output.push({ name: current.status, + displayName, value: 1, - itemStyle: itemStyle, + itemStyle, showInTable: !rootState.gui?.view.history.hidePrintStatus.includes(current.status), label: { color: '#fff', @@ -122,6 +128,9 @@ export const getters: GetterTree = { const index = output.findIndex((element) => element.name === current.status) if (index !== -1) output[index].value += 1 else { + const displayName = i18n.te(`History.StatusValues.${current.status}`, 'en') + ? i18n.t(`History.StatusValues.${current.status}`).toString() + : current.status const itemStyle = { opacity: 0.9, color: '#424242', @@ -146,6 +155,7 @@ export const getters: GetterTree = { output.push({ name: current.status, + displayName, value: 1, itemStyle: itemStyle, showInTable: !rootState.gui?.view.history.hidePrintStatus.includes(current.status), diff --git a/src/store/server/history/types.ts b/src/store/server/history/types.ts index 55ba2890..87f9a345 100644 --- a/src/store/server/history/types.ts +++ b/src/store/server/history/types.ts @@ -26,6 +26,7 @@ export interface ServerHistoryStateJob { export interface ServerHistoryStateAllPrintStatusEntry { name: string + displayName: string value: number showInTable: boolean itemStyle: {