Skip to content

Commit 5acfe03

Browse files
author
Tim Levett
committed
Merge pull request uPortal-Attic#163 from UW-Madison-DoIT/sticky_layout_selection
MUMUP-1746 : Sticky layout selection
2 parents 47a11f2 + 7313888 commit 5acfe03

File tree

12 files changed

+193
-63
lines changed

12 files changed

+193
-63
lines changed

angularjs-portal-frame/src/main/webapp/js/app-config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
(function() {
33
angular.module('app-config', [])
44
.constant('APP_FLAGS', {
5-
'enableToggle': true
5+
'enableToggle': true,
6+
'defaultView' : 'list',
7+
'list' : true,
8+
'widgets' : true
69
}
710
)
811
.constant('SERVICE_LOC', {

angularjs-portal-frame/src/main/webapp/js/main/main-controllers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
profileImg: "img/terrace.jpg",
1414
notificationsDemo : false,
1515
typeaheadSearch: false,
16-
exampleWidgets: false
16+
exampleWidgets: false,
17+
layoutMode : 'list' //other option is 'widgets'
1718
};
1819
$scope.$storage = $localStorage.$default(defaults);
1920

angularjs-portal-home/src/main/webapp/js/angular-page.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
when('/static/:fname', {templateUrl: 'partials/static-content-max.html'}).
3636
when('/widgets', {templateUrl: 'partials/home-widget-view.html'}).
3737
when('/list', {templateUrl: 'partials/home-list-view.html'}).
38-
otherwise({templateUrl: 'partials/home-list-view.html'});
38+
otherwise({ redirectTo : '/list'});
3939
}
4040
]);
4141

angularjs-portal-home/src/main/webapp/js/app-config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
(function() {
33
angular.module('app-config', [])
44
.constant('APP_FLAGS', {
5-
'enableToggle': true
5+
'enableToggle': true,
6+
'defaultView' : 'list',
7+
'list' : true,
8+
'widgets' : true
69
}
710
)
811
.constant('SERVICE_LOC', {

angularjs-portal-home/src/main/webapp/js/layout/layout-controller.js

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010
'$rootScope',
1111
'layoutService',
1212
'miscService',
13-
'sharedPortletService',
14-
'APP_FLAGS',
13+
'sharedPortletService',
1514
function($location,
1615
$localStorage,
1716
$sessionStorage,
1817
$scope,
1918
$rootScope,
2019
layoutService,
2120
miscService,
22-
sharedPortletService,
23-
APP_FLAGS) {
24-
miscService.pushPageview();
25-
$scope.toggle = APP_FLAGS.enableToggle;
21+
sharedPortletService) {
2622
if(typeof $rootScope.layout === 'undefined' || $rootScope.layout == null) {
2723

2824
$rootScope.layout = [];
@@ -108,22 +104,15 @@
108104
'$rootScope',
109105
'layoutService',
110106
'miscService',
111-
'sharedPortletService',
112-
'APP_FLAGS',
107+
'sharedPortletService',
113108
function($location,
114109
$localStorage,
115110
$sessionStorage,
116111
$scope,
117112
$rootScope,
118113
layoutService,
119114
miscService,
120-
sharedPortletService,
121-
APP_FLAGS) {
122-
123-
miscService.pushPageview();
124-
$scope.toggle = APP_FLAGS.enableToggle;
125-
var that = this;
126-
115+
sharedPortletService) {
127116
if(typeof $rootScope.layout === 'undefined' || $rootScope.layout == null) {
128117

129118
$rootScope.layout = [];
@@ -333,6 +322,46 @@
333322
return date >= today;
334323
}
335324
}]);
325+
326+
app.controller('ToggleController',['$localStorage',
327+
'$scope',
328+
'$location',
329+
'miscService',
330+
'APP_FLAGS', function($localStorage,
331+
$scope,
332+
$location,
333+
miscService,
334+
APP_FLAGS){
335+
//scope functions
336+
$scope.switchMode = function(mode) {
337+
$localStorage.layoutMode = mode;
338+
$location.path('/' + mode);
339+
}
340+
341+
$scope.modeIs = function(mode) {
342+
return $localStorage.layoutMode === mode;
343+
}
344+
345+
//local functions
346+
this.init = function() {
347+
$scope.toggle = APP_FLAGS.enableToggle;
348+
if($localStorage.layoutMode
349+
&& $location.url().indexOf($localStorage.layoutMode) == -1) {
350+
//opps, we are in the wrong mode, switch!
351+
if(APP_FLAGS[$localStorage.layoutMode]) { //check to make sure that mode is active
352+
$location.path('/' + $localStorage.layoutMode);
353+
} else {
354+
console.log("Something is weird, resetting to default layout view");
355+
$scope.switchMode(APP_FLAGS.defaultView);
356+
}
357+
} else {
358+
//all is well, ga pageview, go
359+
miscService.pushPageview();
360+
}
361+
}
362+
363+
this.init();
364+
}]);
336365

337366

338367

angularjs-portal-home/src/main/webapp/js/layout/layout-directives.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,13 @@
102102
templateUrl: 'partials/example-widgets.html'
103103
}
104104
});
105+
106+
app.directive('homeToggle', function(){
107+
return {
108+
restrict: 'E',
109+
templateUrl: 'partials/home-toggle.html',
110+
controller: 'ToggleController'
111+
};
112+
});
105113

106114
})();

