better typing for queries

This commit is contained in:
Jörn-Michael Miehe 2022-09-16 21:45:59 +00:00
parent 1ebaf9389f
commit 208af9d55b
2 changed files with 61 additions and 22 deletions

View file

@ -89,10 +89,18 @@ export default class App extends Vue {
private update(): void { private update(): void {
// Update Logo Config // Update Logo Config
this.$ovdashboard.api_query_simple_object("misc/config/logo", (data) => { type LogoConfig = {
this.logo_above = data.above as string; above: string;
this.logo_below = data.below as string; below: string;
}); };
this.$ovdashboard.api_query_simple_object<LogoConfig>(
"misc/config/logo",
(data) => {
this.logo_above = data.above;
this.logo_below = data.below;
}
);
// Update Title // Update Title
this.$ovdashboard.api_query_simple_string("text/get/html/title", (data) => { this.$ovdashboard.api_query_simple_string("text/get/html/title", (data) => {
@ -107,11 +115,20 @@ export default class App extends Vue {
}); });
// Update Image Config // Update Image Config
this.$ovdashboard.api_query_simple_object("image/config", (data) => { type ImageConfig = {
this.image_height = data.height as number; height: number;
this.image_contain = data.contain as boolean; contain: boolean;
this.image_speed = data.speed as number; speed: number;
}); };
this.$ovdashboard.api_query_simple_object<ImageConfig>(
"image/config",
(data) => {
this.image_height = data.height;
this.image_contain = data.contain;
this.image_speed = data.speed;
}
);
// Update Message // Update Message
this.$ovdashboard.api_query_simple_string( this.$ovdashboard.api_query_simple_string(
@ -140,15 +157,30 @@ export default class App extends Vue {
}); });
// Update Calendar Config // Update Calendar Config
this.$ovdashboard.api_query_simple_object("calendar/config", (data) => { type CalendarConfig = {
this.calendar_speed = data.speed as number; speed: number;
}); };
this.$ovdashboard.api_query_simple_object<CalendarConfig>(
"calendar/config",
(data) => {
this.calendar_speed = data.speed;
}
);
// Update Server Config // Update Server Config
this.$ovdashboard.api_query_simple_object("misc/config/server", (data) => { type ServerConfig = {
this.server_host = data.host as string; host: string;
this.server_name = data.name as string; name: string;
}); };
this.$ovdashboard.api_query_simple_object<ServerConfig>(
"misc/config/server",
(data) => {
this.server_host = data.host;
this.server_name = data.name;
}
);
// Update Version // Update Version
this.$ovdashboard.api_query_simple_string("misc/version", (data) => { this.$ovdashboard.api_query_simple_string("misc/version", (data) => {
@ -166,9 +198,16 @@ export default class App extends Vue {
}); });
// Update Ticker Config // Update Ticker Config
this.$ovdashboard.api_query_simple_object("ticker/config", (data) => { type TickerConfig = {
this.ticker_color = data.color as string; color: string;
}); };
this.$ovdashboard.api_query_simple_object<TickerConfig>(
"ticker/config",
(data) => {
this.ticker_color = data.color;
}
);
} }
public created(): void { public created(): void {

View file

@ -83,15 +83,15 @@ export class OVDashboardPlugin {
}); });
} }
public api_query_simple_object( public api_query_simple_object<Type extends object>(
endpoint: string, endpoint: string,
on_success: (data: Record<string, unknown>) => void on_success: (data: Type) => void
): void { ): void {
this.api_query_simple(endpoint, (data) => { this.api_query_simple(endpoint, (data) => {
if (typeof data !== "object") return; if (typeof data !== "object") return;
if (data === null) return; if (data === null) return;
on_success(data as Record<string, unknown>); on_success(data as Type);
}); });
} }
} }