Created
October 14, 2018 14:01
-
-
Save michelarteta/df07925549cb052fbfa0072daeb8c024 to your computer and use it in GitHub Desktop.
Notification
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
'use strict'; | |
(function () { | |
Date.prototype.subDays = function(days) { | |
date = new Date(this.valueOf()) | |
date.setDate(date.getDate() - days) | |
return date | |
} | |
function NotificationController($scope, NotificationService) { | |
$scope.current_page = 1; | |
$scope.notifications = [] | |
$scope.max = 2; | |
// diff = +1 | -1 | |
$scope.paginate = function(diff){ | |
let today = new Date() | |
$scope.current_page+= diff | |
if ($scope.current_page < 1){ | |
$scope.current_page = 1 | |
} | |
if ($scope.current_page > $scope.max){ | |
$scope.current_page = $scope.max | |
} | |
NotificationService.notifications({settings: { | |
offset: ($scope.current_page-1) * 10, | |
limit: 10, | |
timestamp: today.subDays(7) | |
}}).$promise.then(function(data){ | |
$scope.notifications = data.list | |
$scope.max = data.max_pages | |
}) | |
} | |
} | |
angular.module('app').controller('NotificationController', NotificationController); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment