UNPKG

molstar

Version:

A comprehensive macromolecular library.

98 lines 5.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OverlayTaskProgress = exports.BackgroundTaskProgress = void 0; var tslib_1 = require("tslib"); var jsx_runtime_1 = require("react/jsx-runtime"); /** * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info. * * @author David Sehnal <david.sehnal@gmail.com> */ var base_1 = require("./base"); var immutable_1 = require("immutable"); var operators_1 = require("rxjs/operators"); var common_1 = require("./controls/common"); var icons_1 = require("./controls/icons"); var BackgroundTaskProgress = /** @class */ (function (_super) { (0, tslib_1.__extends)(BackgroundTaskProgress, _super); function BackgroundTaskProgress() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { tracked: (0, immutable_1.OrderedMap)() }; return _this; } BackgroundTaskProgress.prototype.componentDidMount = function () { var _this = this; var _a; var hideOverlay = !!((_a = this.plugin.spec.components) === null || _a === void 0 ? void 0 : _a.hideTaskOverlay); this.subscribe(this.plugin.events.task.progress.pipe((0, operators_1.filter)(function (e) { return e.level === 'background' && (hideOverlay || !e.useOverlay); })), function (e) { _this.setState({ tracked: _this.state.tracked.set(e.id, e) }); }); this.subscribe(this.plugin.events.task.finished, function (_a) { var id = _a.id; _this.setState({ tracked: _this.state.tracked.delete(id) }); }); }; BackgroundTaskProgress.prototype.render = function () { return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-background-tasks' }, { children: this.state.tracked.valueSeq().map(function (e) { return (0, jsx_runtime_1.jsx)(ProgressEntry, { event: e }, e.id); }) }), void 0); }; return BackgroundTaskProgress; }(base_1.PluginUIComponent)); exports.BackgroundTaskProgress = BackgroundTaskProgress; var ProgressEntry = /** @class */ (function (_super) { (0, tslib_1.__extends)(ProgressEntry, _super); function ProgressEntry() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.abort = function () { _this.plugin.managers.task.requestAbort(_this.props.event.progress.root.progress.taskId, 'User Request'); }; return _this; } ProgressEntry.prototype.render = function () { var root = this.props.event.progress.root; var subtaskCount = countSubtasks(this.props.event.progress.root) - 1; var pr = root.progress.isIndeterminate ? void 0 : (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["[", root.progress.current, "/", root.progress.max, "]"] }, void 0); var subtasks = subtaskCount > 0 ? (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["[", subtaskCount, " subtask(s)]"] }, void 0) : void 0; return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-task-state' }, { children: (0, jsx_runtime_1.jsxs)("div", { children: [root.progress.canAbort && (0, jsx_runtime_1.jsx)(common_1.IconButton, { svg: icons_1.CancelSvg, onClick: this.abort, title: 'Abort' }, void 0), (0, jsx_runtime_1.jsxs)("div", { children: [root.progress.message, " ", pr, " ", subtasks] }, void 0)] }, void 0) }), void 0); }; return ProgressEntry; }(base_1.PluginUIComponent)); function countSubtasks(progress) { if (progress.children.length === 0) return 1; var sum = 0; for (var _i = 0, _a = progress.children; _i < _a.length; _i++) { var c = _a[_i]; sum += countSubtasks(c); } return sum; } var OverlayTaskProgress = /** @class */ (function (_super) { (0, tslib_1.__extends)(OverlayTaskProgress, _super); function OverlayTaskProgress() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = { tracked: (0, immutable_1.OrderedMap)() }; return _this; } OverlayTaskProgress.prototype.componentDidMount = function () { var _this = this; this.subscribe(this.plugin.events.task.progress.pipe((0, operators_1.filter)(function (e) { return !!e.useOverlay; })), function (e) { _this.setState({ tracked: _this.state.tracked.set(e.id, e) }); }); this.subscribe(this.plugin.events.task.finished, function (_a) { var id = _a.id; _this.setState({ tracked: _this.state.tracked.delete(id) }); }); }; OverlayTaskProgress.prototype.render = function () { if (this.state.tracked.size === 0) return null; return (0, jsx_runtime_1.jsx)("div", (0, tslib_1.__assign)({ className: 'msp-overlay-tasks' }, { children: this.state.tracked.valueSeq().map(function (e) { return (0, jsx_runtime_1.jsx)(ProgressEntry, { event: e }, e.id); }) }), void 0); }; return OverlayTaskProgress; }(base_1.PluginUIComponent)); exports.OverlayTaskProgress = OverlayTaskProgress; //# sourceMappingURL=task.js.map