UNPKG

molstar

Version:

A comprehensive macromolecular library.

77 lines (76 loc) 3.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelExportUI = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2021 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ var react_1 = require("react"); var base_1 = require("../../mol-plugin-ui/base"); var common_1 = require("../../mol-plugin-ui/controls/common"); var icons_1 = require("../../mol-plugin-ui/controls/icons"); var parameters_1 = require("../../mol-plugin-ui/controls/parameters"); var use_behavior_1 = require("../../mol-plugin-ui/hooks/use-behavior"); var param_definition_1 = require("../../mol-util/param-definition"); var export_1 = require("./export"); var ModelExportUI = /** @class */ (function (_super) { tslib_1.__extends(ModelExportUI, _super); function ModelExportUI() { return _super !== null && _super.apply(this, arguments) || this; } ModelExportUI.prototype.defaultState = function () { return { header: 'Export Models', isCollapsed: true, brand: { accent: 'cyan', svg: icons_1.GetAppSvg } }; }; ModelExportUI.prototype.renderControls = function () { return (0, jsx_runtime_1.jsx)(ExportControls, { plugin: this.plugin }); }; return ModelExportUI; }(base_1.CollapsableControls)); exports.ModelExportUI = ModelExportUI; var Params = { format: param_definition_1.ParamDefinition.Select('cif', [['cif', 'mmCIF'], ['bcif', 'Binary mmCIF']]) }; var DefaultParams = param_definition_1.ParamDefinition.getDefaultValues(Params); function ExportControls(_a) { var _this = this; var plugin = _a.plugin; var _b = (0, react_1.useState)(DefaultParams), params = _b[0], setParams = _b[1]; var _c = (0, react_1.useState)(false), exporting = _c[0], setExporting = _c[1]; (0, use_behavior_1.useBehavior)(plugin.managers.structure.hierarchy.behaviors.selection); // triggers UI update var isBusy = (0, use_behavior_1.useBehavior)(plugin.behaviors.state.isBusy); var hierarchy = plugin.managers.structure.hierarchy.current; var label = 'Nothing to Export'; if (hierarchy.structures.length === 1) { label = 'Export'; } if (hierarchy.structures.length > 1) { label = 'Export (as ZIP)'; } var onExport = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: setExporting(true); _a.label = 1; case 1: _a.trys.push([1, , 3, 4]); return [4 /*yield*/, (0, export_1.exportHierarchy)(plugin, { format: params.format })]; case 2: _a.sent(); return [3 /*break*/, 4]; case 3: setExporting(false); return [7 /*endfinally*/]; case 4: return [2 /*return*/]; } }); }); }; return (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(parameters_1.ParameterControls, { params: Params, values: params, onChangeValues: setParams, isDisabled: isBusy || exporting }), (0, jsx_runtime_1.jsx)(common_1.Button, tslib_1.__assign({ onClick: onExport, style: { marginTop: 1 }, disabled: isBusy || hierarchy.structures.length === 0 || exporting, commit: hierarchy.structures.length ? 'on' : 'off' }, { children: label }))] }); }