Skip to content

Commit

Permalink
refactor: extract some logic into a separate methods
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Dej <[email protected]>
  • Loading branch information
meteyou committed Sep 15, 2024
1 parent 908d3c7 commit 45f3e5a
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/components/mixins/historyStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {
} from '@/store/server/history/types'
import i18n from '@/plugins/i18n'

type StatusKeys = 'completed' | 'in_progress' | 'cancelled' | 'default'

@Component
export default class HistoryStatsMixin extends Vue {
valueName!: HistoryStatsValueNames
Expand All @@ -21,17 +19,27 @@ export default class HistoryStatsMixin extends Vue {
return this.getChartData(this.$store.getters['server/history/getSelectedJobs'])
}

private getChartData(jobs: ServerHistoryStateJob[]) {
const output: ServerHistoryStateAllPrintStatusEntry[] = []
const hidePrintStatus = this.$store.state.gui.view.history.hidePrintStatus ?? []

const colorMap: Record<StatusKeys, string> = {
private getStatusColor(status: string) {
const colorMap: Record<string, string> = {
completed: '#BDBDBD',
in_progress: '#EEEEEE',
cancelled: '#616161',
default: '#424242',
}

return colorMap[status] ?? colorMap.default
}

private getLocalizedStatusName(status: string) {
return i18n.te(`History.StatusValues.${status}`, 'en')
? i18n.t(`History.StatusValues.${status}`).toString()
: status
}

private getChartData(jobs: ServerHistoryStateJob[]) {
const output: ServerHistoryStateAllPrintStatusEntry[] = []
const hidePrintStatus = this.$store.state.gui.view.history.hidePrintStatus ?? []

jobs.forEach((current: ServerHistoryStateJob) => {
const index = output.findIndex((element) => element.name === current.status)
if (index !== -1) {
Expand All @@ -41,19 +49,15 @@ export default class HistoryStatsMixin extends Vue {
return
}

const displayName = i18n.te(`History.StatusValues.${current.status}`, 'en')
? i18n.t(`History.StatusValues.${current.status}`).toString()
: current.status

output.push({
name: current.status,
displayName,
displayName: this.getLocalizedStatusName(current.status),
value: 1,
valueFilament: current.filament_used,
valueTime: current.print_duration,
itemStyle: {
opacity: 0.9,
color: colorMap[current.status as StatusKeys] ?? colorMap.default,
color: this.getStatusColor(current.status),
borderColor: '#1E1E1E',
borderWidth: 2,
borderRadius: 3,
Expand Down

0 comments on commit 45f3e5a

Please sign in to comment.