Last active
April 25, 2017 22:55
-
-
Save jaygraygray/b55a691da5b711763183f95b114c1850 to your computer and use it in GitHub Desktop.
Function in an AngularJS controller for displaying author notifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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