From 1da3b98715c481ae65056f1a005bb9d1b98745f9 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Fri, 23 Jun 2017 02:56:57 +0200 Subject: [PATCH] notification system fixed --- www/css/colors.css | 5 ++ www/js/app.js | 88 ++++++++++++++++---------------- www/js/main.js | 24 +++++++-- www/js/menu.js | 2 + www/js/notifications.js | 61 ++++++++++++++++------ www/templates/menu.html | 4 +- www/templates/newTravel.html | 4 +- www/templates/notifications.html | 24 ++++++--- 8 files changed, 138 insertions(+), 74 deletions(-) diff --git a/www/css/colors.css b/www/css/colors.css index 570c924..a130884 100644 --- a/www/css/colors.css +++ b/www/css/colors.css @@ -478,6 +478,11 @@ color: #ffffff; } + +.ctext_blueGrey500{ + color: #607D8B!important; +} + .c_blueGradient1{ background: #2d4a56; background: -moz-linear-gradient(left, #2d4a56 0%, #1c2b36 100%); diff --git a/www/js/app.js b/www/js/app.js index 31ab112..6738fa4 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -6,8 +6,8 @@ // 'starter.controllers' is found in controllers.js -//var urlapi = "http://localhost:3000/api/"; -var urlapi = "http://192.168.1.36:3000/api/"; +var urlapi = "http://localhost:3000/api/"; +//var urlapi = "http://192.168.1.36:3000/api/"; //var urlapi = "http://51.255.193.106:3000/api/"; angular.module('starter', [ @@ -24,8 +24,8 @@ angular.module('starter', [ 'app.travel', 'app.newTravel', 'app.offerCar', -/* 'app.askCar', - 'app.askPackage',*/ + /* 'app.askCar', + 'app.askPackage',*/ 'app.users', 'app.user', 'app.userTravels', @@ -56,12 +56,14 @@ angular.module('starter', [ $stateProvider .state('app', { + cache: false, url: '/app', abstract: true, templateUrl: 'templates/menu.html', controller: 'MenuCtrl' }) .state('app.main', { + cache: false, url: '/main', views: { 'menuContent': { @@ -209,19 +211,19 @@ angular.module('starter', [ }); // if none of the above states are matched, use this as the fallback if ((localStorage.getItem("cim_app_token")) && (JSON.parse(localStorage.getItem("cim_app_userdata")) != "null") && (JSON.parse(localStorage.getItem("cim_app_userdata")) != null)) { - if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) { - window.location = '#/app/main'; - } - $urlRouterProvider.otherwise('/app/main'); - } else { - if ((window.location != "#/app/login") || (window.location != "#/app/signup")) { - console.log("removing data, and going to login"); - localStorage.removeItem("cim_app_token"); - localStorage.removeItem("cim_app_userdata"); - window.location = "#/app/login"; - $urlRouterProvider.otherwise('/app/login'); - } - } + if ((window.location.hash == "#/app/login") || (window.location.hash == "#/app/signup")) { + window.location = '#/app/main'; + } + $urlRouterProvider.otherwise('/app/main'); + } else { + if ((window.location != "#/app/login") || (window.location != "#/app/signup")) { + console.log("removing data, and going to login"); + localStorage.removeItem("cim_app_token"); + localStorage.removeItem("cim_app_userdata"); + window.location = "#/app/login"; + $urlRouterProvider.otherwise('/app/login'); + } + } }) @@ -244,29 +246,29 @@ angular.module('starter', [ }]) .factory('httpInterceptor', function httpInterceptor($q, $window, $location) { - return { - request: function (config) { - return config; - }, - requestError: function (config) { - return config; - }, - response: function (res) { - return res; - }, - responseError: function (res) { - return res; - } - } - }) - .factory('api', function ($http) { - return { - init: function () { - $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token"); - $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token"); - } - }; - }) - .run(function (api) { - api.init(); - }); + return { + request: function(config) { + return config; + }, + requestError: function(config) { + return config; + }, + response: function(res) { + return res; + }, + responseError: function(res) { + return res; + } + } + }) + .factory('api', function($http) { + return { + init: function() { + $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem("cim_app_token"); + $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem("cim_app_token"); + } + }; + }) + .run(function(api) { + api.init(); + }); diff --git a/www/js/main.js b/www/js/main.js index f93070a..75dc812 100644 --- a/www/js/main.js +++ b/www/js/main.js @@ -1,5 +1,23 @@ angular.module('app.main', ['pascalprecht.translate']) -.controller('MainCtrl', function($scope, $stateParams, $translate, $filter) { - -}); + .controller('MainCtrl', function($scope, $stateParams, $translate, $filter, + $ionicLoading, $http) { + if (localStorage.getItem("cim_app_userdata")) { + $scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); + console.log($scope.storageuser); + } + //get the num of pendent notifications each time + $http.get(urlapi + 'numnotifications') + .then(function(data) { + $scope.storageuser.notifications = data.data; + console.log(data.data); + localStorage.setItem("cim_app_storageuser", JSON.stringify($scope.storageuser)); + }, function(data) { + console.log('data error'); + $ionicLoading.show({ + template: 'Error connecting server', + noBackdrop: true, + duration: 2000 + }); + }); + }); diff --git a/www/js/menu.js b/www/js/menu.js index c3052dc..cee7fa0 100644 --- a/www/js/menu.js +++ b/www/js/menu.js @@ -10,6 +10,8 @@ angular.module('app.menu', ['pascalprecht.translate']) $scope.logout = function() { localStorage.removeItem("cim_app_token"); localStorage.removeItem("cim_app_userdata"); + localStorage.removeItem("cim_app_storageuser"); + localStorage.removeItem("cim_app_notifications"); $window.location.reload(true); }; }); diff --git a/www/js/notifications.js b/www/js/notifications.js index 4c19a0b..1743a59 100644 --- a/www/js/notifications.js +++ b/www/js/notifications.js @@ -1,25 +1,52 @@ angular.module('app.notifications', ['pascalprecht.translate']) -.controller('NotificationsCtrl', function($scope, $http, $ionicLoading, - $stateParams, $translate, $filter) { - $scope.notifications=[]; - $scope.doRefresh = function(){ - $http.get(urlapi + 'notifications') - .then(function(data){ - console.log(data); // for browser console - $scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); - $scope.storageuser.notifications = data.data; - localStorage.setItem("cim_app_userdata", JSON.stringify($scope.storageuser)); + .controller('NotificationsCtrl', function($scope, $http, $ionicLoading, + $stateParams, $translate, $filter) { + $scope.notifications = []; + $scope.doRefresh = function() { + //first, if already have notifications, set to viewed + if(localStorage.getItem("cim_app_notifications")!=undefined){ + //console.log(localStorage.getItem("cim_app_notifications")); + $scope.notifications = JSON.parse(localStorage.getItem("cim_app_notifications")); + for(var i=0; i<$scope.notifications.length; i++){ + $scope.notifications[i].state = "viewed"; + } + localStorage.setItem("cim_app_notifications", JSON.stringify($scope.notifications)); + } + $http.get(urlapi + 'notifications') + .then(function(data) { + //console.log(data); // for browser console + /*$scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); + $scope.storageuser.notifications = []; + console.log($scope.storageuser.notifications.length); + localStorage.setItem("cim_app_userdata", JSON.stringify($scope.storageuser));*/ - $scope.notifications = data.data; // for UI - $scope.$broadcast('scroll.refreshComplete');//refresher stop + //get the storage notifications + if (localStorage.getItem("cim_app_notifications")) { + $scope.notifications = JSON.parse(localStorage.getItem("cim_app_notifications")); + $scope.notifications = $scope.notifications.concat(data.data); // for UI + } else { + $scope.notifications = data.data; + } + //store the notifications + localStorage.setItem("cim_app_notifications", JSON.stringify($scope.notifications)); - }, function(data){ - console.log('data error'); - $scope.$broadcast('scroll.refreshComplete');//refresher stop - $ionicLoading.show({ template: 'Error connecting server', noBackdrop: true, duration: 2000 }); + //now clean the notification number that is showed in the menu and main page, from the storageuser.notifications + /*$scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); + $scope.storageuser.pendentnotifications = []; + localStorage.setItem("cim_app_userdata", JSON.stringify($scope.storageuser));*/ + $scope.$broadcast('scroll.refreshComplete'); //refresher stop + + }, function(data) { + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete'); //refresher stop + $ionicLoading.show({ + template: 'Error connecting server', + noBackdrop: true, + duration: 2000 + }); }); }; $scope.doRefresh(); -}); + }); diff --git a/www/templates/menu.html b/www/templates/menu.html index 2870616..2ad9af5 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -47,11 +47,11 @@ {{'Users' | translate }} - + {{'Settings' | translate }} diff --git a/www/templates/newTravel.html b/www/templates/newTravel.html index a6c0473..e0140a0 100644 --- a/www/templates/newTravel.html +++ b/www/templates/newTravel.html @@ -4,11 +4,11 @@ {{'Offer_Car' | translate}} - + {{'Ask_for_Car' | translate}} (not yet) - + {{'Ask_for_Package' | translate}} (not yet) diff --git a/www/templates/notifications.html b/www/templates/notifications.html index a85b423..f9ffad6 100644 --- a/www/templates/notifications.html +++ b/www/templates/notifications.html @@ -1,12 +1,22 @@ - - - - + + +
+ No notifications yet +
+
+ +

{{notification.message}}

+
+
{{notification.date | date:"dd/MM"}}
+
{{notification.date | date:"HH:mm:ss"}}
+
+
+ +

{{notification.message}}

{{notification.date | date:"dd/MM"}}