🔨 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 }>(); defineProps<{ loading: boolean }>();
const backupConfigStore = useBackupConfigStore(); const backupConfigStore = useBackupConfigStore();
const { data, addons, invertedAddons } = storeToRefs(backupConfigStore); const { data, addons, invertedAddons } = storeToRefs(backupConfigStore);
watch(invertedAddons, () => { watch(invertedAddons, manageInverted);
manageInverted();
function manageInverted() {
if (!data.value.exclude) { 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) { for (const addon of addons.value) {
if (!invertedAddons.value.includes(addon.slug)) { if (!invertedAddons.value.includes(addon.slug)) {
data.value.exclude.addon.push(addon.slug); data.value.exclude!.addon.push(addon.slug);
} }
} }
}); }
</script> </script>
<style scoped></style> <style scoped></style>

View File

@ -33,14 +33,21 @@ defineProps<{ loading: boolean }>();
const backupConfigStore = useBackupConfigStore(); const backupConfigStore = useBackupConfigStore();
const { data, folders, invertedFolders } = storeToRefs(backupConfigStore); const { data, folders, invertedFolders } = storeToRefs(backupConfigStore);
watch(invertedFolders, () => { watch(invertedFolders, manageInverted);
data.value.exclude.folder = [];
manageInverted();
function manageInverted() {
if (!data.value.exclude) {
backupConfigStore.initExcludes();
}
data.value.exclude!.folder = [];
for (const folder of folders.value) { for (const folder of folders.value) {
if (!invertedFolders.value.includes(folder.slug)) { if (!invertedFolders.value.includes(folder.slug)) {
data.value.exclude.folder.push(folder.slug); data.value.exclude!.folder.push(folder.slug);
} }
} }
}); }
</script> </script>
<style scoped></style> <style scoped></style>

View File

@ -1,6 +1,6 @@
import { getBackupConfig } from "@/services/configService"; import { getBackupConfig } from "@/services/configService";
import { getAddons, getFolders } from "@/services/homeAssistantService"; 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 type { Folder, AddonModel } from "@/types/homeAssistant";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref } from "vue"; import { ref } from "vue";
@ -20,16 +20,19 @@ export const useBackupConfigStore = defineStore("backupConfig", () => {
const foldersProm = getFolders(); const foldersProm = getFolders();
const addonsProm = getAddons(); const addonsProm = getAddons();
return Promise.all([conf, foldersProm, addonsProm]).then((value) => { return Promise.all([conf, foldersProm, addonsProm]).then((value) => {
for (const folder of value[1]) { if (value[0].backupType == BackupType.Partial && value[0].exclude) {
if (!value[0].exclude.folder.includes(folder.slug)) { for (const folder of value[1]) {
invertedFolders.value.push(folder.slug); 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)) { for (const addon of value[2].addons) {
invertedAddons.value.push(addon.slug); if (!value[0].exclude.addon.includes(addon.slug)) {
invertedAddons.value.push(addon.slug);
}
} }
} }
data.value = value[0]; data.value = value[0];
folders.value = value[1]; folders.value = value[1];
addons.value = value[2].addons; 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) { function removeCron(id: string) {
data.value.cron = data.value.cron.filter((value) => value.id != id); data.value.cron = data.value.cron.filter((value) => value.id != id);
} }
@ -56,5 +69,6 @@ export const useBackupConfigStore = defineStore("backupConfig", () => {
loadAll, loadAll,
addEmptyCron, addEmptyCron,
removeCron, removeCron,
initExcludes,
}; };
}); });