molstar
Version:
A comprehensive macromolecular library.
95 lines • 4.74 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { PluginUIComponent } from './base';
import { OrderedMap } from 'immutable';
import { filter } from 'rxjs/operators';
import { IconButton } from './controls/common';
import { CancelSvg } from './controls/icons';
var BackgroundTaskProgress = /** @class */ (function (_super) {
__extends(BackgroundTaskProgress, _super);
function BackgroundTaskProgress() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { tracked: 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(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 _jsx("div", __assign({ className: 'msp-background-tasks' }, { children: this.state.tracked.valueSeq().map(function (e) { return _jsx(ProgressEntry, { event: e }, e.id); }) }), void 0);
};
return BackgroundTaskProgress;
}(PluginUIComponent));
export { BackgroundTaskProgress };
var ProgressEntry = /** @class */ (function (_super) {
__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
: _jsxs(_Fragment, { children: ["[", root.progress.current, "/", root.progress.max, "]"] }, void 0);
var subtasks = subtaskCount > 0
? _jsxs(_Fragment, { children: ["[", subtaskCount, " subtask(s)]"] }, void 0)
: void 0;
return _jsx("div", __assign({ className: 'msp-task-state' }, { children: _jsxs("div", { children: [root.progress.canAbort && _jsx(IconButton, { svg: CancelSvg, onClick: this.abort, title: 'Abort' }, void 0), _jsxs("div", { children: [root.progress.message, " ", pr, " ", subtasks] }, void 0)] }, void 0) }), void 0);
};
return ProgressEntry;
}(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) {
__extends(OverlayTaskProgress, _super);
function OverlayTaskProgress() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.state = { tracked: OrderedMap() };
return _this;
}
OverlayTaskProgress.prototype.componentDidMount = function () {
var _this = this;
this.subscribe(this.plugin.events.task.progress.pipe(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 _jsx("div", __assign({ className: 'msp-overlay-tasks' }, { children: this.state.tracked.valueSeq().map(function (e) { return _jsx(ProgressEntry, { event: e }, e.id); }) }), void 0);
};
return OverlayTaskProgress;
}(PluginUIComponent));
export { OverlayTaskProgress };
//# sourceMappingURL=task.js.map