-
-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into develop
- Loading branch information
Showing
9 changed files
with
236 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,27 @@ | ||
<template> | ||
<v-simple-table> | ||
<tbody> | ||
<tr v-for="status in printStatusArray" :key="status.name"> | ||
<td>{{ status.displayName }}</td> | ||
<td class="text-right">{{ status.value }}</td> | ||
</tr> | ||
<history-all-print-status-table-item | ||
v-for="status in printStatusArray" | ||
:key="status.name" | ||
:item="status" | ||
:value-name="valueName" /> | ||
</tbody> | ||
</v-simple-table> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Component from 'vue-class-component' | ||
import { Mixins } from 'vue-property-decorator' | ||
import { Mixins, Prop } from 'vue-property-decorator' | ||
import BaseMixin from '@/components/mixins/base' | ||
import { ServerHistoryStateAllPrintStatusEntry } from '@/store/server/history/types' | ||
import HistoryStatsMixin from '@/components/mixins/historyStats' | ||
import HistoryAllPrintStatusTableItem from '@/components/charts/HistoryAllPrintStatusTableItem.vue' | ||
import { HistoryStatsValueNames } from '@/store/server/history/types' | ||
@Component({ | ||
components: {}, | ||
components: { HistoryAllPrintStatusTableItem }, | ||
}) | ||
export default class HistoryAllPrintStatusTable extends Mixins(BaseMixin) { | ||
get selectedJobs() { | ||
return this.$store.getters['server/history/getSelectedJobs'] | ||
} | ||
get allPrintStatusArray() { | ||
return this.$store.getters['server/history/getAllPrintStatusArrayAll'] | ||
} | ||
get selectedPrintStatusArray() { | ||
return this.$store.getters['server/history/getSelectedPrintStatusArray'] | ||
} | ||
get printStatusArray() { | ||
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 | ||
} | ||
export default class HistoryAllPrintStatusTable extends Mixins(BaseMixin, HistoryStatsMixin) { | ||
@Prop({ type: String, default: 'amount' }) valueName!: HistoryStatsValueNames | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<tr> | ||
<td>{{ item.displayName }}</td> | ||
<td class="text-right">{{ value }}</td> | ||
</tr> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import Component from 'vue-class-component' | ||
import { Mixins, Prop } from 'vue-property-decorator' | ||
import BaseMixin from '@/components/mixins/base' | ||
import { HistoryStatsValueNames, ServerHistoryStateAllPrintStatusEntry } from '@/store/server/history/types' | ||
import { formatPrintTime } from '@/plugins/helpers' | ||
@Component({ | ||
components: {}, | ||
}) | ||
export default class HistoryAllPrintStatusTableItem extends Mixins(BaseMixin) { | ||
@Prop({ type: Object }) item!: ServerHistoryStateAllPrintStatusEntry | ||
@Prop({ type: String, default: 'amount' }) valueName!: HistoryStatsValueNames | ||
get value() { | ||
if (this.valueName === 'filament') { | ||
if (this.item.value > 1000) return Math.round(this.item.value / 1000).toFixed(2) + ' m' | ||
return this.item.value.toFixed(0) + ' mm' | ||
} | ||
if (this.valueName === 'time') { | ||
return formatPrintTime(this.item.value, false) | ||
} | ||
return this.item.value.toString() | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import Vue from 'vue' | ||
import Component from 'vue-class-component' | ||
import { | ||
HistoryStatsValueNames, | ||
ServerHistoryStateAllPrintStatusEntry, | ||
ServerHistoryStateJob, | ||
} from '@/store/server/history/types' | ||
import i18n from '@/plugins/i18n' | ||
|
||
@Component | ||
export default class HistoryStatsMixin extends Vue { | ||
valueName!: HistoryStatsValueNames | ||
|
||
get allPrintStatusChartData() { | ||
return this.getChartData(this.$store.state.server.history.jobs ?? []) | ||
} | ||
|
||
get selectedPrintStatusChartData() { | ||
return this.getChartData(this.$store.getters['server/history/getSelectedJobs']) | ||
} | ||
|
||
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) { | ||
output[index].value += 1 | ||
output[index].valueFilament += current.filament_used | ||
output[index].valueTime += current.print_duration | ||
return | ||
} | ||
|
||
output.push({ | ||
name: current.status, | ||
displayName: this.getLocalizedStatusName(current.status), | ||
value: 1, | ||
valueFilament: current.filament_used, | ||
valueTime: current.print_duration, | ||
itemStyle: { | ||
opacity: 0.9, | ||
color: this.getStatusColor(current.status), | ||
borderColor: '#1E1E1E', | ||
borderWidth: 2, | ||
borderRadius: 3, | ||
}, | ||
showInTable: !hidePrintStatus.includes(current.status), | ||
}) | ||
}) | ||
|
||
return output | ||
} | ||
|
||
private groupSmallEntries( | ||
entries: ServerHistoryStateAllPrintStatusEntry[], | ||
threshold: number | ||
): ServerHistoryStateAllPrintStatusEntry[] { | ||
const totalCount = entries.reduce((acc, cur) => acc + cur.value, 0) | ||
const otherLimit = totalCount * threshold | ||
const others = entries.filter((entry) => entry.value < otherLimit) | ||
|
||
if (others.length < 2) return entries | ||
|
||
const value = others.reduce((acc, cur) => acc + cur.value, 0) | ||
const remaining = entries.filter((entry) => entry.value >= otherLimit) | ||
const displayName = i18n.t(`History.StatusValues.Others`).toString() + ` (${others.length})` | ||
|
||
remaining.push({ | ||
name: displayName, | ||
displayName, | ||
value, | ||
valueFilament: 0, | ||
valueTime: 0, | ||
itemStyle: { | ||
opacity: 0.9, | ||
color: '#616161', | ||
borderColor: '#1E1E1E', | ||
borderWidth: 2, | ||
borderRadius: 3, | ||
}, | ||
showInTable: true, | ||
}) | ||
|
||
return remaining | ||
} | ||
|
||
get printStatusArray() { | ||
const countSelected = this.$store.getters['server/history/getSelectedJobs'].length | ||
const orgArray = countSelected ? this.selectedPrintStatusChartData : this.allPrintStatusChartData | ||
|
||
return orgArray.map((status) => ({ | ||
...status, | ||
name: status.displayName, | ||
value: | ||
this.valueName === 'filament' | ||
? status.valueFilament | ||
: this.valueName === 'time' | ||
? status.valueTime | ||
: status.value, | ||
})) | ||
} | ||
|
||
get groupedPrintStatusArray() { | ||
return this.groupSmallEntries(this.printStatusArray, 0.05) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.