Add a subscribe button to worklists

This also makes worklists be pre-resolved instead of loading
them after the view is displayed.

Change-Id: I1bfa8fccda2e39d797559774c4c21643333cd756
Depends-On: I14b0b4ddd6138ac23f9e1c10d0de2419f8e8cb4b
This commit is contained in:
Adam Coldrick 2016-06-02 13:59:11 +00:00
parent 9c1aba673b
commit 6c03f276ac
7 changed files with 88 additions and 14 deletions

View File

@ -18,7 +18,7 @@
* A controller that manages the dashboard for worklists and boards.
*/
angular.module('sb.dashboard').controller('BoardsWorklistsController',
function ($scope, currentUser, Worklist, Board) {
function ($scope, currentUser, Worklist, Board, SubscriptionList) {
'use strict';
var params = {user_id: currentUser.id};
@ -36,4 +36,7 @@ angular.module('sb.dashboard').controller('BoardsWorklistsController',
$scope.loadingWorklists = false;
$scope.worklists = worklists;
});
$scope.worklistSubscriptions = SubscriptionList.subsList(
'worklist', currentUser);
});

View File

@ -19,7 +19,7 @@
*/
angular.module('sb.dashboard').controller('DashboardSubscriptionsController',
function ($scope, Story, Project, ProjectGroup, SubscriptionList,
currentUser) {
Worklist, currentUser) {
'use strict';
$scope.storySubscriptions = SubscriptionList.subsList(
@ -35,4 +35,7 @@ angular.module('sb.dashboard').controller('DashboardSubscriptionsController',
$scope.projectGroups = ProjectGroup.browse(
{subscriber_id: currentUser.id});
$scope.worklistSubscriptions = SubscriptionList.subsList(
'worklist', currentUser);
$scope.worklists = Worklist.browse({subscriber_id: currentUser.id});
});

View File

@ -66,6 +66,11 @@
<tbody>
<tr ng-repeat="worklist in worklists">
<td>
<subscribe class="pull-right"
resource="worklist"
resource-id="worklist.id"
subscriptions="worklistSubscriptions">
</subscribe>
<p>
<a href="#!/worklist/{{worklist.id}}">
{{worklist.title}}

View File

@ -18,10 +18,8 @@
<div class="row">
<div class="col-xs-12">
<view-title>Subscriptions</view-title>
<h1><i class="fa fa-star"
ng-if="!saving"></i>
<i class="fa fa-spin fa-star"
ng-if="saving"></i>
<h1>
<i class="fa fa-star" ng-if="!saving"></i>
Subscriptions
</h1>
</div>
@ -132,5 +130,47 @@
</tbody>
</table>
</div>
<div class="col-sm-6">
<hr class="visible-xs"/>
<table class="table table-striped">
<thead>
<th>
<i class="fa fa-sb-task fa-lg"></i>
Worklists
</th>
</thead>
<tbody>
<tr ng-repeat="worklist in worklists">
<td>
<subscribe class="pull-right"
resource="worklist"
resource-id="worklist.id"
subscriptions="worklistSubscriptions">
</subscribe>
<p>
<a href="#!/worklist/{{worklist.id}}">
{{worklist.title}}
</a>
</p>
<small>
<span class="badge"
ng-class="{'badge-primary': worklist.items.length > 0}">
{{worklist.items.length}}
</span> Items
</small>
</td>
</tr>
</tbody>
<tbody ng-show="worklists.length == 0">
<tr>
<td colspan="3" class="text-center text-muted">
<em>
You are not currently subscribed to any worklists.
</em>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>

View File

@ -19,7 +19,7 @@
*/
angular.module('sb.worklist').controller('WorklistDetailController',
function ($scope, $modal, $timeout, $stateParams, Worklist, BoardHelper,
$document, User, $q) {
$document, User, $q, worklist, permissions) {
'use strict';
function resolvePermissions() {
@ -321,6 +321,10 @@ angular.module('sb.worklist').controller('WorklistDetailController',
event.preventDefault();
};
// Load the worklist.
loadWorklist();
$scope.worklist = worklist;
$scope.permissions = {
editWorklist: permissions.indexOf('edit_worklist') > -1,
moveItems: permissions.indexOf('move_items') > -1
};
resolvePermissions();
});

View File

@ -37,6 +37,20 @@ angular.module('sb.worklist',
.state('sb.worklist.detail', {
url: '/{worklistID:[0-9]+}',
controller: 'WorklistDetailController',
templateUrl: 'app/worklists/template/detail.html'
templateUrl: 'app/worklists/template/detail.html',
resolve: {
worklist: function (Worklist, $stateParams) {
// Pre-resolve the worklist.
return Worklist.get({
id: $stateParams.worklistID
}).$promise;
},
permissions: function(Worklist, $stateParams) {
// Pre-resolve the permissions.
return Worklist.Permissions.get({
id: $stateParams.worklistID
}).$promise;
}
}
});
});

View File

@ -35,10 +35,15 @@
<div class="col-sm-12" ng-show="!editing">
<h1 view-title>
{{worklist.title}}
<a ng-click="toggleEditMode()"
ng-show="permissions.editWorklist">
<i class="fa fa-pencil"></i>
</a>
<small ng-show="isLoggedIn">
<a ng-click="toggleEditMode()"
ng-show="permissions.editWorklist">
<i class="fa fa-pencil"></i>
</a>
<subscribe resource="worklist"
resource-id="worklist.id">
</subscribe>
</small>
</h1>
</div>
</div>