diff --git a/src/components/charts/HistoryAllPrintStatus.vue b/src/components/charts/HistoryAllPrintStatus.vue new file mode 100644 index 00000000..9ddb5fed --- /dev/null +++ b/src/components/charts/HistoryAllPrintStatus.vue @@ -0,0 +1,87 @@ + + + \ No newline at end of file diff --git a/src/components/charts/HistoryFilamentUsage.vue b/src/components/charts/HistoryFilamentUsage.vue new file mode 100644 index 00000000..6a9bf143 --- /dev/null +++ b/src/components/charts/HistoryFilamentUsage.vue @@ -0,0 +1,160 @@ + + + \ No newline at end of file diff --git a/src/components/charts/HistoryPrinttimeAvg.vue b/src/components/charts/HistoryPrinttimeAvg.vue new file mode 100644 index 00000000..3d046c88 --- /dev/null +++ b/src/components/charts/HistoryPrinttimeAvg.vue @@ -0,0 +1,136 @@ + + + \ No newline at end of file diff --git a/src/components/panels/HistoryListPanel.vue b/src/components/panels/HistoryListPanel.vue new file mode 100644 index 00000000..e68d6a60 --- /dev/null +++ b/src/components/panels/HistoryListPanel.vue @@ -0,0 +1,348 @@ + + + \ No newline at end of file diff --git a/src/components/panels/index.js b/src/components/panels/index.js index 3206ecbe..4f68c0b9 100644 --- a/src/components/panels/index.js +++ b/src/components/panels/index.js @@ -12,6 +12,7 @@ import WebcamPanel from "./WebcamPanel"; import MiniconsolePanel from "./MiniconsolePanel"; import Settings from "./Settings/"; import PowerControlPanel from "./PowerControlPanel.vue"; +import HistoryListPanel from "./HistoryListPanel.vue"; Vue.component('status-panel', StatusPanel); Vue.component('klippy-state-panel', KlippyStatePanel); @@ -24,6 +25,7 @@ Vue.component('miscellaneous-panel', Miscellaneous); Vue.component('webcam-panel', WebcamPanel); Vue.component('miniconsole-panel', MiniconsolePanel); Vue.component('power-control-panel', PowerControlPanel); +Vue.component('history-list-panel', HistoryListPanel); export default { Settings diff --git a/src/pages/History.vue b/src/pages/History.vue new file mode 100644 index 00000000..de70dacc --- /dev/null +++ b/src/pages/History.vue @@ -0,0 +1,156 @@ + + + + diff --git a/src/plugins/vuetify.js b/src/plugins/vuetify.js index 4d27f5a5..282bbf60 100644 --- a/src/plugins/vuetify.js +++ b/src/plugins/vuetify.js @@ -11,22 +11,25 @@ Vue.use(VueToast, { }) Vue.use(Vuetify,{ - components: { - VSnackbar, - VBtn, - VIcon, - } + options: { + customProperties: true + }, + components: { + VSnackbar, + VBtn, + VIcon, + } }) export default new Vuetify({ - theme: { - themes: { - dark: { + theme: { + themes: { + dark: { - } - } - }, - icons: { - iconfont: 'mdi', - }, + } + } + }, + icons: { + iconfont: 'mdi', + }, }) diff --git a/src/routes/index.js b/src/routes/index.js index 64361a58..3b4e0802 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -4,6 +4,7 @@ import Farm from '../pages/Farm.vue' import Console from '../pages/Console.vue' import Heightmap from '../pages/Heightmap.vue' import Files from '../pages/Files.vue' +import History from '../pages/History.vue' import Settings from '../pages/Settings.vue' import SettingsInterface from '../pages/settings/interface.vue' import SettingsMachine from '../pages/settings/machine.vue' @@ -56,6 +57,13 @@ const routes = [ component: Files, alwaysShow: false, }, + { + title: "History", + path: '/history', + icon: 'history', + component: History, + alwaysShow: false, + }, { title: "Settings", path: '/settings', diff --git a/src/store/files/mutations.js b/src/store/files/mutations.js index 39efb346..e5daaedd 100644 --- a/src/store/files/mutations.js +++ b/src/store/files/mutations.js @@ -22,6 +22,7 @@ export default { item.isDirectory && 'filename' in item && 'dirs' in payload && + payload.dirs !== undefined && payload.dirs.length > 0 && payload.dirs.findIndex(element => element.dirname === item.filename) < 0 ) parent.splice(key, 1) diff --git a/src/store/gui/actions.js b/src/store/gui/actions.js index 47b98ce8..2d5be061 100644 --- a/src/store/gui/actions.js +++ b/src/store/gui/actions.js @@ -144,5 +144,13 @@ export default { dispatch('farm/readStoredPrinters', {}, { root: true }) } dispatch('printer/init', null, { root: true }) - } + }, + + setHistoryColumns({ commit, dispatch, state }, data) { + commit('setHistoryColumns', data) + dispatch('updateSettings', { + keyName: 'history', + newVal: state.history + }) + }, } \ No newline at end of file diff --git a/src/store/gui/index.js b/src/store/gui/index.js index 2c09ab6b..950cab74 100644 --- a/src/store/gui/index.js +++ b/src/store/gui/index.js @@ -59,6 +59,11 @@ export function getDefaultState() { showHiddenFiles: false, hideMetadataColums: [] }, + history: { + countPerPage: 10, + toggleChartCol3: 'filament_usage', + hideColums: [] + }, settings: { configfiles: { countPerPage: 10, diff --git a/src/store/gui/mutations.js b/src/store/gui/mutations.js index a1036e6c..0e2e6fb4 100644 --- a/src/store/gui/mutations.js +++ b/src/store/gui/mutations.js @@ -88,5 +88,13 @@ export default { Vue.set(state.tempchart.datasetSettings[payload.name]['additionalSensors'], payload.sensor, {}) Vue.set(state.tempchart.datasetSettings[payload.name]['additionalSensors'][payload.sensor], 'boolList', payload.value) - } + }, + + setHistoryColumns(state, data) { + if (data.value && state.history.hideColums.includes(data.name)) { + state.history.hideColums.splice(state.history.hideColums.indexOf(data.name), 1) + } else if (!data.value && !state.history.hideColums.includes(data.name)) { + state.history.hideColums.push(data.name) + } + }, } \ No newline at end of file diff --git a/src/store/server/actions.js b/src/store/server/actions.js index 9a6b7442..bf358f0b 100644 --- a/src/store/server/actions.js +++ b/src/store/server/actions.js @@ -53,6 +53,9 @@ export default { if (payload.plugins.includes("update_manager") !== false) Vue.prototype.$socket.sendObj('machine.update.status', {}, 'server/updateManager/getStatus') + + if (payload.plugins.includes("history") !== false) + Vue.prototype.$socket.sendObj('server.history.list', {}, 'server/history/getHistory') } if (state.registered_directories.length === 0 && 'registered_directories' in payload) { diff --git a/src/store/server/history/actions.js b/src/store/server/history/actions.js new file mode 100644 index 00000000..c236e79e --- /dev/null +++ b/src/store/server/history/actions.js @@ -0,0 +1,17 @@ +export default { + reset({ commit }) { + commit('reset') + }, + + getHistory({ commit, state }, payload) { + commit('reset') + + payload.jobs.forEach(job => { + const index = state.jobs.findIndex(tmpJob => tmpJob.job_id === job.job_id) + if (index === -1) { + commit('addJob', job) + } + }) + } + +} \ No newline at end of file diff --git a/src/store/server/history/getters.js b/src/store/server/history/getters.js new file mode 100644 index 00000000..0a6fdd06 --- /dev/null +++ b/src/store/server/history/getters.js @@ -0,0 +1,135 @@ +export default { + + getTotalPrintTime(state) { + let output = 0 + + state.jobs.forEach(current => { + output += current.print_duration + }) + + return output + }, + + getTotalCompletedPrintTime(state) { + let output = 0 + + state.jobs.forEach(current => { + if (current.status === "completed") output += current.print_duration + }) + + return output + }, + + getLongestPrintTime(state) { + let output = 0 + + state.jobs.forEach(current => { + if (current.print_duration > output) output = current.print_duration + }) + + return output + }, + + getTotalFilamentUsed(state) { + let output = 0 + + state.jobs.forEach(current => { + output += current.filament_used + }) + + return output + }, + + getTotalJobsCount(state) { + return state.jobs.length + }, + + getTotalCompletedJobsCount(state) { + return state.jobs.filter(job => job.status === "completed").length + }, + + getAvgPrintTime(state, getters) { + const totalCompletedPrintTime = getters.getTotalCompletedPrintTime + const totalCompletedJobsCount = getters.getTotalCompletedJobsCount + + return totalCompletedPrintTime > 0 && totalCompletedJobsCount > 0 ? Math.round(totalCompletedPrintTime / totalCompletedJobsCount) : 0 + }, + + getAllPrintStatusArray(state) { + let output = [] + + state.jobs.forEach(current => { + const index = output.findIndex(element => element.name === current.status) + if (index !== -1) output[index].value +=1 + else { + let itemStyle = { + opacity: 0.9, + color: '#212121' + } + + switch (current.status) { + case 'completed': + itemStyle['color'] = '#BDBDBD' + break + + case 'in_progress': + itemStyle['color'] = '#EEEEEE' + break + + case 'cancelled': + itemStyle['color'] = '#424242' + break + } + + output.push({ + name: current.status, + value: 1, + itemStyle: itemStyle + }) + } + }) + + return output + }, + + getFilamentUsageArray(state) { + let output = [] + const startDate = new Date(new Date().getDate() - 14) + const jobsFiltered = state.jobs.filter(job => job.start_time * 1000 >= startDate && job.filament_used > 0) + + if (jobsFiltered.length) { + jobsFiltered.forEach(current => { + const currentStartDate = new Date(current.start_time * 1000).setHours(0,0,0,0) + const index = output.findIndex(element => element[0] === currentStartDate) + if (index !== -1) output[index][1] += Math.round(current.filament_used) / 1000 + else + output.push([ + currentStartDate, + Math.round(current.filament_used) / 1000 + ]) + }) + } + + return output.sort((a,b) => { + return b[0] - a[0] + }) + }, + + getPrinttimeAvgArray(state) { + let output = [0,0,0,0,0] + const startDate = new Date(new Date().getDate() - 14) + const jobsFiltered = state.jobs.filter(job => job.start_time * 1000 >= startDate && job.status === 'completed') + + if (jobsFiltered.length) { + jobsFiltered.forEach(current => { + if (current.print_duration > 0 && current.print_duration <= 60*60*2) output[0]++ + else if (current.print_duration > 60*60*2 && current.print_duration <= 60*60*6) output[1]++ + else if (current.print_duration > 60*60*6 && current.print_duration <= 60*60*12) output[2]++ + else if (current.print_duration > 60*60*12 && current.print_duration <= 60*60*24) output[3]++ + else if (current.print_duration > 60*60*24) output[4]++ + }) + } + + return output + } +} \ No newline at end of file diff --git a/src/store/server/history/index.js b/src/store/server/history/index.js new file mode 100644 index 00000000..6e724dc4 --- /dev/null +++ b/src/store/server/history/index.js @@ -0,0 +1,20 @@ +import actions from './actions' +import mutations from './mutations' +import getters from './getters' + +export function getDefaultState() { + return { + jobs: [] + } +} + +// initial state +const state = getDefaultState() + +export default { + namespaced: true, + state, + getters, + actions, + mutations +} \ No newline at end of file diff --git a/src/store/server/history/mutations.js b/src/store/server/history/mutations.js new file mode 100644 index 00000000..2af3c4d5 --- /dev/null +++ b/src/store/server/history/mutations.js @@ -0,0 +1,11 @@ +import { getDefaultState } from './index' + +export default { + reset(state) { + Object.assign(state, getDefaultState()) + }, + + addJob(state, payload) { + state.jobs.push(payload) + } +} \ No newline at end of file diff --git a/src/store/server/index.js b/src/store/server/index.js index d3ce878e..4cd8de4d 100644 --- a/src/store/server/index.js +++ b/src/store/server/index.js @@ -5,6 +5,7 @@ import getters from './getters' // import modules import power from './power' import updateManager from './updateManager' +import history from './history' // create getDefaultState export function getDefaultState() { @@ -32,5 +33,6 @@ export default { modules: { power, updateManager, + history, } } \ No newline at end of file