Skip to content

Instantly share code, notes, and snippets.

@michelarteta
Created October 14, 2018 14:01
Show Gist options
  • Save michelarteta/df07925549cb052fbfa0072daeb8c024 to your computer and use it in GitHub Desktop.
Save michelarteta/df07925549cb052fbfa0072daeb8c024 to your computer and use it in GitHub Desktop.
Notification
'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