Skip to content

Commit

Permalink
feat: adds optional confirmation for power device toggle (fluidd-core…
Browse files Browse the repository at this point in the history
…#388)

Signed-off-by: Pedro Lamas <[email protected]>

Co-authored-by: Paweł Służalec <[email protected]>
  • Loading branch information
2 people authored and matmen committed Jun 27, 2022
1 parent 13791d5 commit c18d9b9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/components/common/SystemCommands.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,19 @@ export default class SystemCommands extends Mixins(StateMixin, ServicesMixin) {
})
}
togglePowerDevice (device: Device, wait?: string) {
const state = (device.status === 'on') ? 'off' : 'on'
SocketActions.machineDevicePowerToggle(device.device, state, wait)
async togglePowerDevice (device: Device, wait?: string) {
const confirmOnPowerDeviceChange = this.$store.state.config.uiSettings.general.confirmOnPowerDeviceChange
let res: boolean | undefined = true
if (confirmOnPowerDeviceChange) {
res = await this.$confirm(
this.$tc('app.general.simple_form.msg.confirm_power_device_toggle'),
{ title: this.$tc('app.general.label.confirm'), color: 'card-heading', icon: '$error' }
)
}
if (res) {
const state = (device.status === 'on') ? 'off' : 'on'
SocketActions.machineDevicePowerToggle(device.device, state, wait)
}
}
getPowerIcon (device: Device) {
Expand Down
25 changes: 25 additions & 0 deletions src/components/settings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@
class="mb-5"
></v-switch>
</app-setting>

<v-divider></v-divider>

<app-setting
:title="$t('app.setting.label.confirm_on_power_device_change')"
>
<v-switch
@click.native.stop
v-model="confirmOnPowerDeviceChange"
hide-details
class="mb-5"
></v-switch>
</app-setting>
</v-card>
</div>
</template>
Expand Down Expand Up @@ -109,5 +122,17 @@ export default class GeneralSettings extends Mixins(StateMixin) {
server: true
})
}
get confirmOnPowerDeviceChange () {
return this.$store.state.config.uiSettings.general.confirmOnPowerDeviceChange
}
set confirmOnPowerDeviceChange (value: boolean) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.general.confirmOnPowerDeviceChange',
value,
server: true
})
}
}
</script>
2 changes: 2 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ app:
confirm: Are you sure?
confirm_reboot_host: Are you sure? This will reboot your host system.
confirm_shutdown_host: Are you sure? This will shutdown your host system.
confirm_power_device_toggle: Are you sure? This will toggle the power of this device.
table:
header:
actions: Actions
Expand Down Expand Up @@ -343,6 +344,7 @@ app:
camera_stream_type: Stream type
camera_url: Camera Url
confirm_on_estop: Require confirm on Emergency Stop
confirm_on_power_device_change: Require confirm on Device Power changes
dark_mode: Dark mode
default_extrude_length: Default extrude length
default_extrude_speed: Default extrude speed
Expand Down
3 changes: 2 additions & 1 deletion src/store/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export const defaultState = (): ConfigState => {
useGcodeCoords: false,
zAdjustDistances: [0.005, 0.01, 0.025, 0.050],
enableVersionNotifications: true,
confirmOnEstop: false
confirmOnEstop: false,
confirmOnPowerDeviceChange: false
},
theme: {
isDark: true,
Expand Down
1 change: 1 addition & 0 deletions src/store/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface GeneralConfig {
zAdjustDistances: number[];
enableVersionNotifications: boolean;
confirmOnEstop: boolean;
confirmOnPowerDeviceChange: boolean;
}

// Config stored in moonraker db
Expand Down

0 comments on commit c18d9b9

Please sign in to comment.