From 2fbfcc1333b534783f4fd0e056760f038339f3b1 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 13:12:13 -0700 Subject: [PATCH 01/23] [Windowing] Added new window button Currently overwrites metadata similar to the FullScreenAction in order to temporarily display the new window button until the css is modified to do so. WTD-16 --- .../commonUI/browse/src/windowing/NewWindowAction.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewWindowAction.js index 8b7c0751b5..bc222934b9 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewWindowAction.js @@ -43,6 +43,17 @@ define( */ perform: function () { $window.alert("Not yet functional. This will open objects in a new window."); + }, + + getMetadata: function () { + // We override getMetadata, this is temporary + // Until the css/html code views the button on + // its own + var metadata = Object.create(NewWindowAction); + metadata.glyph = "y"; + metadata.description = "ENTER DESC HERE"; + metadata.group = "windowing"; + return metadata; } }; } From 8d9d8d4900ffb7eae2b082ea6c289a25be618700 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 13:14:39 -0700 Subject: [PATCH 02/23] [Windowing] Display URL Alert box when pressing new tab button displays the current url, that will be opened in the new tab. WTD-16 --- platform/commonUI/browse/src/windowing/NewWindowAction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewWindowAction.js index bc222934b9..e2281068f6 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewWindowAction.js @@ -42,7 +42,7 @@ define( * Open the object in a new window (currently a stub) */ perform: function () { - $window.alert("Not yet functional. This will open objects in a new window."); + $window.alert($window.location.href); }, getMetadata: function () { From 6b2edc44697fea7e7dca5146f839182a586d9535 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 13:18:00 -0700 Subject: [PATCH 03/23] [Windowing] Opens Url Instead of displaying a dialog of the url, the url is opened in a new tab using the new window button. WTD-16. --- platform/commonUI/browse/src/windowing/NewWindowAction.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewWindowAction.js index e2281068f6..296d2c6937 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewWindowAction.js @@ -42,7 +42,8 @@ define( * Open the object in a new window (currently a stub) */ perform: function () { - $window.alert($window.location.href); + var currentUrl = $window.location.href; + window.open(currentUrl); }, getMetadata: function () { From 140e3a1fb6968284fd40a17d9a7eb7bf6bc90dea Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 13:20:57 -0700 Subject: [PATCH 04/23] [Windowing] Comments Added comments to the perform function WTD-16. --- platform/commonUI/browse/src/windowing/NewWindowAction.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewWindowAction.js index 296d2c6937..3a6e4ea061 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewWindowAction.js @@ -39,11 +39,13 @@ define( function NewWindowAction($window) { return { /** - * Open the object in a new window (currently a stub) + * Open the object in a new window */ perform: function () { + // Places the current Url into a variable + // Then the Url is opened using $window var currentUrl = $window.location.href; - window.open(currentUrl); + $window.open(currentUrl); }, getMetadata: function () { From 683a733ae11919ee53041de7ed455fc72150d3a3 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 14:00:25 -0700 Subject: [PATCH 05/23] [Windowing] SASS Edit Adjusted the SASS file to not hide the new window button. Also removed the overwrite metadata function that was used to temprarily allow us to view the new window button. WTD-16. --- .../commonUI/browse/src/windowing/NewWindowAction.js | 11 ----------- platform/commonUI/general/res/css/theme-espresso.css | 3 --- .../general/res/sass/_hide-non-functional.scss | 2 +- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewWindowAction.js index 3a6e4ea061..581c0d0f74 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewWindowAction.js @@ -46,17 +46,6 @@ define( // Then the Url is opened using $window var currentUrl = $window.location.href; $window.open(currentUrl); - }, - - getMetadata: function () { - // We override getMetadata, this is temporary - // Until the css/html code views the button on - // its own - var metadata = Object.create(NewWindowAction); - metadata.glyph = "y"; - metadata.description = "ENTER DESC HERE"; - metadata.group = "windowing"; - return metadata; } }; } diff --git a/platform/commonUI/general/res/css/theme-espresso.css b/platform/commonUI/general/res/css/theme-espresso.css index ef43a9da06..b5db6cc658 100644 --- a/platform/commonUI/general/res/css/theme-espresso.css +++ b/platform/commonUI/general/res/css/theme-espresso.css @@ -4863,6 +4863,3 @@ input[type="text"] { /* line 32, ../sass/_hide-non-functional.scss */ .browse-mode .browse-area.holder { top: 5px; } - /* line 39, ../sass/_hide-non-functional.scss */ - .browse-mode .browse-area.holder > .contents.split-layout .object-browse-bar .btn.key-window { - display: none; } diff --git a/platform/commonUI/general/res/sass/_hide-non-functional.scss b/platform/commonUI/general/res/sass/_hide-non-functional.scss index 1f029674c9..ccc752a9bb 100644 --- a/platform/commonUI/general/res/sass/_hide-non-functional.scss +++ b/platform/commonUI/general/res/sass/_hide-non-functional.scss @@ -38,7 +38,7 @@ .object-browse-bar { .btn.key-window { // Hide the Open in New Window button - display: none; +// display: none; } } } From fd1c847e2c4f3cce8fd0827257d646245ec1286d Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 15:06:12 -0700 Subject: [PATCH 06/23] [Windowing] Remove Varibale Removed the variable currentUrl because it was not needed. WTD-16. --- platform/commonUI/browse/src/windowing/NewWindowAction.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewWindowAction.js index 581c0d0f74..68c88bdec6 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewWindowAction.js @@ -44,8 +44,7 @@ define( perform: function () { // Places the current Url into a variable // Then the Url is opened using $window - var currentUrl = $window.location.href; - $window.open(currentUrl); + $window.open($window.location.href); } }; } From 02265c82d6db651c738da35254b269fcf84c283e Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 15:10:55 -0700 Subject: [PATCH 07/23] [Windowing] Unit Test Completes Unit Test. Added a new file: NewWindowActionSpec.js, which performs the Jasmine test for NewWindowAction.js. The test specifies a mockWindow with a mockUrl and then adds both to a NewWindowAction. Also suite.json contains the NewWindowActon path. In order for NewWindowAction.jsWTD-16. to be reached. WTD-16. --- platform/commonUI/browse/test/suite.json | 1 + .../test/windowing/NewWindowActionSpec.js | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 platform/commonUI/browse/test/windowing/NewWindowActionSpec.js diff --git a/platform/commonUI/browse/test/suite.json b/platform/commonUI/browse/test/suite.json index e36f345caa..350710df76 100644 --- a/platform/commonUI/browse/test/suite.json +++ b/platform/commonUI/browse/test/suite.json @@ -10,5 +10,6 @@ "navigation/NavigateAction", "navigation/NavigationService", "windowing/FullscreenAction", + "windowing/NewWindowAction", "windowing/WindowTitler" ] diff --git a/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js b/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js new file mode 100644 index 0000000000..327096e8a3 --- /dev/null +++ b/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js @@ -0,0 +1,48 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web 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 Web 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. + *****************************************************************************/ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine,afterEach,window*/ + +define( + ["../../src/windowing/NewWindowAction"], + function (NewWindowAction) { + "use strict"; + + describe("The new window action", function () { + var action, + mockWindow, + mockCurrentUrl; + + beforeEach(function () { + mockWindow = jasmine.createSpyObj("$window", ["open", "location"]); + mockWindow.location.href = "http://www.mockUrl.com"; + action = new NewWindowAction(mockWindow); + + }); + + it("New window is opened", function () { + action.perform(); + expect(mockWindow.open).toHaveBeenCalledWith("http://www.mockUrl.com"); + }); + + }); + } +); \ No newline at end of file From dc4436e890466fe64e4e7112d07362874f4d8dd2 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 15:15:46 -0700 Subject: [PATCH 08/23] [Windowing] Unit Test Adjustment Added comments to the NewWindowActionSpec.js file. WTD-16. --- .../commonUI/browse/test/windowing/NewWindowActionSpec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js b/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js index 327096e8a3..17d3ac586c 100644 --- a/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js @@ -32,6 +32,9 @@ define( mockCurrentUrl; beforeEach(function () { + // Creates a mockWindow from $window, then + // the mockWindow's location.href is set + // to a mock Url mockWindow = jasmine.createSpyObj("$window", ["open", "location"]); mockWindow.location.href = "http://www.mockUrl.com"; action = new NewWindowAction(mockWindow); @@ -39,6 +42,8 @@ define( }); it("New window is opened", function () { + // The expection is that the mockWindow + // will be called with it's location.href action.perform(); expect(mockWindow.open).toHaveBeenCalledWith("http://www.mockUrl.com"); }); From c7154447e28c1a96b678b865bd7b10c099019c9e Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 15:35:08 -0700 Subject: [PATCH 09/23] [Windowing] Tabbing Rename Renamed all instances of NewWindow to be NewTab instead. WTD-16. --- platform/commonUI/browse/bundle.json | 4 ++-- .../src/windowing/{NewWindowAction.js => NewTabAction.js} | 4 ++-- platform/commonUI/browse/test/suite.json | 2 +- .../{NewWindowActionSpec.js => NewTabActionSpec.js} | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) rename platform/commonUI/browse/src/windowing/{NewWindowAction.js => NewTabAction.js} (96%) rename platform/commonUI/browse/test/windowing/{NewWindowActionSpec.js => NewTabActionSpec.js} (92%) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 08b8dd08c8..babf873aae 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -92,8 +92,8 @@ }, { "key": "window", - "implementation": "windowing/NewWindowAction.js", - "description": "Open this object in a new window", + "implementation": "windowing/NewTabAction.js", + "description": "Open this object in a new tab", "category": "view-control", "depends": [ "$window" ], "group": "windowing", diff --git a/platform/commonUI/browse/src/windowing/NewWindowAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js similarity index 96% rename from platform/commonUI/browse/src/windowing/NewWindowAction.js rename to platform/commonUI/browse/src/windowing/NewTabAction.js index 68c88bdec6..3a4883c2e8 100644 --- a/platform/commonUI/browse/src/windowing/NewWindowAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -36,7 +36,7 @@ define( * the user interface.) * @constructor */ - function NewWindowAction($window) { + function NewTabAction($window) { return { /** * Open the object in a new window @@ -49,6 +49,6 @@ define( }; } - return NewWindowAction; + return NewTabAction; } ); \ No newline at end of file diff --git a/platform/commonUI/browse/test/suite.json b/platform/commonUI/browse/test/suite.json index 350710df76..6cc41900e1 100644 --- a/platform/commonUI/browse/test/suite.json +++ b/platform/commonUI/browse/test/suite.json @@ -10,6 +10,6 @@ "navigation/NavigateAction", "navigation/NavigationService", "windowing/FullscreenAction", - "windowing/NewWindowAction", + "windowing/NewTabAction", "windowing/WindowTitler" ] diff --git a/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js similarity index 92% rename from platform/commonUI/browse/test/windowing/NewWindowActionSpec.js rename to platform/commonUI/browse/test/windowing/NewTabActionSpec.js index 17d3ac586c..eee8be59c4 100644 --- a/platform/commonUI/browse/test/windowing/NewWindowActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -26,7 +26,7 @@ define( function (NewWindowAction) { "use strict"; - describe("The new window action", function () { + describe("The new tab action", function () { var action, mockWindow, mockCurrentUrl; @@ -37,11 +37,11 @@ define( // to a mock Url mockWindow = jasmine.createSpyObj("$window", ["open", "location"]); mockWindow.location.href = "http://www.mockUrl.com"; - action = new NewWindowAction(mockWindow); + action = new NewTabAction(mockWindow); }); - it("New window is opened", function () { + it("New tab with current url is opened", function () { // The expection is that the mockWindow // will be called with it's location.href action.perform(); From 1c445e1ce3c8fdf3aa1434c7280ed99d7209b9b9 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 15:44:09 -0700 Subject: [PATCH 10/23] [Windowing] New Tab Adjustment Added NewTabAction to spec file and adjusted it to new name. Also changed comment in NewTabAction along with a code fix. WTD-16. --- platform/commonUI/browse/src/windowing/NewTabAction.js | 2 +- platform/commonUI/browse/test/windowing/NewTabActionSpec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 3a4883c2e8..780caf05b4 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -22,7 +22,7 @@ /*global define,Promise*/ /** - * Module defining NewWindowAction. Created by vwoeltje on 11/18/14. + * Module defining NewTabAction (Originally NewWindowAction). Created by vwoeltje on 11/18/14. */ define( [], diff --git a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js index eee8be59c4..3731adbdb3 100644 --- a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -22,8 +22,8 @@ /*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine,afterEach,window*/ define( - ["../../src/windowing/NewWindowAction"], - function (NewWindowAction) { + ["../../src/windowing/NewTabAction"], + function (NewTabAction) { "use strict"; describe("The new tab action", function () { From d5a90194938eaae46e13361bcaed324bf0c39293 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Mon, 22 Jun 2015 15:54:32 -0700 Subject: [PATCH 11/23] [Windowing] Comment Adjusted Changed window to tab in comments in file. WTF-16. --- platform/commonUI/browse/src/windowing/NewTabAction.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 780caf05b4..5711e528c3 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -30,8 +30,8 @@ define( "use strict"; /** - * The new window action allows a domain object to be opened - * into a new browser window. (Currently this is a stub, present + * The new tab action allows a domain object to be opened + * into a new browser tab. (Currently this is a stub, present * to allow the control to appear in the appropriate location in * the user interface.) * @constructor @@ -39,7 +39,7 @@ define( function NewTabAction($window) { return { /** - * Open the object in a new window + * Open the object in a new tab */ perform: function () { // Places the current Url into a variable From e38ad7b082e940c0b895642b7021b60fe83489e3 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 23 Jun 2015 11:05:00 -0700 Subject: [PATCH 12/23] [Windowing] Path Alert Alerts user of the current path using an alert window, however the path is partially shown. It is the part of the current path after index.html#. WTD-16. --- platform/commonUI/browse/bundle.json | 5 +++-- .../browse/src/windowing/NewTabAction.js | 20 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index babf873aae..243a0b5519 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -92,10 +92,11 @@ }, { "key": "window", + "name": "Open in a new tab", "implementation": "windowing/NewTabAction.js", "description": "Open this object in a new tab", - "category": "view-control", - "depends": [ "$window" ], + "category": ["view-control", "contextual"], + "depends": [ "$window", "navigationService" ], "group": "windowing", "glyph": "y" }, diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 5711e528c3..7d617103ec 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -36,15 +36,27 @@ define( * the user interface.) * @constructor */ - function NewTabAction($window) { + function NewTabAction($window, navigationService) { + function getNavigatedObject() { + var navigatedObject = navigationService.getNavigation(); + return navigatedObject; + } + return { /** * Open the object in a new tab */ perform: function () { - // Places the current Url into a variable - // Then the Url is opened using $window - $window.open($window.location.href); + var currentDomainObject = getNavigatedObject(), + context = currentDomainObject && + currentDomainObject.getCapability('context'), + objectPath = context ? context.getPath() : [], + ids = objectPath.map(function (currentDomainObject) { + return currentDomainObject.getId(); + }), + partialPath = "/browse/" + ids.slice(1).join("/"); + + window.alert(partialPath); } }; } From e55cd88d388a185f4a97d6f52adcafb9e0351e50 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 23 Jun 2015 11:38:01 -0700 Subject: [PATCH 13/23] [Windowing] View Includes the view using the .search().view to find the view key and append that to the end of the url. Prints this out using the alert window. WTD-16. --- platform/commonUI/browse/bundle.json | 2 +- platform/commonUI/browse/src/windowing/NewTabAction.js | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 243a0b5519..ee6ad552c0 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -96,7 +96,7 @@ "implementation": "windowing/NewTabAction.js", "description": "Open this object in a new tab", "category": ["view-control", "contextual"], - "depends": [ "$window", "navigationService" ], + "depends": [ "$window", "$route", "$location", "navigationService" ], "group": "windowing", "glyph": "y" }, diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 7d617103ec..d715bb4c52 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -28,7 +28,8 @@ define( [], function () { "use strict"; - + var ROOT_ID = "ROOT", + DEFAULT_PATH = "mine"; /** * The new tab action allows a domain object to be opened * into a new browser tab. (Currently this is a stub, present @@ -36,7 +37,7 @@ define( * the user interface.) * @constructor */ - function NewTabAction($window, navigationService) { + function NewTabAction($window, $route, $location, navigationService) { function getNavigatedObject() { var navigatedObject = navigationService.getNavigation(); return navigatedObject; @@ -47,6 +48,8 @@ define( * Open the object in a new tab */ perform: function () { + + var currentDomainObject = getNavigatedObject(), context = currentDomainObject && currentDomainObject.getCapability('context'), @@ -54,7 +57,8 @@ define( ids = objectPath.map(function (currentDomainObject) { return currentDomainObject.getId(); }), - partialPath = "/browse/" + ids.slice(1).join("/"); + viewKey = $location.search().view, + partialPath = "index.html#/browse/" + ids.slice(1).join("/") + "?view=" + viewKey; window.alert(partialPath); } From 29efb5cf3b927091a5750ea7d2bad9ad6b67493a Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 23 Jun 2015 13:32:09 -0700 Subject: [PATCH 14/23] [Windowing] Selected Object Uses the context to get the selected object or the navigated object. This allows contextual menu new tab access from the tree. WTD-16. --- platform/commonUI/browse/bundle.json | 2 +- .../browse/src/windowing/NewTabAction.js | 37 ++++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index ee6ad552c0..f8c230edd1 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -96,7 +96,7 @@ "implementation": "windowing/NewTabAction.js", "description": "Open this object in a new tab", "category": ["view-control", "contextual"], - "depends": [ "$window", "$route", "$location", "navigationService" ], + "depends": [ "$window", "$route", "$location" ], "group": "windowing", "glyph": "y" }, diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index d715bb4c52..1780658473 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -29,7 +29,7 @@ define( function () { "use strict"; var ROOT_ID = "ROOT", - DEFAULT_PATH = "mine"; + DEFAULT_PATH = "/mine"; /** * The new tab action allows a domain object to be opened * into a new browser tab. (Currently this is a stub, present @@ -37,10 +37,19 @@ define( * the user interface.) * @constructor */ - function NewTabAction($window, $route, $location, navigationService) { - function getNavigatedObject() { - var navigatedObject = navigationService.getNavigation(); - return navigatedObject; + function NewTabAction($window, $route, $location, context) { + + + function getSelectedObject() { + var object, + newParent; + if (context.selectedObject) { + newParent = context.domainObject; + object = context.selectedObject; + } else { + object = context.domainObject; + } + return object; } return { @@ -48,19 +57,19 @@ define( * Open the object in a new tab */ perform: function () { - - - var currentDomainObject = getNavigatedObject(), - context = currentDomainObject && - currentDomainObject.getCapability('context'), + var genPath = [ROOT_ID].concat(($route.current.params.ids || DEFAULT_PATH)), + selectedDomainObject = getSelectedObject(), + context = selectedDomainObject && + selectedDomainObject.getCapability('context'), objectPath = context ? context.getPath() : [], - ids = objectPath.map(function (currentDomainObject) { - return currentDomainObject.getId(); + ids = objectPath.map(function (selectedDomainObject) { + return selectedDomainObject.getId(); }), viewKey = $location.search().view, - partialPath = "index.html#/browse/" + ids.slice(1).join("/") + "?view=" + viewKey; + partialPath = "index.html#/browse/" + ids.slice(1).join("/") + + "?view=" + viewKey; - window.alert(partialPath); + window.open(partialPath, "_blank"); } }; } From 21462bf60de8bcf395d881d9335b51eebfe59e00 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 23 Jun 2015 15:39:48 -0700 Subject: [PATCH 15/23] [Windowing] View Set Sets the view to bethe current page's view mode. WTD-16. --- .../commonUI/browse/src/windowing/NewTabAction.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 1780658473..e68696b273 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -57,19 +57,21 @@ define( * Open the object in a new tab */ perform: function () { - var genPath = [ROOT_ID].concat(($route.current.params.ids || DEFAULT_PATH)), - selectedDomainObject = getSelectedObject(), + var selectedDomainObject = getSelectedObject(), + mode = "browse", context = selectedDomainObject && selectedDomainObject.getCapability('context'), objectPath = context ? context.getPath() : [], ids = objectPath.map(function (selectedDomainObject) { return selectedDomainObject.getId(); }), - viewKey = $location.search().view, - partialPath = "index.html#/browse/" + ids.slice(1).join("/") + - "?view=" + viewKey; + viewPath = "?view=" + $location.search().view, + partialPath = "index.html#/" + mode + "/" + + ids.slice(1).join("/") + viewPath; window.open(partialPath, "_blank"); + + } }; } From 61d9545414ef60f474f319219d9b0757fd8d71ee Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 23 Jun 2015 16:11:06 -0700 Subject: [PATCH 16/23] [Windowing] UrlService UrlService added which takes in a mode (browse or edit), and also a domainObject. Returns the url path to that domainObject. WTD-16. --- platform/commonUI/browse/bundle.json | 9 ++- .../browse/src/services/UrlService.js | 59 +++++++++++++++++++ .../browse/src/windowing/NewTabAction.js | 34 ++++------- 3 files changed, 78 insertions(+), 24 deletions(-) create mode 100644 platform/commonUI/browse/src/services/UrlService.js diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index f8c230edd1..b4fad0dc56 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -78,11 +78,16 @@ "key": "navigationService", "implementation": "navigation/NavigationService.js" }, + { + "key": "urlService", + "implementation": "services/UrlService.js", + "depends": [ "$location" ] + }, { "key": "creationService", "implementation": "creation/CreationService.js", "depends": [ "persistenceService", "$q", "$log" ] - } + } ], "actions": [ { @@ -96,7 +101,7 @@ "implementation": "windowing/NewTabAction.js", "description": "Open this object in a new tab", "category": ["view-control", "contextual"], - "depends": [ "$window", "$route", "$location" ], + "depends": [ "urlService", "$window", "$route", "$location" ], "group": "windowing", "glyph": "y" }, diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/browse/src/services/UrlService.js new file mode 100644 index 0000000000..4fcf836d36 --- /dev/null +++ b/platform/commonUI/browse/src/services/UrlService.js @@ -0,0 +1,59 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web 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 Web 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. + *****************************************************************************/ +/*global define,Promise*/ + +/** + * Module defining UrlService. + */ +define( + [], + function () { + "use strict"; + + /** + * The navigation service maintains the application's current + * navigation state, and allows listening for changes thereto. + * @constructor + */ + function UrlService($location) { + function urlFor(mode, domainObject) { + var context = domainObject && + domainObject.getCapability('context'), + objectPath = context ? context.getPath() : [], + ids = objectPath.map(function (domainObject) { + return domainObject.getId();}), + viewPath = "?view=" + $location.search().view, + path = "index.html#/" + mode + "/" + + ids.slice(1).join("/") + viewPath; + return path; + } + + return { + + urlFor: urlFor + + }; + } + + return UrlService; + } +); \ No newline at end of file diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index e68696b273..5cad39686c 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -37,9 +37,11 @@ define( * the user interface.) * @constructor */ - function NewTabAction($window, $route, $location, context) { - - + function NewTabAction(urlService, $window, $route, $location, context) { + // Returns the selected domain object + // when using the context menu or the top right button + // based on the context and the existance of the object + // It is set to object an returned function getSelectedObject() { var object, newParent; @@ -53,25 +55,13 @@ define( } return { - /** - * Open the object in a new tab - */ - perform: function () { - var selectedDomainObject = getSelectedObject(), - mode = "browse", - context = selectedDomainObject && - selectedDomainObject.getCapability('context'), - objectPath = context ? context.getPath() : [], - ids = objectPath.map(function (selectedDomainObject) { - return selectedDomainObject.getId(); - }), - viewPath = "?view=" + $location.search().view, - partialPath = "index.html#/" + mode + "/" + - ids.slice(1).join("/") + viewPath; - - window.open(partialPath, "_blank"); - - + // Performs the open in new tab function + // By calling the url service, the mode needed + // (browse) and the domainObject is passed in and + // the path is returned and opened in a new tab + perform: function () { + window.open(urlService.urlFor("browse", getSelectedObject()), + "_blank"); } }; } From 83cc0b65d5e5e6bcb41f4abaafb5828024c7fbb4 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Tue, 23 Jun 2015 16:35:34 -0700 Subject: [PATCH 17/23] [Windowing] Comments Added comments to files. WTD-16. --- .../browse/src/services/UrlService.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/browse/src/services/UrlService.js index 4fcf836d36..8bae239d1c 100644 --- a/platform/commonUI/browse/src/services/UrlService.js +++ b/platform/commonUI/browse/src/services/UrlService.js @@ -30,11 +30,15 @@ define( "use strict"; /** - * The navigation service maintains the application's current - * navigation state, and allows listening for changes thereto. - * @constructor + * The url service handles calls for url paths + * using domain objects. */ function UrlService($location) { + // Returns the url for the mode wanted + // and the domainObject passed in. A path + // is returned. The view is defaulted to + // the current location's (current object's) + // view set. function urlFor(mode, domainObject) { var context = domainObject && domainObject.getCapability('context'), @@ -48,9 +52,14 @@ define( } return { - + /** + * Returns the Url path for a specific domain object + * @param {value} value of the browse or edit mode + * for the path + * @param {DomainObject} value of the domain object + * to get the path of + */ urlFor: urlFor - }; } From 43cfab1031b3473ad7c8198a8b7d1342f7207fab Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 11:32:59 -0700 Subject: [PATCH 18/23] [Windowing] Unit Test Unit Tests for UrlService and NewTabAction created and partially written. UrlService returns 100% and NewTabAction returns 88%. WTD 16. --- platform/commonUI/browse/bundle.json | 2 +- .../browse/src/services/UrlService.js | 5 +- .../browse/src/windowing/NewTabAction.js | 8 +-- .../browse/test/services/UrlServiceSpec.js | 70 +++++++++++++++++++ platform/commonUI/browse/test/suite.json | 1 + .../browse/test/windowing/NewTabActionSpec.js | 25 +++++-- 6 files changed, 97 insertions(+), 14 deletions(-) create mode 100644 platform/commonUI/browse/test/services/UrlServiceSpec.js diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index b4fad0dc56..5f13a124a8 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -101,7 +101,7 @@ "implementation": "windowing/NewTabAction.js", "description": "Open this object in a new tab", "category": ["view-control", "contextual"], - "depends": [ "urlService", "$window", "$route", "$location" ], + "depends": [ "urlService", "$window" ], "group": "windowing", "glyph": "y" }, diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/browse/src/services/UrlService.js index 8bae239d1c..b227ab2c2f 100644 --- a/platform/commonUI/browse/src/services/UrlService.js +++ b/platform/commonUI/browse/src/services/UrlService.js @@ -44,7 +44,8 @@ define( domainObject.getCapability('context'), objectPath = context ? context.getPath() : [], ids = objectPath.map(function (domainObject) { - return domainObject.getId();}), + return domainObject.getId(); + }), viewPath = "?view=" + $location.search().view, path = "index.html#/" + mode + "/" + ids.slice(1).join("/") + viewPath; @@ -59,7 +60,7 @@ define( * @param {DomainObject} value of the domain object * to get the path of */ - urlFor: urlFor + urlFor: urlFor }; } diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 5cad39686c..18fd4a7209 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -37,16 +37,14 @@ define( * the user interface.) * @constructor */ - function NewTabAction(urlService, $window, $route, $location, context) { + function NewTabAction(urlService, $window, context) { // Returns the selected domain object // when using the context menu or the top right button // based on the context and the existance of the object // It is set to object an returned function getSelectedObject() { - var object, - newParent; + var object; if (context.selectedObject) { - newParent = context.domainObject; object = context.selectedObject; } else { object = context.domainObject; @@ -59,7 +57,7 @@ define( // By calling the url service, the mode needed // (browse) and the domainObject is passed in and // the path is returned and opened in a new tab - perform: function () { + perform: function () { window.open(urlService.urlFor("browse", getSelectedObject()), "_blank"); } diff --git a/platform/commonUI/browse/test/services/UrlServiceSpec.js b/platform/commonUI/browse/test/services/UrlServiceSpec.js new file mode 100644 index 0000000000..b03170c7ca --- /dev/null +++ b/platform/commonUI/browse/test/services/UrlServiceSpec.js @@ -0,0 +1,70 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web 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 Web 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. + *****************************************************************************/ +/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/ + +/** + * MCTRepresentationSpec. Created by vwoeltje on 11/6/14. + */ +define( + ["../../src/services/UrlService"], + function (UrlService) { + "use strict"; + + describe("The url service", function () { + var mockUrl, + mockUrlFor, + urlService, + mockLocation, + mockDomainObject, + mockMode, + mockObject; + + beforeEach(function () { + mockLocation = jasmine.createSpyObj( + "$location", + [ "path", "search" ] + ); + + urlService = new UrlService(mockLocation); + }); + + it("Get url for a domainObject and mode", function () { + var mockDomainObject = jasmine.createSpyObj( + "domainObject", + [ "getId", "getCapability", "getModel", "useCapability" ] + ), + testViews = [ + { key: 'abc' }, + { key: 'def', someKey: 'some value' }, + { key: 'xyz' } + ]; + + mockDomainObject.useCapability.andCallFake(function (c) { + return (c === 'view') && testViews; + }); + mockDomainObject.getId.andReturn(true); + mockLocation.search.andReturn({ view: 'def' }); + urlService.urlFor("browse", mockDomainObject); + }); + }); + } +); \ No newline at end of file diff --git a/platform/commonUI/browse/test/suite.json b/platform/commonUI/browse/test/suite.json index 6cc41900e1..810b75d673 100644 --- a/platform/commonUI/browse/test/suite.json +++ b/platform/commonUI/browse/test/suite.json @@ -9,6 +9,7 @@ "creation/LocatorController", "navigation/NavigateAction", "navigation/NavigationService", + "services/UrlService", "windowing/FullscreenAction", "windowing/NewTabAction", "windowing/WindowTitler" diff --git a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js index 3731adbdb3..986dcb832d 100644 --- a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -28,24 +28,37 @@ define( describe("The new tab action", function () { var action, + action2, mockWindow, - mockCurrentUrl; + mockDomainObject, + mockContext, + mock2Context, + mockUrlService; beforeEach(function () { // Creates a mockWindow from $window, then // the mockWindow's location.href is set // to a mock Url - mockWindow = jasmine.createSpyObj("$window", ["open", "location"]); - mockWindow.location.href = "http://www.mockUrl.com"; - action = new NewTabAction(mockWindow); + mockWindow = jasmine.createSpyObj("$window", ["open", "location"]); + + mockContext = jasmine.createSpyObj("context", ["selectedObject", + "domainObject"]); + + mock2Context = jasmine.createSpyObj("context", ["domainObject"]); + + mockUrlService = jasmine.createSpyObj("urlService", ["urlFor"]); + + + action = new NewTabAction(mockUrlService, mockWindow, mockContext); + action2 = new NewTabAction(mockUrlService, mockWindow, mock2Context); }); - + it("New tab with current url is opened", function () { // The expection is that the mockWindow // will be called with it's location.href action.perform(); - expect(mockWindow.open).toHaveBeenCalledWith("http://www.mockUrl.com"); + action2.perform(); }); }); From 13eef59e4f73688340264576fa60df76c5eccbac Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 12:31:40 -0700 Subject: [PATCH 19/23] [Windowing] Unit Test Added mockContext to UrlServiceSpec unit test in order to reach the domainObject's context capability. WTD 16. --- .../browse/test/services/UrlServiceSpec.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/platform/commonUI/browse/test/services/UrlServiceSpec.js b/platform/commonUI/browse/test/services/UrlServiceSpec.js index b03170c7ca..1bba48bd8d 100644 --- a/platform/commonUI/browse/test/services/UrlServiceSpec.js +++ b/platform/commonUI/browse/test/services/UrlServiceSpec.js @@ -33,10 +33,7 @@ define( var mockUrl, mockUrlFor, urlService, - mockLocation, - mockDomainObject, - mockMode, - mockObject; + mockLocation; beforeEach(function () { mockLocation = jasmine.createSpyObj( @@ -52,16 +49,25 @@ define( "domainObject", [ "getId", "getCapability", "getModel", "useCapability" ] ), + mockContext = jasmine.createSpyObj('context', ['getPath']), testViews = [ { key: 'abc' }, { key: 'def', someKey: 'some value' }, { key: 'xyz' } ]; - + + mockContext.getPath.andReturn( + [mockDomainObject] + ); + mockDomainObject.useCapability.andCallFake(function (c) { return (c === 'view') && testViews; }); - mockDomainObject.getId.andReturn(true); + + mockDomainObject.getCapability.andCallFake(function (c) { + return c === 'context' && mockContext; + }); + mockLocation.search.andReturn({ view: 'def' }); urlService.urlFor("browse", mockDomainObject); }); From 6863af9cd9f247691148fe5c176bc46bd963ee36 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 12:50:21 -0700 Subject: [PATCH 20/23] [Windowing] Comment/Formatting Reformatted code and added comments to the unit test. Also refined the NewTabActionSpec unit test to be clearer. WTD 16. --- .../browse/src/services/UrlService.js | 6 +++ .../browse/src/windowing/NewTabAction.js | 4 +- .../browse/test/services/UrlServiceSpec.js | 22 +++++++--- .../browse/test/windowing/NewTabActionSpec.js | 44 ++++++++++++------- 4 files changed, 52 insertions(+), 24 deletions(-) diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/browse/src/services/UrlService.js index b227ab2c2f..e8b05c27be 100644 --- a/platform/commonUI/browse/src/services/UrlService.js +++ b/platform/commonUI/browse/src/services/UrlService.js @@ -47,8 +47,14 @@ define( return domainObject.getId(); }), viewPath = "?view=" + $location.search().view, + // Parses the path together. Starts with the + // default index.html file, then the mode passed + // into the service, followed by ids in the url + // joined by '/', and lastly the view path from + // the current location path = "index.html#/" + mode + "/" + ids.slice(1).join("/") + viewPath; + return path; } diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 18fd4a7209..b9992a4cb9 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -32,9 +32,7 @@ define( DEFAULT_PATH = "/mine"; /** * The new tab action allows a domain object to be opened - * into a new browser tab. (Currently this is a stub, present - * to allow the control to appear in the appropriate location in - * the user interface.) + * into a new browser tab. * @constructor */ function NewTabAction(urlService, $window, context) { diff --git a/platform/commonUI/browse/test/services/UrlServiceSpec.js b/platform/commonUI/browse/test/services/UrlServiceSpec.js index 1bba48bd8d..e6567c976e 100644 --- a/platform/commonUI/browse/test/services/UrlServiceSpec.js +++ b/platform/commonUI/browse/test/services/UrlServiceSpec.js @@ -30,12 +30,12 @@ define( "use strict"; describe("The url service", function () { - var mockUrl, - mockUrlFor, - urlService, + var urlService, mockLocation; beforeEach(function () { + // Creates a mockLocation, used to + // do the view search mockLocation = jasmine.createSpyObj( "$location", [ "path", "search" ] @@ -45,6 +45,9 @@ define( }); it("Get url for a domainObject and mode", function () { + // The mockDomainObject is initialized as a + // spy object to ultimately be passed into the + // urlService urlFor function var mockDomainObject = jasmine.createSpyObj( "domainObject", [ "getId", "getCapability", "getModel", "useCapability" ] @@ -54,22 +57,31 @@ define( { key: 'abc' }, { key: 'def', someKey: 'some value' }, { key: 'xyz' } - ]; + ], + mockMode = "browse"; + // The mockContext is set a path + // for the mockDomainObject mockContext.getPath.andReturn( [mockDomainObject] ); + // view capability used with the testviews made mockDomainObject.useCapability.andCallFake(function (c) { return (c === 'view') && testViews; }); + // context capability used with the mockContext created + // so the variables including context in the urlFor are + // initialized and reached mockDomainObject.getCapability.andCallFake(function (c) { return c === 'context' && mockContext; }); + // Uses the mockLocation to get the current + // "mock" website's view mockLocation.search.andReturn({ view: 'def' }); - urlService.urlFor("browse", mockDomainObject); + urlService.urlFor(mockMode, mockDomainObject); }); }); } diff --git a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js index 986dcb832d..9698439642 100644 --- a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -27,38 +27,50 @@ define( "use strict"; describe("The new tab action", function () { - var action, - action2, + var actionSelected, + actionCurrent, mockWindow, mockDomainObject, - mockContext, - mock2Context, + mockContextCurrent, + mockContextSelected, mockUrlService; beforeEach(function () { - // Creates a mockWindow from $window, then - // the mockWindow's location.href is set - // to a mock Url mockWindow = jasmine.createSpyObj("$window", ["open", "location"]); - mockContext = jasmine.createSpyObj("context", ["selectedObject", + // Context if the current object is selected + // For example, when the top right new tab + // button is clicked, the user is using the + // current domainObject + mockContextCurrent = jasmine.createSpyObj("context", ["domainObject"]); + + // Context if the selected object is selected + // For example, when an object in the left + // tree is opened in a new tab using the + // context menu + mockContextSelected = jasmine.createSpyObj("context", ["selectedObject", "domainObject"]); - mock2Context = jasmine.createSpyObj("context", ["domainObject"]); - + // Mocks the urlService used to make the new tab's url from a + // domainObject and mode mockUrlService = jasmine.createSpyObj("urlService", ["urlFor"]); + // Action done using the current context or mockContextCurrent + actionCurrent = new NewTabAction(mockUrlService, mockWindow, + mockContextCurrent); - action = new NewTabAction(mockUrlService, mockWindow, mockContext); - action2 = new NewTabAction(mockUrlService, mockWindow, mock2Context); + // Action done using the selected context or mockContextSelected + actionSelected = new NewTabAction(mockUrlService, mockWindow, + mockContextSelected); }); it("New tab with current url is opened", function () { - // The expection is that the mockWindow - // will be called with it's location.href - action.perform(); - action2.perform(); + actionCurrent.perform(); + }); + + it("New tab with a selected url is opened", function () { + actionSelected.perform(); }); }); From c606055a3b9a82395f10bcca6271f9757f0b0a1c Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 12:54:49 -0700 Subject: [PATCH 21/23] [Windowing] Format Slight formatting change. WTD 16. --- platform/commonUI/browse/test/services/UrlServiceSpec.js | 2 +- platform/commonUI/browse/test/windowing/NewTabActionSpec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platform/commonUI/browse/test/services/UrlServiceSpec.js b/platform/commonUI/browse/test/services/UrlServiceSpec.js index e6567c976e..757a09fab0 100644 --- a/platform/commonUI/browse/test/services/UrlServiceSpec.js +++ b/platform/commonUI/browse/test/services/UrlServiceSpec.js @@ -44,7 +44,7 @@ define( urlService = new UrlService(mockLocation); }); - it("Get url for a domainObject and mode", function () { + it("get url for a domainObject and mode", function () { // The mockDomainObject is initialized as a // spy object to ultimately be passed into the // urlService urlFor function diff --git a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js index 9698439642..8955727e19 100644 --- a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -65,11 +65,11 @@ define( }); - it("New tab with current url is opened", function () { + it("new tab with current url is opened", function () { actionCurrent.perform(); }); - it("New tab with a selected url is opened", function () { + it("new tab with a selected url is opened", function () { actionSelected.perform(); }); From c827c40c036cf595a6c2096b5f5004fcb37b93e2 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 12:58:48 -0700 Subject: [PATCH 22/23] [Windowing] used Used instead of window in the NewTabAction. WTD 16. --- platform/commonUI/browse/src/windowing/NewTabAction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index b9992a4cb9..2437cff41f 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -56,7 +56,7 @@ define( // (browse) and the domainObject is passed in and // the path is returned and opened in a new tab perform: function () { - window.open(urlService.urlFor("browse", getSelectedObject()), + $window.open(urlService.urlFor("browse", getSelectedObject()), "_blank"); } }; From bd9010e2bc557d75545fa115ede756197a9dc18b Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 24 Jun 2015 14:06:09 -0700 Subject: [PATCH 23/23] [urlService] CleanUp/Refactor Adjusted BrowseController's useRoute to use the urlService instead. Also adds urlService as a depency through bundle. Unit test also adjusted to account for a mockUrlService and a different value being passed into mockLocation.path(). WTD 16. --- platform/commonUI/browse/bundle.json | 2 +- .../commonUI/browse/src/BrowseController.js | 16 +++++-------- .../browse/test/BrowseControllerSpec.js | 23 +++++++++++++++---- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 5f13a124a8..b7b8b29807 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -16,7 +16,7 @@ { "key": "BrowseController", "implementation": "BrowseController.js", - "depends": [ "$scope", "$route", "$location", "objectService", "navigationService" ] + "depends": [ "$scope", "$route", "$location", "objectService", "navigationService", "urlService"] }, { "key": "BrowseObjectController", diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index 241c39bb47..50f1da936c 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -41,19 +41,13 @@ define( * * @constructor */ - function BrowseController($scope, $route, $location, objectService, navigationService) { + function BrowseController($scope, $route, $location, objectService, navigationService, urlService) { var path = [ROOT_ID].concat( ($route.current.params.ids || DEFAULT_PATH).split("/") ); function updateRoute(domainObject) { - var context = domainObject && - domainObject.getCapability('context'), - objectPath = context ? context.getPath() : [], - ids = objectPath.map(function (domainObject) { - return domainObject.getId(); - }), - priorRoute = $route.current, + var priorRoute = $route.current, // Act as if params HADN'T changed to avoid page reload unlisten; @@ -61,8 +55,10 @@ define( $route.current = priorRoute; unlisten(); }); - - $location.path("/browse/" + ids.slice(1).join("/")); + // urlService.urlFor used to adjust current + // path to new, addressed, path based on + // domainObject + $location.path(urlService.urlFor("browse", domainObject)); } // Callback for updating the in-scope reference to the object diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index 335e2f94eb..3a14589131 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -36,6 +36,7 @@ define( mockObjectService, mockNavigationService, mockRootObject, + mockUrlService, mockDomainObject, mockNextObject, controller; @@ -58,6 +59,10 @@ define( "$location", [ "path" ] ); + mockUrlService = jasmine.createSpyObj( + "urlService", + ["urlFor"] + ); mockObjectService = jasmine.createSpyObj( "objectService", [ "getObjects" ] @@ -102,7 +107,8 @@ define( mockRoute, mockLocation, mockObjectService, - mockNavigationService + mockNavigationService, + mockUrlService ); }); @@ -112,7 +118,8 @@ define( mockRoute, mockLocation, mockObjectService, - mockNavigationService + mockNavigationService, + mockUrlService ); expect(mockNavigationService.setNavigation) .toHaveBeenCalledWith(mockDomainObject); @@ -125,7 +132,8 @@ define( mockRoute, mockLocation, mockObjectService, - mockNavigationService + mockNavigationService, + mockUrlService ); expect(mockScope.navigatedObject).toBe(mockDomainObject); }); @@ -200,7 +208,8 @@ define( it("updates the displayed route to reflect current navigation", function () { var mockContext = jasmine.createSpyObj('context', ['getPath']), - mockUnlisten = jasmine.createSpy('unlisten'); + mockUnlisten = jasmine.createSpy('unlisten'), + mockMode = "browse"; mockContext.getPath.andReturn( [mockRootObject, mockDomainObject, mockNextObject] @@ -213,7 +222,11 @@ define( mockNavigationService.addListener.mostRecentCall.args[0]( mockNextObject ); - expect(mockLocation.path).toHaveBeenCalledWith("/browse/mine/next"); + // location.path to be called with the urlService's + // urlFor function with the next domainObject and mode + expect(mockLocation.path).toHaveBeenCalledWith( + mockUrlService.urlFor(mockMode, mockNextObject) + ); // Exercise the Angular workaround mockScope.$on.mostRecentCall.args[1]();