backup read, upload and restore
This commit is contained in:
parent
e5cb8fecc6
commit
f8fb222ebb
13 changed files with 555 additions and 8 deletions
81
package-lock.json
generated
81
package-lock.json
generated
|
@ -17,7 +17,7 @@
|
|||
"@headlessui/vue": "^1.7.13",
|
||||
"@heroicons/vue": "^2.1.5",
|
||||
"@vueup/vue-quill": "^1.2.0",
|
||||
"axios": "^0.26.1",
|
||||
"axios": "^1.7.9",
|
||||
"event-source-polyfill": "^1.0.31",
|
||||
"grapesjs": "^0.22.4",
|
||||
"grapesjs-preset-newsletter": "^1.0.2",
|
||||
|
@ -3951,6 +3951,12 @@
|
|||
"integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/at-least-node": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
|
||||
|
@ -4013,11 +4019,14 @@
|
|||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||
"integrity": "sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==",
|
||||
"version": "1.7.9",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.14.8"
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/b4a": {
|
||||
|
@ -4515,6 +4524,18 @@
|
|||
"integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/combined-stream": {
|
||||
"version": "1.0.8",
|
||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"delayed-stream": "~1.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/commander": {
|
||||
"version": "2.20.3",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||
|
@ -4875,6 +4896,15 @@
|
|||
"integrity": "sha512-mEQCMmwJu317oSz8CwdIOdwf3xMif1ttiM8LTufzc3g6kR+9Pe236twL8j3IYT1F7GfRgGcW6MWxzZjLIkuHIg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/detect-libc": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.3.tgz",
|
||||
|
@ -5714,6 +5744,20 @@
|
|||
"url": "https://github.com/sponsors/isaacs"
|
||||
}
|
||||
},
|
||||
"node_modules/form-data": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
|
||||
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"asynckit": "^0.4.0",
|
||||
"combined-stream": "^1.0.8",
|
||||
"mime-types": "^2.1.12"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 6"
|
||||
}
|
||||
},
|
||||
"node_modules/fraction.js": {
|
||||
"version": "4.3.7",
|
||||
"resolved": "https://registry.npmjs.org/fraction.js/-/fraction.js-4.3.7.tgz",
|
||||
|
@ -7172,6 +7216,27 @@
|
|||
"node": ">=8.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.52.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
|
||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mime-types": {
|
||||
"version": "2.1.35",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
|
||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/mimic-response": {
|
||||
"version": "3.1.0",
|
||||
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",
|
||||
|
@ -8115,6 +8180,12 @@
|
|||
"integrity": "sha512-H5oELycFml5yto/atYqmjyigJoAo3+OXwolYiH7OfQuYlAqhxNvTfiNMbV9hsC6Yp83yE5r2KTVmtrG6R9i6Pg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/pump": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
"@headlessui/vue": "^1.7.13",
|
||||
"@heroicons/vue": "^2.1.5",
|
||||
"@vueup/vue-quill": "^1.2.0",
|
||||
"axios": "^0.26.1",
|
||||
"axios": "^1.7.9",
|
||||
"event-source-polyfill": "^1.0.31",
|
||||
"grapesjs": "^0.22.4",
|
||||
"grapesjs-preset-newsletter": "^1.0.2",
|
||||
|
|
58
src/components/admin/user/backup/BackupListItem.vue
Normal file
58
src/components/admin/user/backup/BackupListItem.vue
Normal file
|
@ -0,0 +1,58 @@
|
|||
<template>
|
||||
<div class="flex flex-col h-fit w-full border border-primary rounded-md">
|
||||
<div class="bg-primary p-2 text-white flex flex-row justify-between items-center">
|
||||
<p>{{ backup }}</p>
|
||||
<div class="flex flex-row">
|
||||
<div @click="downloadBackup">
|
||||
<ArrowDownTrayIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
|
||||
</div>
|
||||
<div v-if="can('admin', 'user', 'backup')" @click="openRestoreModal">
|
||||
<BarsArrowUpIcon class="w-5 h-5 p-1 box-content cursor-pointer" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineComponent, defineAsyncComponent, markRaw, type PropType } from "vue";
|
||||
import { mapState, mapActions } from "pinia";
|
||||
import { ArchiveBoxArrowDownIcon, ArrowDownTrayIcon, BarsArrowUpIcon } from "@heroicons/vue/24/outline";
|
||||
import { useAbilityStore } from "@/stores/ability";
|
||||
import { useModalStore } from "@/stores/modal";
|
||||
import { useBackupStore } from "../../../../stores/admin/user/backup";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default defineComponent({
|
||||
props: {
|
||||
backup: { type: String, default: "" },
|
||||
},
|
||||
computed: {
|
||||
...mapState(useAbilityStore, ["can"]),
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useModalStore, ["openModal"]),
|
||||
...mapActions(useBackupStore, ["fetchBackupById"]),
|
||||
openRestoreModal() {
|
||||
this.openModal(
|
||||
markRaw(defineAsyncComponent(() => import("@/components/admin/user/backup/RestoreBackupModal.vue"))),
|
||||
this.backup
|
||||
);
|
||||
},
|
||||
downloadBackup() {
|
||||
this.fetchBackupById(this.backup)
|
||||
.then((response) => {
|
||||
const fileURL = window.URL.createObjectURL(new Blob([JSON.stringify(response.data, null, 2)]));
|
||||
const fileLink = document.createElement("a");
|
||||
fileLink.href = fileURL;
|
||||
fileLink.setAttribute("download", this.backup);
|
||||
document.body.appendChild(fileLink);
|
||||
fileLink.click();
|
||||
fileLink.remove();
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
67
src/components/admin/user/backup/CreateBackupModal.vue
Normal file
67
src/components/admin/user/backup/CreateBackupModal.vue
Normal file
|
@ -0,0 +1,67 @@
|
|||
<template>
|
||||
<div class="w-full md:max-w-md">
|
||||
<div class="flex flex-col items-center">
|
||||
<p class="text-xl font-medium">Backup erstellen</p>
|
||||
</div>
|
||||
<br />
|
||||
<form class="flex flex-col gap-4 py-2" @submit.prevent="triggerCreateBackup">
|
||||
<div class="flex flex-row gap-2">
|
||||
<button primary type="submit" :disabled="status == 'loading' || status?.status == 'success'">erstellen</button>
|
||||
<Spinner v-if="status == 'loading'" class="my-auto" />
|
||||
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
||||
<FailureXMark v-else-if="status?.status == 'failed'" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="flex flex-row justify-end">
|
||||
<div class="flex flex-row gap-4 py-2">
|
||||
<button primary-outline @click="closeModal" :disabled="status == 'loading' || status?.status == 'success'">
|
||||
abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { mapState, mapActions } from "pinia";
|
||||
import { useModalStore } from "@/stores/modal";
|
||||
import Spinner from "@/components/Spinner.vue";
|
||||
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
||||
import FailureXMark from "@/components/FailureXMark.vue";
|
||||
import { useBackupStore } from "@/stores/admin/user/backup";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default defineComponent({
|
||||
data() {
|
||||
return {
|
||||
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
||||
timeout: undefined as any,
|
||||
};
|
||||
},
|
||||
beforeUnmount() {
|
||||
try {
|
||||
clearTimeout(this.timeout);
|
||||
} catch (error) {}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useModalStore, ["closeModal"]),
|
||||
...mapActions(useBackupStore, ["triggerBackupCreate"]),
|
||||
triggerCreateBackup(e: any) {
|
||||
this.status = "loading";
|
||||
this.triggerBackupCreate()
|
||||
.then(() => {
|
||||
this.status = { status: "success" };
|
||||
this.timeout = setTimeout(() => {
|
||||
this.closeModal();
|
||||
}, 1500);
|
||||
})
|
||||
.catch(() => {
|
||||
this.status = { status: "failed" };
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
101
src/components/admin/user/backup/RestoreBackupModal.vue
Normal file
101
src/components/admin/user/backup/RestoreBackupModal.vue
Normal file
|
@ -0,0 +1,101 @@
|
|||
<template>
|
||||
<div class="w-full md:max-w-md">
|
||||
<div class="flex flex-col items-center">
|
||||
<p class="text-xl font-medium">Backup {{ data }} laden</p>
|
||||
</div>
|
||||
<br />
|
||||
<form class="flex flex-col gap-4 py-2" @submit.prevent="triggerCreateBackup">
|
||||
<div class="flex flex-row items-center gap-2">
|
||||
<input type="checkbox" id="partial" v-model="partial" />
|
||||
<label for="partial">Backup vollständig laden</label>
|
||||
</div>
|
||||
<div v-if="!partial">
|
||||
<label for="sections">Module zur Wiederherstellung auswählen:</label>
|
||||
<select id="sections" multiple>
|
||||
<option v-for="section in backupSections" :value="section">{{ section }}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<br />
|
||||
<p class="flex">
|
||||
<InformationCircleIcon class="min-h-5 h-5 min-w-5 w-5" />Je nach Auswahl, werden die entsprechenden
|
||||
Bestandsdaten ersetzt. Dadurch können Daten, die seit diesem Backup erstellt wurden, verloren gehen.
|
||||
</p>
|
||||
|
||||
<div class="flex flex-row gap-2">
|
||||
<button primary type="submit" :disabled="status == 'loading' || status?.status == 'success'">
|
||||
Backup laden
|
||||
</button>
|
||||
<Spinner v-if="status == 'loading'" class="my-auto" />
|
||||
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
||||
<FailureXMark v-else-if="status?.status == 'failed'" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<div class="flex flex-row justify-end">
|
||||
<div class="flex flex-row gap-4 py-2">
|
||||
<button primary-outline @click="closeModal" :disabled="status == 'loading' || status?.status == 'success'">
|
||||
abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { mapState, mapActions } from "pinia";
|
||||
import { useModalStore } from "@/stores/modal";
|
||||
import Spinner from "@/components/Spinner.vue";
|
||||
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
||||
import FailureXMark from "@/components/FailureXMark.vue";
|
||||
import { useBackupStore } from "@/stores/admin/user/backup";
|
||||
import type { BackupRestoreViewModel } from "../../../../viewmodels/admin/user/backup.models";
|
||||
import { InformationCircleIcon } from "@heroicons/vue/24/outline";
|
||||
import { backupSections, type BackupSection } from "../../../../types/backupTypes";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default defineComponent({
|
||||
props: {
|
||||
data: { type: String, default: "" },
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
||||
timeout: undefined as any,
|
||||
partial: true,
|
||||
};
|
||||
},
|
||||
beforeUnmount() {
|
||||
try {
|
||||
clearTimeout(this.timeout);
|
||||
} catch (error) {}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useModalStore, ["closeModal"]),
|
||||
...mapActions(useBackupStore, ["restoreBackup"]),
|
||||
triggerCreateBackup(e: any) {
|
||||
let formData = e.target.elements;
|
||||
let restoreBackup: BackupRestoreViewModel = {
|
||||
filename: this.data,
|
||||
partial: !formData.partial.checked,
|
||||
include: Array.from(formData?.sections?.selectedOptions ?? []).map(
|
||||
(t) => (t as HTMLOptionElement).value
|
||||
) as Array<BackupSection>,
|
||||
};
|
||||
this.status = "loading";
|
||||
this.restoreBackup(restoreBackup)
|
||||
.then(() => {
|
||||
this.status = { status: "success" };
|
||||
this.timeout = setTimeout(() => {
|
||||
this.closeModal();
|
||||
}, 1500);
|
||||
})
|
||||
.catch(() => {
|
||||
this.status = { status: "failed" };
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
93
src/components/admin/user/backup/UploadBackupModal.vue
Normal file
93
src/components/admin/user/backup/UploadBackupModal.vue
Normal file
|
@ -0,0 +1,93 @@
|
|||
<template>
|
||||
<div class="w-full md:max-w-md">
|
||||
<div class="flex flex-col items-center">
|
||||
<p class="text-xl font-medium">Backup hochladen</p>
|
||||
</div>
|
||||
<br />
|
||||
<div
|
||||
class="hidden md:flex flex-col gap-2 py-7 bg-gray-200 justify-center items-center w-full grow rounded-lg"
|
||||
@drop.prevent="fileDrop"
|
||||
@dragover.prevent
|
||||
>
|
||||
<p class="text-lg text-dark-gray">Datei hierher ziehen</p>
|
||||
</div>
|
||||
<p class="hidden md:block text-center">oder</p>
|
||||
<div class="flex flex-row gap-2 items-center">
|
||||
<input
|
||||
class="!hidden"
|
||||
type="file"
|
||||
ref="fileSelect"
|
||||
accept="application/JSON"
|
||||
@change="(e) => uploadFile((e.target as HTMLInputElement)?.files?.[0])"
|
||||
multiple
|
||||
/>
|
||||
<button primary @click="openFileSelect">Datei auswählen</button>
|
||||
</div>
|
||||
<div class="flex flex-row gap-2 pt-4 items-center justify-center">
|
||||
<Spinner v-if="status == 'loading'" class="my-auto" />
|
||||
<SuccessCheckmark v-else-if="status?.status == 'success'" />
|
||||
<FailureXMark v-else-if="status?.status == 'failed'" />
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row justify-end">
|
||||
<div class="flex flex-row gap-4 py-2">
|
||||
<button primary-outline @click="closeModal" :disabled="status == 'loading' || status?.status == 'success'">
|
||||
abbrechen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { mapState, mapActions } from "pinia";
|
||||
import { useModalStore } from "@/stores/modal";
|
||||
import Spinner from "@/components/Spinner.vue";
|
||||
import SuccessCheckmark from "@/components/SuccessCheckmark.vue";
|
||||
import FailureXMark from "@/components/FailureXMark.vue";
|
||||
import { useBackupStore } from "@/stores/admin/user/backup";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default defineComponent({
|
||||
data() {
|
||||
return {
|
||||
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
||||
timeout: undefined as any,
|
||||
};
|
||||
},
|
||||
beforeUnmount() {
|
||||
try {
|
||||
clearTimeout(this.timeout);
|
||||
} catch (error) {}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useModalStore, ["closeModal"]),
|
||||
...mapActions(useBackupStore, ["uploadBackup"]),
|
||||
openFileSelect(event: Event) {
|
||||
(this.$refs.fileSelect as HTMLInputElement).click();
|
||||
},
|
||||
fileDrop(event: DragEvent) {
|
||||
const file = event.dataTransfer?.files[0];
|
||||
console.log("hi", file);
|
||||
if (file?.type.toLocaleLowerCase() != "application/json") return;
|
||||
this.uploadFile(file);
|
||||
},
|
||||
uploadFile(file?: File) {
|
||||
if (!file) return;
|
||||
this.status = "loading";
|
||||
this.uploadBackup(file)
|
||||
.then(() => {
|
||||
this.status = { status: "success" };
|
||||
this.timeout = setTimeout(() => {
|
||||
this.closeModal();
|
||||
}, 1500);
|
||||
})
|
||||
.catch(() => {
|
||||
this.status = { status: "failed" };
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
|
@ -634,6 +634,13 @@ const router = createRouter({
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "backup",
|
||||
name: "admin-user-backup",
|
||||
component: () => import("@/views/admin/user/backup/Backup.vue"),
|
||||
meta: { type: "read", section: "user", module: "backup" },
|
||||
beforeEnter: [abilityAndNavUpdate],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
@ -133,6 +133,7 @@ export const useNavigationStore = defineStore("navigation", {
|
|||
...(abilityStore.can("read", "user", "user") ? [{ key: "user", title: "Benutzer" }] : []),
|
||||
...(abilityStore.can("read", "user", "role") ? [{ key: "role", title: "Rollen" }] : []),
|
||||
...(abilityStore.can("read", "user", "webapi") ? [{ key: "webapi", title: "Webapi-Token" }] : []),
|
||||
...(abilityStore.can("read", "user", "backup") ? [{ key: "backup", title: "Backups" }] : []),
|
||||
],
|
||||
},
|
||||
} as navigationModel;
|
||||
|
|
56
src/stores/admin/user/backup.ts
Normal file
56
src/stores/admin/user/backup.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import { defineStore } from "pinia";
|
||||
import { http } from "@/serverCom";
|
||||
import type { AxiosResponse, AxiosProgressEvent } from "axios";
|
||||
import type { BackupRestoreViewModel } from "../../../viewmodels/admin/user/backup.models";
|
||||
|
||||
export const useBackupStore = defineStore("backup", {
|
||||
state: () => {
|
||||
return {
|
||||
backups: [] as Array<string>,
|
||||
loading: null as null | "loading" | "success" | "failed",
|
||||
};
|
||||
},
|
||||
actions: {
|
||||
fetchBackups() {
|
||||
this.loading = "loading";
|
||||
http
|
||||
.get("/admin/backup")
|
||||
.then((result) => {
|
||||
this.backups = result.data;
|
||||
this.loading = "success";
|
||||
})
|
||||
.catch((err) => {
|
||||
this.loading = "failed";
|
||||
});
|
||||
},
|
||||
fetchBackupById(filename: string): Promise<AxiosResponse<any, any>> {
|
||||
return http.get(`/admin/backup/${filename}`);
|
||||
},
|
||||
async triggerBackupCreate(): Promise<AxiosResponse<any, any>> {
|
||||
const result = await http.post("/admin/backup");
|
||||
this.fetchBackups();
|
||||
return result;
|
||||
},
|
||||
async restoreBackup(backup: BackupRestoreViewModel): Promise<AxiosResponse<any, any>> {
|
||||
return await http.post("/admin/backup/restore", backup);
|
||||
},
|
||||
async uploadBackup(file: File): Promise<AxiosResponse<any, any>> {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
|
||||
const options = {
|
||||
headers: {
|
||||
"Content-Type": "multipart/form-data",
|
||||
},
|
||||
onUploadProgress: (progressEvent: AxiosProgressEvent) => {
|
||||
const { loaded, total = 1 } = progressEvent;
|
||||
console.log("progress", Math.floor((loaded * 100) / total));
|
||||
},
|
||||
};
|
||||
|
||||
const result = await http.post("/admin/backup/upload", formData, options);
|
||||
this.fetchBackups();
|
||||
return result;
|
||||
},
|
||||
},
|
||||
});
|
24
src/types/backupTypes.ts
Normal file
24
src/types/backupTypes.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
export type BackupSection =
|
||||
| "member"
|
||||
| "memberBase"
|
||||
| "protocol"
|
||||
| "newsletter"
|
||||
| "newsletter_config"
|
||||
| "calendar"
|
||||
| "query"
|
||||
| "template"
|
||||
| "user"
|
||||
| "webapi";
|
||||
|
||||
export const backupSections: Array<BackupSection> = [
|
||||
"member",
|
||||
"memberBase",
|
||||
"protocol",
|
||||
"newsletter",
|
||||
"newsletter_config",
|
||||
"calendar",
|
||||
"query",
|
||||
"template",
|
||||
"user",
|
||||
"webapi",
|
||||
];
|
|
@ -19,7 +19,8 @@ export type PermissionModule =
|
|||
| "query"
|
||||
| "query_store"
|
||||
| "template"
|
||||
| "template_usage";
|
||||
| "template_usage"
|
||||
| "backup";
|
||||
|
||||
export type PermissionType = "read" | "create" | "update" | "delete";
|
||||
|
||||
|
@ -63,6 +64,7 @@ export const permissionModules: Array<PermissionModule> = [
|
|||
"query_store",
|
||||
"template",
|
||||
"template_usage",
|
||||
"backup",
|
||||
];
|
||||
export const permissionTypes: Array<PermissionType> = ["read", "create", "update", "delete"];
|
||||
export const sectionsAndModules: SectionsAndModulesObject = {
|
||||
|
@ -80,5 +82,5 @@ export const sectionsAndModules: SectionsAndModulesObject = {
|
|||
"template_usage",
|
||||
"newsletter_config",
|
||||
],
|
||||
user: ["user", "role", "webapi"],
|
||||
user: ["user", "role", "webapi", "backup"],
|
||||
};
|
||||
|
|
7
src/viewmodels/admin/user/backup.models.ts
Normal file
7
src/viewmodels/admin/user/backup.models.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import type { BackupSection } from "../../../types/backupTypes";
|
||||
|
||||
export interface BackupRestoreViewModel {
|
||||
filename: string;
|
||||
partial: boolean;
|
||||
include: Array<BackupSection>;
|
||||
}
|
60
src/views/admin/user/backup/Backup.vue
Normal file
60
src/views/admin/user/backup/Backup.vue
Normal file
|
@ -0,0 +1,60 @@
|
|||
<template>
|
||||
<MainTemplate>
|
||||
<template #topBar>
|
||||
<div class="flex flex-row items-center justify-between pt-5 pb-3 px-7">
|
||||
<h1 class="font-bold text-xl h-8">Backups</h1>
|
||||
</div>
|
||||
</template>
|
||||
<template #diffMain>
|
||||
<div class="flex flex-col gap-4 h-full pl-7">
|
||||
<div class="flex flex-col gap-2 grow overflow-y-scroll pr-7">
|
||||
<BackupListItem v-for="backup in backups" :key="backup" :backup="backup" />
|
||||
</div>
|
||||
<div class="flex flex-row gap-4">
|
||||
<button v-if="can('create', 'user', 'backup')" primary class="!w-fit" @click="openCreateModal">
|
||||
Backup erstellen
|
||||
</button>
|
||||
<button v-if="can('create', 'user', 'backup')" primary class="!w-fit" @click="openUploadModal">
|
||||
Backup hochladen
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</MainTemplate>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { defineAsyncComponent, defineComponent, markRaw } from "vue";
|
||||
import { mapState, mapActions } from "pinia";
|
||||
import MainTemplate from "@/templates/Main.vue";
|
||||
import { useBackupStore } from "@/stores/admin/user/backup";
|
||||
import BackupListItem from "@/components/admin/user/backup/BackupListItem.vue";
|
||||
import { useModalStore } from "@/stores/modal";
|
||||
import { useAbilityStore } from "@/stores/ability";
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default defineComponent({
|
||||
computed: {
|
||||
...mapState(useBackupStore, ["backups"]),
|
||||
...mapState(useAbilityStore, ["can"]),
|
||||
},
|
||||
mounted() {
|
||||
this.fetchBackups();
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useBackupStore, ["fetchBackups"]),
|
||||
...mapActions(useModalStore, ["openModal"]),
|
||||
openCreateModal() {
|
||||
this.openModal(
|
||||
markRaw(defineAsyncComponent(() => import("@/components/admin/user/backup/CreateBackupModal.vue")))
|
||||
);
|
||||
},
|
||||
openUploadModal() {
|
||||
this.openModal(
|
||||
markRaw(defineAsyncComponent(() => import("@/components/admin/user/backup/UploadBackupModal.vue")))
|
||||
);
|
||||
},
|
||||
},
|
||||
});
|
||||
</script>
|
Loading…
Add table
Reference in a new issue