🔨 Fix backup type chang

This commit is contained in:
SebClem 2023-02-05 18:59:23 +01:00
parent 6cb6705c93
commit ff21d77f78
Signed by: sebclem
GPG Key ID: 5A4308F6A359EA50
3 changed files with 43 additions and 18 deletions

View File

@ -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);
}
}
}
});
</script>
<style scoped></style>

View File

@ -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);
}
}
}
});
</script>
<style scoped></style>

View File

@ -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,6 +20,7 @@ export const useBackupConfigStore = defineStore("backupConfig", () => {
const foldersProm = getFolders();
const addonsProm = getAddons();
return Promise.all([conf, foldersProm, addonsProm]).then((value) => {
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);
@ -30,6 +31,8 @@ export const useBackupConfigStore = defineStore("backupConfig", () => {
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,
};
});