2023-01-17 18:25:56 +00:00
|
|
|
<template>
|
2023-09-14 12:51:30 +00:00
|
|
|
<BulmaDrawer header="Türchen bearbeiten" @open="on_open">
|
2023-09-10 03:38:24 +00:00
|
|
|
<div class="is-flex is-align-items-center is-justify-content-space-between">
|
2023-09-10 00:54:29 +00:00
|
|
|
<BulmaButton
|
|
|
|
:disabled="current_step === 0"
|
|
|
|
class="is-link"
|
|
|
|
@click="current_step--"
|
|
|
|
icon="fa-solid fa-backward"
|
|
|
|
/>
|
|
|
|
<BulmaBreadcrumbs :steps="steps" v-model="current_step" class="mb-0" />
|
|
|
|
<BulmaButton
|
|
|
|
:disabled="current_step === 2"
|
|
|
|
class="is-link"
|
|
|
|
@click="current_step++"
|
|
|
|
icon="fa-solid fa-forward"
|
|
|
|
/>
|
|
|
|
</div>
|
2023-01-19 00:22:01 +00:00
|
|
|
|
2023-09-10 00:54:29 +00:00
|
|
|
<DoorPlacer v-if="current_step === 0" v-model:doors="doors" />
|
|
|
|
<DoorChooser v-if="current_step === 1" v-model:doors="doors" />
|
2023-09-10 03:38:24 +00:00
|
|
|
<div v-if="current_step === 2" class="card-content">
|
2023-09-10 00:54:29 +00:00
|
|
|
<Calendar :doors="doors" />
|
|
|
|
</div>
|
2023-09-09 22:18:16 +00:00
|
|
|
|
2023-09-10 03:38:24 +00:00
|
|
|
<footer class="card-footer is-flex is-justify-content-space-around">
|
2023-09-10 00:54:29 +00:00
|
|
|
<BulmaButton
|
2023-09-10 03:38:24 +00:00
|
|
|
class="card-footer-item is-danger"
|
2023-09-10 00:54:29 +00:00
|
|
|
@click="on_download"
|
|
|
|
icon="fa-solid fa-cloud-arrow-down"
|
2023-09-13 14:07:09 +00:00
|
|
|
:busy="loading_doors"
|
2023-09-10 00:54:29 +00:00
|
|
|
text="Laden"
|
|
|
|
/>
|
|
|
|
<BulmaButton
|
2023-09-10 03:38:24 +00:00
|
|
|
class="card-footer-item is-warning"
|
2023-09-10 00:54:29 +00:00
|
|
|
@click="on_discard"
|
|
|
|
icon="fa-solid fa-trash"
|
|
|
|
text="Löschen"
|
|
|
|
/>
|
|
|
|
<BulmaButton
|
2023-09-10 03:38:24 +00:00
|
|
|
class="card-footer-item is-success"
|
2023-09-10 00:54:29 +00:00
|
|
|
@click="on_upload"
|
|
|
|
icon="fa-solid fa-cloud-arrow-up"
|
2023-09-13 14:07:09 +00:00
|
|
|
:busy="saving_doors"
|
2023-09-10 00:54:29 +00:00
|
|
|
text="Speichern"
|
|
|
|
/>
|
2023-09-10 03:38:24 +00:00
|
|
|
</footer>
|
2023-09-09 22:18:16 +00:00
|
|
|
</BulmaDrawer>
|
2023-01-17 18:25:56 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2023-09-12 16:55:34 +00:00
|
|
|
import { DoorsSaved } from "@/lib/api";
|
|
|
|
import { Door } from "@/lib/door";
|
2023-09-06 16:25:35 +00:00
|
|
|
import { Options, Vue } from "vue-class-component";
|
2023-01-17 18:25:56 +00:00
|
|
|
|
2023-09-13 16:08:05 +00:00
|
|
|
import Calendar from "../Calendar.vue";
|
|
|
|
import BulmaBreadcrumbs, { Step } from "../bulma/Breadcrumbs.vue";
|
|
|
|
import BulmaButton from "../bulma/Button.vue";
|
2023-09-14 12:51:30 +00:00
|
|
|
import BulmaDrawer from "../bulma/Drawer.vue";
|
2023-09-13 16:08:05 +00:00
|
|
|
import DoorChooser from "../editor/DoorChooser.vue";
|
|
|
|
import DoorPlacer from "../editor/DoorPlacer.vue";
|
2023-01-24 00:14:50 +00:00
|
|
|
|
2023-01-17 18:25:56 +00:00
|
|
|
@Options({
|
|
|
|
components: {
|
2023-02-02 12:50:12 +00:00
|
|
|
BulmaBreadcrumbs,
|
2023-09-07 15:43:05 +00:00
|
|
|
BulmaButton,
|
2023-09-09 22:18:16 +00:00
|
|
|
BulmaDrawer,
|
2023-01-19 17:59:18 +00:00
|
|
|
DoorPlacer,
|
2023-01-24 00:14:50 +00:00
|
|
|
DoorChooser,
|
2023-09-07 00:41:38 +00:00
|
|
|
Calendar,
|
2023-01-17 18:25:56 +00:00
|
|
|
},
|
|
|
|
})
|
2023-01-24 23:19:25 +00:00
|
|
|
export default class extends Vue {
|
2023-09-06 16:25:35 +00:00
|
|
|
public readonly steps: Step[] = [
|
2023-01-20 00:42:47 +00:00
|
|
|
{ label: "Platzieren", icon: "fa-solid fa-crosshairs" },
|
|
|
|
{ label: "Ordnen", icon: "fa-solid fa-list-ol" },
|
2023-09-09 23:53:49 +00:00
|
|
|
{ label: "Vorschau", icon: "fa-solid fa-magnifying-glass" },
|
2023-01-20 00:42:47 +00:00
|
|
|
];
|
2023-09-06 16:25:35 +00:00
|
|
|
public current_step = 0;
|
|
|
|
public doors: Door[] = [];
|
2023-09-07 03:30:21 +00:00
|
|
|
|
2023-09-13 14:07:09 +00:00
|
|
|
public loading_doors = false;
|
|
|
|
public saving_doors = false;
|
2023-09-07 16:44:44 +00:00
|
|
|
|
2023-09-14 12:51:30 +00:00
|
|
|
private load_doors(): Promise<void> {
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
2023-09-13 15:24:25 +00:00
|
|
|
this.$advent22
|
|
|
|
.api_get<DoorsSaved>("admin/doors")
|
|
|
|
.then((data) => {
|
|
|
|
this.doors.length = 0;
|
|
|
|
|
|
|
|
for (const value of data) {
|
|
|
|
this.doors.push(Door.load(value));
|
|
|
|
}
|
|
|
|
|
2023-09-14 12:51:30 +00:00
|
|
|
resolve();
|
2023-09-13 15:24:25 +00:00
|
|
|
})
|
2023-09-13 15:58:15 +00:00
|
|
|
.catch((error) => {
|
|
|
|
alert(this.$advent22.format_user_error(error));
|
2023-09-13 15:24:25 +00:00
|
|
|
reject();
|
|
|
|
});
|
|
|
|
});
|
2023-09-07 16:44:44 +00:00
|
|
|
}
|
|
|
|
|
2023-09-09 22:18:16 +00:00
|
|
|
private save_doors(): Promise<void> {
|
2023-09-13 15:24:25 +00:00
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
const data: DoorsSaved = [];
|
|
|
|
|
|
|
|
for (const door of this.doors) {
|
|
|
|
data.push(door.save());
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$advent22
|
|
|
|
.api_put("admin/doors", data)
|
|
|
|
.then(resolve)
|
2023-09-13 15:58:15 +00:00
|
|
|
.catch((error) => {
|
|
|
|
alert(this.$advent22.format_user_error(error));
|
2023-09-13 15:24:25 +00:00
|
|
|
reject();
|
|
|
|
});
|
|
|
|
});
|
2023-09-07 03:30:21 +00:00
|
|
|
}
|
2023-09-07 20:54:11 +00:00
|
|
|
|
2023-09-14 12:51:30 +00:00
|
|
|
public on_open(ready: () => void, fail: () => void): void {
|
|
|
|
console.log(ready, fail);
|
2023-09-13 15:58:15 +00:00
|
|
|
|
2023-09-14 12:51:30 +00:00
|
|
|
this.load_doors().then(ready).catch(fail);
|
2023-09-09 22:18:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public on_download() {
|
|
|
|
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
2023-09-13 14:07:09 +00:00
|
|
|
this.loading_doors = true;
|
|
|
|
|
2023-09-13 15:24:25 +00:00
|
|
|
this.load_doors()
|
2023-09-13 19:20:11 +00:00
|
|
|
.then(() => alert("Erfolgreich!"))
|
2023-09-13 15:24:25 +00:00
|
|
|
.catch(() => {})
|
|
|
|
.finally(() => (this.loading_doors = false));
|
2023-09-09 22:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public on_discard() {
|
|
|
|
if (confirm("Alle Türchen löschen? (nur lokal)")) {
|
|
|
|
// empty `doors` array
|
|
|
|
this.doors.length = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public on_upload() {
|
|
|
|
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
2023-09-13 14:07:09 +00:00
|
|
|
this.saving_doors = true;
|
|
|
|
|
2023-09-13 15:24:25 +00:00
|
|
|
this.save_doors()
|
|
|
|
.then(() => {
|
|
|
|
this.load_doors()
|
2023-09-13 19:20:11 +00:00
|
|
|
.then(() => alert("Erfolgreich!"))
|
2023-09-13 15:24:25 +00:00
|
|
|
.catch(() => {})
|
|
|
|
.finally(() => (this.saving_doors = false));
|
|
|
|
})
|
|
|
|
.catch(() => (this.saving_doors = false));
|
2023-09-09 22:18:16 +00:00
|
|
|
}
|
|
|
|
}
|
2023-09-07 20:54:11 +00:00
|
|
|
}
|
2023-09-09 22:18:16 +00:00
|
|
|
</script>
|