From 53ccc9c17fd1a4e607fe9680a428b48170ce9555 Mon Sep 17 00:00:00 2001 From: arnaucode Date: Tue, 18 Oct 2016 13:19:51 +0200 Subject: [PATCH] notification system almost implemented at the app --- www/img/comment.png | Bin 0 -> 754 bytes www/img/fav.png | Bin 0 -> 722 bytes www/img/join.png | Bin 0 -> 291 bytes www/img/notification.png | Bin 0 -> 797 bytes www/js/app.js | 10 ++++- www/js/controllers.js | 69 ++++++++++++++++++++++--------- www/js/translations.js | 1 + www/templates/menu.html | 5 +++ www/templates/notifications.html | 14 +++++++ www/templates/settings.html | 2 +- 10 files changed, 79 insertions(+), 22 deletions(-) create mode 100644 www/img/comment.png create mode 100644 www/img/fav.png create mode 100644 www/img/join.png create mode 100644 www/img/notification.png create mode 100644 www/templates/notifications.html diff --git a/www/img/comment.png b/www/img/comment.png new file mode 100644 index 0000000000000000000000000000000000000000..1483eb8915fbf2b913c425835dc82824674cdfc3 GIT binary patch literal 754 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE3?yBabR7dy%*9TgAsieWw;%dH0CG7CJR*x3 z7}ytsFr$I~rlUYX$r9IylHmNblJdl&REF~Ma=pyF?Be9af>gcyqV(DCY@`?%7?}cm zLR|m<|IYwK4gVQd!AKxu(SL@S{~4x%$$9@7rvGP{`=4#*f3|u5*=GG`oByA6?tj+V z|5<1KXPx(-WzK)*x&N7G{b!yHW&pWB23QcJW)4^}Q2ktxN){kF8_EFb0xAP4fFY0q zpe#fskc|z&)nk=~3$o4q&olo&--7?*i~mb3`7gWdzw(OzE?fUsociB>;s2y7|1Z7$ z|N8s?AAkP;?#bH;3^MnUAirQ>pfIzradPtuiinCyX=rKd>KmJydwBZz2Zn}6#U-Ys zW)#%bH+1$)nKgI8qNQurZQgn4_=z(YE?>QN`@zF!Z{B_V@$=W;e=#bL<^Thj-_yl0 zL_)ImAb0e^00y=P{vk!nS4?qQw#8{u%;k)IEAE{7|6luN-?tfa_Ud1And-Io_Un*t zP5pnx=}}w0oEFUSFv(oJ+HOsuCUaia@q~|4cC?l?*|X*?J*u!o^WwLI0#`H^A6gLP z)z853a*8(diHnZ+xvyl*(rbBNzRp|GA<;t2E;HC=PTwkzOM&c>T$6X6&2b6lPZv=u zo_(`pnI7NE6@AQBs~Fas@E$jd7ZG_dZ`sR3&z?6g(#B3>dk2BsOAnOib4ITB~xlUwiqcXxTr#j6TopPoGU`K&_z#_pgcyqV(DCY@~pSeg^o2 zxc&zM28REkq5B;i&ZHUNPjGk~8hR$p_hPKu-B6dSq3*XsJugT4U5jzQ5#e_`+Vgg} z=dEz>Ycampqr9(2`rL^0x)$YeBgXqilowD0#Etg629ol+76}poGrX?>WurZBM1dGU z1t67Cp4TJ2uY+^}O#mYAYcTHhXfL2jpg4pCF+jF>1I0n+01?P!u;CCc$TWx`&}4`d zoP=6|A?~&FgXC#oAOw{J`2{mDGPAI9aB^|;3yF$LO35f|8W~%9c=`DUg@s2%rlh53 z6*e|Cx3qTj^!81dHh2D-En9c)*>~X3;iD%{UATDV>W$lvo;-c_^6ke@pTB*?YcA|W~TAb0e^1PQhW#}`iNo#nDbgcyqV(DCY@~pS6a#!h zT>t<7uP{GAVZN90B43q-z94cDkn{sGAn4{RWgVbmu96_XUi|nn+iL_)}M9P U?L{)!fi^LCy85}Sb4q9e07_tCZvX%Q literal 0 HcmV?d00001 diff --git a/www/img/notification.png b/www/img/notification.png new file mode 100644 index 0000000000000000000000000000000000000000..63d5c6ed30f6be8b2010755dd62a012027915d60 GIT binary patch literal 797 zcmV+&1LFLNP) zzVANIv+w(TyYq=s3T=Fn;|Q-XIfTN)WgZyijQXleCE5nwOAj`S7?`-M0br5BrN9RJ zIj>fA=nOq|Ai)a^ObU!Ms5%)`ofH_yB8kO>E}eb{a`FR%6sJjo@-}GnF|%Kh0sERY?RVy1}xGIYib)Q^fkx8 zgru+{)RpQC**ulD_y)SU8cE!5E2SBXZ=h6l3bG+_iL1EG0E za0i5w@eK&aLh~Dd7ntpjZ@{E8Fy{b;kk1MSV;T?x6U#T{0r>{(LI+5wM!12GT=T6^ zz&id%Z+o4P4L^$E1}q-b#frc$f_Hu`gu6R4@J>c(p{Me!D7QRM*rxNtS>DJ{pg-S# z!xTeuo|T>7}A78)DKNIN#Gl(1q5`oSeZSM3{9{Rk3V$7#AafJKp; zwZZKMGSUuQZo2dqt}rDBssmdin3N@;cNfL0@tq5*8@6|#@k>YZu=oFB>sL;=h2jQk z2X_S>2p$H{E00?Df-$j4FbZ@9RQ#mKGajk+$bPghCif*pfjht{;KXM13ou8L$J|qE bI&}X4qxHH@(dPet00000NkvXXu0mjf$?#LL literal 0 HcmV?d00001 diff --git a/www/js/app.js b/www/js/app.js index f6314a0..9d1b86d 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -52,7 +52,15 @@ angular.module('starter', ['ionic', } } }) - + .state('app.notifications', { + url: '/notifications/:username', + views: { + 'menuContent': { + templateUrl: 'templates/notifications.html', + controller: 'NotificationsCtrl' + } + } + }) .state('app.users', { url: '/users', views: { diff --git a/www/js/controllers.js b/www/js/controllers.js index 4ca131d..9b8bc85 100644 --- a/www/js/controllers.js +++ b/www/js/controllers.js @@ -23,6 +23,8 @@ angular.module('starter.controllers', ['pascalprecht.translate']) $scope.storageusername=localStorage.getItem("c_username"); $scope.storageavatar=localStorage.getItem("c_avatar"); + $scope.userdata=JSON.parse(localStorage.getItem('c_userdata')); + console.log($scope.userdata); // Create the login modal that we will use later $ionicModal.fromTemplateUrl('templates/login.html', { scope: $scope @@ -189,7 +191,7 @@ angular.module('starter.controllers', ['pascalprecht.translate']) }) -.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading) { +.controller('TravelsCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { if(localStorage.getItem('c_token')){// adding token to the headers //console.log("token added to headers in run module"); //console.log($http.defaults); @@ -204,13 +206,14 @@ angular.module('starter.controllers', ['pascalprecht.translate']) $scope.travels=""; $scope.travels=JSON.parse(localStorage.getItem('c_travels')); $scope.userdata=JSON.parse(localStorage.getItem('c_userdata')); + //$scope.storageusername=JSON.parse(localStorage.getItem('c_username')); console.log($scope.userdata); $scope.doRefresh = function() { /* travels refresh: */ $http.get(urlapi + 'travels') .success(function(data, status, headers,config){ - console.log('data success'); + console.log('data success travels'); console.log(data); // for browser console $scope.travels = data; // for UI localStorage.setItem('c_travels', JSON.stringify($scope.travels)); @@ -232,11 +235,17 @@ angular.module('starter.controllers', ['pascalprecht.translate']) /* users refresh: */ $http.get(urlapi + 'users') .success(function(data, status, headers, config){ - console.log('data success'); + console.log('data success users'); console.log(data); // for browser console $scope.users = data; // for UI localStorage.setItem('c_users', JSON.stringify($scope.users)); $scope.$broadcast('scroll.refreshComplete');//refresher stop + + //set userdata + $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0]; + console.log("userdata"); + console.log($scope.userdata); + localStorage.setItem("c_userdata", JSON.stringify($scope.userdata)); }) .error(function(data, status, headers,config){ console.log('data error'); @@ -307,9 +316,9 @@ angular.module('starter.controllers', ['pascalprecht.translate']) console.log('Doing new travel', $scope.newtravel); $scope.newtravel.icon="lorry"; $scope.newtravel.generateddate=$scope.newtravel.date; - $scope.newtravel.owner=localStorage.getItem("c_username"); + /*$scope.newtravel.owner=localStorage.getItem("c_username"); $scope.newtravel.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; - $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone; + $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ $scope.newtravel.modality="offering"; //$scope.newtravel.token=localStorage.getItem("c_token"); console.log($scope.newtravel); @@ -349,9 +358,9 @@ angular.module('starter.controllers', ['pascalprecht.translate']) console.log('Doing new travel', $scope.newtravel); $scope.newtravel.icon="lorry"; $scope.newtravel.generateddate=$scope.newtravel.date; - $scope.newtravel.owner=localStorage.getItem("c_username"); + /*$scope.newtravel.owner=localStorage.getItem("c_username"); $scope.newtravel.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; - $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone; + $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ $scope.newtravel.modality="asking"; console.log($scope.newtravel); @@ -391,9 +400,9 @@ angular.module('starter.controllers', ['pascalprecht.translate']) console.log('Doing new package', $scope.newtravel); $scope.newtravel.icon="lorry"; $scope.newtravel.generateddate=$scope.newtravel.date; - $scope.newtravel.owner=localStorage.getItem("c_username"); + /*$scope.newtravel.owner=localStorage.getItem("c_username"); $scope.newtravel.telegram=JSON.parse(localStorage.getItem("c_userdata")).telegram; - $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone; + $scope.newtravel.phone=JSON.parse(localStorage.getItem("c_userdata")).phone;*/ $scope.newtravel.package=true; @@ -487,9 +496,9 @@ angular.module('starter.controllers', ['pascalprecht.translate']) $scope.joinTravel = function(){ $scope.newjoin={ //travelId: $stateParams.travelId, - joinedUserId: localStorage.getItem("c_userid"), + /*joinedUserId: localStorage.getItem("c_userid"), joinedUsername: localStorage.getItem("c_username"), - joinedAvatar: localStorage.getItem("c_avatar") + joinedAvatar: localStorage.getItem("c_avatar")*/ }; $http({ url: urlapi + 'travels/'+ $stateParams.travelId+'/join', @@ -515,9 +524,9 @@ angular.module('starter.controllers', ['pascalprecht.translate']) console.log("unjoin"); $scope.unjoin={ travelId: $stateParams.travelId, - joinedUserId: localStorage.getItem("c_userid"), + /*joinedUserId: localStorage.getItem("c_userid"), joinedUsername: localStorage.getItem("c_username"), - joinedAvatar: localStorage.getItem("c_avatar") + joinedAvatar: localStorage.getItem("c_avatar")*/ }; $http({ url: urlapi + 'travels/'+ $stateParams.travelId+'/unjoin', @@ -551,9 +560,9 @@ angular.module('starter.controllers', ['pascalprecht.translate']) $scope.doingNewComment=false; }; $scope.doNewComment = function() { - $scope.newComment.commentUserId=localStorage.getItem("c_userid"); + /*$scope.newComment.commentUserId=localStorage.getItem("c_userid"); $scope.newComment.commentUsername=localStorage.getItem("c_username"); - $scope.newComment.commentAvatar=localStorage.getItem("c_avatar"); + $scope.newComment.commentAvatar=localStorage.getItem("c_avatar");*/ console.log($scope.newComment); $http({ url: urlapi + 'travels/'+ $stateParams.travelId+'/comment', @@ -600,7 +609,7 @@ console.log($scope.newComment); }; }) -.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading) { +.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading, $filter) { $scope.users=""; $scope.users=JSON.parse(localStorage.getItem('c_users')); @@ -636,6 +645,12 @@ console.log($scope.newComment); $scope.users = data; // for UI localStorage.setItem('c_users', JSON.stringify($scope.users)); $scope.$broadcast('scroll.refreshComplete');//refresher stop + + //set userdata + $scope.userdata = $filter('filter')($scope.users, {username: $scope.storageusername}, true)[0]; + console.log("userdata"); + console.log($scope.userdata); + localStorage.setItem("c_userdata", JSON.stringify($scope.userdata)); }) .error(function(data, status, headers,config){ console.log('data error'); @@ -687,9 +702,9 @@ console.log($scope.newComment); $scope.favUser = function(){ $scope.newfav={ //travelId: $stateParams.travelId, - userId: localStorage.getItem("c_userid"), + /*userId: localStorage.getItem("c_userid"), username: localStorage.getItem("c_username"), - avatar: localStorage.getItem("c_avatar") + avatar: localStorage.getItem("c_avatar")*/ }; $scope.user.favs.push($scope.newfav);//al unfav no cal fer aquest simulacre pq ja no existeix a l'array i no el resta dos cops en cas de que cliquin dos cops $http({ @@ -715,9 +730,9 @@ console.log($scope.newComment); $scope.unfavUser = function(){ console.log("unfav"); $scope.unfav={ - userId: localStorage.getItem("c_userid"), + /*userId: localStorage.getItem("c_userid"), username: localStorage.getItem("c_username"), - avatar: localStorage.getItem("c_avatar") + avatar: localStorage.getItem("c_avatar")*/ }; $http({ //url: urlapi + 'users/'+ $stateParams.username+'/fav', @@ -766,6 +781,20 @@ console.log($scope.newComment); return -1; }; }) +.controller('NotificationsCtrl', function($scope, $stateParams, $translate, $filter) { + if(localStorage.getItem('c_token')){// adding token to the headers + // $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token'); + } + $scope.storageusername=localStorage.getItem("c_username"); + $scope.users= JSON.parse(localStorage.getItem('c_users')); + $scope.user = $filter('filter')($scope.users, {username: $stateParams.username}, true)[0]; + $scope.notifications=$scope.user.notifications; + + console.log($stateParams.username); + console.log($scope.notifications); + console.log("notifications page"); +}) + .controller('SettingsCtrl', function($scope, $stateParams, $translate) { if(localStorage.getItem('lang'))//initialization { diff --git a/www/js/translations.js b/www/js/translations.js index e8c9529..b32010d 100644 --- a/www/js/translations.js +++ b/www/js/translations.js @@ -6,6 +6,7 @@ var translations = { "Login": "Login", "Travels": "Travels", "Users": "Users", + "Notifications": "Notifications", "Logout": "Logout", "Settings": "Settings", "Help": "Help", diff --git a/www/templates/menu.html b/www/templates/menu.html index 13b514d..43061a1 100644 --- a/www/templates/menu.html +++ b/www/templates/menu.html @@ -32,6 +32,11 @@ {{'Users' | translate }} + + + {{'Notifications' | translate }} + {{userdata.notifications.length}} + {{storageusername}} diff --git a/www/templates/notifications.html b/www/templates/notifications.html new file mode 100644 index 0000000..e73d36f --- /dev/null +++ b/www/templates/notifications.html @@ -0,0 +1,14 @@ + + + + + diff --git a/www/templates/settings.html b/www/templates/settings.html index ddd89e9..aa744b6 100644 --- a/www/templates/settings.html +++ b/www/templates/settings.html @@ -10,7 +10,7 @@

- version: CarsInCommon-v011 + version: CarsInCommon-v012