mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
update "store" from ConfigView
This commit is contained in:
parent
41889d9160
commit
e2a14821ba
2 changed files with 64 additions and 42 deletions
|
@ -255,10 +255,13 @@ export default class extends Vue {
|
||||||
|
|
||||||
public on_open(ready: () => void, fail: () => void): void {
|
public on_open(ready: () => void, fail: () => void): void {
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
this.store.update(),
|
||||||
this.$advent22.api_get<AdminConfigModel>("admin/config_model"),
|
this.$advent22.api_get<AdminConfigModel>("admin/config_model"),
|
||||||
this.$advent22.api_get<DoorSaved[]>("admin/doors"),
|
this.$advent22.api_get<DoorSaved[]>("admin/doors"),
|
||||||
])
|
])
|
||||||
.then(([admin_config_model, doors]) => {
|
.then(([store_update, admin_config_model, doors]) => {
|
||||||
|
store_update; // discard value
|
||||||
|
|
||||||
this.admin_config_model = admin_config_model;
|
this.admin_config_model = admin_config_model;
|
||||||
this.doors = doors;
|
this.doors = doors;
|
||||||
|
|
||||||
|
|
|
@ -60,53 +60,72 @@ export const advent22Store = defineStore({
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
init(): void {
|
init(): void {
|
||||||
this.update_is_admin();
|
this.update()
|
||||||
|
.then(() => {
|
||||||
this.advent22
|
|
||||||
.api_get_blob("user/favicon")
|
|
||||||
.then((favicon_src) => {
|
|
||||||
const link: HTMLLinkElement =
|
|
||||||
document.querySelector("link[rel*='icon']") ||
|
|
||||||
document.createElement("link");
|
|
||||||
link.rel = "shortcut icon";
|
|
||||||
link.type = "image/x-icon";
|
|
||||||
link.href = favicon_src;
|
|
||||||
|
|
||||||
if (link.parentElement === null)
|
|
||||||
document.getElementsByTagName("head")[0].appendChild(link);
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
|
|
||||||
Promise.all([
|
|
||||||
this.advent22.api_get<SiteConfigModel>("user/site_config"),
|
|
||||||
this.advent22.api_get_blob("user/background_image"),
|
|
||||||
this.advent22.api_get<DoorSaved[]>("user/doors"),
|
|
||||||
this.advent22.api_get<number | null>("user/next_door"),
|
|
||||||
])
|
|
||||||
.then(([site_config, background_image, user_doors, next_door]) => {
|
|
||||||
document.title = site_config.title;
|
|
||||||
|
|
||||||
if (site_config.subtitle !== "")
|
|
||||||
document.title += " – " + site_config.subtitle;
|
|
||||||
|
|
||||||
this.site_config = site_config;
|
|
||||||
|
|
||||||
this.calendar_background_image = background_image;
|
|
||||||
|
|
||||||
this.user_doors.length = 0;
|
|
||||||
for (const door_saved of user_doors) {
|
|
||||||
this.user_doors.push(Door.load(door_saved));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next_door !== null)
|
|
||||||
this.next_door_target = Date.now() + next_door;
|
|
||||||
|
|
||||||
this.is_initialized = true;
|
this.is_initialized = true;
|
||||||
for (const callback of this.on_initialized) callback();
|
for (const callback of this.on_initialized) callback();
|
||||||
})
|
})
|
||||||
.catch(this.advent22.alert_user_error);
|
.catch(this.advent22.alert_user_error);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
update(): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.advent22
|
||||||
|
.api_get_blob("user/favicon")
|
||||||
|
.then((favicon_src) => {
|
||||||
|
const link: HTMLLinkElement =
|
||||||
|
document.querySelector("link[rel*='icon']") ||
|
||||||
|
document.createElement("link");
|
||||||
|
link.rel = "shortcut icon";
|
||||||
|
link.type = "image/x-icon";
|
||||||
|
link.href = favicon_src;
|
||||||
|
|
||||||
|
if (link.parentElement === null)
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(link);
|
||||||
|
})
|
||||||
|
.catch(() => {});
|
||||||
|
|
||||||
|
Promise.all([
|
||||||
|
this.update_is_admin(),
|
||||||
|
this.advent22.api_get<SiteConfigModel>("user/site_config"),
|
||||||
|
this.advent22.api_get_blob("user/background_image"),
|
||||||
|
this.advent22.api_get<DoorSaved[]>("user/doors"),
|
||||||
|
this.advent22.api_get<number | null>("user/next_door"),
|
||||||
|
])
|
||||||
|
.then(
|
||||||
|
([
|
||||||
|
is_admin,
|
||||||
|
site_config,
|
||||||
|
background_image,
|
||||||
|
user_doors,
|
||||||
|
next_door,
|
||||||
|
]) => {
|
||||||
|
is_admin; // discard value
|
||||||
|
|
||||||
|
document.title = site_config.title;
|
||||||
|
|
||||||
|
if (site_config.subtitle !== "")
|
||||||
|
document.title += " – " + site_config.subtitle;
|
||||||
|
|
||||||
|
this.site_config = site_config;
|
||||||
|
|
||||||
|
this.calendar_background_image = background_image;
|
||||||
|
|
||||||
|
this.user_doors.length = 0;
|
||||||
|
for (const door_saved of user_doors) {
|
||||||
|
this.user_doors.push(Door.load(door_saved));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (next_door !== null)
|
||||||
|
this.next_door_target = Date.now() + next_door;
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.catch(reject);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
when_initialized(callback: () => void): void {
|
when_initialized(callback: () => void): void {
|
||||||
if (this.is_initialized) {
|
if (this.is_initialized) {
|
||||||
callback();
|
callback();
|
||||||
|
|
Loading…
Reference in a new issue