From c472ab044bc9f6c3b94a08ad8c144b9cb8465588 Mon Sep 17 00:00:00 2001 From: Deep Tailor Date: Thu, 10 Aug 2017 10:30:05 -0700 Subject: [PATCH] Add functionality to allow users to add hideParameters to the url, which will hide tree and/or the inspector New Tab automatically appends hideTree and hideInspector params to hide those panes by default Add appropriate tests for new functionality and fix broken tests --- .gitignore | 2 ++ package.json | 2 +- platform/commonUI/browse/bundle.js | 8 +++-- .../commonUI/browse/res/templates/browse.html | 6 ++-- .../browse/src/InspectorPaneController.js | 5 ++- .../commonUI/browse/src/PaneController.js | 13 +++++--- .../browse/src/windowing/NewTabAction.js | 1 + .../test/InspectorPaneControllerSpec.js | 11 +++++-- .../browse/test/PaneControllerSpec.js | 31 +++++++++++++++++-- 9 files changed, 62 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index b8eea4a5be..3d231f100b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,5 @@ protractor/logs # npm-debug log npm-debug.log + +package-lock.json diff --git a/package.json b/package.json index 3ce8d519ba..c238c3e008 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "bower": "^1.7.7", "git-rev-sync": "^1.4.0", "glob": ">= 3.0.0", - "gulp": "^3.9.0", + "gulp": "^3.9.1", "gulp-header": "^1.8.8", "gulp-jscs": "^3.0.2", "gulp-jshint": "^2.0.0", diff --git a/platform/commonUI/browse/bundle.js b/platform/commonUI/browse/bundle.js index 1526b63384..58300402e4 100644 --- a/platform/commonUI/browse/bundle.js +++ b/platform/commonUI/browse/bundle.js @@ -107,7 +107,9 @@ define([ "depends": [ "$scope", "agentService", - "$window" + "$window", + "$location", + "$attrs" ] }, { @@ -134,7 +136,9 @@ define([ "$scope", "agentService", "$window", - "navigationService" + "navigationService", + "$location", + "$attrs" ] } ], diff --git a/platform/commonUI/browse/res/templates/browse.html b/platform/commonUI/browse/res/templates/browse.html index b6d4dd0b92..0ffc1d22c4 100644 --- a/platform/commonUI/browse/res/templates/browse.html +++ b/platform/commonUI/browse/res/templates/browse.html @@ -24,7 +24,7 @@
+ ng-class="modelPaneTree.visible() ? 'pane-tree-showing' : 'pane-tree-hidden'" hide-parameter="hideTree">
@@ -58,7 +58,8 @@
+ ng-class="modelPaneInspect.visible() ? 'pane-inspect-showing' : 'pane-inspect-hidden'" + hide-parameter="hideInspector">
@@ -87,4 +88,3 @@
- diff --git a/platform/commonUI/browse/src/InspectorPaneController.js b/platform/commonUI/browse/src/InspectorPaneController.js index dbefbc4d72..2ba97cda9c 100644 --- a/platform/commonUI/browse/src/InspectorPaneController.js +++ b/platform/commonUI/browse/src/InspectorPaneController.js @@ -35,9 +35,8 @@ define( * @param navigationService * @constructor */ - function InspectorPaneController($scope, agentService, $window, navigationService) { - PaneController.call(this, $scope, agentService, $window); - + function InspectorPaneController($scope, agentService, $window, navigationService, $location, $attrs) { + PaneController.call(this, $scope, agentService, $window, $location, $attrs); var statusListener, self = this; diff --git a/platform/commonUI/browse/src/PaneController.js b/platform/commonUI/browse/src/PaneController.js index 46f47e1f6f..4f4e587764 100644 --- a/platform/commonUI/browse/src/PaneController.js +++ b/platform/commonUI/browse/src/PaneController.js @@ -31,12 +31,17 @@ define( * @constructor * @memberof platform/commonUI/browse */ - function PaneController($scope, agentService, $window) { + function PaneController($scope, agentService, $window, $location, $attrs) { var self = this; this.agentService = agentService; + var hideParameterPresent = $location.search().hasOwnProperty($attrs.hideParameter); - // Fast and cheap: if this has been opened in a new window, hide panes by default - this.state = !$window.opener; + if ($attrs.hideParameter && hideParameterPresent) { + this.state = false; + $location.search($attrs.hideParameter, undefined); + } else { + this.state = true; + } /** * Callback to invoke when any selection occurs in the tree. @@ -70,7 +75,7 @@ define( * @returns {boolean} true when visible */ PaneController.prototype.visible = function () { - return this.state; + return !!this.state; }; return PaneController; diff --git a/platform/commonUI/browse/src/windowing/NewTabAction.js b/platform/commonUI/browse/src/windowing/NewTabAction.js index c132d73709..80e2ec689e 100644 --- a/platform/commonUI/browse/src/windowing/NewTabAction.js +++ b/platform/commonUI/browse/src/windowing/NewTabAction.js @@ -38,6 +38,7 @@ define( this.urlService = urlService; this.open = function () { + arguments[0] += "&hideTree=true&hideInspector=true"; $window.open.apply($window, arguments); }; diff --git a/platform/commonUI/browse/test/InspectorPaneControllerSpec.js b/platform/commonUI/browse/test/InspectorPaneControllerSpec.js index 635396902b..016e88ecf5 100644 --- a/platform/commonUI/browse/test/InspectorPaneControllerSpec.js +++ b/platform/commonUI/browse/test/InspectorPaneControllerSpec.js @@ -33,7 +33,9 @@ define( mockNavigationService, mockNavigationUnlistener, mockStatusUnlistener, - controller; + controller, + mockLocation, + mockAttrs; beforeEach(function () { mockScope = jasmine.createSpyObj("$scope", ["$on"]); @@ -71,7 +73,12 @@ define( mockDomainObject.hasCapability.andReturn(true); mockDomainObject.getCapability.andReturn(mockStatusCapability); - controller = new InspectorPaneController(mockScope, mockAgentService, mockWindow, mockNavigationService); + mockLocation = jasmine.createSpyObj('location', ['search']); + mockLocation.search.andReturn({}); + + mockAttrs = {}; + + controller = new InspectorPaneController(mockScope, mockAgentService, mockWindow, mockNavigationService, mockLocation, mockAttrs); }); it("listens for changes to navigation and attaches a status" + diff --git a/platform/commonUI/browse/test/PaneControllerSpec.js b/platform/commonUI/browse/test/PaneControllerSpec.js index 1748db6a31..f98c7c4c7a 100644 --- a/platform/commonUI/browse/test/PaneControllerSpec.js +++ b/platform/commonUI/browse/test/PaneControllerSpec.js @@ -29,7 +29,9 @@ define( mockAgentService, mockDomainObjects, mockWindow, - controller; + controller, + mockLocation, + mockAttrs; // We want to reinstantiate for each test case // because device state can influence constructor-time behavior @@ -37,7 +39,9 @@ define( return new PaneController( mockScope, mockAgentService, - mockWindow + mockWindow, + mockLocation, + mockAttrs ); } @@ -59,6 +63,11 @@ define( ["isMobile", "isPhone", "isTablet", "isPortrait", "isLandscape"] ); mockWindow = jasmine.createSpyObj("$window", ["open"]); + + mockLocation = jasmine.createSpyObj('location', ['search']); + mockLocation.search.andReturn({}); + + mockAttrs = {}; }); it("is initially visible", function () { @@ -86,6 +95,24 @@ define( // Tree should have collapsed expect(controller.visible()).toBeFalsy(); }); + + describe("specifying hideParameter", function () { + beforeEach(function () { + mockAttrs = {hideParameter: 'hideTree'}; + }); + + it("sets pane state to false when in location.search", function () { + mockLocation.search.andReturn({'hideTree': true}); + expect(instantiateController().visible()).toBe(false); + expect(mockLocation.search).toHaveBeenCalledWith('hideTree', undefined); + }); + + it("sets state to true when not found in location.search", function () { + mockLocation.search.andReturn({}); + expect(instantiateController().visible()).toBe(true); + expect(mockLocation.search).not.toHaveBeenCalledWith('hideTree', undefined); + }); + }); }); } );