From 6e7f4df5e37da939b30e12afa97be9e98d02f5b7 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 20 May 2016 16:13:51 -0700 Subject: [PATCH 01/12] [Mobile] Remove usage of element.scope() Usage is unnecessary and is sensitive to initialization ordering of representations, resulting in #948. --- platform/commonUI/inspect/src/gestures/InfoButtonGesture.js | 6 ------ .../commonUI/inspect/test/gestures/InfoButtonGestureSpec.js | 5 +++++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/platform/commonUI/inspect/src/gestures/InfoButtonGesture.js b/platform/commonUI/inspect/src/gestures/InfoButtonGesture.js index 81a3fd9e84..045202aa7a 100644 --- a/platform/commonUI/inspect/src/gestures/InfoButtonGesture.js +++ b/platform/commonUI/inspect/src/gestures/InfoButtonGesture.js @@ -38,7 +38,6 @@ define( function InfoGestureButton($document, agentService, infoService, element, domainObject) { var dismissBubble, touchPosition, - scopeOff, body = $document.find('body'); function trackPosition(event) { @@ -94,10 +93,6 @@ define( element.on('click', showBubble); } - // Also make sure we dismiss bubble if representation is destroyed - // before the mouse actually leaves it - scopeOff = element.scope().$on('$destroy', hideBubble); - return { /** * Detach any event handlers associated with this gesture. @@ -109,7 +104,6 @@ define( hideBubble(); // ...and detach listeners element.off('click', showBubble); - scopeOff(); } }; } diff --git a/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js b/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js index 781bfd3769..5be65650cb 100644 --- a/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js +++ b/platform/commonUI/inspect/test/gestures/InfoButtonGestureSpec.js @@ -137,6 +137,11 @@ define( ); }); + // https://github.com/nasa/openmct/issues/948 + it("does not try to access scope", function () { + expect(mockElement.scope).not.toHaveBeenCalled(); + }); + }); } ); From f35947361ca0a5c1d69a4a645d007167559d7604 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 23 May 2016 15:32:48 -0700 Subject: [PATCH 02/12] [Timeline] Remain centered during zoom #936 --- platform/features/timeline/res/templates/timeline.html | 4 ++-- .../timeline/src/controllers/TimelineZoomController.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/features/timeline/res/templates/timeline.html b/platform/features/timeline/res/templates/timeline.html index 41a1c67a87..fc2e779a36 100644 --- a/platform/features/timeline/res/templates/timeline.html +++ b/platform/features/timeline/res/templates/timeline.html @@ -104,14 +104,14 @@
X Y diff --git a/platform/features/timeline/src/controllers/TimelineZoomController.js b/platform/features/timeline/src/controllers/TimelineZoomController.js index 4c8acd0061..4208a7465c 100644 --- a/platform/features/timeline/src/controllers/TimelineZoomController.js +++ b/platform/features/timeline/src/controllers/TimelineZoomController.js @@ -80,11 +80,13 @@ define( * @returns {number} current zoom level (as the size of a * major tick mark, in pixels) */ - zoom: function (amount) { + zoom: function (amount, bounds) { // Update the zoom level if called with an argument if (arguments.length > 0 && !isNaN(amount)) { + var center = this.toMillis(bounds.x + bounds.width / 2); setZoomLevel(zoomIndex + amount); storeZoom(zoomIndex); + bounds.x = this.toPixels(center) - bounds.width / 2; } return zoomLevels[zoomIndex]; }, From 0818a7cda089d6a7aeb18ca7a011b99cf5ac4bf3 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 23 May 2016 15:36:26 -0700 Subject: [PATCH 03/12] [Timeline] Increase maximum zoom level #936 --- platform/features/timeline/bundle.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/features/timeline/bundle.js b/platform/features/timeline/bundle.js index a6c0931f4e..eb66456ce4 100644 --- a/platform/features/timeline/bundle.js +++ b/platform/features/timeline/bundle.js @@ -127,7 +127,16 @@ define([ 14400000, 28800000, 43200000, - 86400000 + 86400000, + 86400000 * 2, + 86400000 * 5, + 86400000 * 10, + 86400000 * 20, + 86400000 * 30, + 86400000 * 60, + 86400000 * 120, + 86400000 * 240, + 86400000 * 365 ], "width": 200 } From 9a5209f7c2d3d03ca9f268e7dad28c2642dca64e Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Mon, 23 May 2016 16:06:10 -0700 Subject: [PATCH 04/12] [Timeline] Add zoom-to-fit button --- .../timeline/res/templates/timeline.html | 7 +++ .../src/controllers/TimelineZoomController.js | 46 ++++++++++++++++--- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/platform/features/timeline/res/templates/timeline.html b/platform/features/timeline/res/templates/timeline.html index fc2e779a36..8dc145b7f0 100644 --- a/platform/features/timeline/res/templates/timeline.html +++ b/platform/features/timeline/res/templates/timeline.html @@ -103,6 +103,13 @@
+ + I + + 0 && !isNaN(amount)) { var center = this.toMillis(bounds.x + bounds.width / 2); @@ -90,22 +120,24 @@ define( } return zoomLevels[zoomIndex]; }, + fit: function () { + if ($scope.domainObject) { + initializeZoom($scope.domainObject); + storeZoom(); + } + }, /** * Get the width, in pixels, of a specific time duration at * the current zoom level. * @returns {number} the number of pixels */ - toPixels: function (millis) { - return tickWidth * millis / zoomLevels[zoomIndex]; - }, + toPixels: toPixels, /** * Get the time duration, in milliseconds, occupied by the * width (specified in pixels) at the current zoom level. * @returns {number} the number of pixels */ - toMillis: function (pixels) { - return (pixels / tickWidth) * zoomLevels[zoomIndex]; - }, + toMillis: toMillis, /** * Get or set the current displayed duration. If used as a * setter, this will typically be rounded up to ensure extra From 85432af187408be0acfea560f46e4619864bf451 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 11:53:27 -0700 Subject: [PATCH 05/12] [Timeline] Don't store zoom configuration https://github.com/nasa/openmct/issues/936#issuecomment-221343620 --- .../src/controllers/TimelineZoomController.js | 20 ++++--------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/platform/features/timeline/src/controllers/TimelineZoomController.js b/platform/features/timeline/src/controllers/TimelineZoomController.js index 884904e7ba..0ba5abbb28 100644 --- a/platform/features/timeline/src/controllers/TimelineZoomController.js +++ b/platform/features/timeline/src/controllers/TimelineZoomController.js @@ -62,19 +62,6 @@ define( } } - // Persist current zoom level - function storeZoom() { - var isEditMode = $scope.commit && - $scope.domainObject && - $scope.domainObject.hasCapability('editor') && - $scope.domainObject.getCapability('editor').inEditContext(); - if (isEditMode) { - $scope.configuration = $scope.configuration || {}; - $scope.configuration.zoomLevel = zoomIndex; - $scope.commit(); - } - } - function initializeZoomFromTimespan(timespan) { var duration = timespan.getDuration(); zoomIndex = 0; @@ -96,7 +83,6 @@ define( bounds = scroll; }); $scope.$watch("domainObject", initializeZoom); - $scope.$watch("configuration.zoomLevel", setZoomLevel); return { /** @@ -115,15 +101,17 @@ define( if (arguments.length > 0 && !isNaN(amount)) { var center = this.toMillis(bounds.x + bounds.width / 2); setZoomLevel(zoomIndex + amount); - storeZoom(zoomIndex); bounds.x = this.toPixels(center) - bounds.width / 2; } return zoomLevels[zoomIndex]; }, + /** + * Set the zoom level to fit the bounds of the timeline + * being viewed. + */ fit: function () { if ($scope.domainObject) { initializeZoom($scope.domainObject); - storeZoom(); } }, /** From 757da1dff45aae24bbea5f733311e572e6d5f3fb Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 11:54:49 -0700 Subject: [PATCH 06/12] [Timeline] Remove obsolete test cases --- .../controllers/TimelineZoomControllerSpec.js | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js index 1365fca7d6..35b5bad8b4 100644 --- a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js @@ -74,34 +74,6 @@ define( expect(controller.zoom()).toEqual(3500); }); - it("does not normally persist zoom changes", function () { - controller.zoom(1); - expect(mockScope.commit).not.toHaveBeenCalled(); - }); - - it("persists zoom changes in Edit mode", function () { - mockScope.domainObject = jasmine.createSpyObj( - 'domainObject', - ['hasCapability', 'getCapability'] - ); - mockScope.domainObject.hasCapability.andCallFake(function (c) { - return c === 'editor'; - }); - mockScope.domainObject.getCapability.andCallFake(function (c) { - if (c === 'editor') { - return { - inEditContext: function () { - return true; - } - }; - } - }); - controller.zoom(1); - expect(mockScope.commit).toHaveBeenCalled(); - expect(mockScope.configuration.zoomLevel) - .toEqual(jasmine.any(Number)); - }); - }); } From eb5566f0417f7bc139329610e5791bbc88a18bb4 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 12:33:19 -0700 Subject: [PATCH 07/12] [Timeline] Add tests for timeline zoom changes --- .../src/controllers/TimelineZoomController.js | 2 +- .../controllers/TimelineZoomControllerSpec.js | 63 +++++++++++++++++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/platform/features/timeline/src/controllers/TimelineZoomController.js b/platform/features/timeline/src/controllers/TimelineZoomController.js index 0ba5abbb28..1c21cbfe8c 100644 --- a/platform/features/timeline/src/controllers/TimelineZoomController.js +++ b/platform/features/timeline/src/controllers/TimelineZoomController.js @@ -66,7 +66,7 @@ define( var duration = timespan.getDuration(); zoomIndex = 0; while (toMillis(bounds.width) < duration && - zoomIndex < zoomLevels.length) { + zoomIndex < zoomLevels.length - 1) { zoomIndex += 1; } bounds.x = toPixels(timespan.getStart()); diff --git a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js index 35b5bad8b4..b5f8e32f6f 100644 --- a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js @@ -32,11 +32,7 @@ define( beforeEach(function () { testConfiguration = { - levels: [ - 1000, - 2000, - 3500 - ], + levels: [ 1000, 2000, 3500 ], width: 12321 }; mockScope = jasmine.createSpyObj("$scope", ['$watch']); @@ -74,6 +70,63 @@ define( expect(controller.zoom()).toEqual(3500); }); + it("observes scroll bounds", function () { + expect(mockScope.$watch) + .toHaveBeenCalledWith("scroll", jasmine.any(Function)); + }); + + describe("when watches have fired", function () { + var mockDomainObject, + mockPromise, + mockTimespan, + testStart, + testEnd; + + beforeEach(function () { + testStart = 3000; + testEnd = 5500; + + mockDomainObject = jasmine.createSpyObj('domainObject', [ + 'getId', + 'getModel', + 'getCapability', + 'useCapability' + ]); + mockPromise = jasmine.createSpyObj('promise', ['then']); + mockTimespan = jasmine.createSpyObj('timespan', [ + 'getStart', + 'getEnd', + 'getDuration' + ]); + + mockDomainObject.useCapability.andCallFake(function (c) { + return c === 'timespan' && mockPromise; + }); + mockPromise.then.andCallFake(function (callback) { + callback(mockTimespan); + }); + mockTimespan.getStart.andReturn(testStart); + mockTimespan.getEnd.andReturn(testEnd); + mockTimespan.getDuration.andReturn(testEnd - testStart); + + mockScope.scroll = { x: 0, width: 20000 }; + mockScope.domainObject = mockDomainObject; + + mockScope.$watch.calls.forEach(function (call) { + call.args[1](mockScope[call.args[0]]); + }); + }); + + it("zooms to fit the timeline", function () { + var x1 = mockScope.scroll.x, + x2 = mockScope.scroll.x + mockScope.scroll.width; + expect(Math.round(controller.toMillis(x1))) + .toEqual(testStart); + expect(Math.round(controller.toMillis(x2))) + .toBeGreaterThan(testEnd); + }); + }); + }); } From 16d20eabd2d61c8af245b7a219781cf9182e930d Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 12:33:47 -0700 Subject: [PATCH 08/12] [Timeline] Simplify method --- .../src/controllers/TimelineZoomController.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/platform/features/timeline/src/controllers/TimelineZoomController.js b/platform/features/timeline/src/controllers/TimelineZoomController.js index 1c21cbfe8c..7bd64eb408 100644 --- a/platform/features/timeline/src/controllers/TimelineZoomController.js +++ b/platform/features/timeline/src/controllers/TimelineZoomController.js @@ -72,9 +72,9 @@ define( bounds.x = toPixels(timespan.getStart()); } - function initializeZoom(domainObject) { - if (domainObject) { - domainObject.useCapability('timespan') + function initializeZoom() { + if ($scope.domainObject) { + $scope.domainObject.useCapability('timespan') .then(initializeZoomFromTimespan); } } @@ -109,11 +109,7 @@ define( * Set the zoom level to fit the bounds of the timeline * being viewed. */ - fit: function () { - if ($scope.domainObject) { - initializeZoom($scope.domainObject); - } - }, + fit: initializeZoom, /** * Get the width, in pixels, of a specific time duration at * the current zoom level. From 362248a02e1114c09f1188c839375251f755bd4c Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 12:37:10 -0700 Subject: [PATCH 09/12] [Timeline] Run gulp fixstyle --- .../timeline/test/controllers/TimelineZoomControllerSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js index b5f8e32f6f..47e79fefa8 100644 --- a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js @@ -32,7 +32,7 @@ define( beforeEach(function () { testConfiguration = { - levels: [ 1000, 2000, 3500 ], + levels: [1000, 2000, 3500], width: 12321 }; mockScope = jasmine.createSpyObj("$scope", ['$watch']); From 379557093870d2ef35505167b495de69033cb62d Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 12:45:25 -0700 Subject: [PATCH 10/12] [Timeline] Rename shadowing variable --- .../timeline/src/controllers/TimelineZoomController.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/platform/features/timeline/src/controllers/TimelineZoomController.js b/platform/features/timeline/src/controllers/TimelineZoomController.js index 7bd64eb408..d94a05d291 100644 --- a/platform/features/timeline/src/controllers/TimelineZoomController.js +++ b/platform/features/timeline/src/controllers/TimelineZoomController.js @@ -63,9 +63,9 @@ define( } function initializeZoomFromTimespan(timespan) { - var duration = timespan.getDuration(); + var timelineDuration = timespan.getDuration(); zoomIndex = 0; - while (toMillis(bounds.width) < duration && + while (toMillis(bounds.width) < timelineDuration && zoomIndex < zoomLevels.length - 1) { zoomIndex += 1; } From 00534f8af7349ccab364bd5659cd8d5b276a2b3b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 24 May 2016 13:02:30 -0700 Subject: [PATCH 11/12] [Timeline] Account for tick size Account for tick size in duration reported by TimelineZoomController, to avoid tick marks being cut off prematurely due to changes for #936 --- platform/features/timeline/res/templates/timeline.html | 2 +- .../timeline/src/controllers/TimelineZoomController.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/platform/features/timeline/res/templates/timeline.html b/platform/features/timeline/res/templates/timeline.html index 8dc145b7f0..6e74a8c7b2 100644 --- a/platform/features/timeline/res/templates/timeline.html +++ b/platform/features/timeline/res/templates/timeline.html @@ -128,7 +128,7 @@