angularjs-portal-home/src/main/webapp/partials/home-header.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,22 @@ <h1>MyUW Home</h1>
1515
<div class="col-xs-12 notification-section" ng-show="{{$storage.notificationsDemo}}">
1616
<h3 class="home-section-header">Notifications</h3>
1717
<notifications></notifications>
18+
</div>
19+
<div class="inner-nav-container">
20+
<ul class="inner-nav">
21+
<li class="active home-title">
22+
<a>My Favorites</a>
23+
</li>
24+
<li class="hide-mobile">
25+
<a href='#/apps'
26+
tooltip="Browse for more apps"
27+
tooltip-trigger="mouseenter"
28+
tooltip-placement="top"
29+
tooltip-popup-delay="500">
30+
<i class='fa fa-plus'></i>
31+
</a>
32+
</li>
33+
<home-toggle></home-toggle>
34+
</ul>
35+
1836
</div>

angularjs-portal-home/src/main/webapp/partials/home-list-view.html

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
2-
31
<div class="row portlet-frame">
42
<home-header></home-header>
53
<div class="col-xs-12 no-padding portlet-body" ng-controller="LayoutController as layoutCtrl">
6-
<div class="inner-nav-container">
7-
<ul class="inner-nav">
8-
<li class="active home-title">
9-
<a>My Favorites</a>
10-
</li>
11-
<li class="hide-mobile">
12-
<a href='#/apps'
13-
tooltip="Browse for more apps"
14-
tooltip-trigger="mouseenter"
15-
tooltip-placement="top"
16-
tooltip-popup-delay="500">
17-
<i class='fa fa-plus'></i>
18-
</a>
19-
</li>
20-
<span class="layout-chooser" ng-if="toggle">
21-
<li class="active"><a><i class="fa fa-th" ng-if="toggle"></i></a></li>
22-
<li><a href="#/widgets"><i class="fa fa-th-large" ng-if="toggle"></i></a></li>
23-
</span>
24-
</ul>
25-
26-
</div>
274
<loading-gif data-object='layout' data-empty='layoutEmpty'></loading-gif>
285
<!-- List View -->
296
<ul ui-sortable="sortableOptions" ng-model="layout" class="tile-list">
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<span class="layout-chooser" ng-if="toggle">
2+
<li ng-class="{active : modeIs('list')}"><a href="javascript:;" ng-click="switchMode('list')"><i class="fa fa-th"></i></a></li>
3+
<li ng-class="{active : modeIs('widgets')}" ><a href="javascript:;" ng-click="switchMode('widgets')"><i class="fa fa-th-large"></i></a></li>
4+
</span>

angularjs-portal-home/src/main/webapp/partials/home-widget-view.html

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,6 @@
11
<div class="row portlet-frame">
22
<home-header></home-header>
33
<div class="col-xs-12 no-padding portlet-body" ng-controller="WidgetController as widgetCtrl">
4-
<div class="inner-nav-container">
5-
<ul class="inner-nav">
6-
<li class="active home-title">
7-
<a>My Favorites</a>
8-
</li>
9-
<li class="hide-mobile">
10-
<a href='#/apps'
11-
tooltip="Browse for more apps"
12-
tooltip-trigger="mouseenter"
13-
tooltip-placement="top"
14-
tooltip-popup-delay="500">
15-
<i class='fa fa-plus'></i>
16-
</a>
17-
</li>
18-
<span class="layout-chooser" ng-if="toggle">
19-
<li><a href="#/list"><i class="fa fa-th" ng-if="toggle"></i></a></li>
20-
<li class="active"><a href="#/widgets"><i class="fa fa-th-large" ng-if="toggle"></i></a></li>
21-
</span>
22-
</ul>
23-
24-
</div>
254
<loading-gif data-object='layout' data-empty='layoutEmpty'></loading-gif>
265
<!-- Widget View -->
276
<ul ui-sortable="sortableOptions" ng-model="layout" class="tile-list">

0 commit comments

Comments
 (0)