open door progress + fail
This commit is contained in:
parent
391f3e8fba
commit
23820bc9dc
4 changed files with 62 additions and 20 deletions
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<LoginModal ref="login_modal" />
|
<LoginModal ref="login_modal" />
|
||||||
<ImageModal ref="image_modal" />
|
<MultiModal ref="multi_modal" />
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<h1 class="title has-text-centered is-uppercase">
|
<h1 class="title has-text-centered is-uppercase">
|
||||||
|
@ -11,7 +11,8 @@
|
||||||
|
|
||||||
<DoorMapEditor />
|
<DoorMapEditor />
|
||||||
|
|
||||||
<CalendarDoor v-for="(_, index) in 24" :key="index" :day="index" @openDoor="open_calendar_door" />
|
<CalendarDoor v-for="(_, index) in 24" :key="index" :day="index" @click="click_calendar_door"
|
||||||
|
@openDoor="open_calendar_door" @abortDoor="abort_calendar_door" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="section">
|
<div class="section">
|
||||||
|
@ -23,19 +24,20 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { AxiosError } from "axios";
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
|
|
||||||
import CalendarDoor from "./components/CalendarDoor.vue";
|
import CalendarDoor from "./components/CalendarDoor.vue";
|
||||||
import DoorMapEditor from "./components/DoorMapEditor.vue";
|
import DoorMapEditor from "./components/DoorMapEditor.vue";
|
||||||
import ImageModal from "./components/ImageModal.vue";
|
|
||||||
import LoginModal from "./components/LoginModal.vue";
|
import LoginModal from "./components/LoginModal.vue";
|
||||||
|
import MultiModal from "./components/MultiModal.vue";
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {
|
components: {
|
||||||
CalendarDoor,
|
CalendarDoor,
|
||||||
DoorMapEditor,
|
DoorMapEditor,
|
||||||
ImageModal,
|
|
||||||
LoginModal,
|
LoginModal,
|
||||||
|
MultiModal,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
|
@ -44,7 +46,7 @@ export default class extends Vue {
|
||||||
|
|
||||||
declare $refs: {
|
declare $refs: {
|
||||||
login_modal: LoginModal;
|
login_modal: LoginModal;
|
||||||
image_modal: ImageModal;
|
multi_modal: MultiModal;
|
||||||
};
|
};
|
||||||
|
|
||||||
public mounted() {
|
public mounted() {
|
||||||
|
@ -60,8 +62,20 @@ export default class extends Vue {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public click_calendar_door() {
|
||||||
|
this.$refs.multi_modal.show_progress();
|
||||||
|
}
|
||||||
|
|
||||||
public open_calendar_door(image_src: string) {
|
public open_calendar_door(image_src: string) {
|
||||||
this.$refs.image_modal.show_src(image_src);
|
this.$refs.multi_modal.show_image(image_src);
|
||||||
|
}
|
||||||
|
|
||||||
|
public abort_calendar_door(name: string, reason: unknown) {
|
||||||
|
this.$refs.multi_modal.set_active(false);
|
||||||
|
|
||||||
|
if ((reason as AxiosError).response?.status == 401) {
|
||||||
|
alert("Nice try!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -9,14 +9,23 @@ import { Options, Vue } from "vue-class-component";
|
||||||
props: {
|
props: {
|
||||||
day: Number,
|
day: Number,
|
||||||
},
|
},
|
||||||
|
emits: [
|
||||||
|
"click",
|
||||||
|
"openDoor",
|
||||||
|
"abortDoor",
|
||||||
|
],
|
||||||
})
|
})
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
day!: number;
|
day!: number;
|
||||||
|
|
||||||
public on_click() {
|
public on_click() {
|
||||||
this.$advent22.api_get_blob(`days/image/${this.day}`, (data) => {
|
this.$emit("click");
|
||||||
this.$emit("openDoor", data);
|
|
||||||
});
|
this.$advent22.api_get_blob(
|
||||||
|
`days/image/${this.day}`,
|
||||||
|
(data) => this.$emit("openDoor", data),
|
||||||
|
(name, reason) => this.$emit("abortDoor", name, reason),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -3,9 +3,14 @@
|
||||||
<div class="modal-background" />
|
<div class="modal-background" />
|
||||||
|
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="image is-square">
|
<template v-if="progress">
|
||||||
<img :src="image_src" alt="Kalender-Bild" />
|
<progress class="progress is-primary" max="100" />
|
||||||
</div>
|
</template>
|
||||||
|
<template v-else>
|
||||||
|
<div class="image is-square">
|
||||||
|
<img :src="image_src" alt="Kalender-Bild" />
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -15,6 +20,7 @@ import { Vue } from "vue-class-component";
|
||||||
|
|
||||||
export default class extends Vue {
|
export default class extends Vue {
|
||||||
public active = false;
|
public active = false;
|
||||||
|
public progress = false;
|
||||||
public image_src = "";
|
public image_src = "";
|
||||||
|
|
||||||
public created() {
|
public created() {
|
||||||
|
@ -27,9 +33,16 @@ export default class extends Vue {
|
||||||
this.active = state;
|
this.active = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
public show_src(src: string) {
|
public show_image(src: string) {
|
||||||
|
this.progress = false;
|
||||||
this.image_src = src;
|
this.image_src = src;
|
||||||
this.set_active(true);
|
this.set_active(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public show_progress() {
|
||||||
|
this.progress = true;
|
||||||
|
this.image_src = "";
|
||||||
|
this.set_active(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -37,14 +37,14 @@ export class Advent22 {
|
||||||
this.api_auth = { username: username, password: password };
|
this.api_auth = { username: username, password: password };
|
||||||
}
|
}
|
||||||
|
|
||||||
private fail(name: string): (reason: unknown) => void {
|
private fail(name: string, reason: unknown): void {
|
||||||
return (reason: unknown) =>
|
console.warn("Failed to query", name, "-", reason);
|
||||||
console.warn("Failed to query", name, "-", reason);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private api_get<T>(
|
private api_get<T>(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
on_success: (data: T) => void,
|
on_success: (data: T) => void,
|
||||||
|
on_failure: (name: string, reason: unknown) => void,
|
||||||
responseType: ResponseType = "json",
|
responseType: ResponseType = "json",
|
||||||
) {
|
) {
|
||||||
const req_data = {
|
const req_data = {
|
||||||
|
@ -54,12 +54,13 @@ export class Advent22 {
|
||||||
|
|
||||||
this.axios.get<T>(this.api_url(endpoint), req_data)
|
this.axios.get<T>(this.api_url(endpoint), req_data)
|
||||||
.then((response) => on_success(response.data))
|
.then((response) => on_success(response.data))
|
||||||
.catch(this.fail(endpoint));
|
.catch((reason) => on_failure(endpoint, reason));
|
||||||
}
|
}
|
||||||
|
|
||||||
public api_get_blob(
|
public api_get_blob(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
on_success: (data: string) => void,
|
on_success: (data: string) => void,
|
||||||
|
on_failure: (name: string, reason: unknown) => void = this.fail,
|
||||||
) {
|
) {
|
||||||
this.api_get<Blob>(
|
this.api_get<Blob>(
|
||||||
endpoint,
|
endpoint,
|
||||||
|
@ -71,9 +72,10 @@ export class Advent22 {
|
||||||
on_success(reader.result);
|
on_success(reader.result);
|
||||||
|
|
||||||
else
|
else
|
||||||
this.fail(endpoint);
|
on_failure(endpoint, "failed data url");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
on_failure,
|
||||||
"blob",
|
"blob",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -81,24 +83,28 @@ export class Advent22 {
|
||||||
public api_get_string(
|
public api_get_string(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
on_success: (data: string) => void,
|
on_success: (data: string) => void,
|
||||||
|
on_failure: (name: string, reason: unknown) => void = this.fail,
|
||||||
) {
|
) {
|
||||||
this.api_get<string>(
|
this.api_get<string>(
|
||||||
endpoint,
|
endpoint,
|
||||||
(data: string) => {
|
(data: string) => {
|
||||||
on_success(data);
|
on_success(data);
|
||||||
}
|
},
|
||||||
|
on_failure,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public api_get_number(
|
public api_get_number(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
on_success: (data: number) => void,
|
on_success: (data: number) => void,
|
||||||
|
on_failure: (name: string, reason: unknown) => void = this.fail,
|
||||||
) {
|
) {
|
||||||
this.api_get<number>(
|
this.api_get<number>(
|
||||||
endpoint,
|
endpoint,
|
||||||
(data: number) => {
|
(data: number) => {
|
||||||
on_success(data);
|
on_success(data);
|
||||||
}
|
},
|
||||||
|
on_failure,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue