feat: multiselect in history jobs (#509)

select jobs to show stats only from this jobs and you can delete selected jobs from the history
This commit is contained in:
Stefan Dej authored and GitHub committed 2022-02-15 23:34:15 +01:00
1 parent 6563b7ce47
commit 455a3aa194
9 files changed
+280 -64

No files matched your search

@@ -56,17 +56,29 @@ export default class HistoryAllPrintStatus extends Mixins(BaseMixin) {
],
}
get selectedJobs() {
return this.$store.state.gui.view.history.selectedJobs ?? []
}
get allPrintStatusArray() {
return this.$store.getters['server/history/getAllPrintStatusArray']
}
get selectedPrintStatusArray() {
return this.$store.getters['server/history/getSelectedPrintStatusArray']
}
get printStatusArray() {
return this.selectedJobs.length ? this.selectedPrintStatusArray : this.allPrintStatusArray
}
get chart(): ECharts | null {
const historyAllPrintStatus = this.$refs.historyAllPrintStatus
return historyAllPrintStatus?.inst ?? null
}
mounted() {
this.chartOptions.series[0].data = this.allPrintStatusArray
this.chartOptions.series[0].data = this.printStatusArray
this.chart?.setOption(this.chartOptions)
window.addEventListener('resize', this.eventListenerResize)
@@ -81,8 +93,8 @@ export default class HistoryAllPrintStatus extends Mixins(BaseMixin) {
if (this.chart) this.chart.dispose()
}
@Watch('allPrintStatusArray')
allPrintStatusArrayChanged(newVal: any) {
@Watch('printStatusArray')
printStatusArrayChanged(newVal: any) {
this.chart?.setOption({
series: {
data: newVal,
+74 -9
View File
@@ -1,3 +1,11 @@
<style lang="scss">
.history-jobs-table {
th.text-start {
padding-right: 0 !important;
}
}
</style>
<template>
<div>
<panel
@@ -20,6 +28,15 @@
></v-text-field>
</v-col>
<v-col class="offset-4 col-4 d-flex align-center justify-end">
<template v-if="selectedJobs.length">
<v-btn
:title="$t('History.Delete')"
color="warning"
class="px-2 minwidth-0 ml-3"
@click="deleteSelectedDialog = true"
><v-icon>mdi-delete</v-icon></v-btn
>
</template>
<v-btn
:title="$t('History.TitleRefreshHistory')"
class="px-2 minwidth-0 ml-3"
@@ -75,8 +92,9 @@
</v-card-text>
<v-divider class="mb-3"></v-divider>
<v-data-table
v-model="selectedJobs"
:items="jobs"
class="files-table"
class="history-jobs-table"
:headers="filteredHeaders"
:options="options"
:custom-sort="sortFiles"
@@ -88,20 +106,23 @@
itemsPerPageAllText: $t('History.AllJobs'),
itemsPerPageOptions: [10, 25, 50, 100, -1],
}"
item-key="name"
item-key="job_id"
:search="search"
:custom-filter="advancedSearch"
mobile-breakpoint="0"
show-select
>
<template slot="items" slot-scope="props">
<td v-for="header in filteredHeaders" v-bind:key="header.text">{{ props.item[header.value] }}</td>
<td v-for="header in filteredHeaders" v-bind:key="header.text" class="text-no-wrap">
{{ props.item[header.value] }}
</td>
</template>
<template #no-data>
<template slot="no-data">
<div class="text-center">{{ $t('History.Empty') }}</div>
</template>
<template #item="{ index, item }">
<template v-slot:item="{ index, item, isSelected, select }">
<tr
:key="`${index} ${item.filename}`"
v-longpress:600="(e) => showContextMenu(e, item)"
@@ -109,7 +130,15 @@
@click="clickRow(item)"
:class="'file-list-cursor user-select-none ' + (item.exists ? '' : 'text--disabled')"
>
<td class="pr-0 text-center" style="width: 32px">
<td class="pr-0">
<v-simple-checkbox
:value="isSelected"
class="pa-0 mr-0"
v-ripple
@click.stop="select(!isSelected)"
></v-simple-checkbox>
</td>
<td class="px-0 text-center" style="width: 32px">
<template v-if="!item.exists">
<v-icon class="text--disabled">mdi-file-cancel</v-icon>
</template>
@@ -390,6 +419,21 @@
</v-card-text>
</panel>
</v-dialog>
<v-dialog v-model="deleteSelectedDialog" max-width="400">
<panel :title="$t('History.Delete')" card-class="history-delete-selected-dialog" :margin-bottom="false">
<template v-slot:buttons>
<v-btn icon tile @click="deleteSelectedDialog = false"><v-icon>mdi-close-thick</v-icon></v-btn>
</template>
<v-card-text>
<p class="mb-0">{{ $t('History.DeleteSelectedQuestion', { count: selectedJobs.length }) }}</p>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn color="" text @click="deleteSelectedDialog = false">{{ $t('History.Cancel') }}</v-btn>
<v-btn color="error" text @click="deleteSelectedJobs">{{ $t('History.Delete') }}</v-btn>
</v-card-actions>
</panel>
</v-dialog>
</div>
</template>
@@ -406,12 +450,9 @@ import { thumbnailBigMin, thumbnailSmallMax, thumbnailSmallMin } from '@/store/v
export default class HistoryListPanel extends Mixins(BaseMixin) {
formatFilesize = formatFilesize
private boolAllData = false
private search = ''
private sortBy = 'start_time'
private sortDesc = true
private selected = []
private hideHeaderColums = []
private options = {}
private contextMenu = {
shown: false,
@@ -420,15 +461,26 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
y: 0,
item: {},
}
private detailsDialog = {
item: {},
boolShow: false,
}
private deleteSelectedDialog = false
get jobs() {
return this.$store.getters['server/history/getFilterdJobList'] ?? []
}
get selectedJobs() {
return this.$store.state.gui.view.history.selectedJobs ?? []
}
set selectedJobs(newVal) {
this.$store.dispatch('gui/saveSettingWithoutUpload', { name: 'view.history.selectedJobs', value: newVal })
}
get headers() {
const headers = [
{
@@ -788,6 +840,19 @@ export default class HistoryListPanel extends Mixins(BaseMixin) {
)
}
deleteSelectedJobs() {
this.selectedJobs.forEach((item: ServerHistoryStateJob) => {
this.$socket.emit(
'server.history.delete_job',
{ uid: item.job_id },
{ action: 'server/history/getDeletedJobs' }
)
})
this.selectedJobs = []
this.deleteSelectedDialog = false
}
getStatusIcon(status: string) {
return this.$store.getters['server/history/getPrintStatusChipIcon'](status)
}
@@ -10,26 +10,50 @@
<v-col class="col-12 col-sm-6 col-md-4">
<v-simple-table>
<tbody>
<tr>
<td>{{ $t('History.TotalPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(totalPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.LongestPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(longestPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.AvgPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(avgPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.TotalFilamentUsed') }}</td>
<td class="text-right">{{ Math.round(totalFilamentUsed / 100) / 10 }} m</td>
</tr>
<tr>
<td>{{ $t('History.TotalJobs') }}</td>
<td class="text-right">{{ totalJobsCount }}</td>
</tr>
<template v-if="existsSelectedJobs">
<tr>
<td>{{ $t('History.SelectedPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(selectedPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.LongestPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(selectedLongestPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.AvgPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(selectedAvgPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.SelectedFilamentUsed') }}</td>
<td class="text-right">{{ Math.round(selectedFilamentUsed / 100) / 10 }} m</td>
</tr>
<tr>
<td>{{ $t('History.SelectedJobs') }}</td>
<td class="text-right">{{ selectedJobs.length }}</td>
</tr>
</template>
<template v-else>
<tr>
<td>{{ $t('History.TotalPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(totalPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.LongestPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(longestPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.AvgPrinttime') }}</td>
<td class="text-right">{{ formatPrintTime(avgPrintTime) }}</td>
</tr>
<tr>
<td>{{ $t('History.TotalFilamentUsed') }}</td>
<td class="text-right">{{ Math.round(totalFilamentUsed / 100) / 10 }} m</td>
</tr>
<tr>
<td>{{ $t('History.TotalJobs') }}</td>
<td class="text-right">{{ totalJobsCount }}</td>
</tr>
</template>
</tbody>
</v-simple-table>
</v-col>
@@ -62,22 +86,51 @@ import Panel from '@/components/ui/Panel.vue'
import HistoryFilamentUsage from '@/components/charts/HistoryFilamentUsage.vue'
import HistoryPrinttimeAvg from '@/components/charts/HistoryPrinttimeAvg.vue'
import HistoryAllPrintStatus from '@/components/charts/HistoryAllPrintStatus.vue'
import { ServerHistoryStateJob } from '@/store/server/history/types'
@Component({
components: { Panel, HistoryFilamentUsage, HistoryPrinttimeAvg, HistoryAllPrintStatus },
})
export default class HistoryStatisticsPanel extends Mixins(BaseMixin) {
get selectedJobs() {
return this.$store.state.gui.view.history.selectedJobs ?? []
}
get existsSelectedJobs() {
return this.selectedJobs.length > 0
}
get totalPrintTime() {
return 'total_print_time' in this.$store.state.server.history.job_totals
? this.$store.state.server.history.job_totals.total_print_time
: 0
}
get selectedPrintTime() {
let printtime = 0
this.selectedJobs.forEach((job: ServerHistoryStateJob) => {
printtime += job.print_duration
})
return printtime
}
get longestPrintTime() {
return 'longest_print' in this.$store.state.server.history.job_totals
? this.$store.state.server.history.job_totals.longest_print
: 0
}
get selectedLongestPrintTime() {
let printtime = 0
this.selectedJobs.forEach((job: ServerHistoryStateJob) => {
if (job.print_duration > printtime) printtime = job.print_duration
})
return printtime
}
get avgPrintTime() {
if (this.totalJobsCount > 0 && this.totalPrintTime > 0)
return Math.round(this.totalPrintTime / this.totalJobsCount)
@@ -85,12 +138,29 @@ export default class HistoryStatisticsPanel extends Mixins(BaseMixin) {
return 0
}
get selectedAvgPrintTime() {
if (this.selectedJobs.length > 0 && this.selectedPrintTime > 0)
return Math.round(this.selectedPrintTime / this.selectedJobs.length)
return 0
}
get totalFilamentUsed() {
return 'total_filament_used' in this.$store.state.server.history.job_totals
? this.$store.state.server.history.job_totals.total_filament_used
: 0
}
get selectedFilamentUsed() {
let filamentUsed = 0
this.selectedJobs.forEach((job: ServerHistoryStateJob) => {
filamentUsed += job.filament_used
})
return filamentUsed
}
get totalJobsCount() {
return 'total_jobs' in this.$store.state.server.history.job_totals
? this.$store.state.server.history.job_totals.total_jobs
+6 -1
View File
@@ -260,10 +260,13 @@
"History": {
"Statistics": "Statistics",
"TotalPrinttime": "Total Printtime",
"SelectedPrinttime": "Selected Printtime",
"LongestPrinttime": "Longest Printtime",
"AvgPrinttime": "Avg. Printtime",
"SelectedFilamentUsed": "Selected Filament Used",
"TotalFilamentUsed": "Total Filament Used",
"TotalJobs": "Total Jobs",
"SelectedJobs": "Selected Jobs",
"FilamentUsage": "Filament usage",
"PrinttimeAvg": "Printtime AVG",
"PrintHistory": "Print History",
@@ -275,6 +278,7 @@
"Empty": "empty",
"Details": "Details",
"Reprint": "Reprint",
"Cancel": "Cancel",
"Delete": "Delete",
"JobDetails": "Job Details",
"Filename": "Filename",
@@ -301,7 +305,8 @@
"SlicerVersion": "Slicer Version",
"HistoryFilamentUsage": "Filament",
"HistoryPrinttimeAVG": "Prints",
"ShowStatusName": "Show \"{name}\" ({count})"
"ShowStatusName": "Show \"{name}\" ({count})",
"DeleteSelectedQuestion": "Do you really want to delete {count} selected jobs?"
},
"Timelapse": {
"TimelapseFiles": "Timelapse Files",
+2 -2
View File
@@ -1,10 +1,10 @@
import '@mdi/font/css/materialdesignicons.css'
import Vue from 'vue'
import Vuetify from 'vuetify/lib'
import { Touch } from 'vuetify/lib/directives'
import { Touch, Ripple } from 'vuetify/lib/directives'
Vue.use(Vuetify, {
directives: { Touch },
directives: { Touch, Ripple },
})
export default new Vuetify({
+1
View File
@@ -180,6 +180,7 @@ export const getDefaultState = (): GuiState => {
'layer_height',
'object_height',
],
selectedJobs: [],
},
jobqueue: {
countPerPage: 10,
+2
View File
@@ -2,6 +2,7 @@ import { GuiMacrosState } from '@/store/gui/macros/types'
import { GuiConsoleState } from '@/store/gui/console/types'
import { GuiPresetsState } from '@/store/gui/presets/types'
import { GuiRemoteprintersState } from '@/store/gui/remoteprinters/types'
import { ServerHistoryStateJob } from '@/store/server/history/types'
export interface GuiState {
general: {
@@ -118,6 +119,7 @@ export interface GuiState {
toggleChartCol3: string
hidePrintStatus: string[]
hideColums: string[]
selectedJobs: ServerHistoryStateJob[]
}
jobqueue: {
countPerPage: number
+74 -29
View File
@@ -1,5 +1,9 @@
import { GetterTree } from 'vuex'
import { ServerHistoryState, ServerHistoryStateJob } from '@/store/server/history/types'
import {
ServerHistoryState,
ServerHistoryStateAllPrintStatusEntry,
ServerHistoryStateJob,
} from '@/store/server/history/types'
// eslint-disable-next-line
export const getters: GetterTree<ServerHistoryState, any> = {
@@ -61,26 +65,7 @@ export const getters: GetterTree<ServerHistoryState, any> = {
},
getAllPrintStatusArray(state, getters, rootState) {
interface allPrintStatusEntryItemStyle {
opacity: number
color: string
borderColor: string
borderWidth: number
borderRadius: number
}
interface allPrintStatusEntryLabel {
color: string
}
interface allPrintStatusEntry {
name: string
value: number
showInTable: boolean
itemStyle: allPrintStatusEntryItemStyle
label: allPrintStatusEntryLabel
}
const output: allPrintStatusEntry[] = []
const output: ServerHistoryStateAllPrintStatusEntry[] = []
state.jobs.forEach((current) => {
const index = output.findIndex((element) => element.name === current.status)
@@ -123,15 +108,67 @@ export const getters: GetterTree<ServerHistoryState, any> = {
return output
},
getFilamentUsageArray(state) {
getSelectedPrintStatusArray(state, getters, rootState) {
const output: ServerHistoryStateAllPrintStatusEntry[] = []
rootState.gui.view.history.selectedJobs.forEach((current: ServerHistoryStateJob) => {
const index = output.findIndex((element) => element.name === current.status)
if (index !== -1) output[index].value += 1
else {
const itemStyle = {
opacity: 0.9,
color: '#424242',
borderColor: '#1E1E1E',
borderWidth: 2,
borderRadius: 3,
}
switch (current.status) {
case 'completed':
itemStyle['color'] = '#BDBDBD'
break
case 'in_progress':
itemStyle['color'] = '#EEEEEE'
break
case 'cancelled':
itemStyle['color'] = '#616161'
break
}
output.push({
name: current.status,
value: 1,
itemStyle: itemStyle,
showInTable: !rootState.gui?.view.history.hidePrintStatus.includes(current.status),
label: {
color: '#fff',
},
})
}
})
return output
},
getFilamentUsageArray(state, getters, rootState) {
// eslint-disable-next-line
const output: any = []
const startDate = new Date()
startDate.setTime(startDate.getTime() - 60 * 60 * 24 * 14 * 1000)
startDate.setHours(0, 0, 0, 0)
const jobsFiltered = state.jobs.filter(
(job) => new Date(job.start_time * 1000) >= startDate && job.filament_used > 0
)
let jobsFiltered = [
...state.jobs.filter((job) => new Date(job.start_time * 1000) >= startDate && job.filament_used > 0),
]
if (rootState.gui.view.history.selectedJobs.length)
jobsFiltered = [
...rootState.gui.view.history.selectedJobs.filter(
(job: ServerHistoryStateJob) =>
new Date(job.start_time * 1000) >= startDate && job.filament_used > 0
),
]
for (let i = 0; i <= 14; i++) {
const tmpDate = new Date()
@@ -155,12 +192,20 @@ export const getters: GetterTree<ServerHistoryState, any> = {
})
},
getPrinttimeAvgArray(state) {
getPrinttimeAvgArray(state, getters, rootState) {
const output = [0, 0, 0, 0, 0]
const startDate = new Date(new Date().getTime() - 60 * 60 * 24 * 14 * 1000)
const jobsFiltered = state.jobs.filter(
(job) => new Date(job.start_time * 1000) >= startDate && job.status === 'completed'
)
let jobsFiltered = [
...state.jobs.filter((job) => new Date(job.start_time * 1000) >= startDate && job.status === 'completed'),
]
if (rootState.gui.view.history.selectedJobs.length)
jobsFiltered = [
...rootState.gui.view.history.selectedJobs.filter(
(job: ServerHistoryStateJob) =>
new Date(job.start_time * 1000) >= startDate && job.status === 'completed'
),
]
if (jobsFiltered.length) {
jobsFiltered.forEach((current) => {
+16
View File
@@ -23,3 +23,19 @@ export interface ServerHistoryStateJob {
start_time: number
total_duration: number
}
export interface ServerHistoryStateAllPrintStatusEntry {
name: string
value: number
showInTable: boolean
itemStyle: {
opacity: number
color: string
borderColor: string
borderWidth: number
borderRadius: number
}
label: {
color: string
}
}