advent22/ui/src/components/DoorMapEditor.vue

136 lines
3.5 KiB
Vue
Raw Normal View History

2023-01-17 18:25:56 +00:00
<template>
2023-09-10 00:54:29 +00:00
<BulmaDrawer header="Türchen bearbeiten">
<div class="panel-tabs is-justify-content-space-between">
<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" />
<div v-if="current_step === 2" class="panel-block">
<Calendar :doors="doors" />
</div>
2023-09-09 22:18:16 +00:00
2023-09-10 00:54:29 +00:00
<div class="panel-block is-flex is-justify-content-space-around">
<BulmaButton
class="is-danger"
@click="on_download"
icon="fa-solid fa-cloud-arrow-down"
text="Laden"
/>
<BulmaButton
class="is-warning"
@click="on_discard"
icon="fa-solid fa-trash"
text="Löschen"
/>
<BulmaButton
class="is-success"
@click="on_upload"
icon="fa-solid fa-cloud-arrow-up"
text="Speichern"
/>
</div>
2023-09-09 22:18:16 +00:00
</BulmaDrawer>
2023-01-17 18:25:56 +00:00
</template>
2023-09-09 22:18:16 +00:00
<style scoped>
div.panel-block.is-flex button {
min-width: 150px;
}
</style>
2023-01-17 18:25:56 +00:00
<script lang="ts">
2023-09-07 19:34:11 +00:00
import { Door, DoorsSaved } 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-10 00:10:11 +00:00
import BulmaBreadcrumbs, { Step } from "./bulma/Breadcrumbs.vue";
import BulmaButton from "./bulma/Button.vue";
import BulmaDrawer from "./bulma/Drawer.vue";
2023-09-07 00:41:38 +00:00
import Calendar from "./Calendar.vue";
2023-09-07 02:08:56 +00:00
import DoorChooser from "./calendar/editor/DoorChooser.vue";
import DoorPlacer from "./calendar/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-09 22:18:16 +00:00
private load_doors(): Promise<void | DoorsSaved> {
return this.$advent22.api_get<DoorsSaved>("/general/doors").then((data) => {
2023-09-07 17:00:28 +00:00
this.doors.length = 0;
2023-09-07 16:44:44 +00:00
2023-09-07 17:00:28 +00:00
for (const value of data) {
2023-09-07 19:34:11 +00:00
this.doors.push(Door.load(value));
2023-09-07 17:00:28 +00:00
}
});
2023-09-07 16:44:44 +00:00
}
2023-09-09 22:18:16 +00:00
private save_doors(): Promise<void> {
2023-09-07 19:34:11 +00:00
const data: DoorsSaved = [];
2023-09-07 03:30:21 +00:00
for (const door of this.doors) {
if (door.day === -1) {
continue;
}
2023-09-07 19:34:11 +00:00
data.push(door.save());
2023-09-07 03:30:21 +00:00
}
2023-09-09 22:18:16 +00:00
return this.$advent22.api_put("/general/doors", data);
2023-09-07 03:30:21 +00:00
}
2023-09-07 20:54:11 +00:00
2023-09-09 22:18:16 +00:00
public mounted(): void {
this.load_doors().catch((reason) => alert(`Fehler: ${reason}`));
}
public on_download() {
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
this.load_doors()
.then(() => alert("Erfolgeich!"))
.catch((reason) => alert(`Fehler: ${reason}`));
}
}
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?")) {
this.save_doors()
.then(() => alert("Erfolgeich!"))
.catch((reason) => alert(`Fehler: ${reason}`));
}
}
2023-09-07 20:54:11 +00:00
}
2023-09-09 22:18:16 +00:00
</script>