Skip to content

Instantly share code, notes, and snippets.

@jaygraygray
Last active April 25, 2017 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaygraygray/b55a691da5b711763183f95b114c1850 to your computer and use it in GitHub Desktop.
Save jaygraygray/b55a691da5b711763183f95b114c1850 to your computer and use it in GitHub Desktop.
Function in an AngularJS controller for displaying author notifications
//
// Declare function
//
$scope.getNotifcations = headerSvc.getNotifications().then(function(resp){
$scope.notifications = resp.data
for (var i = 0; i < $scope.notifications.length; i++) {
$scope.notifications[i].title = ''
for (var prop in $scope.notifications[i]) {
//
// Create proper textual responses based on the action stored in the database
//
switch($scope.notifications[i].action) {
case 'l':
$scope.notifications[i].action = 'liked your';
break;
case 'b':
$scope.notifications[i].action = 'bookmarked your';
break;
case 'f':
$scope.notifications[i].action = 'followed you';
break;
case 's':
$scope.notifications[i].action = 'shared your';
break;
case 'r':
$scope.notifications[i].action = 'responded to';
break;
}
}
//
// Loop through all notifications for articles
//
if ($scope.notifications[i].article === true) {
(function(i) {
headerSvc.getArticleTitle($scope.notifications[i].action_on_id)
.then(function(resp) {
$scope.notifications[i].title = ' your article ' + resp.data[0].title
})
})(i);
}
//
// Loop through all notifications for article responses
//
if ($scope.notifications[i].response === true) {
(function(i) {
headerSvc.getArticleTitleByResponse($scope.notifications[i].action_on_id)
.then(function(resp) {
$scope.notifications[i].title = resp.data[0].title
})
})(i);
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment