UNPKG

@rcsb/rcsb-saguaro-app

Version:
96 lines (95 loc) 5.41 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RcsbFvCoreBuilder = void 0; const tslib_1 = require("tslib"); const RcsbFvContextManager_1 = require("./RcsbFvContextManager"); const ComponentsManager_1 = require("../RcsbFvComponents/ComponentsManager"); const RcsbRequestContextManager_1 = require("../../RcsbRequest/RcsbRequestContextManager"); /** * This class provides static methods to build PFVs. PFVs should be always created using methods in this class * */ class RcsbFvCoreBuilder { /** * @description The main purpose of this method is to have a unique point where Entity to Instance maps are collected. It forces to generate a <PolymerEntityInstanceTranslate> that will be passed to the PFV create method <getPolymerEntityInstanceMapAndBuildFv> * @param entryId PDB entry Id * @param createFvBuilder This is the function used to create the PFV. Cases where buttons are needed will be created in custom definitions of createFvBuilder. The PFV should be always created calling RcsbFvCoreBuilder.createFv * */ static getPolymerEntityInstanceMapAndCustomBuildFv(entryId, createFvBuilder) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const entityToInstance = yield RcsbRequestContextManager_1.rcsbRequestCtxManager.getEntityToInstance(entryId); return yield createFvBuilder(entityToInstance); }); } /** * @description Generic method to create PFVs. This method must be used if no other elements such as buttons are needed. * */ static getPolymerEntityInstanceMapAndBuildFv(elementId, entryId, fvModuleI, config) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const entityToInstance = yield RcsbRequestContextManager_1.rcsbRequestCtxManager.getEntityToInstance(entryId); return yield RcsbFvCoreBuilder.createFv({ elementId: elementId, fvModuleI: fvModuleI, config: config, p: entityToInstance }); }); } /** * @description This method implements a centralized point where PFVs are created. All PFV should be created using this method directly or through <CreateFvInterface.getPolymerEntityInstanceMapAndBuildFv>. In any case PFV should be built using a custom implementation. * */ static createFv(createFvI) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a; const elementId = createFvI.elementId; const fvModuleI = createFvI.fvModuleI; const config = createFvI.config; const p = createFvI.p; const rcsbFv = RcsbFvContextManager_1.rcsbFvCtxManager.getFv(elementId, (_a = createFvI.config.additionalConfig) === null || _a === void 0 ? void 0 : _a.boardConfig); yield rcsbFv.then(() => { console.info(`PFV ${elementId} render complete`); }); const rcsbFvInstance = new fvModuleI(elementId, rcsbFv); if (p != null) rcsbFvInstance.setPolymerEntityInstanceTranslator(p); yield rcsbFvInstance.build(config); if (!rcsbFvInstance.activeDisplay()) throw "ERROR: Module display failed"; config.resolve(rcsbFvInstance); return rcsbFvInstance; }); } static unmount(elementId) { var _a; if (RcsbFvContextManager_1.rcsbFvCtxManager.hasFv(elementId)) { if (RcsbFvContextManager_1.rcsbFvCtxManager.getButtonList(elementId) != null) { (_a = RcsbFvContextManager_1.rcsbFvCtxManager.getButtonList(elementId)) === null || _a === void 0 ? void 0 : _a.forEach(buttonId => { ComponentsManager_1.ComponentsManager.clearSelectButton(buttonId); }); } RcsbFvContextManager_1.rcsbFvCtxManager.getFv(elementId).unmount(); RcsbFvContextManager_1.rcsbFvCtxManager.removeFv(elementId); } } static buildSelectButton(elementFvId, selectButtonId, options, config) { RcsbFvContextManager_1.rcsbFvCtxManager.setButton(elementFvId, selectButtonId); ComponentsManager_1.ComponentsManager.buildSelectButton(selectButtonId, options, config); } static clearAdditionalSelectButton(elementFvId, selectButtonId) { var _a, _b; if ((_a = RcsbFvContextManager_1.rcsbFvCtxManager.getButtonList(elementFvId)) === null || _a === void 0 ? void 0 : _a.has(selectButtonId)) { (_b = RcsbFvContextManager_1.rcsbFvCtxManager.getButtonList(elementFvId)) === null || _b === void 0 ? void 0 : _b.delete(selectButtonId); } ComponentsManager_1.ComponentsManager.clearAdditionalSelectButton(selectButtonId); } static addSelectButton(elementFvId, selectButtonId, options, config) { RcsbFvContextManager_1.rcsbFvCtxManager.setButton(elementFvId, selectButtonId); ComponentsManager_1.ComponentsManager.addSelectButton(selectButtonId, options, config); } static showMessage(elementId, message) { var _a; const domElement = document.createElement("h4"); domElement.innerHTML = message; (_a = document.getElementById(elementId)) === null || _a === void 0 ? void 0 : _a.append(domElement); } } exports.RcsbFvCoreBuilder = RcsbFvCoreBuilder;