Browse Source

user favs system implemented

master
idoctnef 8 years ago
parent
commit
689fa19a53
2 changed files with 93 additions and 8 deletions
  1. +80
    -6
      www/js/controllers.js
  2. +13
    -2
      www/templates/user.html

+ 80
- 6
www/js/controllers.js

@ -430,7 +430,7 @@ angular.module('starter.controllers', ['pascalprecht.translate'])
$scope.travels= JSON.parse(localStorage.getItem('c_travels'));
$scope.travel = $filter('filter')($scope.travels, $stateParams.travelId, true)[0];
$http.get(urlapi + 'travels/comment/'+$stateParams.travelId)
/*$http.get(urlapi + 'travels/comment/'+$stateParams.travelId)
.success(function(data, status, headers,config){
console.log(data); // for browser console
$scope.comments = data; // for UI
@ -440,7 +440,7 @@ angular.module('starter.controllers', ['pascalprecht.translate'])
})
.then(function(result){
comments = result.data;
});
});*/
$scope.deleteTravel = function(){
@ -582,7 +582,7 @@ console.log($scope.newComment);
}
//console.log("i: -1");
return -1;
}
};
})
.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout, $ionicLoading) {
@ -632,10 +632,16 @@ console.log($scope.newComment);
};
})
.controller('UserCtrl', function($scope, $stateParams, $http) {
.controller('UserCtrl', function($scope, $stateParams, $http, $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, $stateParams.username, true)[0];
//$scope.user="";
console.log($stateParams.username);
$http.get(urlapi + 'users/byusername/'+$stateParams.username)
/*$http.get(urlapi + 'users/byusername/'+$stateParams.username)
.success(function(data, status, headers,config){
console.log('data success');
console.log(data); // for browser console
@ -646,7 +652,7 @@ console.log($scope.newComment);
})
.then(function(result){
user = result.data;
});
});*/
$http.get(urlapi + 'travels/user/'+$stateParams.username)
.success(function(data, status, headers,config){
@ -660,6 +666,74 @@ console.log($scope.newComment);
.then(function(result){
travels = result.data;
});
$scope.favUser = function(){
$scope.newfav={
//travelId: $stateParams.travelId,
userId: localStorage.getItem("c_userid"),
username: localStorage.getItem("c_username"),
avatar: localStorage.getItem("c_avatar")
};
$http({
//url: urlapi + 'users/'+ $stateParams.username+'/fav',
url: urlapi + 'users/'+ $scope.user._id+'/fav',
method: "POST",
data: $scope.newfav
})
.then(function(response) {
// success
console.log("response: ");
console.log(response);
$scope.users=response.data;
localStorage.setItem('c_users', JSON.stringify($scope.users));
$scope.user = $filter('filter')($scope.users, $stateParams.username, true)[0];
},
function(response) { // optional
// failed
});
};
$scope.unfavUser = function(){
console.log("unfav");
$scope.unfav={
userId: localStorage.getItem("c_userid"),
username: localStorage.getItem("c_username"),
avatar: localStorage.getItem("c_avatar")
};
$http({
//url: urlapi + 'users/'+ $stateParams.username+'/fav',
url: urlapi + 'users/'+ $scope.user._id+'/unfav',
method: "POST",
data: $scope.unfav
})
.then(function(response) {
// success
console.log("response: ");
console.log(response);
$scope.users=response.data;
localStorage.setItem('c_users', JSON.stringify($scope.users));
$scope.user = $filter('filter')($scope.users, $stateParams.username, true)[0];
},
function(response) { // optional
// failed
});
};
$scope.arrayObjectIndexOf = function(myArray, searchTerm, property) {
if(myArray){
for(var i = 0, len = myArray.length; i < len; i++) {
if (myArray[i][property] === searchTerm){
return i;
}
}
}
return -1;
};
})
.controller('SettingsCtrl', function($scope, $stateParams, $translate) {
if(localStorage.getItem('lang'))//initialization

+ 13
- 2
www/templates/user.html

@ -10,6 +10,19 @@
<p>
<img class='o-imgMenu' src="img/telegram.png" /> @{{user.telegram}}
</p>
<div class="o-text-right">
<b>favs:</b>
<span class="o-badge-calm">{{user.favs.length}}</span>
<br>
<div ng-show="storageusername && storageusername!=user.username">
<a ng-show="arrayObjectIndexOf(user.favs, storageusername, 'username')==-1" ng-click="favUser()" class="button button-calm o-pull-right">+1</a>
<a ng-show="arrayObjectIndexOf(user.favs, storageusername, 'username')!=-1" ng-click="unfavUser()" class="button button-assertive o-pull-right">unfav</a>
</div>
<!--<a ng-repeat="join in user.favs" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
<img ng-src="img/avatars/{{join.joinedAvatar}}.png" class="o-img-joined" />{{join.joinedUsername}}<br>
</a>-->
</div>
</div>
<div class="item item-body">
{{'history_of' | translate}} {{user.username}}:
@ -30,8 +43,6 @@
<p>
{{travel.description}}
</p>
</a>
</div>
</ion-content>

Loading…
Cancel
Save