diff --git a/src/components/.i18nignore b/src/components/.i18nignore index b669939d..c6ce9136 100644 --- a/src/components/.i18nignore +++ b/src/components/.i18nignore @@ -13,4 +13,21 @@ $t('App.ThrottledStates.DescriptionTemperatureLimitActive') $t('App.ThrottledStates.DescriptionPreviouslyUnderVolted') $t('App.ThrottledStates.DescriptionPreviouslyFrequencyCapped') $t('App.ThrottledStates.DescriptionPreviouslyThrottled') -$t('App.ThrottledStates.DescriptionPreviouslyTemperatureLimited') \ No newline at end of file +$t('App.ThrottledStates.DescriptionPreviouslyTemperatureLimited') +$t('App.TopCornerMenu.Start') +$t('App.TopCornerMenu.Restart') +$t('App.TopCornerMenu.Stop') +$t('App.TopCornerMenu.ConfirmationDialog.Title.KlipperRestart') +$t('App.TopCornerMenu.ConfirmationDialog.Title.KlipperFirmwareRestart') +$t('App.TopCornerMenu.ConfirmationDialog.Title.ServiceStart') +$t('App.TopCornerMenu.ConfirmationDialog.Title.ServiceRestart') +$t('App.TopCornerMenu.ConfirmationDialog.Title.ServiceStop') +$t('App.TopCornerMenu.ConfirmationDialog.Title.HostReboot') +$t('App.TopCornerMenu.ConfirmationDialog.Title.HostShutdown') +$t('App.TopCornerMenu.ConfirmationDialog.Description.KlipperRestart') +$t('App.TopCornerMenu.ConfirmationDialog.Description.KlipperFirmwareRestart') +$t('App.TopCornerMenu.ConfirmationDialog.Description.ServiceStart') +$t('App.TopCornerMenu.ConfirmationDialog.Description.ServiceRestart') +$t('App.TopCornerMenu.ConfirmationDialog.Description.ServiceStop') +$t('App.TopCornerMenu.ConfirmationDialog.Description.HostReboot') +$t('App.TopCornerMenu.ConfirmationDialog.Description.HostShutdown') \ No newline at end of file diff --git a/src/components/TheTopCornerMenu.vue b/src/components/TheTopCornerMenu.vue index dfb3d288..5658603e 100644 --- a/src/components/TheTopCornerMenu.vue +++ b/src/components/TheTopCornerMenu.vue @@ -15,13 +15,13 @@ @@ -59,13 +59,13 @@ {{ $t("App.TopCornerMenu.HostControl") }} - + {{ $t("App.TopCornerMenu.Reboot") }} mdi-power - + {{ $t("App.TopCornerMenu.Shutdown") }} mdi-power @@ -84,6 +84,29 @@ + + + + + + +

{{ dialogConfirmation.description }}

+
+
+
+ + + + {{ $t('App.TopCornerMenu.Cancel') }} + + + {{ dialogConfirmation.actionButtonText }} + + +
+
@@ -93,6 +116,7 @@ import Component from 'vue-class-component' import { Mixins } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import {ServerPowerStateDevice} from '@/store/server/power/types' +import Panel from '@/components/ui/Panel.vue' interface dialogPowerDeviceChange { show: boolean @@ -100,7 +124,18 @@ interface dialogPowerDeviceChange { value: string } -@Component +interface dialogConfirmation { + show: boolean + serviceName: string | null + executableFunction: any | null + title: string + description: string + actionButtonText: string +} + +@Component({ + components: {Panel} +}) export default class TheTopCornerMenu extends Mixins(BaseMixin) { showMenu = false @@ -110,6 +145,15 @@ export default class TheTopCornerMenu extends Mixins(BaseMixin) { value: '' } + dialogConfirmation: dialogConfirmation = { + show: false, + serviceName: null, + executableFunction: null, + title: '', + description: '', + actionButtonText: '' + } + get services() { const services = this.$store.state.server.system_info?.available_services?.filter((name: string) => name !== 'klipper_mcu') ?? [] services.sort() @@ -136,6 +180,32 @@ export default class TheTopCornerMenu extends Mixins(BaseMixin) { return null } + checkDialog(executableFunction: any, serviceName: string | null = null) { + if (this.printerIsPrinting) { + const functionName = (executableFunction.name ?? 'unknown').replace('bound ', '') + let action: string = 'Restart' + const actionTypes = ['Start', 'Restart', 'Stop', 'Reboot', 'Shutdown'] + + actionTypes.forEach((actionType: string) => { + if (functionName.endsWith(actionType)) action = actionType + }) + + this.dialogConfirmation.executableFunction = executableFunction + this.dialogConfirmation.serviceName = serviceName + + const functionNameUppercase = functionName.trim().charAt(0).toUpperCase() + functionName.trim().slice(1) + this.dialogConfirmation.title = this.$t('App.TopCornerMenu.ConfirmationDialog.Title.' + functionNameUppercase)+'' + this.dialogConfirmation.description = this.$t('App.TopCornerMenu.ConfirmationDialog.Description.' + functionNameUppercase)+'' + this.dialogConfirmation.actionButtonText = this.$t('App.TopCornerMenu.' + action.charAt(0).toUpperCase() + action.slice(1))+'' + this.dialogConfirmation.show = true + } else executableFunction(serviceName) + } + + executeDialog() { + this.dialogConfirmation.executableFunction(this.dialogConfirmation.serviceName) + this.dialogConfirmation.show = false + } + klipperRestart() { this.showMenu = false this.$store.dispatch('server/addEvent', { message: 'RESTART', type: 'command' }) @@ -170,8 +240,7 @@ export default class TheTopCornerMenu extends Mixins(BaseMixin) { const confirmOnPowerDeviceChange = this.$store.state.gui.uiSettings.confirmOnPowerDeviceChange if (confirmOnPowerDeviceChange) { this.dialogPowerDeviceChange.show = true - } - else { + } else { this.powerDeviceToggle() } } diff --git a/src/locales/en.json b/src/locales/en.json index 83d1c3d4..9041dc24 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -17,8 +17,32 @@ "ServiceControl": "Service Control", "PowerDevices": "Power Devices", "HostControl": "Host Control", + "Start": "Start", + "Stop": "Stop", + "Restart": "Restart", "Reboot": "Reboot", - "Shutdown": "Shutdown" + "Shutdown": "Shutdown", + "Cancel": "Cancel", + "ConfirmationDialog": { + "Title": { + "KlipperRestart": "Klipper restart", + "KlipperFirmwareRestart": "Klipper firmware restart", + "ServiceStart": "Service start", + "ServiceRestart": "Service restart", + "ServiceStop": "Service stop", + "HostReboot": "Host reboot", + "HostShutdown": "Host shutdown" + }, + "Description": { + "KlipperRestart": "If you restart Klipper now, the current print will fail.", + "KlipperFirmwareRestart": "If you restart the Klipper firmware now, the current print will fail.", + "ServiceStart": "If you start this service now, you are very likely risking a failure of your ongoing print job.", + "ServiceRestart": "If you restart this service now, you are very likely risking a failure of your ongoing print job.", + "ServiceStop": "If you stop this service now, you are very likely risking a failure of your ongoing print job.", + "HostReboot": "If you reboot the host now, the current print will fail.", + "HostShutdown": "If you shutdown the host now, the current print will fail." + } + } }, "UpdateDialog": { "Updating": "Updating {software}...",