mirror of
https://github.com/arnaucube/commonroutesApp.git
synced 2026-02-07 03:26:44 +01:00
travel comments system added
This commit is contained in:
@@ -314,7 +314,7 @@ angular.module('starter.controllers', [])
|
|||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('TravelCtrl', function($scope, $stateParams, $http) {
|
.controller('TravelCtrl', function($scope, $stateParams, $http, $ionicModal) {
|
||||||
if(localStorage.getItem('c_token')){// adding token to the headers
|
if(localStorage.getItem('c_token')){// adding token to the headers
|
||||||
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token');
|
$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('c_token');
|
||||||
}
|
}
|
||||||
@@ -345,6 +345,17 @@ angular.module('starter.controllers', [])
|
|||||||
.then(function(result){
|
.then(function(result){
|
||||||
joins = result.data;
|
joins = result.data;
|
||||||
});
|
});
|
||||||
|
$http.get(urlapi + 'travels/comment/'+$stateParams.travelId)
|
||||||
|
.success(function(data, status, headers,config){
|
||||||
|
console.log(data); // for browser console
|
||||||
|
$scope.comments = data; // for UI
|
||||||
|
})
|
||||||
|
.error(function(data, status, headers,config){
|
||||||
|
console.log('data error');
|
||||||
|
})
|
||||||
|
.then(function(result){
|
||||||
|
comments = result.data;
|
||||||
|
});
|
||||||
|
|
||||||
$scope.deleteTravel = function(){
|
$scope.deleteTravel = function(){
|
||||||
console.log("delete travel: " + $stateParams.travelId);
|
console.log("delete travel: " + $stateParams.travelId);
|
||||||
@@ -380,6 +391,40 @@ angular.module('starter.controllers', [])
|
|||||||
// failed
|
// failed
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* adding comment */
|
||||||
|
$scope.doingNewComment=false;
|
||||||
|
$scope.newComment={};
|
||||||
|
|
||||||
|
$scope.showNewComment = function() {
|
||||||
|
$scope.doingNewComment=true;
|
||||||
|
};
|
||||||
|
$scope.closeNewComment = function() {
|
||||||
|
$scope.doingNewComment=false;
|
||||||
|
};
|
||||||
|
$scope.doNewComment = function() {
|
||||||
|
$scope.newComment.commentUserId=localStorage.getItem("c_userid");
|
||||||
|
$scope.newComment.commentUsername=localStorage.getItem("c_username");
|
||||||
|
console.log($scope.newComment);
|
||||||
|
$http({
|
||||||
|
url: urlapi + 'travels/comment/' + $stateParams.travelId,
|
||||||
|
method: "POST",
|
||||||
|
data: $scope.newComment
|
||||||
|
})
|
||||||
|
.then(function(response) {
|
||||||
|
// success
|
||||||
|
console.log("newComment added to server: " + response);
|
||||||
|
console.log(response);
|
||||||
|
if(response.data.success==false){
|
||||||
|
|
||||||
|
$ionicLoading.show({ template: 'failed to generate new asking package', noBackdrop: true, duration: 2000 });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function(response) { // optional
|
||||||
|
// failed
|
||||||
|
});
|
||||||
|
$scope.closeNewComment();
|
||||||
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout) {
|
.controller('UsersCtrl', function($scope, $http, $ionicModal, $timeout) {
|
||||||
|
|||||||
@@ -43,11 +43,34 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="item item-body">
|
<div class="item item-body" ng-show="joins[0]">
|
||||||
Joined users:<br>
|
Joined users:<br>
|
||||||
<a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
|
<a ng-repeat="join in joins" ng-href="#/app/users/{{join.joinedUsername}}" class="button button-small button-dark">
|
||||||
{{join.joinedUsername}}<br>
|
{{join.joinedUsername}}<br>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="item item-body">
|
||||||
|
<div ng-show="comments[0]">
|
||||||
|
Comments:<br>
|
||||||
|
<a ng-repeat="comment in comments" ng-href="#/app/users/{{comment.commentUsername}}" class="item">
|
||||||
|
<h3>{{comment.commentUsername}}</h3>
|
||||||
|
<p>{{comment.comment}}</p>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<a ng-click="showNewComment()" ng-show="!doingNewComment" class="button button-calm right">New comment</a>
|
||||||
|
<form class="list" ng-show="doingNewComment">
|
||||||
|
<label class="item item-input item-floating-label">
|
||||||
|
<span class="input-label">Comment</span>
|
||||||
|
<input ng-model="newComment.comment" type="text" placeholder="Comment">
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<button ng-click="closeNewComment()" class="button button-assertive">
|
||||||
|
Cancel
|
||||||
|
</button>
|
||||||
|
<button ng-click="doNewComment()" class="button button-calm">
|
||||||
|
Post comment
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</ion-content>
|
</ion-content>
|
||||||
</ion-view>
|
</ion-view>
|
||||||
|
|||||||
Reference in New Issue
Block a user