Skip to content

Commit

Permalink
changes to support arg mapping update
Browse files Browse the repository at this point in the history
  • Loading branch information
davedf committed Jun 26, 2018
1 parent 7879adf commit c7b5a34
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 36 deletions.
12 changes: 10 additions & 2 deletions specs/browser/dom-map-controller-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
45 changes: 30 additions & 15 deletions specs/browser/update-connector-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion specs/core/layout/calculate-layout-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 14 additions & 3 deletions specs/core/layout/extract-connectors-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions specs/core/map-model-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2401,15 +2401,15 @@ 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');
underTest.addEventListener('connectorSelected', connectorSelected);
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'});

});
});
Expand Down
12 changes: 6 additions & 6 deletions specs/core/theme/theme-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']});
});

});
Expand Down
2 changes: 1 addition & 1 deletion src/browser/dom-map-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/browser/update-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions src/core/layout/extract-connectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/map-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/theme/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit c7b5a34

Please sign in to comment.