From ff21d77f7876a5324ee14ca70a94c8b2379d0669 Mon Sep 17 00:00:00 2001 From: SebClem Date: Sun, 5 Feb 2023 18:59:23 +0100 Subject: [PATCH] :hammer: Fix backup type chang --- .../BackupConfig/BackupConfigAddon.vue | 14 +++++--- .../BackupConfig/BackupConfigFolder.vue | 15 ++++++--- .../frontend/src/stores/backupConfig.ts | 32 +++++++++++++------ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigAddon.vue b/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigAddon.vue index 2890c0d..9415bf4 100644 --- a/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigAddon.vue +++ b/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigAddon.vue @@ -32,17 +32,21 @@ import { watch } from "vue"; defineProps<{ loading: boolean }>(); const backupConfigStore = useBackupConfigStore(); const { data, addons, invertedAddons } = storeToRefs(backupConfigStore); -watch(invertedAddons, () => { +watch(invertedAddons, manageInverted); + +manageInverted(); + +function manageInverted() { if (!data.value.exclude) { - data.value.exclude = { addon: [], folder: [] }; + backupConfigStore.initExcludes(); } - data.value.exclude.addon = []; + data.value.exclude!.addon = []; for (const addon of addons.value) { if (!invertedAddons.value.includes(addon.slug)) { - data.value.exclude.addon.push(addon.slug); + data.value.exclude!.addon.push(addon.slug); } } -}); +} diff --git a/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigFolder.vue b/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigFolder.vue index da25dce..fcc1dc4 100644 --- a/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigFolder.vue +++ b/nextcloud_backup/frontend/src/components/settings/BackupConfig/BackupConfigFolder.vue @@ -33,14 +33,21 @@ defineProps<{ loading: boolean }>(); const backupConfigStore = useBackupConfigStore(); const { data, folders, invertedFolders } = storeToRefs(backupConfigStore); -watch(invertedFolders, () => { - data.value.exclude.folder = []; +watch(invertedFolders, manageInverted); + +manageInverted(); + +function manageInverted() { + if (!data.value.exclude) { + backupConfigStore.initExcludes(); + } + data.value.exclude!.folder = []; for (const folder of folders.value) { if (!invertedFolders.value.includes(folder.slug)) { - data.value.exclude.folder.push(folder.slug); + data.value.exclude!.folder.push(folder.slug); } } -}); +} diff --git a/nextcloud_backup/frontend/src/stores/backupConfig.ts b/nextcloud_backup/frontend/src/stores/backupConfig.ts index 0c500e8..efbf976 100644 --- a/nextcloud_backup/frontend/src/stores/backupConfig.ts +++ b/nextcloud_backup/frontend/src/stores/backupConfig.ts @@ -1,6 +1,6 @@ import { getBackupConfig } from "@/services/configService"; import { getAddons, getFolders } from "@/services/homeAssistantService"; -import { CronMode, type BackupConfig } from "@/types/backupConfig"; +import { BackupType, CronMode, type BackupConfig } from "@/types/backupConfig"; import type { Folder, AddonModel } from "@/types/homeAssistant"; import { defineStore } from "pinia"; import { ref } from "vue"; @@ -20,16 +20,19 @@ export const useBackupConfigStore = defineStore("backupConfig", () => { const foldersProm = getFolders(); const addonsProm = getAddons(); return Promise.all([conf, foldersProm, addonsProm]).then((value) => { - for (const folder of value[1]) { - if (!value[0].exclude.folder.includes(folder.slug)) { - invertedFolders.value.push(folder.slug); - } - } - for (const addon of value[2].addons) { - if (!value[0].exclude.addon.includes(addon.slug)) { - invertedAddons.value.push(addon.slug); + if (value[0].backupType == BackupType.Partial && value[0].exclude) { + for (const folder of value[1]) { + if (!value[0].exclude.folder.includes(folder.slug)) { + invertedFolders.value.push(folder.slug); + } + } + for (const addon of value[2].addons) { + if (!value[0].exclude.addon.includes(addon.slug)) { + invertedAddons.value.push(addon.slug); + } } } + data.value = value[0]; folders.value = value[1]; addons.value = value[2].addons; @@ -43,6 +46,16 @@ export const useBackupConfigStore = defineStore("backupConfig", () => { }); } + function initExcludes() { + data.value.exclude = { addon: [], folder: [] }; + addons.value.forEach((value) => { + invertedAddons.value.push(value.slug); + }); + folders.value.forEach((value) => { + invertedFolders.value.push(value.slug); + }); + } + function removeCron(id: string) { data.value.cron = data.value.cron.filter((value) => value.id != id); } @@ -56,5 +69,6 @@ export const useBackupConfigStore = defineStore("backupConfig", () => { loadAll, addEmptyCron, removeCron, + initExcludes, }; });