Allow the Subscribe directive to work without a list of subscriptions

This commit tidies up the subscribe directive a little, and allows it to
handle not being given a list of subscriptions by falling back onto the
old behaviour of doing a browse for the subscription matching the given
resource type and ID.

Change-Id: I610ab65d4ad1a0df6d1b4dd1de184cf88b17de88
This commit is contained in:
Adam Coldrick 2016-06-02 13:48:29 +00:00
parent 22c3818d04
commit b92cb6bbb4
3 changed files with 15 additions and 26 deletions

View File

@ -21,8 +21,7 @@ angular.module('sb.story').controller('StoryDetailController',
function ($log, $rootScope, $scope, $state, $stateParams, $modal, Session,
Preference, TimelineEvent, Comment, TimelineEventTypes, story,
Story, creator, tasks, Task, DSCacheFactory, User, $q,
storyboardApiBase, SubscriptionList, CurrentUser,
SessionModalService, moment, $document) {
storyboardApiBase, SessionModalService, moment, $document) {
'use strict';
var pageSize = Preference.get('story_detail_page_size');
@ -512,12 +511,4 @@ angular.module('sb.story').controller('StoryDetailController',
},
handleServiceError);
};
//GET subscriptions
var cuPromise = CurrentUser.resolve();
cuPromise.then(function(user){
$scope.storySubscriptions = SubscriptionList.subsList(
'story', user);
});
});

View File

@ -56,8 +56,7 @@
<i class="fa fa-pencil"></i>
</a>
<subscribe resource="story"
resource-id="story.id"
subscriptions="storySubscriptions">
resource-id="story.id">
</subscribe>
<button type="button"
class="btn btn-link"

View File

@ -188,23 +188,22 @@ angular.module('sb.util').directive('subscribe',
$scope.resolving = true;
cuPromise.then(
function () {
angular.forEach($scope.subscriptions,
function(subscription) {
if ($scope.resourceId ===
subscription.target_id) {
setSubscription(subscription);
}
}
);
$scope.resolving = false;
}
);
cuPromise.then(function () {
angular.forEach($scope.subscriptions, function(sub) {
if ($scope.resourceId === sub.target_id) {
setSubscription(sub);
}
});
$scope.resolving = false;
});
}
// On initialization, resolve.
$scope.subscriptions.$promise.then(resolveSubsList);
if (!!$scope.subscriptions) {
$scope.subscriptions.$promise.then(resolveSubsList);
} else {
resolveSubscription();
}
}
};
});