From 6422298d955eb6c7e0a8737c61ffc291ac27100a Mon Sep 17 00:00:00 2001 From: Milton Bittencourt Date: Sun, 8 Oct 2023 17:52:59 -0300 Subject: [PATCH 1/3] Add copyAll, pastAll and deletAll on elementSelector --- app/angular/editor/elementSelector.js | 92 ++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/app/angular/editor/elementSelector.js b/app/angular/editor/elementSelector.js index 0233aab6..ccaab3d2 100644 --- a/app/angular/editor/elementSelector.js +++ b/app/angular/editor/elementSelector.js @@ -21,12 +21,21 @@ joint.ui.ElementSelector = Backbone.View.extend({ ...a.paper.model, ...this.options, graph: a.paper.model, + copyContext: { + clones: [], + event: null + } }; this.start = this.start.bind(this); this.stop = this.stop.bind(this); this.adjust = this.adjust.bind(this); this.pointerup = this.pointerup.bind(this); + this.deleteAll = this.deleteAll.bind(this); + this.copyAll = this.copyAll.bind(this); + this.pasteAll = this.pasteAll.bind(this); + this.cancel = this.cancel.bind(this); + this.getSelectedElements = this.getSelectedElements.bind(this); $(document.body).on("mousemove.selectionView touchmove.selectionView", this.adjust); $(document).on("mouseup.selectionView touchend.selectionView", this.pointerup); @@ -53,6 +62,84 @@ joint.ui.ElementSelector = Backbone.View.extend({ this.trigger("selection-box:pointerdown", normalizedEvent); }, + deleteAll: function() { + if(this.model.length > 0) { + this.options.graph.trigger("batch:start"); + this.model.forEach(model => model.remove()); + this.options.graph.trigger("batch:stop"); + this.cancel(); + } + }, + copyAll: function() { + if(this.model.length > 0) { + this.options.copyContext.clones = this.options.graph.cloneSubgraph(this.model.models, { + deep: true, + }); + } + }, + setCopyContext: function (event) { + if(event.type === "mousedown") { + const normalizedEvent = joint.util.normalizeEvent(event); + let localPoint = this.options.paper.clientToLocalPoint({ x: normalizedEvent.clientX, y: normalizedEvent.clientY }); + this.options.copyContext.event = { + "x": localPoint.x, + "y": localPoint.y + } + } + }, + pasteAll: function() { + const options = Object.assign({}, this.defaults, options); + const graph = this.options.graph; + const pastePoint = this.options.copyContext.event; + const copiedCells = this.options.copyContext.clones; + const origin = this.findbBox(Object.values(copiedCells)); + if (origin) { + const originX = origin.x == 0 ? pastePoint.x : (pastePoint.x - origin.x); + const originY = origin.y == 0 ? pastePoint.y : (pastePoint.y - origin.y); + const translation = { + dx: originX, + dy: originY + }; + options.translate = translation; + let zIndex = graph.maxZIndex(); + const context = this; + const modifiedCells = Object.values(copiedCells).map(cell => { + return context.moveCell(cell, options, zIndex += 1); + }); + graph.startBatch("paste"); + graph.addCells(modifiedCells); + graph.stopBatch("paste"); + this.options.copyContext = { + clones: [], + event: null + } + } + }, + findbBox: function(cells, opt){ + return joint.util.toArray(cells).reduce(function(memo, cell) { + if (cell.isLink()) return memo; + let rect = cell.getBBox(opt); + const angle = cell.angle(); + if (angle) rect = rect.bbox(angle); + if (memo) { + return memo.union(rect); + } else { + return rect; + } + }, null); + }, + moveCell: function(cell, options, zIndex) { + cell.set("z", zIndex); + if (cell.isLink() && options.link) { + cell.set(options.link); + } + if (options.translate) { + const { dx, dy } = options.translate; + cell.translate(Number.isFinite(dx) ? dx : 0, Number.isFinite(dy) ? dy : 0); + } + cell.collection = null; + return cell; + }, start: function(event) { const normalizedEvent = joint.util.normalizeEvent(event); this.cancel(); @@ -275,5 +362,8 @@ joint.ui.ElementSelector = Backbone.View.extend({ var d = Array.prototype.slice.call(arguments, 2); d.unshift("action:" + a + ":" + b); this.trigger.apply(this, d); - } + }, + getSelectedElements: function() { + return this.model.models; + } }); \ No newline at end of file From 90b5a83e815031512fb8e68731b89c5638f1dd39 Mon Sep 17 00:00:00 2001 From: Milton Bittencourt Date: Sun, 8 Oct 2023 17:53:32 -0300 Subject: [PATCH 2/3] Add new features to conceptual editor --- app/angular/conceptual/conceptual.js | 9 +++++---- app/angular/conceptual/sidebarControl.html | 12 ++++++------ app/i18n/languages/en.js | 3 ++- app/i18n/languages/pt_BR.js | 3 ++- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/app/angular/conceptual/conceptual.js b/app/angular/conceptual/conceptual.js index bc258d05..83c1f2de 100644 --- a/app/angular/conceptual/conceptual.js +++ b/app/angular/conceptual/conceptual.js @@ -157,6 +157,7 @@ const controller = function (ModelAPI, $stateParams, $rootScope, $timeout, $uibM ctrl.onSelectElement = (cellView) => { if (cellView != null) { + configs.elementSelector.cancel(); $timeout(() => { const elementType = cellView.model.isLink() ? "Link" : cellView.model.attributes.supertype; ctrl.selectedElement = { @@ -352,7 +353,7 @@ const controller = function (ModelAPI, $stateParams, $rootScope, $timeout, $uibM } else { configs.editorScroller.startPanning(evt); } - configs.editorActions.setCopyContext(evt); + configs.elementSelector.setCopyContext(evt); }); paper.on('link:options', (cellView) => { @@ -402,9 +403,9 @@ const controller = function (ModelAPI, $stateParams, $rootScope, $timeout, $uibM configs.keyboardController.registerHandler(types.ZOOM_OUT, () => ctrl.zoomOut()); configs.keyboardController.registerHandler(types.ZOOM_NONE, () => ctrl.zoomNone()); configs.keyboardController.registerHandler(types.ESC, () => ctrl.unselectAll()); - configs.keyboardController.registerHandler(types.COPY, () => configs.editorActions.copyElement(ctrl.selectedElement.element)); - configs.keyboardController.registerHandler(types.PASTE, () => configs.editorActions.pasteElement()); - configs.keyboardController.registerHandler(types.DELETE, () => configs.selectedElementActions?.removeElement() ); + configs.keyboardController.registerHandler(types.COPY, () => configs.elementSelector.copyAll()); + configs.keyboardController.registerHandler(types.PASTE, () => configs.elementSelector.pasteAll()); + configs.keyboardController.registerHandler(types.DELETE, () => configs.elementSelector.deleteAll() ); } const registerGraphEvents = (graph) => { diff --git a/app/angular/conceptual/sidebarControl.html b/app/angular/conceptual/sidebarControl.html index 068ec447..9d9cc748 100644 --- a/app/angular/conceptual/sidebarControl.html +++ b/app/angular/conceptual/sidebarControl.html @@ -13,7 +13,7 @@ -
+
-
+
-
+
-
+
-
+
-
+
Date: Sun, 8 Oct 2023 17:58:19 -0300 Subject: [PATCH 3/3] Add new features to logic editor --- app/angular/logic/logic.html | 2 +- app/angular/logic/logic.js | 6 ++++++ app/angular/logic/sidebarControl.html | 2 +- app/angular/service/logicService.js | 24 ++++++++++++++++++------ 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/app/angular/logic/logic.html b/app/angular/logic/logic.html index c293fa1a..8694c08c 100644 --- a/app/angular/logic/logic.html +++ b/app/angular/logic/logic.html @@ -47,7 +47,7 @@

{{ 'Logical model of:' | translate }} {{$ctrl.model.nam
  • diff --git a/app/angular/logic/logic.js b/app/angular/logic/logic.js index aaa91141..bb398741 100644 --- a/app/angular/logic/logic.js +++ b/app/angular/logic/logic.js @@ -154,6 +154,12 @@ const controller = function ( } }); + $rootScope.$on("model:warning-copy", function () { + $timeout(() => { + ctrl.showFeedback("Copy is not allowed on this module when element has references.", true, "warning"); + }); + }); + ctrl.updateCardA = function (card) { LogicService.editCardinalityA(card); } diff --git a/app/angular/logic/sidebarControl.html b/app/angular/logic/sidebarControl.html index 1844a1a4..47acc5ee 100644 --- a/app/angular/logic/sidebarControl.html +++ b/app/angular/logic/sidebarControl.html @@ -13,7 +13,7 @@

    -
    +