UNPKG

@rcsb/rcsb-saguaro-app

Version:
92 lines 4.89 kB
import { __awaiter } from "tslib"; import { rcsbFvCtxManager } from "./RcsbFvContextManager"; import { ComponentsManager } from "../RcsbFvComponents/ComponentsManager"; import { rcsbRequestCtxManager } from "../../RcsbRequest/RcsbRequestContextManager"; /** * This class provides static methods to build PFVs. PFVs should be always created using methods in this class * */ export 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 __awaiter(this, void 0, void 0, function* () { const entityToInstance = yield 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 __awaiter(this, void 0, void 0, function* () { const entityToInstance = yield 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 __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 = 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 (rcsbFvCtxManager.hasFv(elementId)) { if (rcsbFvCtxManager.getButtonList(elementId) != null) { (_a = rcsbFvCtxManager.getButtonList(elementId)) === null || _a === void 0 ? void 0 : _a.forEach(buttonId => { ComponentsManager.clearSelectButton(buttonId); }); } rcsbFvCtxManager.getFv(elementId).unmount(); rcsbFvCtxManager.removeFv(elementId); } } static buildSelectButton(elementFvId, selectButtonId, options, config) { rcsbFvCtxManager.setButton(elementFvId, selectButtonId); ComponentsManager.buildSelectButton(selectButtonId, options, config); } static clearAdditionalSelectButton(elementFvId, selectButtonId) { var _a, _b; if ((_a = rcsbFvCtxManager.getButtonList(elementFvId)) === null || _a === void 0 ? void 0 : _a.has(selectButtonId)) { (_b = rcsbFvCtxManager.getButtonList(elementFvId)) === null || _b === void 0 ? void 0 : _b.delete(selectButtonId); } ComponentsManager.clearAdditionalSelectButton(selectButtonId); } static addSelectButton(elementFvId, selectButtonId, options, config) { rcsbFvCtxManager.setButton(elementFvId, selectButtonId); 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); } } //# sourceMappingURL=RcsbFvCoreBuilder.js.map