arnaucube
arnaucube/commonroutesWebAppPublic Self-hosted repository
commonroutesWebApp/views/notifications/notifications.js
views/notifications/notifications.jsRaw
 1'use strict';
 2
 3angular.module('app.notifications', ['ngRoute'])
 4
 5    .config(['$routeProvider', function($routeProvider) {
 6        $routeProvider.when('/notifications', {
 7            templateUrl: 'views/notifications/notifications.html',
 8            controller: 'NotificationsCtrl'
 9        });
10    }])
11
12    .controller('NotificationsCtrl', function($scope, $http) {
13        $scope.notifications = [];
14
15        $http.get(urlapi + 'notifications')
16          .then(function(data) {
17            //get the storage notifications
18            if (localStorage.getItem("cr_webapp_notifications")) {
19              $scope.notifications = JSON.parse(localStorage.getItem("cr_webapp_notifications"));
20              $scope.notifications = $scope.notifications.concat(data.data); // for UI
21            } else {
22              $scope.notifications = data.data;
23            }
24            //store the notifications
25            localStorage.setItem("cr_webapp_notifications", JSON.stringify($scope.notifications));
26            console.log($scope.notifications);
27
28          }, function(data) {
29            console.log('data error');
30            toastr.error("Error connecting server");
31
32          });
33    });