diff --git a/lib/features/label-editing/LabelEditingProvider.js b/lib/features/label-editing/LabelEditingProvider.js index 0ff5d8af..9b6a7319 100644 --- a/lib/features/label-editing/LabelEditingProvider.js +++ b/lib/features/label-editing/LabelEditingProvider.js @@ -4,11 +4,8 @@ var UpdateLabelHandler = require('./cmd/UpdateLabelHandler'); var LabelUtil = require('./LabelUtil'); -var minBoundsLabel = require('../../util/LabelUtil').DEFAULT_LABEL_SIZE; - var is = require('../../util/ModelUtil').is, - isExpanded = require('../../util/DiUtil').isExpanded, - assign = require('lodash/object/assign'); + isExpanded = require('../../util/DiUtil').isExpanded; var MIN_BOUNDS = { @@ -17,8 +14,7 @@ var MIN_BOUNDS = { }; - -function LabelEditingProvider(eventBus, canvas, directEditing, commandStack, elementFactory) { +function LabelEditingProvider(eventBus, canvas, directEditing, commandStack) { directEditing.registerProvider(this); commandStack.registerHandler('element.updateLabel', UpdateLabelHandler); @@ -68,10 +64,9 @@ function LabelEditingProvider(eventBus, canvas, directEditing, commandStack, ele this._canvas = canvas; this._commandStack = commandStack; - this._elementFactory = elementFactory; } -LabelEditingProvider.$inject = [ 'eventBus', 'canvas', 'directEditing', 'commandStack', 'elementFactory' ]; +LabelEditingProvider.$inject = [ 'eventBus', 'canvas', 'directEditing', 'commandStack' ]; module.exports = LabelEditingProvider; @@ -85,7 +80,7 @@ LabelEditingProvider.prototype.activate = function(element) { } var bbox = this.getEditingBBox(element); - var options = {}; + // adjust for expanded pools AND lanes if ((is(element, 'bpmn:Participant') && isExpanded(element)) || is(element, 'bpmn:Lane')) { @@ -120,28 +115,14 @@ LabelEditingProvider.prototype.activate = function(element) { bbox.x = bbox.mid.x - element.width / 2; } - // autosizing for TextAnnotation - if (is(element, 'bpmn:TextAnnotation')) { - options.autosizing = true; - options.textAlignment = 'left'; - options.defaultHeight = this._elementFactory._getDefaultSize(element).height; - options.maxHeight = 100; - } - - // and external label - if(element.label || element.type === 'label') { - options.autosizing = true; - options.defaultHeight = 50; - options.maxHeight = 100; - } - - return { bounds: bbox, text: text, options: options }; + return { bounds: bbox, text: text }; }; LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) { var target = element.label || element; + var bbox = this._canvas.getAbsoluteBBox(target); var mid = { @@ -162,37 +143,10 @@ LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) { return bbox; }; -LabelEditingProvider.prototype.update = function(element, newLabel, newSize) { - var newBounds = {}; - - var target = element.label || element; - - if(is(target, 'bpmn:TextAnnotation') || target.type === 'label'){ - var newX = null; - if (target.type === 'label') { - // newSize-obj carries dimensions of the textarea which have to be adapted - newSize.width = newSize.width <= MIN_BOUNDS.width ? minBoundsLabel.width : newSize.width; - newSize.height = Math.max(minBoundsLabel.height, newSize.height); - - // x coordinate gets calculated related to the old position - var deltaX = target.width - newSize.width; - newX = target.x + deltaX / 2; - } - - assign(newBounds, { - x: newX || target.x, - y: target.y, - width: newSize.width, - height: newSize.height - }); - } - else { - newBounds = null; - } +LabelEditingProvider.prototype.update = function(element, newLabel) { this._commandStack.execute('element.updateLabel', { element: element, - newLabel: newLabel, - newBounds: newBounds + newLabel: newLabel }); }; diff --git a/lib/features/label-editing/cmd/UpdateLabelHandler.js b/lib/features/label-editing/cmd/UpdateLabelHandler.js index 49e84757..7807295b 100644 --- a/lib/features/label-editing/cmd/UpdateLabelHandler.js +++ b/lib/features/label-editing/cmd/UpdateLabelHandler.js @@ -1,14 +1,12 @@ 'use strict'; var LabelUtil = require('../LabelUtil'); -var is = require('../../../util/ModelUtil').is; /** * A handler that updates the text of a BPMN element. */ -function UpdateLabelHandler(modeling) { - this._modeling = modeling; +function UpdateLabelHandler() { /** * Set the label and return the changed elements. @@ -39,30 +37,10 @@ function UpdateLabelHandler(modeling) { return setText(ctx.element, ctx.oldLabel); } - function postExecute(ctx) { - if (ctx.newBounds){ - - // resize textannotation to size of textarea - if(is(ctx.element, 'bpmn:TextAnnotation')){ - return modeling.resizeShape(ctx.element, ctx.newBounds); - } - - // resize external labels - if( ctx.element.label || ctx.element.type === 'label'){ - var target = ctx.element.type === 'label' ? ctx.element : ctx.element.label; - - return modeling.resizeShape(target, ctx.newBounds); - } - - } - } - // API + this.execute = execute; this.revert = revert; - this.postExecute = postExecute; } -UpdateLabelHandler.$inject = [ 'modeling' ]; - -module.exports = UpdateLabelHandler; +module.exports = UpdateLabelHandler; \ No newline at end of file diff --git a/lib/features/modeling/Modeling.js b/lib/features/modeling/Modeling.js index b46dbc01..93d43fc0 100644 --- a/lib/features/modeling/Modeling.js +++ b/lib/features/modeling/Modeling.js @@ -49,11 +49,10 @@ Modeling.prototype.getHandlers = function() { }; -Modeling.prototype.updateLabel = function(element, newLabel, newBounds) { +Modeling.prototype.updateLabel = function(element, newLabel) { this._commandStack.execute('element.updateLabel', { element: element, - newLabel: newLabel, - newBounds: newBounds + newLabel: newLabel }); }; diff --git a/test/spec/features/label-editing/LabelEditingProviderSpec.js b/test/spec/features/label-editing/LabelEditingProviderSpec.js index 2ac596b6..b792d921 100644 --- a/test/spec/features/label-editing/LabelEditingProviderSpec.js +++ b/test/spec/features/label-editing/LabelEditingProviderSpec.js @@ -2,24 +2,15 @@ require('../../../TestHelper'); -var is = require('../../../../lib/util/ModelUtil').is; - /* global bootstrapViewer, inject */ var labelEditingModule = require('../../../../lib/features/label-editing'), coreModule = require('../../../../lib/core'), - draggingModule = require('diagram-js/lib/features/dragging'), - modelingModule = require('../../../../lib/features/modeling'); - + draggingModule = require('diagram-js/lib/features/dragging'); var LabelUtil = require('../../../../lib/features/label-editing/LabelUtil'); -var minBoundsLabel = require('../../../../lib/util/LabelUtil').DEFAULT_LABEL_SIZE, - minBoundsTextbox = { - width: 150, - height: 50 - }; function triggerKeyEvent(element, event, code) { var e = document.createEvent('Events'); @@ -41,12 +32,13 @@ describe('features - label-editing', function() { describe('basics', function() { - var testModules = [ labelEditingModule, coreModule, draggingModule, modelingModule ]; + var testModules = [ labelEditingModule, coreModule, draggingModule ]; beforeEach(bootstrapViewer(diagramXML, { modules: testModules })); it('should register on dblclick', inject(function(elementRegistry, directEditing, eventBus) { + // given var shape = elementRegistry.get('task-nested-embedded'); @@ -59,6 +51,7 @@ describe('features - label-editing', function() { it('should cancel on ', inject(function(elementRegistry, directEditing, eventBus) { + // given var shape = elementRegistry.get('task-nested-embedded'), task = shape.businessObject; @@ -83,6 +76,7 @@ describe('features - label-editing', function() { it('should complete on drag start', inject(function(elementRegistry, directEditing, dragging) { + // given var shape = elementRegistry.get('task-nested-embedded'), task = shape.businessObject; @@ -100,6 +94,7 @@ describe('features - label-editing', function() { it('should submit on root element click', inject(function(elementRegistry, directEditing, canvas, eventBus) { + // given var shape = elementRegistry.get('task-nested-embedded'), task = shape.businessObject; @@ -128,7 +123,7 @@ describe('features - label-editing', function() { describe('details', function() { - var testModules = [ labelEditingModule, coreModule, modelingModule ]; + var testModules = [ labelEditingModule, coreModule ]; beforeEach(bootstrapViewer(diagramXML, { modules: testModules })); @@ -136,13 +131,13 @@ describe('features - label-editing', function() { eventBus, directEditing; - beforeEach(inject([ 'elementRegistry', 'eventBus', 'directEditing', - function(_elementRegistry, _eventBus, _directEditing) { - elementRegistry = _elementRegistry; - eventBus = _eventBus; - directEditing = _directEditing; - } - ])); + + beforeEach(inject([ 'elementRegistry', 'eventBus', 'directEditing', function(_elementRegistry, _eventBus, _directEditing) { + elementRegistry = _elementRegistry; + eventBus = _eventBus; + directEditing = _directEditing; + }])); + function directEditActivate(element) { if (element.waypoints) { @@ -152,271 +147,59 @@ describe('features - label-editing', function() { } } - function directEditUpdateLabel(value) { + function directEditUpdate(value) { directEditing._textbox.textarea.value = value; } - function directEditUpdateShape(bounds) { - var textarea = directEditing._textbox.textarea; - if (bounds.x && bounds.y) { - textarea.style.left = bounds.x + 'px'; - textarea.style.top = bounds.y + 'px'; - } - textarea.style.height = bounds.height + 'px'; - textarea.style.width = bounds.width + 'px'; - } - - function directEditComplete(value, bounds) { - if (value) { - directEditUpdateLabel(value); - } - if (bounds) { - directEditUpdateShape(bounds); - } + function directEditComplete(value) { + directEditUpdate(value); directEditing.complete(); } - function directEditCancel(value, bounds) { - if (value) { - directEditUpdateLabel(value); - } - if (bounds) { - directEditUpdateShape(bounds); - } + function directEditCancel(value) { + directEditUpdate(value); directEditing.cancel(); } describe('command support', function() { - describe('- label', function() { + it('should update via command stack', function() { - it('should update via command stack', function() { - // given - var diagramElement = elementRegistry.get('user-task'); - - var listenerCalled; - - eventBus.on('commandStack.changed', function(e) { - listenerCalled = true; - }); - - // when - directEditActivate(diagramElement); - directEditComplete('BAR', {}); - - // then - expect(listenerCalled).to.be.true; - }); - - - it('should be undone via command stack', inject(function(commandStack) { - // given - var diagramElement = elementRegistry.get('user-task'); - - var oldLabel = LabelUtil.getLabel(diagramElement); - - // when - directEditActivate(diagramElement); - directEditComplete('BAR', {}); - - commandStack.undo(); - - // then - var label = LabelUtil.getLabel(diagramElement); - expect(label).to.eql(oldLabel); - })); - - }); - - - describe('- shape', function() { - - it('of TextAnnotation should update via commandStack', function() { - // given - var diagramElement = elementRegistry.get('text-annotation'); - var oldPosition = { x: diagramElement.x, y: diagramElement.y }; - var newBounds = { height: 100, width: 150 }; - - // when - directEditActivate(diagramElement); - - // then expect textarea to be autosizing - expect(directEditing._textbox.textarea.autosizing).to.be.true; - - // when resizing textarea - directEditComplete('', newBounds); - - // then element should have new bounds - expect(diagramElement.x).to.eql(oldPosition.x); - expect(diagramElement.y).to.eql(oldPosition.y); - expect(diagramElement.height).to.eql(newBounds.height); - expect(diagramElement.width).to.eql(newBounds.width); - }); - - - it('of TextAnnotation should be undone via commandStack', inject(function(commandStack) { - // given - var diagramElement = elementRegistry.get('text-annotation'); - var oldBounds = { - x: diagramElement.x, - y: diagramElement.y, - width: diagramElement.width, - height: diagramElement.height - }; - var newBounds = { height: 100, width: 150 }; - - directEditActivate(diagramElement); - directEditComplete('', newBounds); - - // when - commandStack.undo(); - - // then element should have old bounds - expect(diagramElement.x).to.eql(oldBounds.x); - expect(diagramElement.y).to.eql(oldBounds.y); - expect(diagramElement.height).to.eql(oldBounds.height); - expect(diagramElement.width).to.eql(oldBounds.width); - })); - - - describe('of external label should update via commandStack', function() { - - it('to newBounds if newBoundsTextbox > minBoundsTextbox', function() { - // given - var diagramElement = elementRegistry.get('exclusive-gateway').label; - var newBounds = { height: minBoundsTextbox.height + 10, width: minBoundsTextbox.width + 10 }; - - // when - directEditActivate(diagramElement); - - // then expect textarea to be autosizing - expect(directEditing._textbox.textarea.autosizing).to.be.true; - - // when resizing textarea - directEditComplete('', newBounds); - - // then element should have new bounds - expect(diagramElement.height).to.eql(minBoundsTextbox.height + 10); - expect(diagramElement.width).to.eql(minBoundsTextbox.width + 10); - }); - - - it('to minBoundsLabel.width and correct height if newBoundsTextbox <= minBoundsTextbox', function() { - // given - var diagramElement = elementRegistry.get('exclusive-gateway').label; - var newBounds = { height: minBoundsTextbox.height - 10, width: minBoundsTextbox.width - 10 }; - - // when resizing textarea - directEditActivate(diagramElement); - directEditComplete('', newBounds); - - // then element should have minBoundsLabel.width - expect(diagramElement.width).to.eql(minBoundsLabel.width); - - // then element should have max(minBoundsLabel.height, newBounds.height) - expect(diagramElement.height).to.eql(Math.max(minBoundsLabel.height, newBounds.height)); - }); - }); - - - it('of external label should be undone via commandStack', inject(function(commandStack) { - // given - var diagramElement = elementRegistry.get('exclusive-gateway').label; - var oldBounds = { - x: diagramElement.x, - y: diagramElement.y, - width: diagramElement.width, - height: diagramElement.height - }; - var newBounds = { height: 100, width: 200 }; - - directEditActivate(diagramElement); - directEditComplete('', newBounds); - - // when - commandStack.undo(); - - // then element should have old bounds - expect(diagramElement.height).to.eql(oldBounds.height); - expect(diagramElement.width).to.eql(oldBounds.width); - })); - - - it('of element without autosizing textarea should not update', function() { - // given - var diagramElement = elementRegistry.get('user-task'); - var bounds = { - x: diagramElement.x, - y: diagramElement.y, - width: diagramElement.width, - height: diagramElement.height - }; - var newBounds = { width: 120, height: 100 }; - - // when - directEditActivate(diagramElement); - - // then expect textarea to be not autosizing - expect(!!directEditing._textbox.textarea.autosizing).to.be.false; - - // when resizing textarea - directEditComplete('', newBounds); - - // then expect bounds to stay the same - expect(diagramElement.x).to.eql(bounds.x); - expect(diagramElement.y).to.eql(bounds.y); - expect(diagramElement.height).to.eql(bounds.height); - expect(diagramElement.width).to.eql(bounds.width); - }); - - }); - - }); - - - describe('- position', function() { - - it('of external label should stay centered if completing', function() { // given - var diagramElement = elementRegistry.get('exclusive-gateway').label; - var newBounds = { height: 100, width: 200 }; - var midXOldLabel = diagramElement.x + diagramElement.width / 2; - var oldY = diagramElement.y; + var diagramElement = elementRegistry.get('user-task'); - // when resizing textarea - directEditActivate(diagramElement); - directEditComplete('', newBounds); + var listenerCalled; - //then new label should be centered and y remaining the same - var midXNewLabel = diagramElement.x + newBounds.width / 2; - expect(midXNewLabel).to.eql(midXOldLabel); - expect(diagramElement.y).to.eql(oldY); - }); - - - it('of old external label should be centered if undoing', inject(function(commandStack){ - // given - var diagramElement = elementRegistry.get('exclusive-gateway').label; - var oldBounds = { - x: diagramElement.x, - y: diagramElement.y, - width: diagramElement.width, - height: diagramElement.height - }; - var newBounds = { height: 100, width: 200 }; - var midXOldLabel = diagramElement.x + diagramElement.width / 2; - - directEditActivate(diagramElement); - directEditComplete('', newBounds); + eventBus.on('commandStack.changed', function(e) { + listenerCalled = true; + }); // when + directEditActivate(diagramElement); + directEditComplete('BAR'); + + // then + expect(listenerCalled).to.be.true; + }); + + + it('should undo via command stack', inject(function(commandStack) { + + // given + var diagramElement = elementRegistry.get('user-task'); + + var oldLabel = LabelUtil.getLabel(diagramElement); + + // when + directEditActivate(diagramElement); + directEditComplete('BAR'); + commandStack.undo(); // then - var midXUndoneLabel = diagramElement.x + diagramElement.width / 2; - expect(midXUndoneLabel).to.eql(midXOldLabel); - expect(diagramElement.y).to.eql(oldBounds.y); + var label = LabelUtil.getLabel(diagramElement); + expect(label).to.eql(oldLabel); })); }); @@ -425,6 +208,7 @@ describe('features - label-editing', function() { describe('should trigger redraw', function() { it('on shape change', function() { + // given var diagramElement = elementRegistry.get('user-task'); @@ -438,7 +222,7 @@ describe('features - label-editing', function() { // when directEditActivate(diagramElement); - directEditComplete('BAR', {}); + directEditComplete('BAR'); // then expect(listenerCalled).to.be.true; @@ -460,7 +244,7 @@ describe('features - label-editing', function() { // when directEditActivate(diagramElement); - directEditComplete('BAR', {}); + directEditComplete('BAR'); // then expect(listenerCalled).to.be.true; @@ -472,12 +256,14 @@ describe('features - label-editing', function() { describe('element support, should edit', function() { function directEdit(elementId) { + return inject(function(elementRegistry, eventBus, directEditing) { var diagramElement = elementRegistry.get(elementId); var label = LabelUtil.getLabel(diagramElement); + // when directEditActivate(diagramElement); @@ -487,24 +273,19 @@ describe('features - label-editing', function() { expect(directEditing.isActive()).to.be.true; - // when element has external label or is a textannotation - var LabelOrTextAnnotation = - is(diagramElement, 'bpmn:TextAnnotation') || - !!diagramElement.label || diagramElement.type ==='label'; + // when + directEditComplete('B'); // then - //expect textarea to be autosizing - //else to be not autosizing - expect(!!directEditing._textbox.textarea.autosizing).to.eql(LabelOrTextAnnotation); + // expect update to have happened + label = LabelUtil.getLabel(diagramElement); + expect(label).to.equal('B'); - // when - directEditComplete('B', {}); // when directEditActivate(diagramElement); directEditCancel('C'); - // expect no label update to have happened label = LabelUtil.getLabel(diagramElement); expect(label).to.equal('B'); @@ -519,6 +300,7 @@ describe('features - label-editing', function() { it('gateway via label', directEdit('exclusive-gateway_label')); + it('event', directEdit('intermediate-throw-event')); it('event via label', directEdit('intermediate-throw-event_label')); @@ -553,13 +335,12 @@ describe('features - label-editing', function() { it('lane without label', directEdit('nested-lane-no-label')); }); - }); describe('sizing', function() { - var testModules = [ labelEditingModule, coreModule, modelingModule ]; + var testModules = [ labelEditingModule, coreModule ]; beforeEach(bootstrapViewer(diagramXML, { modules: testModules, @@ -570,7 +351,7 @@ describe('features - label-editing', function() { describe('textbox should have minimum size', function() { function testTextboxSizing(elementId, zoom, width, height) { - return inject(function(canvas, elementRegistry, directEditing) { + return inject(function(canvas, elementRegistry, directEditing){ // zoom in canvas.zoom(zoom); // grab one element diff --git a/test/spec/features/modeling/UpdateLabelSpec.js b/test/spec/features/modeling/UpdateLabelSpec.js index 419e2784..05eb3f48 100644 --- a/test/spec/features/modeling/UpdateLabelSpec.js +++ b/test/spec/features/modeling/UpdateLabelSpec.js @@ -21,7 +21,7 @@ describe('features/modeling - update label', function() { var startEvent_1 = elementRegistry.get('StartEvent_1'); // when - modeling.updateLabel(startEvent_1, 'bar', null); + modeling.updateLabel(startEvent_1, 'bar'); // then expect(startEvent_1.businessObject.name).to.equal('bar'); @@ -35,7 +35,7 @@ describe('features/modeling - update label', function() { var startEvent_2 = elementRegistry.get('StartEvent_2'); // when - modeling.updateLabel(startEvent_2, 'bar', null); + modeling.updateLabel(startEvent_2, 'bar'); // then expect(startEvent_2.businessObject.name).to.equal('bar'); @@ -49,7 +49,7 @@ describe('features/modeling - update label', function() { var startEvent_1 = elementRegistry.get('StartEvent_1'); // when - modeling.updateLabel(startEvent_1, '', null); + modeling.updateLabel(startEvent_1, ''); // then expect(startEvent_1.businessObject.name).to.equal(''); @@ -64,7 +64,7 @@ describe('features/modeling - update label', function() { var startEvent_1_label = elementRegistry.get('StartEvent_1_label'); // when - modeling.updateLabel(startEvent_1_label, 'bar', null); + modeling.updateLabel(startEvent_1_label, 'bar'); // then expect(startEvent_1.businessObject.name).to.equal('bar'); @@ -72,36 +72,6 @@ describe('features/modeling - update label', function() { })); - it('should resize label when bounds given', inject(function(modeling, elementRegistry) { - // given - var startEvent_1_label = elementRegistry.get('StartEvent_1_label'); - var newBounds = { x: startEvent_1_label.x, y: startEvent_1_label.y, height: 100, width: 150 }; - - // when - modeling.updateLabel(startEvent_1_label, 'bar', newBounds); - - // then - expect(startEvent_1_label.width).to.eql(150); - expect(startEvent_1_label.height).to.eql(100); - })); - - - it('should fail bounds given in incorrect form', inject(function(modeling, elementRegistry) { - - // given - var startEvent_1_label = elementRegistry.get('StartEvent_1_label'); - var newBounds = {}; - - // when - function updateLabel() { - modeling.updateLabel(startEvent_1_label, 'bar', newBounds); - } - - // then - expect(updateLabel).to.throw('newBounds must have {x, y, width, height} properties'); - })); - - it('should change name of task', inject(function(modeling, elementRegistry) { // given @@ -129,7 +99,7 @@ describe('features/modeling - update label', function() { }); // when - modeling.updateLabel(startEvent_1, 'foo', null); + modeling.updateLabel(startEvent_1, 'foo'); // then expect(changedEvent.elements).to.include(startEvent_1); @@ -150,7 +120,7 @@ describe('features/modeling - update label', function() { }); // when - modeling.updateLabel(startEvent_1_label, 'foo', null); + modeling.updateLabel(startEvent_1_label, 'foo'); // then expect(changedEvent.elements).to.include(startEvent_1); diff --git a/test/spec/features/snapping/BpmnSnappingSpec.js b/test/spec/features/snapping/BpmnSnappingSpec.js index b0114561..2b17fb60 100644 --- a/test/spec/features/snapping/BpmnSnappingSpec.js +++ b/test/spec/features/snapping/BpmnSnappingSpec.js @@ -381,8 +381,7 @@ describe('features/snapping - BpmnSnapping', function() { modelingModule, resizeModule, rulesModule, - snappingModule, - modelingModule + snappingModule ]; beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules })); @@ -412,8 +411,7 @@ describe('features/snapping - BpmnSnapping', function() { modelingModule, resizeModule, rulesModule, - snappingModule, - modelingModule + snappingModule ]; beforeEach(bootstrapModeler(diagramXML, { modules: testResizeModules }));