Skip to content

Commit

Permalink
Notifications, and fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremiahvpratt committed Feb 18, 2023
1 parent 2079b9b commit 29e5838
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/components/panels/HistoryRemindersPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@
:rules="nameInputRules"
hide-details
outlined
dense
@update:error="isInvalidName = !isInvalidName"></v-text-field>
dense></v-text-field>
</settings-row>
<!-- TODO: translate title -->
<settings-row title="Print Hours">
Expand All @@ -144,8 +143,7 @@
:rules="hoursInputRules"
hide-details
outlined
dense
@update:error="isInvalidHours = !isInvalidHours"></v-text-field>
dense></v-text-field>
</settings-row>
</v-card-text>
<v-card-actions>
Expand All @@ -172,8 +170,7 @@
:rules="nameInputRules"
hide-details
outlined
dense
@update:error="isInvalidName = !isInvalidName"></v-text-field>
dense></v-text-field>
</settings-row>
<!-- TODO: translate title -->
<settings-row title="Print Hours">
Expand All @@ -183,8 +180,7 @@
:rules="hoursInputRules"
hide-details
outlined
dense
@update:error="isInvalidHours = !isInvalidHours"></v-text-field>
dense></v-text-field>
</settings-row>
</v-card-text>
<v-card-actions>
Expand All @@ -210,7 +206,7 @@ import {
mdiCloseThick,
mdiRepeatOnce,
} from '@mdi/js'
import { Component, Mixins } from 'vue-property-decorator'
import { Component, Mixins, Watch } from 'vue-property-decorator'
import { GuiRemindersStateReminder } from '@/store/gui/reminders/types'
import BaseMixin from '@/components/mixins/base'
import Panel from '@/components/ui/Panel.vue'
Expand Down Expand Up @@ -238,7 +234,7 @@ export default class HistoryRemindersPanel extends Mixins(BaseMixin) {
isInvalidName = false
// TODO: translate
hoursInputRules = [(value: number) => value > 0 || 'Must be a postitive number']
hoursInputRules = [(value: number) => value > 0 || 'Must be a positive number']
isInvalidHours = false
sortBy = 'remaining_print_time'
Expand Down Expand Up @@ -416,6 +412,8 @@ export default class HistoryRemindersPanel extends Mixins(BaseMixin) {
start_total_print_time: 0,
time_delta: 0,
}
this.isInvalidHours = true
this.isInvalidName = true
}
createReminder() {
Expand All @@ -431,6 +429,8 @@ export default class HistoryRemindersPanel extends Mixins(BaseMixin) {
openEditReminderDialog(reminder: GuiRemindersStateReminder) {
this.editingReminder = { ...reminder }
this.editingReminder.time_delta = Math.round(this.editingReminder.time_delta / 3600)
this.isInvalidHours = false
this.isInvalidName = false
this.editReminderDialog = true
}
Expand All @@ -442,5 +442,25 @@ export default class HistoryRemindersPanel extends Mixins(BaseMixin) {
this.editReminderDialog = false
this.editingReminder = null
}
@Watch('editingDisplayName')
onEditingDisplayname(val: string) {
this.isInvalidName = !val
}
@Watch('editingPrintHours')
onEditingPrintHours(val: string) {
this.isInvalidHours = parseFloat(val) <= 0
}
@Watch('creatingDisplayName')
onCreatingDisplayName(val: string) {
this.isInvalidName = !val
}
@Watch('creatingPrintHours')
onCreatingPrintHours(val: string) {
this.isInvalidHours = parseFloat(val) <= 0
}
}
</script>
40 changes: 40 additions & 0 deletions src/store/gui/notifications/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import i18n from '@/plugins/i18n.js'
import { RootStateDependency } from '@/store/types'
import { sha256 } from 'js-sha256'
import { PrinterStateKlipperConfigWarning } from '@/store/printer/types'
import { GuiRemindersStateReminder } from '../reminders/types'

export const getters: GetterTree<GuiNotificationState, any> = {
getNotifications: (state, getters) => {
Expand All @@ -28,6 +29,9 @@ export const getters: GetterTree<GuiNotificationState, any> = {
// klipper warnings
notifications = notifications.concat(getters['getNotificationsKlipperWarnings'])

// user-created reminders
notifications = notifications.concat(getters['getNotificationsOverdueReminders'])

const mapType = {
normal: 2,
high: 1,
Expand Down Expand Up @@ -270,6 +274,42 @@ export const getters: GetterTree<GuiNotificationState, any> = {
return notifications
},

getNotificationsOverdueReminders: (state, getters, rootState, rootGetters) => {
const notifications: GuiNotificationStateEntry[] = []
let reminders: GuiRemindersStateReminder[] = rootGetters['gui/reminders/getOverdueReminders']

const date = rootState.server.system_boot_at ?? new Date()

if (reminders.length) {
// get all dismissed reminders and convert it to a string[]
const remindersDismisses = rootGetters['gui/notifications/getDismissByCategory']('reminder').map(
(dismiss: GuiNotificationStateDismissEntry) => {
return dismiss.id
}
)

// filter all dismissed reminders
reminders = reminders.filter((reminder) => !remindersDismisses.includes(reminder.id))

reminders.forEach((reminder) => {
// TODO: translate
const title = 'User Created Reminder'
const description = reminder.name

notifications.push({
id: `reminder/${reminder.id}`,
priority: 'normal',
title: title,
description: description,
date,
dismissed: false,
})
})
}

return notifications
},

getDismiss: (state, getters, rootState) => {
const currentTime = new Date()
const systemBootAt = rootState.server.system_boot_at ?? new Date()
Expand Down
7 changes: 7 additions & 0 deletions src/store/gui/reminders/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ export const getters: GetterTree<GuiRemindersState, any> = {

return reminders.find((reminder: GuiRemindersStateReminder) => reminder.id === id)
},

getOverdueReminders: (state, getters, rootState) => {
const currentTotalPrintTime = rootState.server.history.job_totals.total_print_time
return Object.values(state.reminders).filter(
(reminder) => reminder.time_delta - (currentTotalPrintTime - reminder.start_total_print_time) < 0
)
},
}

0 comments on commit 29e5838

Please sign in to comment.