mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-22 15:53:01 +00:00
fixed some code smells
This commit is contained in:
parent
3da3f7f639
commit
9e303f898a
7 changed files with 39 additions and 33 deletions
|
@ -161,7 +161,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { AdminConfigModel, Credentials, DoorsSaved } from "@/lib/api";
|
import { AdminConfigModel, Credentials, DoorSaved } from "@/lib/api";
|
||||||
import { advent22Store } from "@/plugins/store";
|
import { advent22Store } from "@/plugins/store";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
|
@ -216,7 +216,7 @@ export default class extends Vue {
|
||||||
config_file: "sed diam nonumy",
|
config_file: "sed diam nonumy",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
public doors: DoorsSaved = [];
|
public doors: DoorSaved[] = [];
|
||||||
public dav_credentials: Credentials = ["", ""];
|
public dav_credentials: Credentials = ["", ""];
|
||||||
public ui_credentials: Credentials = ["", ""];
|
public ui_credentials: Credentials = ["", ""];
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ 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.$advent22.api_get<AdminConfigModel>("admin/config_model"),
|
this.$advent22.api_get<AdminConfigModel>("admin/config_model"),
|
||||||
this.$advent22.api_get<DoorsSaved>("admin/doors"),
|
this.$advent22.api_get<DoorSaved[]>("admin/doors"),
|
||||||
])
|
])
|
||||||
.then(([admin_config_model, doors]) => {
|
.then(([admin_config_model, doors]) => {
|
||||||
this.admin_config_model = admin_config_model;
|
this.admin_config_model = admin_config_model;
|
||||||
|
|
|
@ -69,7 +69,7 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { DoorsSaved } from "@/lib/api";
|
import { DoorSaved } from "@/lib/api";
|
||||||
import { Door } from "@/lib/door";
|
import { Door } from "@/lib/door";
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ export default class extends Vue {
|
||||||
private load_doors(): Promise<void> {
|
private load_doors(): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
this.$advent22
|
this.$advent22
|
||||||
.api_get<DoorsSaved>("admin/doors")
|
.api_get<DoorSaved[]>("admin/doors")
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
this.doors.length = 0;
|
this.doors.length = 0;
|
||||||
|
|
||||||
|
@ -124,7 +124,7 @@ export default class extends Vue {
|
||||||
|
|
||||||
private save_doors(): Promise<void> {
|
private save_doors(): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
const data: DoorsSaved = [];
|
const data: DoorSaved[] = [];
|
||||||
|
|
||||||
for (const door of this.doors) {
|
for (const door of this.doors) {
|
||||||
data.push(door.save());
|
data.push(door.save());
|
||||||
|
|
|
@ -21,15 +21,13 @@ import { advent22Store } from "@/plugins/store";
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
|
|
||||||
function get_event_thous(event: MouseEvent): Vector2D {
|
function get_event_thous(event: MouseEvent): Vector2D {
|
||||||
if (event.currentTarget === null) {
|
if (!(event.currentTarget instanceof SVGSVGElement)) {
|
||||||
return new Vector2D();
|
return new Vector2D();
|
||||||
}
|
}
|
||||||
|
|
||||||
const target = event.currentTarget as Element;
|
|
||||||
|
|
||||||
return new Vector2D(
|
return new Vector2D(
|
||||||
Math.round((event.offsetX / target.clientWidth) * 1000),
|
Math.round((event.offsetX / event.currentTarget.clientWidth) * 1000),
|
||||||
Math.round((event.offsetY / target.clientHeight) * 1000),
|
Math.round((event.offsetY / event.currentTarget.clientHeight) * 1000),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ export default class extends Vue {
|
||||||
}
|
}
|
||||||
|
|
||||||
public on_click(event: MouseEvent) {
|
public on_click(event: MouseEvent) {
|
||||||
if (event.target === null || !(event.target instanceof SVGRectElement)) {
|
if (!(event.currentTarget instanceof SVGRectElement)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,6 @@ export interface DoorSaved {
|
||||||
y2: number;
|
y2: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DoorsSaved = DoorSaved[];
|
|
||||||
|
|
||||||
export type Credentials = [username: string, password: string];
|
export type Credentials = [username: string, password: string];
|
||||||
|
|
||||||
export function objForEach<T>(
|
export function objForEach<T>(
|
||||||
|
|
|
@ -8,11 +8,11 @@ import App from "./App.vue";
|
||||||
import "@/main.scss";
|
import "@/main.scss";
|
||||||
|
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
app.use(Advent22Plugin);
|
app.use(Advent22Plugin);
|
||||||
app.use(FontAwesomePlugin);
|
app.use(FontAwesomePlugin);
|
||||||
app.use(createPinia());
|
|
||||||
|
|
||||||
const store = advent22Store();
|
app.use(createPinia());
|
||||||
store.init(app.config.globalProperties.$advent22);
|
advent22Store().init();
|
||||||
|
|
||||||
app.mount("#app");
|
app.mount("#app");
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { Credentials, DoorsSaved, SiteConfigModel } from "@/lib/api";
|
import { Credentials, DoorSaved, SiteConfigModel } from "@/lib/api";
|
||||||
import { Advent22 } from "@/plugins/advent22";
|
import { Advent22 } from "@/plugins/advent22";
|
||||||
import { useLocalStorage } from "@vueuse/core";
|
import { RemovableRef, useLocalStorage } from "@vueuse/core";
|
||||||
import { AxiosBasicCredentials } from "axios";
|
import { AxiosBasicCredentials } from "axios";
|
||||||
import { acceptHMRUpdate, defineStore } from "pinia";
|
import { acceptHMRUpdate, defineStore } from "pinia";
|
||||||
|
|
||||||
|
@ -10,12 +10,23 @@ declare global {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type State = {
|
||||||
|
advent22: Advent22;
|
||||||
|
api_creds: RemovableRef<Credentials>;
|
||||||
|
is_touch_device: boolean;
|
||||||
|
is_admin: boolean;
|
||||||
|
site_config: SiteConfigModel;
|
||||||
|
calendar_aspect_ratio: number;
|
||||||
|
user_doors: DoorSaved[];
|
||||||
|
next_door_target: number | null;
|
||||||
|
};
|
||||||
|
|
||||||
export const advent22Store = defineStore({
|
export const advent22Store = defineStore({
|
||||||
id: "advent22",
|
id: "advent22",
|
||||||
|
|
||||||
state: () => ({
|
state: (): State => ({
|
||||||
advent22: {} as Advent22,
|
advent22: new Advent22(),
|
||||||
api_creds: useLocalStorage<Credentials>("advent22/auth", ["", ""]),
|
api_creds: useLocalStorage("advent22/auth", ["", ""]),
|
||||||
is_touch_device:
|
is_touch_device:
|
||||||
window.matchMedia("(any-hover: none)").matches ||
|
window.matchMedia("(any-hover: none)").matches ||
|
||||||
"ontouchstart" in window ||
|
"ontouchstart" in window ||
|
||||||
|
@ -27,10 +38,10 @@ export const advent22Store = defineStore({
|
||||||
subtitle: "",
|
subtitle: "",
|
||||||
content: "",
|
content: "",
|
||||||
footer: "",
|
footer: "",
|
||||||
} as SiteConfigModel,
|
},
|
||||||
calendar_aspect_ratio: 1,
|
calendar_aspect_ratio: 1,
|
||||||
user_doors: [] as DoorsSaved,
|
user_doors: [],
|
||||||
next_door_target: null as number | null,
|
next_door_target: null,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
|
@ -41,11 +52,10 @@ export const advent22Store = defineStore({
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
init(advent22: Advent22): void {
|
init(): void {
|
||||||
this.advent22 = advent22;
|
|
||||||
this.update_is_admin();
|
this.update_is_admin();
|
||||||
|
|
||||||
advent22
|
this.advent22
|
||||||
.api_get_blob("user/favicon")
|
.api_get_blob("user/favicon")
|
||||||
.then((favicon_src) => {
|
.then((favicon_src) => {
|
||||||
const link: HTMLLinkElement =
|
const link: HTMLLinkElement =
|
||||||
|
@ -61,9 +71,9 @@ export const advent22Store = defineStore({
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
advent22.api_get<SiteConfigModel>("user/site_config"),
|
this.advent22.api_get<SiteConfigModel>("user/site_config"),
|
||||||
advent22.api_get<DoorsSaved>("user/doors"),
|
this.advent22.api_get<DoorSaved[]>("user/doors"),
|
||||||
advent22.api_get<number | null>("user/next_door"),
|
this.advent22.api_get<number | null>("user/next_door"),
|
||||||
])
|
])
|
||||||
.then(([site_config, user_doors, next_door]) => {
|
.then(([site_config, user_doors, next_door]) => {
|
||||||
document.title = site_config.title;
|
document.title = site_config.title;
|
||||||
|
@ -77,11 +87,11 @@ export const advent22Store = defineStore({
|
||||||
if (next_door !== null)
|
if (next_door !== null)
|
||||||
this.next_door_target = Date.now() + next_door;
|
this.next_door_target = Date.now() + next_door;
|
||||||
})
|
})
|
||||||
.catch(advent22.alert_user_error);
|
.catch(this.advent22.alert_user_error);
|
||||||
},
|
},
|
||||||
|
|
||||||
update_is_admin(): Promise<boolean> {
|
update_is_admin(): Promise<boolean> {
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.advent22
|
this.advent22
|
||||||
.api_get<boolean>("admin/is_admin")
|
.api_get<boolean>("admin/is_admin")
|
||||||
.then((is_admin) => {
|
.then((is_admin) => {
|
||||||
|
|
Loading…
Reference in a new issue