From ed69a65f9b1c7c36947a4f6ba7a0127cae2e84c2 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 25 May 2016 11:03:32 -0700 Subject: [PATCH 1/5] [Representation] Restore ordering in mct-representation Revert "[Timeline] Change ordering in mct-representation" This reverts commit 20ecf168f238b9a4b2341508650f4b573bfd4f0b. These changes introduced a regression due to ordering expected by time conductor, #957 --- platform/representation/src/MCTRepresentation.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index 953ed7cf5a..331139b793 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -177,6 +177,10 @@ define( // representation to store local variables into. $scope.representation = {}; + // Change templates (passing in undefined to clear + // if we don't have enough info to show a template.) + changeTemplate(canRepresent ? representation : undefined); + // Any existing representers are no longer valid; release them. destroyRepresenters(); @@ -222,10 +226,6 @@ define( // next change object/key pair changes toClear = uses.concat(['model']); } - - // Change templates (passing in undefined to clear - // if we don't have enough info to show a template.) - changeTemplate(canRepresent ? representation : undefined); } // Update the representation when the key changes (e.g. if a From 70b593e28a4b3657cabf86a6d005f51d2d419817 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 25 May 2016 11:21:20 -0700 Subject: [PATCH 2/5] [Timeline] Watch for configuration object ...to address #908 in a manner which does not cause #957 --- .../src/controllers/TimelineController.js | 2 ++ .../swimlane/TimelineSwimlanePopulator.js | 21 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/platform/features/timeline/src/controllers/TimelineController.js b/platform/features/timeline/src/controllers/TimelineController.js index 796807c76a..64900b586c 100644 --- a/platform/features/timeline/src/controllers/TimelineController.js +++ b/platform/features/timeline/src/controllers/TimelineController.js @@ -97,6 +97,8 @@ define( } } + $scope.$watch("configuration", swimlanePopulator.configure); + // Recalculate swimlane state on changes $scope.$watch("domainObject", swimlanePopulator.populate); diff --git a/platform/features/timeline/src/controllers/swimlane/TimelineSwimlanePopulator.js b/platform/features/timeline/src/controllers/swimlane/TimelineSwimlanePopulator.js index ccc6148997..74c28b46b8 100644 --- a/platform/features/timeline/src/controllers/swimlane/TimelineSwimlanePopulator.js +++ b/platform/features/timeline/src/controllers/swimlane/TimelineSwimlanePopulator.js @@ -43,8 +43,7 @@ define( var swimlanes = [], start = Number.POSITIVE_INFINITY, end = Number.NEGATIVE_INFINITY, - colors = (configuration.colors || {}), - assigner = new TimelineColorAssigner(colors), + assigner, lastDomainObject; // Track extremes of start/end times @@ -152,8 +151,15 @@ define( recalculateSwimlanes(lastDomainObject); } + function initialize() { + var colors = (configuration.colors || {}); + assigner = new TimelineColorAssigner(colors); + configuration.colors = colors; + recalculateSwimlanes(lastDomainObject); + } + // Ensure colors are exposed in configuration - configuration.colors = colors; + initialize(); return { /** @@ -188,6 +194,15 @@ define( */ end: function () { return end; + }, + /** + * Pass a new configuration object (to retrieve and store + * swimlane configuration) + * @param newConfig + */ + configure: function (newConfig) { + configuration = newConfig; + initialize(); } }; } From 0a75a5be1f1f086f572fcc4e970e784afa7dea10 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 25 May 2016 11:27:16 -0700 Subject: [PATCH 3/5] [Timeline] Add minimal test case --- .../timeline/test/controllers/TimelineControllerSpec.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/platform/features/timeline/test/controllers/TimelineControllerSpec.js b/platform/features/timeline/test/controllers/TimelineControllerSpec.js index 9e777b0d8e..2b78829c3a 100644 --- a/platform/features/timeline/test/controllers/TimelineControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineControllerSpec.js @@ -141,6 +141,13 @@ define( expect(mockScope.scroll.y).toEqual(0); }); + it("watches for a configuration object", function () { + expect(mockScope.$watch).toHaveBeenCalledWith( + "configuration", + jasmine.any(Function) + ); + }); + it("repopulates when modifications are made", function () { var fnWatchCall, strWatchCall; From 952f95aa4c9b19fe0a081ab9e073a2087c3a3221 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 25 May 2016 11:33:51 -0700 Subject: [PATCH 4/5] [Timeline] Update failing specs --- .../controllers/TimelineControllerSpec.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/platform/features/timeline/test/controllers/TimelineControllerSpec.js b/platform/features/timeline/test/controllers/TimelineControllerSpec.js index 2b78829c3a..aa88866ebc 100644 --- a/platform/features/timeline/test/controllers/TimelineControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineControllerSpec.js @@ -68,6 +68,14 @@ define( }; } + function fireWatch(expr, value) { + mockScope.$watch.calls.forEach(function (call) { + if (call.args[0] === expr) { + call.args[1](value); + } + }); + } + beforeEach(function () { var mockA, mockB, mockUtilization, mockPromise, mockGraph, testCapabilities; @@ -149,8 +157,7 @@ define( }); it("repopulates when modifications are made", function () { - var fnWatchCall, - strWatchCall; + var fnWatchCall; // Find the $watch that was given a function mockScope.$watch.calls.forEach(function (call) { @@ -158,16 +165,11 @@ define( // white-box: we know the first call is // the one we're looking for fnWatchCall = fnWatchCall || call; - } else if (typeof call.args[0] === 'string') { - strWatchCall = strWatchCall || call; } }); // Make sure string watch was for domainObject - expect(strWatchCall.args[0]).toEqual('domainObject'); - // Initially populate - strWatchCall.args[1](mockDomainObject); - + fireWatch('domainObject', mockDomainObject); // There should be to swimlanes expect(controller.swimlanes().length).toEqual(2); @@ -189,23 +191,23 @@ define( // order of $watch calls in TimelineController. // Initially populate - mockScope.$watch.calls[0].args[1](mockDomainObject); + fireWatch('domainObject', mockDomainObject); // Verify precondition - no graphs expect(controller.graphs().length).toEqual(0); // Execute the watch function for graph state - tmp = mockScope.$watch.calls[2].args[0](); + tmp = mockScope.$watch.calls[3].args[0](); // Change graph state testConfiguration.graph = { a: true, b: true }; // Verify that this would have triggered a watch - expect(mockScope.$watch.calls[2].args[0]()) + expect(mockScope.$watch.calls[3].args[0]()) .not.toEqual(tmp); // Run the function the watch would have triggered - mockScope.$watch.calls[2].args[1](); + mockScope.$watch.calls[3].args[1](); // Should have some graphs now expect(controller.graphs().length).toEqual(2); @@ -218,7 +220,7 @@ define( mockZoom.duration.andReturn(12345); // Initially populate - mockScope.$watch.calls[0].args[1](mockDomainObject); + fireWatch('domainObject', mockDomainObject); expect(controller.width(mockZoom)).toEqual(54321); // Verify interactions; we took zoom's duration for our start/end, From 3935378b0c1f832bde5e64359443fa500a95dd67 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 25 May 2016 11:34:29 -0700 Subject: [PATCH 5/5] Revert "[Timeline] Test mct-representation ordering" This reverts commit 2a4004fd5bcddc8249c8911606d14dad8303d14b. --- .../representation/test/MCTRepresentationSpec.js | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/platform/representation/test/MCTRepresentationSpec.js b/platform/representation/test/MCTRepresentationSpec.js index 98da386c91..025ab0f14d 100644 --- a/platform/representation/test/MCTRepresentationSpec.js +++ b/platform/representation/test/MCTRepresentationSpec.js @@ -194,21 +194,6 @@ define( .toHaveBeenCalledWith(testViews[1]); }); - it("exposes configuration before changing templates", function () { - var observedConfiguration; - - mockChangeTemplate.andCallFake(function () { - observedConfiguration = mockScope.configuration; - }); - - mockScope.key = "xyz"; - mockScope.domainObject = mockDomainObject; - fireWatch('key', mockScope.key); - fireWatch('domainObject', mockDomainObject); - - expect(observedConfiguration).toBeDefined(); - }); - it("does not load templates until there is an object", function () { mockScope.key = "xyz";