From dd053f7e6e7dfd524f28ecc44744e8feb154b6cf Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 21 Mar 2016 17:28:42 -0700 Subject: [PATCH 1/2] [Timeline] Invoke $apply from mct-swimlane-drop ...and add some checks to ensure this is necessary, to avoid triggering a ton of digest cycles while dragging. --- .../src/directives/MCTSwimlaneDrop.js | 26 +++++++++++++++---- .../test/directives/MCTSwimlaneDropSpec.js | 7 ++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/platform/features/timeline/src/directives/MCTSwimlaneDrop.js b/platform/features/timeline/src/directives/MCTSwimlaneDrop.js index cf21ac3105..d8ebadba8f 100644 --- a/platform/features/timeline/src/directives/MCTSwimlaneDrop.js +++ b/platform/features/timeline/src/directives/MCTSwimlaneDrop.js @@ -97,21 +97,37 @@ define( function link(scope, element, attrs) { // Lookup swimlane by evaluating this attribute - function swimlane() { + function lookupSwimlane() { return scope.$eval(attrs.mctSwimlaneDrop); } // Handle dragover element.on('dragover', function (e) { - dragOver(e, element, swimlane()); + var swimlane = lookupSwimlane(), + highlight = swimlane.highlight(), + highlightBottom = swimlane.highlightBottom(); + + dragOver(e, element, swimlane); + + if ((highlightBottom !== swimlane.highlightBottom()) || + highlight !== swimlane.highlight()) { + scope.$apply(); + } }); // Handle drops element.on('drop', function (e) { - drop(e, element, swimlane()); + drop(e, element, lookupSwimlane()); + scope.$apply(); }); // Clear highlights when drag leaves this swimlane element.on('dragleave', function () { - swimlane().highlight(false); - swimlane().highlightBottom(false); + var swimlane = lookupSwimlane(), + wasHighlighted = swimlane.highlight() || + swimlane.highlightBottom(); + swimlane.highlight(false); + swimlane.highlightBottom(false); + if (wasHighlighted) { + scope.$apply(); + } }); } diff --git a/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js b/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js index 7a550b32e8..27fb6d6dbb 100644 --- a/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js +++ b/platform/features/timeline/test/directives/MCTSwimlaneDropSpec.js @@ -55,7 +55,7 @@ define( 'dndService', ['setData', 'getData', 'removeData'] ); - mockScope = jasmine.createSpyObj('$scope', ['$eval']); + mockScope = jasmine.createSpyObj('$scope', ['$eval', '$apply']); mockElement = jasmine.createSpyObj('element', ['on']); testAttrs = { mctSwimlaneDrop: "mockSwimlane" }; mockSwimlane = jasmine.createSpyObj( @@ -118,6 +118,7 @@ define( expect(mockSwimlane.highlight).toHaveBeenCalledWith(true); expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false); + expect(mockScope.$apply).toHaveBeenCalled(); }); it("updates bottom highlights on drag over", function () { @@ -128,6 +129,7 @@ define( expect(mockSwimlane.highlight).toHaveBeenCalledWith(false); expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(true); + expect(mockScope.$apply).toHaveBeenCalled(); }); it("respects swimlane's allowDropIn response", function () { @@ -157,12 +159,15 @@ define( it("notifies swimlane on drop", function () { handlers.drop(testEvent); expect(mockSwimlane.drop).toHaveBeenCalledWith('abc', 'someDomainObject'); + expect(mockScope.$apply).toHaveBeenCalled(); }); it("clears highlights when drag leaves", function () { + mockSwimlane.highlight.andReturn(true); handlers.dragleave(); expect(mockSwimlane.highlight).toHaveBeenCalledWith(false); expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false); + expect(mockScope.$apply).toHaveBeenCalled(); }); }); } From 5e54b193ca54d848553c12c9f580ca8fe59fc34c Mon Sep 17 00:00:00 2001 From: Pete Richards Date: Thu, 24 Mar 2016 13:14:53 -0700 Subject: [PATCH 2/2] [Style] remove unnecessary parenthesis See comment https://github.com/nasa/openmct/pull/782/files#r57380540 --- platform/features/timeline/src/directives/MCTSwimlaneDrop.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/features/timeline/src/directives/MCTSwimlaneDrop.js b/platform/features/timeline/src/directives/MCTSwimlaneDrop.js index d8ebadba8f..2c181a0fa0 100644 --- a/platform/features/timeline/src/directives/MCTSwimlaneDrop.js +++ b/platform/features/timeline/src/directives/MCTSwimlaneDrop.js @@ -108,7 +108,7 @@ define( dragOver(e, element, swimlane); - if ((highlightBottom !== swimlane.highlightBottom()) || + if (highlightBottom !== swimlane.highlightBottom() || highlight !== swimlane.highlight()) { scope.$apply(); }