Skip to content

Commit

Permalink
Save collapsed nav state in localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
spadgett committed Aug 30, 2017
1 parent 493313b commit 6176ddb
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions app/scripts/directives/nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,7 @@ angular.module('openshiftConsole')
if (isMobile !== $scope.isMobile) {
$scope.$evalAsync(function() {
$scope.isMobile = isMobile;
if (isMobile) {
_.set($rootScope, 'nav.collapsed', false);
} else {
if (!isMobile) {
_.set($rootScope, 'nav.showMobileNav', false);
_.each($scope.navItems, function(primaryItem) {
primaryItem.mobileSecondary = false;
Expand Down Expand Up @@ -202,11 +200,32 @@ angular.module('openshiftConsole')
templateUrl: 'views/directives/header/header.html',
link: function($scope, $elem) {
var MAX_PROJETS_TO_DISPLAY = 100;
var NAV_COLLAPSED_STORAGE_KEY = 'openshift/vertical-nav-collapsed';
$scope.project = projects[ $routeParams.project ];

var setCollapsed = function(collapsed, updateSavedState) {
var storageValue;
_.set($rootScope, 'nav.collapsed', collapsed);

if (updateSavedState) {
storageValue = collapsed ? 'true' : 'false';
localStorage.setItem(NAV_COLLAPSED_STORAGE_KEY, storageValue);
}
};

var readSavedCollapsedState = function() {
var savedState = localStorage.getItem(NAV_COLLAPSED_STORAGE_KEY) === 'true';
setCollapsed(savedState);
};
readSavedCollapsedState();

var isCollapsed = function() {
return _.get($rootScope, 'nav.collapsed', false);
};

$scope.toggleNav = function() {
var collapsed = _.get($rootScope, 'nav.collapsed');
_.set($rootScope, 'nav.collapsed', !collapsed);
var collapsed = isCollapsed();
setCollapsed(!collapsed, true);
};

$scope.toggleMobileNav = function() {
Expand All @@ -217,6 +236,7 @@ angular.module('openshiftConsole')
$scope.closeOrderingPanel = function() {
_.set($scope, 'ordering.panelName', "");
};

$scope.showOrderingPanel = function(panelName) {
_.set($scope, 'ordering.panelName', panelName);
};
Expand Down

0 comments on commit 6176ddb

Please sign in to comment.