From c7b5a349e657e90e35e324de7634df61364dc46c Mon Sep 17 00:00:00 2001 From: David de Florinier Date: Tue, 26 Jun 2018 16:26:23 +0100 Subject: [PATCH] changes to support arg mapping update --- specs/browser/dom-map-controller-spec.js | 12 +++++- specs/browser/update-connector-spec.js | 45 +++++++++++++------- specs/core/layout/calculate-layout-spec.js | 2 +- specs/core/layout/extract-connectors-spec.js | 17 ++++++-- specs/core/map-model-spec.js | 4 +- specs/core/theme/theme-spec.js | 12 +++--- src/browser/dom-map-controller.js | 2 +- src/browser/update-connector.js | 2 +- src/core/layout/extract-connectors.js | 11 +++-- src/core/map-model.js | 2 +- src/core/theme/theme.js | 2 +- 11 files changed, 75 insertions(+), 36 deletions(-) diff --git a/specs/browser/dom-map-controller-spec.js b/specs/browser/dom-map-controller-spec.js index 48d94a93..765c79f5 100644 --- a/specs/browser/dom-map-controller-spec.js +++ b/specs/browser/dom-map-controller-spec.js @@ -1106,8 +1106,16 @@ describe('DomMapController', function () { expect(mapModel.selectConnector).toHaveBeenCalledWith('mouse', connector, undefined); expect(evt.isPropagationStopped()).toBeTruthy(); }); - it('should ignore the link hit event if the theme has blockParentConnectorOverride set', () => { - theme = new Theme({name: 'fromTest', blockParentConnectorOverride: true}); + it('wires a link hit event to mapModel selectConnector if the theme has connectorEditingContext set with allowed values', () => { + theme = new Theme({name: 'fromTest', connectorEditingContext: {allowed: ['width']}}); + setTheme(theme); + const evt = new jQuery.Event('tap'); + underTest.find('path.mapjs-link-hit').trigger(evt); + expect(mapModel.selectConnector).toHaveBeenCalledWith('mouse', connector, undefined); + expect(evt.isPropagationStopped()).toBeTruthy(); + }); + it('should ignore the link hit event if the theme has connectorEditingContext set with no allowed values', () => { + theme = new Theme({name: 'fromTest', connectorEditingContext: {allowed: []}}); setTheme(theme); const evt = new jQuery.Event('tap'); underTest.find('path.mapjs-link-hit').trigger(evt); diff --git a/specs/browser/update-connector-spec.js b/specs/browser/update-connector-spec.js index 277230cc..236f088e 100644 --- a/specs/browser/update-connector-spec.js +++ b/specs/browser/update-connector-spec.js @@ -58,23 +58,38 @@ describe('updateConnector', function () { it('sets the path fill to transparent', function () { expect(path.attr('fill')).toEqual('transparent'); }); - describe('when the theme has blockParentConnectorOverride flag', function () { + describe('when the theme has connectorEditingContext flag', function () { let theme; - beforeEach(function () { - theme = new Theme({name: 'blocked', blockParentConnectorOverride: true}); + describe('when has allowed', () => { + beforeEach(function () { + theme = new Theme({name: 'blocked', connectorEditingContext: {allowed: ['width']}}); + }); + it('still adds a connector path', function () { + underTest.updateConnector({theme: theme, connectorBuilder: builder}); + expect(underTest.find('path.mapjs-connector').length).toBe(1); + }); + it('adds a link-hit element', function () { + underTest.updateConnector({theme: theme, connectorBuilder: builder}); + expect(underTest.find('path.mapjs-link-hit').length).toBe(1); + }); }); - it('still adds a connector path', function () { - underTest.updateConnector({theme: theme, connectorBuilder: builder}); - expect(underTest.find('path.mapjs-connector').length).toBe(1); - }); - it('does not add a link-hit element', function () { - underTest.updateConnector({theme: theme, connectorBuilder: builder}); - expect(underTest.find('path.mapjs-link-hit').length).toBe(0); - }); - it('removes a pre-existing link-hit element', function () { - createSVG('path').addClass('mapjs-link-hit').appendTo(underTest); - underTest.updateConnector({theme: theme, connectorBuilder: builder}); - expect(underTest.find('path.mapjs-link-hit').length).toBe(0); + describe('when not allowed', () => { + beforeEach(function () { + theme = new Theme({name: 'blocked', connectorEditingContext: {allowed: []}}); + }); + it('still adds a connector path', function () { + underTest.updateConnector({theme: theme, connectorBuilder: builder}); + expect(underTest.find('path.mapjs-connector').length).toBe(1); + }); + it('does not add a link-hit element', function () { + underTest.updateConnector({theme: theme, connectorBuilder: builder}); + expect(underTest.find('path.mapjs-link-hit').length).toBe(0); + }); + it('removes a pre-existing link-hit element', function () { + createSVG('path').addClass('mapjs-link-hit').appendTo(underTest); + underTest.updateConnector({theme: theme, connectorBuilder: builder}); + expect(underTest.find('path.mapjs-link-hit').length).toBe(0); + }); }); }); }); diff --git a/specs/core/layout/calculate-layout-spec.js b/specs/core/layout/calculate-layout-spec.js index 2f8ec8ed..313fbb89 100644 --- a/specs/core/layout/calculate-layout-spec.js +++ b/specs/core/layout/calculate-layout-spec.js @@ -202,7 +202,7 @@ describe('calculateLayout', function () { }); }); it('should allow the theme to block connector overrides', function () { - optional.theme = new Theme({blockParentConnectorOverride: true}); + optional.theme = new Theme({connectorEditingContext: {allowed: []}}); result = calculateLayout(idea, dimensionProvider, optional); expect(result.connectors[11].attr).toBeFalsy(); expect(result.connectors[12].attr).toBeFalsy(); diff --git a/specs/core/layout/extract-connectors-spec.js b/specs/core/layout/extract-connectors-spec.js index a51f7cca..54ef20e1 100644 --- a/specs/core/layout/extract-connectors-spec.js +++ b/specs/core/layout/extract-connectors-spec.js @@ -65,16 +65,27 @@ describe('extractConnectors', function () { attr: {great: true} })); }); - it('adds parentConnector if the theme is set and does not block parent connector overrides', function () { - const result = extractConnectors(idea, visibleNodes, {blockParentConnectorOverride: false}); + it('adds parentConnector if the theme is set and does not have a connectorEditingContext', function () { + const result = extractConnectors(idea, visibleNodes, {connectorEditingContext: false}); expect(result[12]).toEqual(makeConnector({ from: 1, to: 12, attr: {great: true} })); }); + it('adds parentConnector if the theme is set and has connectorEditingContext with allowed values', function () { + const result = extractConnectors(idea, visibleNodes, {connectorEditingContext: {allowed: ['great']}}); + expect(result[12]).toEqual(makeConnector({ + connectorEditingContext: { + allowed: ['great'] + }, + from: 1, + to: 12, + attr: {great: true} + })); + }); it('ignores parentConnector properties when the theme blocks overrides', function () { - const result = extractConnectors(idea, visibleNodes, {blockParentConnectorOverride: true}); + const result = extractConnectors(idea, visibleNodes, {connectorEditingContext: {allowed: []}}); expect(result[12]).toEqual(makeConnector({ from: 1, to: 12 diff --git a/specs/core/map-model-spec.js b/specs/core/map-model-spec.js index 21f47479..e42238e3 100644 --- a/specs/core/map-model-spec.js +++ b/specs/core/map-model-spec.js @@ -2401,7 +2401,7 @@ describe('MapModel', function () { underTest.selectConnector('source', {from: 1, to: 10}, { x: 100, y: 100 }); - expect(connectorSelected).toHaveBeenCalledWith(10, {x: 100, y: 100}, undefined); + expect(connectorSelected).toHaveBeenCalledWith({from: 1, to: 10}, {x: 100, y: 100}, undefined); }); it('should send any parentConnector attributes of the TO node with the event', function () { const connectorSelected = jasmine.createSpy('connectorSelected'); @@ -2409,7 +2409,7 @@ describe('MapModel', function () { underTest.getIdea().mergeAttrProperty(1, 'parentConnector', 'color', 'green'); underTest.selectConnector('source', {from: 10, to: 1}, { x: 100, y: 100 }); - expect(connectorSelected).toHaveBeenCalledWith(1, {x: 100, y: 100}, {color: 'green'}); + expect(connectorSelected).toHaveBeenCalledWith({from: 10, to: 1}, {x: 100, y: 100}, {color: 'green'}); }); }); diff --git a/specs/core/theme/theme-spec.js b/specs/core/theme/theme-spec.js index e8eef63f..45255d11 100644 --- a/specs/core/theme/theme-spec.js +++ b/specs/core/theme/theme-spec.js @@ -115,14 +115,14 @@ describe('Theme', function () { it('should set the theme name', function () { expect(underTest.name).toEqual('Mike'); }); - describe('blockParentConnectorOverride', function () { - it('should be falsy if blockParentConnectorOverride flag is ommitted', function () { - expect(underTest.blockParentConnectorOverride).toBeFalsy(); + describe('connectorEditingContext', function () { + it('should be falsy if connectorEditingContext flag is ommitted', function () { + expect(underTest.connectorEditingContext).toBeFalsy(); }); - it('should be truthy when blockParentConnectorOverride flag is set', function () { - theme.blockParentConnectorOverride = true; + it('should be truthy when connectorEditingContext flag is set', function () { + theme.connectorEditingContext = {allowed: ['width']}; underTest = new Theme(theme); - expect(underTest.blockParentConnectorOverride).toBeTruthy(); + expect(underTest.connectorEditingContext).toEqual({allowed: ['width']}); }); }); diff --git a/src/browser/dom-map-controller.js b/src/browser/dom-map-controller.js index 66cfede4..9a385fca 100644 --- a/src/browser/dom-map-controller.js +++ b/src/browser/dom-map-controller.js @@ -501,7 +501,7 @@ module.exports = function DomMapController(mapModel, stageElement, touchEnabled, }); element.on('tap', function (event) { const theme = themeSource(); - if (!theme || !theme.blockParentConnectorOverride) { + if (!theme || !theme.connectorEditingContext || (theme.connectorEditingContext.allowed && theme.connectorEditingContext.allowed.length)) { if (event.target && event.target.tagName === 'text') { mapModel.lineLabelClicked(connector); } else { diff --git a/src/browser/update-connector.js b/src/browser/update-connector.js index 190b1807..d7d212f0 100644 --- a/src/browser/update-connector.js +++ b/src/browser/update-connector.js @@ -26,7 +26,7 @@ jQuery.fn.updateConnector = function (optional) { shapeFrom = element.data('nodeFrom'), shapeTo = element.data('nodeTo'), connectorAttr = element.data('attr'), - allowParentConnectorOverride = !(theme && theme.blockParentConnectorOverride), + allowParentConnectorOverride = !theme || !theme.connectorEditingContext || (theme.connectorEditingContext.allowed && theme.connectorEditingContext.allowed.length), applyInnerRect = function (shape, box) { const innerRect = shape.data().innerRect; if (innerRect) { diff --git a/src/core/layout/extract-connectors.js b/src/core/layout/extract-connectors.js index 812c6ba6..e7396768 100644 --- a/src/core/layout/extract-connectors.js +++ b/src/core/layout/extract-connectors.js @@ -3,7 +3,7 @@ const _ = require('underscore'); module.exports = function extractConnectors(aggregate, visibleNodes, theme) { 'use strict'; const result = {}, - allowParentConnectorOverride = !(theme && theme.blockParentConnectorOverride), + allowParentConnectorOverride = !(theme && theme.connectorEditingContext), traverse = function (idea, parentId, isChildNode) { if (isChildNode) { const visibleNode = visibleNodes[idea.id]; @@ -16,8 +16,13 @@ module.exports = function extractConnectors(aggregate, visibleNodes, theme) { from: parentId, to: idea.id }; - if (allowParentConnectorOverride && visibleNode.attr && visibleNode.attr.parentConnector) { - result[idea.id].attr = _.clone(visibleNode.attr.parentConnector); + if (visibleNode.attr && visibleNode.attr.parentConnector) { + if (allowParentConnectorOverride && visibleNode.attr && visibleNode.attr.parentConnector) { + result[idea.id].attr = _.clone(visibleNode.attr.parentConnector); + } else if (theme && theme.connectorEditingContext && theme.connectorEditingContext.allowed && theme.connectorEditingContext.allowed.length) { + result[idea.id].connectorEditingContext = theme.connectorEditingContext; + result[idea.id].attr = _.pick(visibleNode.attr.parentConnector, theme.connectorEditingContext.allowed); + } } } } diff --git a/src/core/map-model.js b/src/core/map-model.js index e41e2442..770362b8 100644 --- a/src/core/map-model.js +++ b/src/core/map-model.js @@ -736,7 +736,7 @@ module.exports = function MapModel(selectAllTitles, defaultReorderMargin, option if (!connector) { return false; } - self.dispatchEvent('connectorSelected', connector.to, selectionPoint, idea.getAttrById(connector.to, 'parentConnector')); + self.dispatchEvent('connectorSelected', connector, selectionPoint, idea.getAttrById(connector.to, 'parentConnector')); }; this.removeLink = function (source, nodeIdFrom, nodeIdTo) { if (!isEditingEnabled) { diff --git a/src/core/theme/theme.js b/src/core/theme/theme.js index d21ee983..66e125ba 100644 --- a/src/core/theme/theme.js +++ b/src/core/theme/theme.js @@ -39,7 +39,7 @@ module.exports = function Theme(themeJson) { return self.attributeValue(['node'], themeStyles, ['text', 'margin'], themeFallbackValues.nodeTheme.margin); }; self.name = themeJson && themeJson.name; - self.blockParentConnectorOverride = themeJson && themeJson.blockParentConnectorOverride; + self.connectorEditingContext = themeJson && themeJson.connectorEditingContext; self.attributeValue = function (prefixes, styles, postfixes, fallback) { const rootElement = getElementForPath(themeDictionary, prefixes); let merged = {};