![]() System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, Directory : /var/www/html/libs/absol-form/js/ciruiteditor/diagrameditor/ |
Upload File : |
import Fragment from "absol/src/AppPattern/Fragment"; import OOP from "absol/src/HTML5/OOP"; import {$, $$, _} from '../../core/FCore'; import '../../../css/includedblockmanager.css'; import 'absol-acomp/css/messagedialog.css' import SearchTextInput from "absol-acomp/js/Searcher"; import FlexiconButton from "absol-acomp/js/FlexiconButton"; import prepareSearchForItem, {searchListByText} from "absol-acomp/js/list/search"; /**** * @extends Fragment * @constructor * @param {CircuitDiagramEditor} editor */ function IncludedBlockManager(editor) { Fragment.call(this); this.editor = editor; this.changed = {}; } OOP.mixClass(IncludedBlockManager, Fragment); IncludedBlockManager.prototype.createView = function () { this.$view = _({ class: ['as-included-block-manager', 'as-message-dialog'], child: [ { class: 'as-message-dialog-header', child: { tag: 'span', class: 'as-message-dialog-title', child: {text: 'Included Block Manager'} } }, { class: ['as-message-dialog-body'], child: [ { class: 'as-included-block-manager-search-ctn', child: [ {tag: SearchTextInput.tag} ] }, { class: ['as-included-block-manager-table-wrapper'], child: [ { class: ['as-included-block-manager-table-scroller', 'as-bscroller'], child: { tag: 'table', class: 'as-included-block-manager-table', child: [ { tag: 'thead', child: [ { tag: 'tr', child: [ {tag: 'th', child: {text: 'Include'}}, {tag: 'th', child: {text: 'ID'}}, {tag: 'th', child: {text: 'Name'}}, {tag: 'th', child: {text: 'Type'}}, {tag: 'th', child: {text: 'Lines'}} ] } ] }, { tag: 'tbody', child: [] } ] } }, { class: 'as-included-block-manager-table-header-ctn', child: [ {class: 'as-included-block-manager-table-header-cell', child: {text: 'Include'}}, {class: 'as-included-block-manager-table-header-cell', child: {text: 'ID'}}, {class: 'as-included-block-manager-table-header-cell', child: {text: 'Type'}}, {class: 'as-included-block-manager-table-header-cell', child: {text: 'Name'}}, {class: 'as-included-block-manager-table-header-cell', child: {text: 'Lines'}} ] } ] }] }, { class: 'as-message-dialog-footer', child: [ { tag: FlexiconButton.tag, class: ['as-included-block-manager-cancel-btn', 'secondary'], props: { text: 'Cancel' } }, { tag: FlexiconButton.tag, class: ['as-included-block-manager-ok-btn', 'primary'], props: { text: 'OK' } } ] } ] }); this.$modal = _('modal'); this.$modal.addChild(this.$view); this.$table = $('.as-included-block-manager-table', this.$view); this.$tbody = $('tbody', this.$table); this.$ths = $$('thead th', this.$table); this.$fixedCells = $$('.as-included-block-manager-table-header-cell', this.$view); this.$okBtn = $('.as-included-block-manager-ok-btn', this.$view) .on('click', this.ok.bind(this)); this.$cancelBtn = $('.as-included-block-manager-cancel-btn', this.$view) .on('click', this.cancel.bind(this)); this.$search = $(SearchTextInput.tag, this.$view) .on('stoptyping', this.ev_search.bind(this)); }; IncludedBlockManager.prototype.onResume = function () { this.getView(); document.body.appendChild(this.$modal); this.$search.value = ''; this.loadTable(); }; IncludedBlockManager.prototype.onPause = function () { this.$modal.remove(); }; IncludedBlockManager.prototype.ok = function () { this.pause(); var nodeSheet = this.editor.getNodeSheet(); var changed = this.changed; var editor = this.editor; var nodeElt; var nodeInf; var count = 0; var posChange = false; var nodesBound = editor.viewBoxCtroller.getNodesBound(); var y = nodesBound.y + nodesBound.height + 10; var x = 0; for (var nodeId in changed) { posChange = true; if (changed[nodeId]) { nodeInf = nodeSheet.byId[nodeId]; nodeElt = editor._makeNodeElt({ typeIcon: nodeInf.clazz.prototype.menuIcon, name: nodeInf.displayName || nodeInf.name || nodeInf.id, inputPins: nodeInf.inputPins, outputPins: nodeInf.outputPins, inputLines: {}, outputLines: {}, title: nodeId, nodeId: nodeId, x: x, y: y }); editor.$nodes[nodeId] = nodeElt; editor.$nodeLayer.addChild(nodeElt); nodeElt.reloadPinPosition(); x += 10 + nodeElt.rect.width; } else { nodeElt = editor.$nodes[nodeId]; nodeElt.remove(); } } }; IncludedBlockManager.prototype.cancel = function () { this.pause(); }; IncludedBlockManager.prototype.query = function (text) { text = text.trim(); if (text.length === 0) { this.$tbody.clearChild() .addChild(this.$rows); this.requestUpdateSize(); return; } var items = this.$rows.map(function (elt) { return elt.searchItem; }); var sItems = searchListByText(text, items); var rows = sItems.map(function (item) { return this.$rows[item.value]; }.bind(this)); this.$tbody.clearChild(); this.$tbody.addChild(rows); this.requestUpdateSize(); }; IncludedBlockManager.prototype.requestUpdateSize = function () { this.$fixedCells.forEach(function (cell, i, arr) { var oCell = this.$ths[i]; var oBound = oCell.getBoundingClientRect(); cell.addStyle('width', (arr.length - 1 === i ? 1 : 0) + oBound.width + 'px'); }.bind(this)); }; IncludedBlockManager.prototype.loadTable = function () { var self = this; var changed = {}; this.changed = changed; this.$tbody.clearChild(); var nodeSheet = this.editor.getNodeSheet(); var lineByU = this.editor.lines.reduce(function (ac, line) { ac[line.u] = ac[line.u] || {}; ac[line.u][line.id] = line; return ac; }, {}); var lineByV = this.editor.lines.reduce(function (ac, line) { ac[line.v] = ac[line.v] || {}; ac[line.v][line.id] = line; return ac; }, {}); this.$rows = nodeSheet.list.map(function (it, idx) { var id = it.id; var name = it.name; var lines = Object.assign({}, lineByU[id], lineByU[name], lineByV[id], lineByV[name]); var lineCount = Object.keys(lines).length; var checked = !!this.editor.$nodes[id]; var rowElt = _({ tag: 'tr', props: { idx: idx, searchItem: prepareSearchForItem({ text: [checked ? 'checked' : '', it.bTag, id || '', name || '', it.displayName || ''].join(' '), value: idx }), blockId: id, }, child: [ { tag: 'td', child: { tag: 'checkboxbutton', props: { checked: checked, disabled: checked && lineCount > 0 }, on: { change: function () { if (this.checked !== checked) { rowElt.addClass(checked ? 'as-will-removed' : 'as-will-added'); changed[id] = this.checked; } else { delete changed[id]; rowElt.removeClass(checked ? 'as-will-removed' : 'as-will-added'); } } } } }, {tag: 'td', child: {tag: 'span', child: {text: it.name}}}, {tag: 'td', child: [it.clazz.prototype.menuIcon, {tag: 'span', child: {text: it.bTag}}]}, {tag: 'td', child: {tag: 'span', child: {text: it.displayName || ''}}}, {tag: 'td', child: {tag: 'span', child: {text: lineCount + ''}}} ] }); return rowElt; }.bind(this)); this.$tbody.addChild(this.$rows); this.requestUpdateSize(); }; IncludedBlockManager.prototype.ev_search = function (event) { this.query(this.$search.value); }; export default IncludedBlockManager;