From 2262fef29ba696252a26bd60ff241ad6b4932948 Mon Sep 17 00:00:00 2001 From: David Hudson Date: Sun, 18 Sep 2016 17:38:34 +0900 Subject: [PATCH 1/7] [Swimlanes] Add resource graph drop directive Issue #599 --- platform/features/timeline/bundle.js | 9 +++ .../src/directives/MCTResourceGraphDrop.js | 70 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 platform/features/timeline/src/directives/MCTResourceGraphDrop.js diff --git a/platform/features/timeline/bundle.js b/platform/features/timeline/bundle.js index 82646b55e9..1c85780dd9 100644 --- a/platform/features/timeline/bundle.js +++ b/platform/features/timeline/bundle.js @@ -37,6 +37,7 @@ define([ "./src/capabilities/CostCapability", "./src/directives/MCTSwimlaneDrop", "./src/directives/MCTSwimlaneDrag", + "./src/directives/MCTResourceGraphDrop", "./src/services/ObjectLoader", "./src/chart/MCTTimelineChart", "text!./res/templates/values.html", @@ -67,6 +68,7 @@ define([ CostCapability, MCTSwimlaneDrop, MCTSwimlaneDrag, + MCTResourceGraphDrop, ObjectLoader, MCTTimelineChart, valuesTemplate, @@ -566,6 +568,13 @@ define([ "$interval", "$log" ] + }, + { + "key": "mctResourceGraphDrop", + "implementation": MCTResourceGraphDrop, + "depends": [ + "dndService" + ] } ], "services": [ diff --git a/platform/features/timeline/src/directives/MCTResourceGraphDrop.js b/platform/features/timeline/src/directives/MCTResourceGraphDrop.js new file mode 100644 index 0000000000..6dbb4437b7 --- /dev/null +++ b/platform/features/timeline/src/directives/MCTResourceGraphDrop.js @@ -0,0 +1,70 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2009-2016, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define( + ['./SwimlaneDragConstants'], + function (SwimlaneDragConstants) { + + /** + * Defines the `mct-resource-graph-drop` directive. When a drop occurs + * on an element with this attribute, the swimlane targeted by the drop + * will receive the dropped domain object (at which point it can handle + * the drop, typically by toggling the swimlane graph.) + * @param {DndService} dndService drag-and-drop service + */ + function MCTResourceGraphDrop(dndService) { + + function link(scope, element, attrs) { + // Handle dragover + element.on('dragover', function (e) { + scope.resourceGraphLegendropOver = true; + scope.$apply(); + }); + // Handle drops + element.on('drop', function (e) { + var swimlane = dndService.getData( + SwimlaneDragConstants.TIMELINE_SWIMLANE_DRAG_TYPE + ); + + // Only toggle if the graph isn't already set + if (!swimlane.graph()) { + swimlane.toggleGraph(); + } + }); + // Clear highlights when drag leaves this swimlane + element.on('dragleave', function () { + scope.resourceGraphLegendropOver = false; + scope.$apply(); + }); + } + + return { + // Applies to attributes + restrict: "A", + // Link using above function + link: link + }; + } + + return MCTResourceGraphDrop; + } +); From 6c5d5f3d0019e15eda506ac6f738b27e85a19b9e Mon Sep 17 00:00:00 2001 From: David Hudson Date: Sun, 18 Sep 2016 17:38:59 +0900 Subject: [PATCH 2/7] [Swimlanes] Implement resource graph directive Issue #599 --- platform/features/timeline/res/sass/_timelines.scss | 4 ++++ platform/features/timeline/res/templates/timeline.html | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/platform/features/timeline/res/sass/_timelines.scss b/platform/features/timeline/res/sass/_timelines.scss index 70b5b43024..2b702f7958 100644 --- a/platform/features/timeline/res/sass/_timelines.scss +++ b/platform/features/timeline/res/sass/_timelines.scss @@ -38,6 +38,10 @@ .l-timeline-pane { @include absPosDefault(); + &.drop-over { + background-color: lighten($colorEditAreaBg, 5%); + } + .l-width-control { position: relative; } diff --git a/platform/features/timeline/res/templates/timeline.html b/platform/features/timeline/res/templates/timeline.html index d4c022f150..2a87921f29 100644 --- a/platform/features/timeline/res/templates/timeline.html +++ b/platform/features/timeline/res/templates/timeline.html @@ -77,7 +77,7 @@ -
+
{{ngModel.title}}Resource Graph Legend
Date: Tue, 20 Sep 2016 17:59:25 +0900 Subject: [PATCH 3/7] [Swimlanes] Check for valid swimlane Issue #599. Also switches class toggle from scope based to element based. --- .../timeline/res/templates/timeline.html | 3 ++- .../src/directives/MCTResourceGraphDrop.js | 21 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/platform/features/timeline/res/templates/timeline.html b/platform/features/timeline/res/templates/timeline.html index 2a87921f29..942a3f0e8f 100644 --- a/platform/features/timeline/res/templates/timeline.html +++ b/platform/features/timeline/res/templates/timeline.html @@ -77,7 +77,8 @@ -
+
{{ngModel.title}}Resource Graph Legend
Date: Mon, 30 Oct 2017 12:25:59 -0700 Subject: [PATCH 4/7] [Timeline] Begin adding spec for MCTResourceGraphDrop ...to follow up on PR #1195, which fixes #599 --- .../directives/MCTResourceGraphDropSpec.js | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js diff --git a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js new file mode 100644 index 0000000000..39119051cf --- /dev/null +++ b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js @@ -0,0 +1,77 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2009-2016, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +define( + ['../../src/directives/MCTResourceGraphDrop', '../../src/directives/SwimlaneDragConstants'], + function (MCTResourceGraphDrop, SwimlaneDragConstants) { + + describe("The mct-resource-graph-drop directive", function () { + var mockDndService, + mockScope, + mockElement, + testAttrs, + mockSwimlane, + testEvent, + handlers, + directive; + + beforeEach(function () { + handlers = {}; + + mockDndService = jasmine.createSpyObj( + 'dndService', + ['setData', 'getData', 'removeData'] + ); + mockScope = jasmine.createSpyObj('$scope', ['$eval', '$apply']); + mockElement = jasmine.createSpyObj('element', ['on']); + testAttrs = { mctSwimlaneDrop: "mockSwimlane" }; + mockSwimlane = jasmine.createSpyObj( + "swimlane", + ["allowDropIn", "allowDropAfter", "drop", "highlight", "highlightBottom"] + ); + + testEvent = { + dataTransfer: { getData: jasmine.createSpy() }, + preventDefault: jasmine.createSpy(), + stopPropagation: jasmine.createSpy() + }; + + testEvent.dataTransfer.getData.andReturn('abc'); + mockDndService.getData.andCallFake(function (key) { + return key === SwimlaneDragConstants.TIMELINE_SWIMLANE_DRAG_TYPE ? + mockSwimlane : undefined; + }); + + directive = new MCTResourceGraphDrop(mockDndService); + directive.link(mockScope, mockElement, testAttrs); + + mockElement.on.calls.forEach(function (call) { + handlers[call.args[0]] = call.args[1]; + }); + }); + + it("is available as an attribute", function () { + expect(directive.restrict).toEqual("A"); + }); + }); + } +); From 14f5f048fb00407b249f0e9224578bf41dceefd8 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 30 Oct 2017 12:40:08 -0700 Subject: [PATCH 5/7] [Timeline] Test MCTResourceGraphDrop's dragover handler --- .../directives/MCTResourceGraphDropSpec.js | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js index 39119051cf..613f886ebe 100644 --- a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js +++ b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js @@ -42,11 +42,11 @@ define( ['setData', 'getData', 'removeData'] ); mockScope = jasmine.createSpyObj('$scope', ['$eval', '$apply']); - mockElement = jasmine.createSpyObj('element', ['on']); + mockElement = jasmine.createSpyObj('element', ['on', 'addClass', 'removeClass']); testAttrs = { mctSwimlaneDrop: "mockSwimlane" }; mockSwimlane = jasmine.createSpyObj( "swimlane", - ["allowDropIn", "allowDropAfter", "drop", "highlight", "highlightBottom"] + ['graph', 'toggleGraph'] ); testEvent = { @@ -61,6 +61,8 @@ define( mockSwimlane : undefined; }); + mockSwimlane.graph.andReturn(false); + directive = new MCTResourceGraphDrop(mockDndService); directive.link(mockScope, mockElement, testAttrs); @@ -72,6 +74,42 @@ define( it("is available as an attribute", function () { expect(directive.restrict).toEqual("A"); }); + + [false, true].forEach(function (graphing) { + describe("when swimlane graph is " + (graphing ? "" : "not ") + "enabled", function () { + beforeEach(function () { + mockSwimlane.graph.andReturn(graphing); + }); + + + describe("on dragover", function () { + var prefix = !graphing ? "does" : "does not"; + + beforeEach(function () { + handlers.dragover(testEvent); + }); + + it(prefix + " add a drop-over class", function () { + var expectAddClass = expect(mockElement.addClass); + (!graphing ? expectAddClass : expectAddClass.not) + .toHaveBeenCalledWith('drop-over'); + }); + + it(prefix + " call $apply on scope", function () { + var expectApply = expect(mockScope.$apply); + (!graphing ? expectApply : expectApply.not) + .toHaveBeenCalled(); + }); + + it(prefix + " prevent default", function () { + var expectPreventDefault = expect(testEvent.preventDefault); + (!graphing ? expectPreventDefault : expectPreventDefault.not) + .toHaveBeenCalled(); + }); + }); + }); + }); + }); } ); From 717fa5edf4703270fd9d903ef7dc7f78cf98fabb Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 30 Oct 2017 12:42:18 -0700 Subject: [PATCH 6/7] [Timeline] Test MCTResourceGraphDrop's drop handler --- .../directives/MCTResourceGraphDropSpec.js | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js index 613f886ebe..e2b09792d9 100644 --- a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js +++ b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js @@ -107,6 +107,31 @@ define( .toHaveBeenCalled(); }); }); + + describe("on drop", function () { + var prefix = !graphing ? "does" : "does not"; + + beforeEach(function () { + handlers.drop(testEvent); + }); + + it("removes any drop-over class", function () { + expect(mockElement.removeClass) + .toHaveBeenCalledWith('drop-over'); + }); + + it(prefix + " toggle the swimlane's resource graph", function () { + var expectToggle = expect(mockSwimlane.toggleGraph); + (!graphing ? expectToggle : expectToggle.not) + .toHaveBeenCalled(); + }); + + it(prefix + " prevent default", function () { + var expectPreventDefault = expect(testEvent.preventDefault); + (!graphing ? expectPreventDefault : expectPreventDefault.not) + .toHaveBeenCalled(); + }); + }); }); }); From 04f47b3db65f809b490b9572faf7f340023c2577 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 30 Oct 2017 12:44:51 -0700 Subject: [PATCH 7/7] [Timeline] Test MCTResourceGraphDrop's dragleave handler --- .../directives/MCTResourceGraphDropSpec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js index e2b09792d9..334c630027 100644 --- a/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js +++ b/platform/features/timeline/test/directives/MCTResourceGraphDropSpec.js @@ -132,6 +132,25 @@ define( .toHaveBeenCalled(); }); }); + + describe("on dragleave", function () { + beforeEach(function () { + handlers.dragleave(testEvent); + }); + + it("removes any drop-over class", function () { + expect(mockElement.removeClass) + .toHaveBeenCalledWith('drop-over'); + }); + + it("calls $apply on scope", function () { + expect(mockScope.$apply).toHaveBeenCalled(); + }); + + it("calls preventDefault on events", function () { + expect(testEvent.preventDefault).toHaveBeenCalled(); + }); + }); }); });