UNPKG

@isaac-platform/isaac-integration-sdk

Version:

A Typescript SDK for integrating with ISAAC

81 lines (80 loc) 3.42 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import isaacConnection from "../controller/isaac.js"; export class PanelController { constructor() { /** * Safely registers a panel to a specific subsystem. Checking if the panel already exists and updating it if it does. * @param panel - The panel to register. */ this.registerPanel = (panel) => __awaiter(this, void 0, void 0, function* () { const knownPanels = yield this.getModulePanels(); let existingPanel; knownPanels.map((knownPanel) => { if (knownPanel.externalRef === panel.externalRef) { existingPanel = knownPanel; } }); if (existingPanel) { return this.updatePanel(panel); } else { return this.addPanel(panel); } }); /** * Safely registers a new iframe panel in the ISAAC module. This will create a new panel if it does not already exist, * and update it if it does. * @param name - The user-friendly name of the panel. * @param description - The description of the panel. * @param url - The URL of the iframe to display. * @param externalRef - The external reference of the panel. This is used to identify the panel programmatically and should be unique. */ this.addIframePanel = (name, description, url, externalRef) => __awaiter(this, void 0, void 0, function* () { const payload = { displayName: name, externalRef: externalRef, subsystemExternalId: isaacConnection.subsystemID, type: "iframe", active: true, description: description, connection: { url: url } }; return this.registerPanel(payload); }); this.deregisterPanel = () => { }; /** * Registers a new Panel in the ISAAC module * @param panel */ this.addPanel = (panel) => { return isaacConnection.postRequest("controlpanels", panel, { location: "registered" }); }; this.updatePanel = (panel) => { }; /** * Get all panels for a specific subsystem. */ this.getModulePanels = (subsystemId) => { return isaacConnection.getRequest("controlpanels", { params: { subsystemExternalId: subsystemId || isaacConnection.subsystemID } }); }; } } const panelController = new PanelController(); export default panelController;