Browse Source

users likes system added to users

master
arnaucode 7 years ago
parent
commit
85e0b7b8e5
6 changed files with 106 additions and 19 deletions
  1. +1
    -0
      www/index.html
  2. +10
    -0
      www/js/app.js
  3. +42
    -2
      www/js/user.js
  4. +21
    -0
      www/js/userLikes.js
  5. +15
    -17
      www/templates/user.html
  6. +17
    -0
      www/templates/userLikes.html

+ 1
- 0
www/index.html

@ -55,6 +55,7 @@
<script src="js/users.js"></script>
<script src="js/user.js"></script>
<script src="js/userTravels.js"></script>
<script src="js/userLikes.js"></script>
<script src="js/editUser.js"></script>
<script src="js/notifications.js"></script>
<script src="js/settings.js"></script>

+ 10
- 0
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: {

+ 42
- 2
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;
}
}

+ 21
- 0
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();
});

+ 15
- 17
www/templates/user.html

@ -9,6 +9,10 @@
<h3 class="o_text_white">{{user.username}}</h3>
<p>{{user.description}}</p>
<p>{{user.email}}</p>
<p><a class="button button-small" ng-href="#/app/users/userLikes/{{user._id}}">
view likes
</a></p>
<p ng-show="storageuser._id==user._id">
<md-button class="o_grey500" ng-href="#/app/editUser">Edit profile</md-button>
</p>
@ -24,24 +28,18 @@
<i class="icon ion-android-car"></i>
{{user.travels.length}} Travels
</a>
<a class="tab-item">
<i class="icon ion-ios-heart"></i>
{{user.favs.length}} favs<br>(not yet)
<a class="tab-item" ng-show="arrayObjectIndexOf(user.likes, storageuser._id)==-1">
<i class="icon ion-ios-heart" ng-click="likeUser()"></i>
<i ng-href="#/app/users/userLikes/{{user._id}}">
{{user.likes.length}} likes
</i>
</a>
<a class="tab-item" ng-show="arrayObjectIndexOf(user.likes, storageuser._id)>-1">
<i class="icon ion-heart-broken" ng-click="unlikeUser()"></i>
<i ng-href="#/app/users/userLikes/{{user._id}}">
{{user.likes.length}} likes
</i>
</a>
</div>
<div class="o-text-right">
<div ng-show="storageusername && storageusername!=user.username">
<a ng-show="arrayObjectIndexOf(user.favs, storageusername, 'username')==-1" ng-click="favUser()">
<img class="o-imgMenu" src="img/unlike.png" />
</a>
<a ng-show="arrayObjectIndexOf(user.favs, storageusername, 'username')!=-1" ng-click="unfavUser()">
<img class="o-imgMenu" src="img/like.png" />
</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">

+ 17
- 0
www/templates/userLikes.html

@ -0,0 +1,17 @@
<ion-view view-title="{{' travels' | translate}}">
<ion-content class="has-footer">
<ion-refresher
pulling-text="{{'Pull_to_refresh' | translate}}..."
on-refresh="doRefresh()">
</ion-refresher>
<div class="list">
<a ng-repeat="user in likes | orderBy: 'date'" class="item item-avatar" ng-href="#/app/users/{{user._id}}">
<img ng-src="{{user.avatar}}">
<h2 class="o_text_purple600">{{user.username}}</h2>
<p>
{{user.description}}
</p>
</a>
</div>
</ion-content>
</ion-view>

Loading…
Cancel
Save