UNPKG

@intuitionrobotics/live-docs

Version:
99 lines 4.56 kB
"use strict"; /* * Permissions management system, define access level for each of * your server apis, and restrict users by giving them access levels * * Copyright (C) 2020 Intuition Robotics * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.LiveDocsModule = exports.LiveDocsModule_Class = exports.RequestKey_UpdateDoc = exports.RequestKey_FetchDoc = void 0; const ts_common_1 = require("@intuitionrobotics/ts-common"); const frontend_1 = require("@intuitionrobotics/thunderstorm/frontend"); const utils_1 = require("../utils"); const thunderstorm_1 = require("@intuitionrobotics/thunderstorm"); exports.RequestKey_FetchDoc = "FetchDoc"; exports.RequestKey_UpdateDoc = "UpdateDoc"; class LiveDocsModule_Class extends ts_common_1.Module { constructor() { super(); this.docs = {}; this._showDocImpl = (docKey, doc) => { this.toasterResolver(docKey).show(); }; } set showDocImpl(value) { this._showDocImpl = value; } init() { utils_1.setDefaultLiveDocEditor(); } get(key) { return this.docs[key]; } setActionsResolver(resolver) { this.toasterResolver = resolver; } showLiveDoc(docKey) { const doc = this.docs[docKey]; if (doc) this._showDocImpl(docKey, doc); else frontend_1.ToastModule.toastInfo("Loading..."); frontend_1.XhrHttpModule .createRequest(thunderstorm_1.HttpMethod.GET, exports.RequestKey_FetchDoc, docKey) .setUrlParams({ key: docKey }) .setRelativeUrl("/v1/live-docs/get") .setLabel(`Fetch live-docs for key: ${docKey}`) .setOnError(`Error fetching live-docs for key: ${docKey}`) .execute((response) => __awaiter(this, void 0, void 0, function* () { const _doc = this.docs[docKey]; if (_doc && response.document === _doc.document) return; this.docs[docKey] = response; this._showDocImpl(docKey, this.docs[docKey]); })); } update(liveDoc) { const docKey = liveDoc.key; frontend_1.XhrHttpModule .createRequest(thunderstorm_1.HttpMethod.POST, exports.RequestKey_UpdateDoc, docKey) .setJsonBody(liveDoc) .setRelativeUrl("/v1/live-docs/update") .setLabel(`Update live-docs with key: ${docKey}`) .setOnError(`Error updating live-docs for key: ${docKey}`) .execute(() => __awaiter(this, void 0, void 0, function* () { return this.showLiveDoc(docKey); })); } changeHistory(docKey, change) { frontend_1.XhrHttpModule .createRequest(thunderstorm_1.HttpMethod.POST, exports.RequestKey_UpdateDoc, docKey) .setJsonBody({ key: docKey, change: change }) .setRelativeUrl("/v1/live-docs/change-history") .setLabel(`${change} live-docs history with key: ${docKey}`) .setOnError(`Error ${change} live-docs history for key: ${docKey}`) .execute(() => __awaiter(this, void 0, void 0, function* () { return this.showLiveDoc(docKey); })); } } exports.LiveDocsModule_Class = LiveDocsModule_Class; exports.LiveDocsModule = new LiveDocsModule_Class(); //# sourceMappingURL=LiveDocsModule.js.map