🚧 wip on ui: rework for vue 3 composition API
This commit is contained in:
parent
f482fd4ec1
commit
96a3747262
3 changed files with 99 additions and 122 deletions
|
|
@ -68,15 +68,13 @@
|
||||||
</BulmaDrawer>
|
</BulmaDrawer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { API } from "@/lib/api";
|
import { API } from "@/lib/api";
|
||||||
import { APIError } from "@/lib/api_error";
|
import { APIError } from "@/lib/api_error";
|
||||||
import { Step } from "@/lib/helpers";
|
import { Step } from "@/lib/helpers";
|
||||||
import { DoorSaved } from "@/lib/model";
|
import { DoorSaved } from "@/lib/model";
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { advent22Store } from "@/lib/store";
|
|
||||||
import { toast } from "bulma-toast";
|
import { toast } from "bulma-toast";
|
||||||
import { Options, Vue } from "vue-class-component";
|
|
||||||
|
|
||||||
import Calendar from "../Calendar.vue";
|
import Calendar from "../Calendar.vue";
|
||||||
import BulmaBreadcrumbs from "../bulma/Breadcrumbs.vue";
|
import BulmaBreadcrumbs from "../bulma/Breadcrumbs.vue";
|
||||||
|
|
@ -85,112 +83,101 @@ import BulmaDrawer from "../bulma/Drawer.vue";
|
||||||
import DoorChooser from "../editor/DoorChooser.vue";
|
import DoorChooser from "../editor/DoorChooser.vue";
|
||||||
import DoorPlacer from "../editor/DoorPlacer.vue";
|
import DoorPlacer from "../editor/DoorPlacer.vue";
|
||||||
|
|
||||||
@Options({
|
const steps: Step[] = [
|
||||||
components: {
|
{ label: "Platzieren", icon: "fa-solid fa-crosshairs" },
|
||||||
BulmaBreadcrumbs,
|
{ label: "Ordnen", icon: "fa-solid fa-list-ol" },
|
||||||
BulmaButton,
|
{ label: "Vorschau", icon: "fa-solid fa-magnifying-glass" },
|
||||||
BulmaDrawer,
|
];
|
||||||
DoorPlacer,
|
|
||||||
DoorChooser,
|
|
||||||
Calendar,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
export default class extends Vue {
|
|
||||||
public readonly steps: Step[] = [
|
|
||||||
{ label: "Platzieren", icon: "fa-solid fa-crosshairs" },
|
|
||||||
{ label: "Ordnen", icon: "fa-solid fa-list-ol" },
|
|
||||||
{ label: "Vorschau", icon: "fa-solid fa-magnifying-glass" },
|
|
||||||
];
|
|
||||||
public current_step = 0;
|
|
||||||
public doors: Door[] = [];
|
|
||||||
private readonly store = advent22Store();
|
|
||||||
|
|
||||||
public loading_doors = false;
|
const doors: Door[] = [];
|
||||||
public saving_doors = false;
|
|
||||||
|
|
||||||
private load_doors(): Promise<void> {
|
// eslint-disable-next-line prefer-const
|
||||||
return new Promise<void>((resolve, reject) => {
|
let current_step = 0; // write access in template
|
||||||
API.request<DoorSaved[]>("admin/doors")
|
let loading_doors = false;
|
||||||
.then((data) => {
|
let saving_doors = false;
|
||||||
this.doors.length = 0;
|
|
||||||
|
|
||||||
for (const value of data) {
|
function load_doors(): Promise<void> {
|
||||||
this.doors.push(Door.load(value));
|
return new Promise<void>((resolve, reject) => {
|
||||||
}
|
API.request<DoorSaved[]>("admin/doors")
|
||||||
|
.then((data) => {
|
||||||
|
doors.length = 0;
|
||||||
|
|
||||||
resolve();
|
for (const value of data) {
|
||||||
})
|
doors.push(Door.load(value));
|
||||||
.catch((error) => {
|
}
|
||||||
APIError.alert(error);
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private save_doors(): Promise<void> {
|
resolve();
|
||||||
return new Promise<void>((resolve, reject) => {
|
})
|
||||||
const data: DoorSaved[] = [];
|
.catch((error) => {
|
||||||
|
APIError.alert(error);
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
for (const door of this.doors) {
|
function save_doors(): Promise<void> {
|
||||||
data.push(door.save());
|
return new Promise<void>((resolve, reject) => {
|
||||||
}
|
const data: DoorSaved[] = [];
|
||||||
|
|
||||||
API.request<void>({ endpoint: "admin/doors", method: "PUT", data: data })
|
for (const door of doors) {
|
||||||
.then(resolve)
|
data.push(door.save());
|
||||||
.catch((error) => {
|
|
||||||
APIError.alert(error);
|
|
||||||
reject();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public on_open(ready: () => void, fail: () => void): void {
|
|
||||||
this.load_doors().then(ready).catch(fail);
|
|
||||||
}
|
|
||||||
|
|
||||||
public on_download() {
|
|
||||||
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
|
||||||
this.loading_doors = true;
|
|
||||||
|
|
||||||
this.load_doors()
|
|
||||||
.then(() =>
|
|
||||||
toast({
|
|
||||||
message: "Erfolgreich!",
|
|
||||||
type: "is-success",
|
|
||||||
duration: 2e3,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.catch(() => {})
|
|
||||||
.finally(() => (this.loading_doors = false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
API.request<void>({ endpoint: "admin/doors", method: "PUT", data: data })
|
||||||
|
.then(resolve)
|
||||||
|
.catch((error) => {
|
||||||
|
APIError.alert(error);
|
||||||
|
reject();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function on_open(ready: () => void, fail: () => void): void {
|
||||||
|
load_doors().then(ready).catch(fail);
|
||||||
|
}
|
||||||
|
|
||||||
|
function on_download() {
|
||||||
|
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
||||||
|
loading_doors = true;
|
||||||
|
|
||||||
|
load_doors()
|
||||||
|
.then(() =>
|
||||||
|
toast({
|
||||||
|
message: "Erfolgreich!",
|
||||||
|
type: "is-success",
|
||||||
|
duration: 2e3,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => (loading_doors = false));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public on_discard() {
|
function on_discard() {
|
||||||
if (confirm("Alle Türchen löschen? (nur lokal)")) {
|
if (confirm("Alle Türchen löschen? (nur lokal)")) {
|
||||||
// empty `doors` array
|
// empty `doors` array
|
||||||
this.doors.length = 0;
|
doors.length = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public on_upload() {
|
function on_upload() {
|
||||||
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
||||||
this.saving_doors = true;
|
saving_doors = true;
|
||||||
|
|
||||||
this.save_doors()
|
save_doors()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.load_doors()
|
load_doors()
|
||||||
.then(() =>
|
.then(() =>
|
||||||
toast({
|
toast({
|
||||||
message: "Erfolgreich!",
|
message: "Erfolgreich!",
|
||||||
type: "is-success",
|
type: "is-success",
|
||||||
duration: 2e3,
|
duration: 2e3,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.catch(() => {})
|
.catch(() => {})
|
||||||
.finally(() => (this.saving_doors = false));
|
.finally(() => (saving_doors = false));
|
||||||
})
|
})
|
||||||
.catch(() => (this.saving_doors = false));
|
.catch(() => (saving_doors = false));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -13,29 +13,21 @@
|
||||||
</SVGRect>
|
</SVGRect>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script setup lang="ts">
|
||||||
import { Door } from "@/lib/rects/door";
|
import { Door } from "@/lib/rects/door";
|
||||||
import { advent22Store } from "@/lib/store";
|
import { advent22Store } from "@/lib/store";
|
||||||
import { Options, Vue } from "vue-class-component";
|
|
||||||
|
|
||||||
import SVGRect from "./SVGRect.vue";
|
import SVGRect from "./SVGRect.vue";
|
||||||
|
|
||||||
@Options({
|
const store = advent22Store();
|
||||||
components: {
|
|
||||||
SVGRect,
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
door: Door,
|
|
||||||
force_visible: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
export default class extends Vue {
|
|
||||||
public readonly store = advent22Store();
|
|
||||||
|
|
||||||
public door!: Door;
|
withDefaults(
|
||||||
public force_visible!: boolean;
|
defineProps<{
|
||||||
}
|
door: Door;
|
||||||
|
force_visible: boolean;
|
||||||
|
}>(),
|
||||||
|
{
|
||||||
|
force_visible: false,
|
||||||
|
},
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -29,14 +29,12 @@ function get_event_thous(event: MouseEvent): Vector2D {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
type TCMouseEvent = [MouseEvent, Vector2D];
|
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
mousedown: TCMouseEvent;
|
(event: "mousedown", e: MouseEvent, point: Vector2D): void;
|
||||||
mouseup: TCMouseEvent;
|
(event: "mouseup", e: MouseEvent, point: Vector2D): void;
|
||||||
mousemove: TCMouseEvent;
|
(event: "mousemove", e: MouseEvent, point: Vector2D): void;
|
||||||
click: TCMouseEvent;
|
(event: "click", e: MouseEvent, point: Vector2D): void;
|
||||||
dblclick: TCMouseEvent;
|
(event: "dblclick", e: MouseEvent, point: Vector2D): void;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
function transform_mouse_event(event: MouseEvent) {
|
function transform_mouse_event(event: MouseEvent) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue