diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index 5c36555fbb..845edff2f7 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", "urlService"] + "depends": [ "$scope", "$route", "$location", "objectService", "navigationService", "urlService" ] }, { "key": "BrowseObjectController", @@ -77,12 +77,7 @@ { "key": "navigationService", "implementation": "navigation/NavigationService.js" - }, - { - "key": "urlService", - "implementation": "services/UrlService.js", - "depends": [ "$location" ] - }, + }, { "key": "creationService", "implementation": "creation/CreationService.js", diff --git a/platform/commonUI/browse/src/BrowseController.js b/platform/commonUI/browse/src/BrowseController.js index 50f1da936c..180fd8102e 100644 --- a/platform/commonUI/browse/src/BrowseController.js +++ b/platform/commonUI/browse/src/BrowseController.js @@ -55,10 +55,11 @@ define( $route.current = priorRoute; unlisten(); }); - // urlService.urlFor used to adjust current + // urlService.urlForLocation used to adjust current // path to new, addressed, path based on // domainObject - $location.path(urlService.urlFor("browse", domainObject)); + $location.path(urlService.urlForLocation("browse", domainObject)); + } // Callback for updating the in-scope reference to the object diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index 2437cff41f..8616a89711 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.urlForNewTab("browse", getSelectedObject()), "_blank"); } }; diff --git a/platform/commonUI/browse/test/BrowseControllerSpec.js b/platform/commonUI/browse/test/BrowseControllerSpec.js index 3a14589131..ca9a926f0d 100644 --- a/platform/commonUI/browse/test/BrowseControllerSpec.js +++ b/platform/commonUI/browse/test/BrowseControllerSpec.js @@ -61,7 +61,7 @@ define( ); mockUrlService = jasmine.createSpyObj( "urlService", - ["urlFor"] + ["urlForLocation"] ); mockObjectService = jasmine.createSpyObj( "objectService", @@ -225,7 +225,7 @@ define( // 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) + mockUrlService.urlForLocation(mockMode, mockNextObject) ); // Exercise the Angular workaround diff --git a/platform/commonUI/browse/test/suite.json b/platform/commonUI/browse/test/suite.json index 810b75d673..6cc41900e1 100644 --- a/platform/commonUI/browse/test/suite.json +++ b/platform/commonUI/browse/test/suite.json @@ -9,7 +9,6 @@ "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 8955727e19..1371f96eda 100644 --- a/platform/commonUI/browse/test/windowing/NewTabActionSpec.js +++ b/platform/commonUI/browse/test/windowing/NewTabActionSpec.js @@ -53,7 +53,7 @@ define( // Mocks the urlService used to make the new tab's url from a // domainObject and mode - mockUrlService = jasmine.createSpyObj("urlService", ["urlFor"]); + mockUrlService = jasmine.createSpyObj("urlService", ["urlForNewTab"]); // Action done using the current context or mockContextCurrent actionCurrent = new NewTabAction(mockUrlService, mockWindow, diff --git a/platform/commonUI/edit/bundle.json b/platform/commonUI/edit/bundle.json index fbfd44b42a..2aed41c2ee 100644 --- a/platform/commonUI/edit/bundle.json +++ b/platform/commonUI/edit/bundle.json @@ -67,7 +67,7 @@ "implementation": "actions/SaveAction.js", "name": "Save", "description": "Save changes made to these objects.", - "depends": [ "$location" ], + "depends": [ "$location", "urlService" ], "priority": "mandatory" }, { @@ -76,7 +76,7 @@ "implementation": "actions/CancelAction.js", "name": "Cancel", "description": "Discard changes made to these objects.", - "depends": [ "$location" ] + "depends": [ "$location", "urlService" ] } ], "policies": [ @@ -116,7 +116,7 @@ "key": "topbar-edit", "templateUrl": "templates/topbar-edit.html" } - ], + ], "representers": [ { "implementation": "representers/EditRepresenter.js", diff --git a/platform/commonUI/edit/src/actions/CancelAction.js b/platform/commonUI/edit/src/actions/CancelAction.js index fce556ba48..725f6ee6a7 100644 --- a/platform/commonUI/edit/src/actions/CancelAction.js +++ b/platform/commonUI/edit/src/actions/CancelAction.js @@ -30,7 +30,7 @@ define( * Edit Mode. Exits the editing user interface and invokes object * capabilities to persist the changes that have been made. */ - function CancelAction($location, context) { + function CancelAction($location, urlService, context) { var domainObject = context.domainObject; // Look up the object's "editor.completion" capability; @@ -50,7 +50,10 @@ define( // Discard the current root view (which will be the editing // UI, which will have been pushed atop the Browise UI.) function returnToBrowse() { - $location.path("/browse"); + $location.path($location.path(urlService.urlForLocation( + "browse", + domainObject + ))); } return { diff --git a/platform/commonUI/edit/src/actions/SaveAction.js b/platform/commonUI/edit/src/actions/SaveAction.js index 301fced802..d5db593742 100644 --- a/platform/commonUI/edit/src/actions/SaveAction.js +++ b/platform/commonUI/edit/src/actions/SaveAction.js @@ -31,7 +31,7 @@ define( * Edit Mode. Exits the editing user interface and invokes object * capabilities to persist the changes that have been made. */ - function SaveAction($location, context) { + function SaveAction($location, urlService, context) { var domainObject = context.domainObject; // Invoke any save behavior introduced by the editor capability; @@ -45,7 +45,10 @@ define( // Discard the current root view (which will be the editing // UI, which will have been pushed atop the Browise UI.) function returnToBrowse() { - return $location.path("/browse"); + return $location.path(urlService.urlForLocation( + "browse", + domainObject + )); } return { diff --git a/platform/commonUI/edit/test/actions/CancelActionSpec.js b/platform/commonUI/edit/test/actions/CancelActionSpec.js index b0c4db6678..1701347165 100644 --- a/platform/commonUI/edit/test/actions/CancelActionSpec.js +++ b/platform/commonUI/edit/test/actions/CancelActionSpec.js @@ -30,6 +30,7 @@ define( var mockLocation, mockDomainObject, mockEditorCapability, + mockUrlService, actionContext, action; @@ -54,7 +55,10 @@ define( "editor", [ "save", "cancel" ] ); - + mockUrlService = jasmine.createSpyObj( + "urlService", + ["urlForLocation"] + ); actionContext = { domainObject: mockDomainObject @@ -64,7 +68,7 @@ define( mockDomainObject.getCapability.andReturn(mockEditorCapability); mockEditorCapability.cancel.andReturn(mockPromise(true)); - action = new CancelAction(mockLocation, actionContext); + action = new CancelAction(mockLocation, mockUrlService, actionContext); }); @@ -91,7 +95,9 @@ define( it("returns to browse when performed", function () { action.perform(); - expect(mockLocation.path).toHaveBeenCalledWith("/browse"); + expect(mockLocation.path).toHaveBeenCalledWith( + mockUrlService.urlForLocation("browse", mockDomainObject) + ); }); }); } diff --git a/platform/commonUI/edit/test/actions/SaveActionSpec.js b/platform/commonUI/edit/test/actions/SaveActionSpec.js index 45901b3f08..74a0923411 100644 --- a/platform/commonUI/edit/test/actions/SaveActionSpec.js +++ b/platform/commonUI/edit/test/actions/SaveActionSpec.js @@ -30,6 +30,7 @@ define( var mockLocation, mockDomainObject, mockEditorCapability, + mockUrlService, actionContext, action; @@ -54,6 +55,10 @@ define( "editor", [ "save", "cancel" ] ); + mockUrlService = jasmine.createSpyObj( + "urlService", + ["urlForLocation"] + ); actionContext = { @@ -64,7 +69,7 @@ define( mockDomainObject.getCapability.andReturn(mockEditorCapability); mockEditorCapability.save.andReturn(mockPromise(true)); - action = new SaveAction(mockLocation, actionContext); + action = new SaveAction(mockLocation, mockUrlService, actionContext); }); @@ -91,7 +96,9 @@ define( it("returns to browse when performed", function () { action.perform(); - expect(mockLocation.path).toHaveBeenCalledWith("/browse"); + expect(mockLocation.path).toHaveBeenCalledWith( + mockUrlService.urlForLocation("browse", mockDomainObject) + ); }); }); } diff --git a/platform/commonUI/general/bundle.json b/platform/commonUI/general/bundle.json index ead610c963..fdac965863 100644 --- a/platform/commonUI/general/bundle.json +++ b/platform/commonUI/general/bundle.json @@ -3,6 +3,13 @@ "description": "General UI elements, meant to be reused across modes", "resources": "res", "extensions": { + "services": [ + { + "key": "urlService", + "implementation": "/services/UrlService.js", + "depends": [ "$location" ] + } + ], "runs": [ { "implementation": "StyleSheetLoader.js", diff --git a/platform/commonUI/browse/src/services/UrlService.js b/platform/commonUI/general/src/services/UrlService.js similarity index 70% rename from platform/commonUI/browse/src/services/UrlService.js rename to platform/commonUI/general/src/services/UrlService.js index e8b05c27be..4562059d0c 100644 --- a/platform/commonUI/browse/src/services/UrlService.js +++ b/platform/commonUI/general/src/services/UrlService.js @@ -39,34 +39,52 @@ define( // is returned. The view is defaulted to // the current location's (current object's) // view set. - function urlFor(mode, domainObject) { + function urlForLocation(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, // 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; - + path = mode + "/" + ids.slice(1).join("/"); return path; } + // Uses the Url for the current location + // from the urlForLocation function and + // includes the view and the index path + function urlForNewTab(mode, domainObject) { + var viewPath = "?view=" + $location.search().view, + newTabPath = + "index.html#" + urlForLocation(mode, domainObject) + viewPath; + return newTabPath; + } + return { /** * Returns the Url path for a specific domain object + * without the index.html path and the view path * @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 + urlForNewTab: urlForNewTab, + /** + * Returns the Url path for a specific domain object + * including the index.html path and the view path + * allowing a new tab to hold the correct characteristics + * @param {value} value of the browse or edit mode + * for the path + * @param {DomainObject} value of the domain object + * to get the path of + */ + urlForLocation: urlForLocation }; } diff --git a/platform/commonUI/browse/test/services/UrlServiceSpec.js b/platform/commonUI/general/test/services/UrlServiceSpec.js similarity index 77% rename from platform/commonUI/browse/test/services/UrlServiceSpec.js rename to platform/commonUI/general/test/services/UrlServiceSpec.js index 757a09fab0..daff0c5448 100644 --- a/platform/commonUI/browse/test/services/UrlServiceSpec.js +++ b/platform/commonUI/general/test/services/UrlServiceSpec.js @@ -31,7 +31,11 @@ define( describe("The url service", function () { var urlService, - mockLocation; + mockLocation, + mockDomainObject, + mockContext, + mockMode, + testViews; beforeEach(function () { // Creates a mockLocation, used to @@ -41,24 +45,20 @@ define( [ "path", "search" ] ); - urlService = new UrlService(mockLocation); - }); - - it("get url for a domainObject and mode", function () { - // The mockDomainObject is initialized as a + // The mockDomainObject is initialized as a // spy object to ultimately be passed into the // urlService urlFor function - var mockDomainObject = jasmine.createSpyObj( + mockDomainObject = jasmine.createSpyObj( "domainObject", [ "getId", "getCapability", "getModel", "useCapability" ] - ), - mockContext = jasmine.createSpyObj('context', ['getPath']), - testViews = [ - { key: 'abc' }, - { key: 'def', someKey: 'some value' }, - { key: 'xyz' } - ], - mockMode = "browse"; + ); + mockContext = jasmine.createSpyObj('context', ['getPath']); + testViews = [ + { key: 'abc' }, + { key: 'def', someKey: 'some value' }, + { key: 'xyz' } + ]; + mockMode = "browse"; // The mockContext is set a path // for the mockDomainObject @@ -81,8 +81,17 @@ define( // Uses the mockLocation to get the current // "mock" website's view mockLocation.search.andReturn({ view: 'def' }); - urlService.urlFor(mockMode, mockDomainObject); + + urlService = new UrlService(mockLocation); }); + + it("get url for a location using domainObject and mode", function () { + urlService.urlForLocation(mockMode, mockDomainObject); + }); + + it("get url for a new tab using domainObject and mode", function () { + urlService.urlForNewTab(mockMode, mockDomainObject); + }); }); } ); \ No newline at end of file diff --git a/platform/commonUI/general/test/suite.json b/platform/commonUI/general/test/suite.json index e8c9674b44..37fc4c4b78 100644 --- a/platform/commonUI/general/test/suite.json +++ b/platform/commonUI/general/test/suite.json @@ -13,5 +13,6 @@ "directives/MCTDrag", "directives/MCTResize", "directives/MCTScroll", + "services/UrlService", "StyleSheetLoader" ] \ No newline at end of file