| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import $ from "jquery"
- import { SystemInfoDescription, SystemInfo as ModelSystemInfo } from "../../src/models/systemInfo";
- import { HostnameServiceDescription } from "../../src/models/service";
- export namespace DAL {
- export class SystemInfo {
- private static lastCachedData: SystemInfoDescription|null = null;
- private static getData(): Promise<void> {
- return new Promise(ok => {
- $.get("/api/sysinfo", response => {
- this.lastCachedData = response;
- ok();
- });
- });
- }
- private static getDataWithCache(): Promise<void> {
- if (this.lastCachedData)
- return Promise.resolve();
- return this.getData();
- }
- public static async getInfo(hostname: string): Promise<ModelSystemInfo|undefined> {
- await this.getDataWithCache();
- return this.lastCachedData?.systemInfo[hostname];
- }
- public static async listHosts(): Promise<Array<string>> {
- await this.getDataWithCache();
- return Object.keys(this.lastCachedData?.systemInfo ?? {});
- }
- public static async getServices(): Promise<HostnameServiceDescription> {
- return new Promise(ok => {
- $.get("/api/services/list", response => {
- ok(response.services);
- });
- });
- }
- }
- }
|