feat: UI Update OS Cancel

This commit is contained in:
Zack Spear
2024-05-09 16:20:53 -07:00
committed by Zack Spear
parent 05c7c481a9
commit f3dc9663b8
4 changed files with 56 additions and 5 deletions
+15 -3
View File
@@ -1,6 +1,7 @@
<script lang="ts" setup>
import {
ArrowPathIcon,
ArrowTopRightOnSquareIcon,
BellAlertIcon,
CheckCircleIcon,
ExclamationTriangleIcon,
@@ -11,10 +12,11 @@ import { storeToRefs } from 'pinia';
import { WEBGUI_TOOLS_REGISTRATION } from '~/helpers/urls';
import useDateTimeHelper from '~/composables/dateTime';
import { useAccountStore } from '~/store/account';
import { useServerStore } from '~/store/server';
import { useUpdateOsStore } from '~/store/updateOs';
import { useUpdateOsActionsStore } from '~/store/updateOsActions';
import type { UserProfileLink } from '~/types/userProfile';
import type { ButtonProps } from '~/types/ui/button';
import BrandLoadingWhite from '~/components/Brand/LoadingWhite.vue';
@@ -34,6 +36,7 @@ const props = withDefaults(defineProps<Props>(), {
subtitle: undefined,
});
const accountStore = useAccountStore();
const serverStore = useServerStore();
const updateOsStore = useUpdateOsStore();
const updateOsActionsStore = useUpdateOsActionsStore();
@@ -65,7 +68,7 @@ const regExpOutput = computed(() => {
const showRebootButton = computed(() => rebootType.value === 'downgrade' || rebootType.value === 'update');
const checkButton = computed((): UserProfileLink => {
const checkButton = computed((): ButtonProps => {
if (!available.value && !availableWithRenewal.value) {
return {
click: () => {
@@ -187,7 +190,16 @@ const checkButton = computed((): UserProfileLink => {
:btn-style="!anyAvailable ? 'outline' : 'fill'"
:icon="checkButton.icon"
:text="checkButton.text"
@click="checkButton.click()"
@click="checkButton.click"
/>
</span>
<span v-if="rebootType !== ''">
<BrandButton
btn-style="outline"
:icon="XCircleIcon"
:text="t('Cancel {0}', [rebootType === 'downgrade' ? t('Downgrade') : t('Update')])"
@click="updateOsStore.cancelUpdate()"
/>
</span>
</div>
+22
View File
@@ -142,3 +142,25 @@ export const WebguiUpdateIgnore = async (payload: WebguiUnraidCheckPayload): Pro
throw new Error('Error ignoring update');
}
};
export interface WebguiUpdateCancelResponse {
message?: string;
success?: boolean;
}
export const WebguiUpdateCancel = async (): Promise<WebguiUpdateCancelResponse> => {
console.debug('[WebguiUpdateCancel]');
try {
const response = await request
.url('/plugins/dynamix.plugin.manager/include/UnraidUpdateCancel.php')
.get()
.json(json => json as WebguiUpdateCancelResponse)
.catch((error) => {
console.error('[WebguiUpdateCancel] catch failed to execute UpdateUpdateCancel', error);
throw new Error('Error attempting to revert OS files to cancel update');
});
return response as WebguiUpdateCancelResponse;
} catch (error) {
console.error('[WebguiUpdateCancel] catch failed to execute UpdateUpdateCancel', error);
throw new Error('Error attempting to revert OS files to cancel update');
}
};
+2 -1
View File
@@ -364,5 +364,6 @@
"Enable update notifications": "Enable update notifications",
"Link Key": "Link Key",
"Not Linked": "Not Linked",
"Learn more and link your key to your account": "Learn more and link your key to your account"
"Learn more and link your key to your account": "Learn more and link your key to your account",
"Cancel {0}": "Cancel {0}"
}
+17 -1
View File
@@ -4,7 +4,10 @@ import relativeTime from 'dayjs/plugin/relativeTime';
import { defineStore, createPinia, setActivePinia } from 'pinia';
import { computed } from 'vue';
import { WebguiCheckForUpdate } from '~/composables/services/webgui';
import {
WebguiCheckForUpdate,
WebguiUpdateCancel,
} from '~/composables/services/webgui';
import { useServerStore } from '~/store/server';
import type { ServerUpdateOsResponse } from '~/types/server';
/**
@@ -70,6 +73,18 @@ export const useUpdateOsStore = defineStore('updateOs', () => {
}
};
const cancelUpdate = async (): Promise<void> => {
try {
const response = await WebguiUpdateCancel();
if (!response.success) {
throw new Error('Unable to cancel update');
}
window.location.reload();
} catch (error) {
throw new Error('[cancelUpdate] Error cancelling update');
}
};
const setModalOpen = (val: boolean) => {
modalOpen.value = val;
};
@@ -86,6 +101,7 @@ export const useUpdateOsStore = defineStore('updateOs', () => {
availableRequiresAuth,
// actions
localCheckForUpdate,
cancelUpdate,
setModalOpen,
};
});