Compare commits
No commits in common. "6f228171f022c6a9f5d06fc03f3bb9053f60f110" and "ac13f60b81052d4e6b3179b10f91a57cc59d710d" have entirely different histories.
6f228171f0
...
ac13f60b81
3 changed files with 85 additions and 132 deletions
100
ui/src/App.vue
100
ui/src/App.vue
|
|
@ -42,7 +42,6 @@
|
|||
|
||||
<script lang="ts">
|
||||
import { Component, Vue } from "vue-property-decorator";
|
||||
import { EventData } from "./components/calendar/EventModel";
|
||||
import { CalendarData } from "./components/calendar/CalendarModel";
|
||||
|
||||
import TitleBar from "./components/title/TitleBar.vue";
|
||||
|
|
@ -90,112 +89,85 @@ export default class App extends Vue {
|
|||
|
||||
private update(): void {
|
||||
// Update Logo Config
|
||||
type LogoConfig = {
|
||||
above: string;
|
||||
below: string;
|
||||
};
|
||||
|
||||
this.$ovdashboard.api_get_object<LogoConfig>("misc/config/logo", (cfg) => {
|
||||
this.logo_above = cfg.above;
|
||||
this.logo_below = cfg.below;
|
||||
this.$ovdashboard.api_query_simple_object("misc/config/logo", (data) => {
|
||||
this.logo_above = data.above as string;
|
||||
this.logo_below = data.below as string;
|
||||
});
|
||||
|
||||
// Update Title
|
||||
this.$ovdashboard.api_get_string("text/get/html/title", (title) => {
|
||||
this.title_html = title;
|
||||
this.$ovdashboard.api_query_simple_string("text/get/html/title", (data) => {
|
||||
this.title_html = data;
|
||||
});
|
||||
|
||||
// Update Images
|
||||
this.$ovdashboard.api_get_list("image/list", (names) => {
|
||||
this.image_urls = names.map((name: string) =>
|
||||
this.$ovdashboard.api_query_simple_list("image/list", (data) => {
|
||||
this.image_urls = data.map((name: string) =>
|
||||
this.$ovdashboard.api_url("image/get/" + name)
|
||||
);
|
||||
});
|
||||
|
||||
// Update Image Config
|
||||
type ImageConfig = {
|
||||
height: number;
|
||||
contain: boolean;
|
||||
speed: number;
|
||||
};
|
||||
|
||||
this.$ovdashboard.api_get_object<ImageConfig>("image/config", (cfg) => {
|
||||
this.image_height = cfg.height;
|
||||
this.image_contain = cfg.contain;
|
||||
this.image_speed = cfg.speed;
|
||||
this.$ovdashboard.api_query_simple_object("image/config", (data) => {
|
||||
this.image_height = data.height as number;
|
||||
this.image_contain = data.contain as boolean;
|
||||
this.image_speed = data.speed as number;
|
||||
});
|
||||
|
||||
// Update Message
|
||||
this.$ovdashboard.api_get_string(
|
||||
this.$ovdashboard.api_query_simple_string(
|
||||
"text/get/html/message",
|
||||
(data) => (this.message_html = data)
|
||||
);
|
||||
|
||||
// Update Calendar Aggregates
|
||||
this.$ovdashboard.api_get_list("aggregate/list", (names) => {
|
||||
this.$ovdashboard.api_get_object_multi<EventData[]>(
|
||||
names.map((name) => "aggregate/get/" + name),
|
||||
(calendars) => {
|
||||
this.$ovdashboard.api_query_simple_list("aggregate/list", (data) => {
|
||||
let promises = data.map((name: string) =>
|
||||
this.$axios.get(this.$ovdashboard.api_url("aggregate/get/" + name))
|
||||
);
|
||||
|
||||
Promise.all(promises)
|
||||
.then((responses) => {
|
||||
this.calendar_data = [];
|
||||
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
this.calendar_data.push({
|
||||
title: names[i],
|
||||
events: calendars[i],
|
||||
title: data[i],
|
||||
events: responses[i].data,
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch(this.$ovdashboard.fail("Calendar Aggregates"));
|
||||
});
|
||||
|
||||
// Update Calendar Config
|
||||
type CalendarConfig = {
|
||||
speed: number;
|
||||
};
|
||||
|
||||
this.$ovdashboard.api_get_object<CalendarConfig>(
|
||||
"calendar/config",
|
||||
(data) => {
|
||||
this.calendar_speed = data.speed;
|
||||
}
|
||||
);
|
||||
this.$ovdashboard.api_query_simple_object("calendar/config", (data) => {
|
||||
this.calendar_speed = data.speed as number;
|
||||
});
|
||||
|
||||
// Update Server Config
|
||||
type ServerConfig = {
|
||||
host: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
this.$ovdashboard.api_get_object<ServerConfig>(
|
||||
"misc/config/server",
|
||||
(data) => {
|
||||
this.server_host = data.host;
|
||||
this.server_name = data.name;
|
||||
}
|
||||
);
|
||||
this.$ovdashboard.api_query_simple_object("misc/config/server", (data) => {
|
||||
this.server_host = data.host as string;
|
||||
this.server_name = data.name as string;
|
||||
});
|
||||
|
||||
// Update Version
|
||||
this.$ovdashboard.api_get_string("misc/version", (data) => {
|
||||
this.$ovdashboard.api_query_simple_string("misc/version", (data) => {
|
||||
this.dashboard_version = data;
|
||||
});
|
||||
|
||||
// Update IP
|
||||
this.$ovdashboard.api_get_string("misc/lanip", (data) => {
|
||||
this.$ovdashboard.api_query_simple_string("misc/lanip", (data) => {
|
||||
this.dashboard_ip = data;
|
||||
});
|
||||
|
||||
// Update Ticker
|
||||
this.$ovdashboard.api_get_string("ticker/html", (data) => {
|
||||
this.$ovdashboard.api_query_simple_string("ticker/html", (data) => {
|
||||
this.ticker_html = data;
|
||||
});
|
||||
|
||||
// Update Ticker Config
|
||||
type TickerConfig = {
|
||||
color: string;
|
||||
};
|
||||
|
||||
this.$ovdashboard.api_get_object<TickerConfig>("ticker/config", (data) => {
|
||||
this.ticker_color = data.color;
|
||||
this.$ovdashboard.api_query_simple_object("ticker/config", (data) => {
|
||||
this.ticker_color = data.color as string;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
30
ui/src/d.ts/shims-ovdashboard.d.ts
vendored
30
ui/src/d.ts/shims-ovdashboard.d.ts
vendored
|
|
@ -1,8 +1,34 @@
|
|||
import { OVDashboardPlugin } from "@/plugins/ovdashboard";
|
||||
import { AxiosInstance } from "axios";
|
||||
|
||||
declare module 'vue/types/vue' {
|
||||
interface Vue {
|
||||
$ovdashboard: OVDashboardPlugin;
|
||||
$axios: AxiosInstance;
|
||||
|
||||
$ovdashboard: {
|
||||
api_url: (endpoint?: string) => string;
|
||||
|
||||
fail: (name: string) => ((arg0: unknown) => void);
|
||||
|
||||
api_query_simple: (
|
||||
endpoint: string,
|
||||
on_success: (data: unknown) => void
|
||||
) => void;
|
||||
|
||||
api_query_simple_string: (
|
||||
endpoint: string,
|
||||
on_success: (data: string) => void
|
||||
) => void;
|
||||
|
||||
api_query_simple_list: (
|
||||
endpoint: string,
|
||||
on_success: (data: string[]) => void
|
||||
) => void;
|
||||
|
||||
api_query_simple_object: (
|
||||
endpoint: string,
|
||||
on_success: (data: Record<string, unknown>) => void
|
||||
) => void;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import axios, { AxiosInstance, AxiosPromise } from 'axios';
|
||||
import axios, { AxiosInstance } from 'axios';
|
||||
import Vue from 'vue';
|
||||
|
||||
export class OVDashboardPlugin {
|
||||
class OVDashboardPlugin {
|
||||
private axios: AxiosInstance;
|
||||
|
||||
public constructor() {
|
||||
|
|
@ -20,6 +20,7 @@ export class OVDashboardPlugin {
|
|||
}
|
||||
|
||||
public install(vue: typeof Vue) {
|
||||
vue.prototype.$axios = this.axios;
|
||||
vue.prototype.$ovdashboard = this;
|
||||
}
|
||||
|
||||
|
|
@ -44,101 +45,55 @@ export class OVDashboardPlugin {
|
|||
return this.api_baseurl + "/" + endpoint;
|
||||
}
|
||||
|
||||
private fail(name: string): (reason: unknown) => void {
|
||||
public fail(name: string): (reason: unknown) => void {
|
||||
return (reason: unknown) =>
|
||||
console.warn("Failed to query", name, "-", reason);
|
||||
}
|
||||
|
||||
private api_get_prepare<T>(endpoint: string): AxiosPromise<T> {
|
||||
return this.axios.get<T>(this.api_url(endpoint));
|
||||
}
|
||||
|
||||
private api_get<T>(
|
||||
public api_query_simple(
|
||||
endpoint: string,
|
||||
on_success: (data: T) => void
|
||||
on_success: (data: unknown) => void
|
||||
): void {
|
||||
this.api_get_prepare<T>(endpoint)
|
||||
this.axios
|
||||
.get(this.api_url(endpoint))
|
||||
.then((response) => on_success(response.data))
|
||||
.catch(this.fail(endpoint));
|
||||
}
|
||||
|
||||
public api_get_string(
|
||||
public api_query_simple_string(
|
||||
endpoint: string,
|
||||
on_success: (data: string) => void
|
||||
): void {
|
||||
this.api_get<string>(endpoint, (data) => {
|
||||
if (typeof data !== "string") {
|
||||
console.error("Endpoint", endpoint, "did not return a string:", data);
|
||||
return;
|
||||
}
|
||||
this.api_query_simple(endpoint, (data) => {
|
||||
if (typeof data !== "string") return;
|
||||
|
||||
on_success(data);
|
||||
});
|
||||
}
|
||||
|
||||
private check_array<T>(value: unknown): value is T[] {
|
||||
if (!Array.isArray(value)) return false;
|
||||
if (!value.every((entry) => typeof entry === "string")) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public api_get_list(
|
||||
public api_query_simple_list(
|
||||
endpoint: string,
|
||||
on_success: (data: string[]) => void
|
||||
): void {
|
||||
this.api_get(endpoint, (data) => {
|
||||
if (!this.check_array<string>(data)) {
|
||||
console.error("Endpoint", endpoint, "did not return a string[]:", data);
|
||||
return;
|
||||
}
|
||||
this.api_query_simple(endpoint, (data) => {
|
||||
if (!Array.isArray(data)) return;
|
||||
if (!data.every((value) => typeof value === "string")) return;
|
||||
|
||||
on_success(data);
|
||||
});
|
||||
}
|
||||
|
||||
private check_object(value: unknown): value is object {
|
||||
if (typeof value !== "object") return false;
|
||||
if (value === null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public api_get_object<Type extends object>(
|
||||
public api_query_simple_object(
|
||||
endpoint: string,
|
||||
on_success: (data: Type) => void
|
||||
on_success: (data: Record<string, unknown>) => void
|
||||
): void {
|
||||
this.api_get<Type>(endpoint, (data) => {
|
||||
if (!this.check_object(data)) {
|
||||
console.error("Endpoint", endpoint, "did not return an Object:", data);
|
||||
return;
|
||||
}
|
||||
this.api_query_simple(endpoint, (data) => {
|
||||
if (typeof data !== "object") return;
|
||||
if (data === null) return;
|
||||
|
||||
on_success(data);
|
||||
on_success(data as Record<string, unknown>);
|
||||
});
|
||||
}
|
||||
|
||||
public api_get_object_multi<Type extends object>(
|
||||
endpoints: string[],
|
||||
on_success: (data: Type[]) => void
|
||||
): void {
|
||||
const promises = endpoints.map((endpoint) => this.api_get_prepare<Type>(endpoint));
|
||||
|
||||
Promise.all(promises)
|
||||
.then((responses) => {
|
||||
const data = responses.map((response) => response.data);
|
||||
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
if (!this.check_object(data[i])) {
|
||||
console.error("Response data was not an Object:", data[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
on_success(data);
|
||||
})
|
||||
.catch(this.fail(endpoints.join(", ")));
|
||||
}
|
||||
}
|
||||
|
||||
export default new OVDashboardPlugin();
|
||||
|
|
|
|||
Loading…
Reference in a new issue