From 85e0b7b8e5a0e611366d4a029ffdcb935c76f64d Mon Sep 17 00:00:00 2001 From: arnaucode Date: Thu, 2 Feb 2017 15:33:07 +0100 Subject: [PATCH] users likes system added to users --- www/index.html | 1 + www/js/app.js | 10 ++++++++ www/js/user.js | 44 ++++++++++++++++++++++++++++++++++-- www/js/userLikes.js | 21 +++++++++++++++++ www/templates/user.html | 32 ++++++++++++-------------- www/templates/userLikes.html | 17 ++++++++++++++ 6 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 www/js/userLikes.js create mode 100644 www/templates/userLikes.html diff --git a/www/index.html b/www/index.html index 0c157e7..ee8dab6 100644 --- a/www/index.html +++ b/www/index.html @@ -55,6 +55,7 @@ + diff --git a/www/js/app.js b/www/js/app.js index bc87a74..5abc3a2 100644 --- a/www/js/app.js +++ b/www/js/app.js @@ -31,6 +31,7 @@ angular.module('starter', [ 'app.users', 'app.user', 'app.userTravels', + 'app.userLikes', 'app.editUser', 'app.notifications', 'app.settings', @@ -163,6 +164,15 @@ angular.module('starter', [ } } }) + .state('app.userLikes', { + url: '/users/userLikes/:userid', + views: { + 'menuContent': { + templateUrl: 'templates/userLikes.html', + controller: 'UserLikesCtrl' + } + } + }) .state('app.editUser', { url: '/editUser', views: { diff --git a/www/js/user.js b/www/js/user.js index 6df5c94..86242f1 100644 --- a/www/js/user.js +++ b/www/js/user.js @@ -23,6 +23,46 @@ angular.module('app.user', ['pascalprecht.translate']) }; $scope.doRefresh(); + $scope.likeUser = function(){ + $http({ + //url: urlapi + 'users/'+ $stateParams.username+'/fav', + url: urlapi + 'users/id/like/'+ $scope.user._id, + method: "POST", + data: {} + }) + .then(function(data) { + // success + if(data.data.success==false){ + console.log("failed"); + $ionicLoading.show({template: 'Error on like', noBackdrop: true, duration: 2000}); + }else{ + $scope.user = data.data; // for UI + } + }, + function(response) { // optional + // failed + }); + }; + $scope.unlikeUser = function(){ + $http({ + //url: urlapi + 'users/'+ $stateParams.username+'/fav', + url: urlapi + 'users/id/unlike/'+ $scope.user._id, + method: "POST", + data: {} + }) + .then(function(data) { + // success + if(data.data.success==false){ + console.log("failed"); + $ionicLoading.show({template: 'Error on unlike', noBackdrop: true, duration: 2000}); + }else{ + $scope.user = data.data; // for UI + } + }, + function(response) { // optional + // failed + }); + }; $scope.favUser = function(){ @@ -96,10 +136,10 @@ angular.module('app.user', ['pascalprecht.translate']) $scope.modalFavsList.hide(); }; - $scope.arrayObjectIndexOf = function(myArray, searchTerm, property) { + $scope.arrayObjectIndexOf = function(myArray, searchTerm) { if(myArray){ for(var i = 0, len = myArray.length; i < len; i++) { - if (myArray[i][property] === searchTerm){ + if (myArray[i] === searchTerm){ return i; } } diff --git a/www/js/userLikes.js b/www/js/userLikes.js new file mode 100644 index 0000000..2813c54 --- /dev/null +++ b/www/js/userLikes.js @@ -0,0 +1,21 @@ +angular.module('app.userLikes', ['pascalprecht.translate']) + +.controller('UserLikesCtrl', function($scope, $http, $ionicModal, + $timeout, $ionicLoading, $filter, $stateParams) { + + $scope.storageuser = JSON.parse(localStorage.getItem("cim_app_userdata")); + $scope.likes=[]; + $scope.doRefresh = function(){ + $http.get(urlapi + 'users/id/likes/'+$stateParams.userid) + .then(function(data, status, headers,config){ + console.log('data success'); + console.log(data); + $scope.likes = data.data; + $scope.$broadcast('scroll.refreshComplete');//refresher stop + },function(data, status, headers,config){ + console.log('data error'); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + }); + }; + $scope.doRefresh(); +}); diff --git a/www/templates/user.html b/www/templates/user.html index 6b27f4c..c423352 100644 --- a/www/templates/user.html +++ b/www/templates/user.html @@ -9,6 +9,10 @@

{{user.username}}

{{user.description}}

{{user.email}}

+ +

+ view likes +

Edit profile

@@ -24,24 +28,18 @@ {{user.travels.length}} Travels - - - {{user.favs.length}} favs
(not yet) +
+ + + {{user.likes.length}} likes + + + + + + {{user.likes.length}} likes + - - -
-
- - - - - - -
-
diff --git a/www/templates/userLikes.html b/www/templates/userLikes.html new file mode 100644 index 0000000..f125a0c --- /dev/null +++ b/www/templates/userLikes.html @@ -0,0 +1,17 @@ + + + + + + +