mirror of
https://github.com/nasa/openmct.git
synced 2025-02-21 17:57:04 +00:00
[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.
This commit is contained in:
parent
ad4c456ca2
commit
dd053f7e6e
@ -97,21 +97,37 @@ define(
|
|||||||
|
|
||||||
function link(scope, element, attrs) {
|
function link(scope, element, attrs) {
|
||||||
// Lookup swimlane by evaluating this attribute
|
// Lookup swimlane by evaluating this attribute
|
||||||
function swimlane() {
|
function lookupSwimlane() {
|
||||||
return scope.$eval(attrs.mctSwimlaneDrop);
|
return scope.$eval(attrs.mctSwimlaneDrop);
|
||||||
}
|
}
|
||||||
// Handle dragover
|
// Handle dragover
|
||||||
element.on('dragover', function (e) {
|
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
|
// Handle drops
|
||||||
element.on('drop', function (e) {
|
element.on('drop', function (e) {
|
||||||
drop(e, element, swimlane());
|
drop(e, element, lookupSwimlane());
|
||||||
|
scope.$apply();
|
||||||
});
|
});
|
||||||
// Clear highlights when drag leaves this swimlane
|
// Clear highlights when drag leaves this swimlane
|
||||||
element.on('dragleave', function () {
|
element.on('dragleave', function () {
|
||||||
swimlane().highlight(false);
|
var swimlane = lookupSwimlane(),
|
||||||
swimlane().highlightBottom(false);
|
wasHighlighted = swimlane.highlight() ||
|
||||||
|
swimlane.highlightBottom();
|
||||||
|
swimlane.highlight(false);
|
||||||
|
swimlane.highlightBottom(false);
|
||||||
|
if (wasHighlighted) {
|
||||||
|
scope.$apply();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ define(
|
|||||||
'dndService',
|
'dndService',
|
||||||
['setData', 'getData', 'removeData']
|
['setData', 'getData', 'removeData']
|
||||||
);
|
);
|
||||||
mockScope = jasmine.createSpyObj('$scope', ['$eval']);
|
mockScope = jasmine.createSpyObj('$scope', ['$eval', '$apply']);
|
||||||
mockElement = jasmine.createSpyObj('element', ['on']);
|
mockElement = jasmine.createSpyObj('element', ['on']);
|
||||||
testAttrs = { mctSwimlaneDrop: "mockSwimlane" };
|
testAttrs = { mctSwimlaneDrop: "mockSwimlane" };
|
||||||
mockSwimlane = jasmine.createSpyObj(
|
mockSwimlane = jasmine.createSpyObj(
|
||||||
@ -118,6 +118,7 @@ define(
|
|||||||
|
|
||||||
expect(mockSwimlane.highlight).toHaveBeenCalledWith(true);
|
expect(mockSwimlane.highlight).toHaveBeenCalledWith(true);
|
||||||
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false);
|
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false);
|
||||||
|
expect(mockScope.$apply).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("updates bottom highlights on drag over", function () {
|
it("updates bottom highlights on drag over", function () {
|
||||||
@ -128,6 +129,7 @@ define(
|
|||||||
|
|
||||||
expect(mockSwimlane.highlight).toHaveBeenCalledWith(false);
|
expect(mockSwimlane.highlight).toHaveBeenCalledWith(false);
|
||||||
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(true);
|
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(true);
|
||||||
|
expect(mockScope.$apply).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("respects swimlane's allowDropIn response", function () {
|
it("respects swimlane's allowDropIn response", function () {
|
||||||
@ -157,12 +159,15 @@ define(
|
|||||||
it("notifies swimlane on drop", function () {
|
it("notifies swimlane on drop", function () {
|
||||||
handlers.drop(testEvent);
|
handlers.drop(testEvent);
|
||||||
expect(mockSwimlane.drop).toHaveBeenCalledWith('abc', 'someDomainObject');
|
expect(mockSwimlane.drop).toHaveBeenCalledWith('abc', 'someDomainObject');
|
||||||
|
expect(mockScope.$apply).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears highlights when drag leaves", function () {
|
it("clears highlights when drag leaves", function () {
|
||||||
|
mockSwimlane.highlight.andReturn(true);
|
||||||
handlers.dragleave();
|
handlers.dragleave();
|
||||||
expect(mockSwimlane.highlight).toHaveBeenCalledWith(false);
|
expect(mockSwimlane.highlight).toHaveBeenCalledWith(false);
|
||||||
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false);
|
expect(mockSwimlane.highlightBottom).toHaveBeenCalledWith(false);
|
||||||
|
expect(mockScope.$apply).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user