Skip to content

Commit d96d147

Browse files
committed
delete comment implementation is fully completed
1 parent 01546e5 commit d96d147

File tree

8 files changed

+113
-14
lines changed

8 files changed

+113
-14
lines changed

www/css/full-recipe.css

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
}
114114
.comment {
115115
margin-top: 15px;
116+
position: relative;
116117
}
117118
.submit-comment-btn {
118119
margin-bottom: 20px;
@@ -149,6 +150,51 @@
149150
.full-recipe-container .recipe-image .item-action-section {
150151
bottom: 5px;
151152
}
153+
.shadow-remove {
154+
background: url("../resources/back.png");
155+
position: absolute;
156+
height: 100%;
157+
width: 100%;
158+
-webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
159+
-moz-box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
160+
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.75);
161+
}
162+
.shadow-remove.ng-enter-active {
163+
opacity: 1;
164+
}
165+
.shadow-remove.ng-leave-active {
166+
opacity: 0;
167+
}
168+
.shadow-remove.ng-enter {
169+
-webkit-animation:0.5s show;
170+
animation:0.5s show;
171+
}
172+
.shadow-remove.ng-leave {
173+
-webkit-animation:0.5s hide;
174+
animation:0.5s hide;
175+
}
176+
.delete-comment {
177+
position: absolute;
178+
right: 0;
179+
padding: 5px;
180+
border: 1px solid #aaa;
181+
font-size: 2.5em;
182+
background: #fff;
183+
height: 100%;
184+
}
185+
.delete-comment::before {
186+
top: 50%;
187+
transform: translate(0, -50%);
188+
-webkit-transform: translate(0, -50%);
189+
position: relative;
190+
}
191+
.no-comment {
192+
padding: 10px 0;
193+
}
194+
.comment-date {
195+
font-size: 0.6em;
196+
float: right;
197+
}
152198
/*.item-input input[type="text"].cloned-text-input ,
153199
.item-input textarea.cloned-text-input{
154200
display: none !important;

www/js/config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ define(['angular'], function (angular) {
5252
ALL_CATEGORY: "http://localhost:3000/getAllCategory",
5353
SET_FAVORITE_RECIPE_BULK: "http://localhost:3000/setFavoriteRecipeInBulk",
5454
RECOMMEND_RECIPE: "http://localhost:3000/recommendRecipe",
55-
SUBMIT_COMMENT: "http://localhost:3000/submitComment"
55+
SUBMIT_COMMENT: "http://localhost:3000/submitComment",
56+
DELETE_COMMENT: "http://localhost:3000/deleteComment"
5657
},
5758
LOCALE: {
5859
AVAILABLE: [{

www/js/locales/recipe/de.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
"all-comment-title": "Bemerkungen",
99
"no_recipe_available": "Kein Rezept erhältlich",
1010
"author": "Autor",
11+
"no_comment": "Keine Kommentare ab jetzt",
1112
"recommend_confirm_title": "Empfehlen Rezept",
1213
"login_require_title": "Anmeldung erforderlich",
1314
"comment_box_placeholder": "Maximale Zeichenbegrenzung: ",
15+
"remove_comment_confirm_title": "Kommentar löschen",
16+
"remove_comment_confirm_description": "Wollen Sie Ihren Kommentar löschen ?",
1417
"login_require_description": "Sie müssen sich einloggen um Ihren Kommentar zu schreiben. Bitte loggen Sie sich zuerst ein.",
1518
"recommend_confirm_description": "Haben Sie dieses Rezept ausprobiert und es hat euch gefallen ? Wollen Sie es für andere zu empfehlen?"
1619
}

www/js/locales/recipe/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"recommend_confirm_title": "Recommend Recipe",
1212
"comment_box_placeholder": "Maximum character limit: ",
1313
"login_require_title": "Login Required",
14+
"no_comment": "No comments as of now",
15+
"remove_comment_confirm_title": "Delete Comment",
16+
"remove_comment_confirm_description": "Do you want to delete your comment?",
1417
"login_require_description": "You have to login to post your comment. Please login first.",
1518
"recommend_confirm_description": "Have you tried this recipe and you liked it? Do you want to recommend it for others?"
1619
}
Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,41 @@
11
define(function () {
22
'use strict';
33

4-
return function() {
4+
return ['recipeService', '$filter', '$ionicPopup', 'appStore', function(recipeService, $filter, $ionicPopup, appStore) {
55
return {
66
restrict: 'E',
77
replace: true,
88
transclude: true,
99
templateUrl: "templates/recipe/comments.html",
10-
scope: true
11-
};
12-
};
10+
scope: {
11+
comments: "=",
12+
recipeId: "="
13+
},
14+
link: function($scope, element) {
15+
16+
var savedUser = appStore.getFromLocal("userLoggedInStatus");
17+
$scope.userId = ((savedUser) ? savedUser.userID : "");
18+
19+
$scope.deleteComment = function(evt, index, time) {
20+
evt.preventDefault();
21+
evt.stopImmediatePropagation();
1322

23+
var confirmPopup = $ionicPopup.confirm({
24+
title: $filter('translate')('recipe.remove_comment_confirm_title'),
25+
template: $filter('translate')('recipe.remove_comment_confirm_description')
26+
});
27+
28+
confirmPopup.then(function(res) {
29+
if(res) {
30+
recipeService.deleteComment($scope.recipeId, time).then(function(flag){
31+
if(flag) {
32+
$scope.comments.splice(index, 1);
33+
}
34+
});
35+
}
36+
});
37+
};
38+
}
39+
};
40+
}];
1441
});

www/js/modules/recipe/services/recipe.service.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ define(function () {
166166
return def.promise;
167167
}
168168

169+
function deleteComment(recipeId, time) {
170+
var def = $q.defer();
171+
172+
$http.post(CONFIG.SERVICE_URL.DELETE_COMMENT, {
173+
recipeId: recipeId,
174+
time: time
175+
}).success(function(flag){
176+
def.resolve(flag);
177+
}).error(function(err) {
178+
console.log("error in deleting comment");
179+
def.reject(false);
180+
});
181+
182+
return def.promise;
183+
}
184+
169185
function __getBase64FormatOfImg(url) {
170186
var img = new Image(), def = $q.defer();
171187
img.crossOrigin = 'Anonymous';
@@ -189,7 +205,8 @@ define(function () {
189205
getPDFDocDefinition: getPDFDocDefinition,
190206
getSavedRecipeList: getSavedRecipeList,
191207
recommendRecipe: recommendRecipe,
192-
postComment: postComment
208+
postComment: postComment,
209+
deleteComment: deleteComment
193210
};
194211

195212
};

www/templates/recipe/comments.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<div class="all-comments" id="allCommentSection">
2-
<div class="comment" ng-repeat="comment in comments">
2+
<div ng-if="comments.length === 0" class="no-comment">{{'recipe.no_comment' | translate}}</div>
3+
<div class="comment" ng-repeat="comment in comments track by $index" ng-init="comment.showRemoveCommentSection = false" on-hold="comment.showRemoveCommentSection = true">
4+
<div class="shadow-remove" ng-if="comment.cook.id === userId && comment.showRemoveCommentSection === true" ng-click="comment.showRemoveCommentSection = false">
5+
<a href="javascript:;" ng-click="deleteComment($event, $index, comment.time)" class="icon ion-trash-b delete-comment assertive"></a>
6+
</div>
37
<header>
4-
<h3 class="comment-cook-name" id="{{comment.cook.id}}">{{comment.cook.name}}</h3>
8+
<h3 class="comment-cook-name" id="{{comment.cook.id}}">
9+
{{comment.cook.name}}
10+
<span class="comment-date">{{comment.time|date: 'mediumDate'}}</span>
11+
</h3>
512
</header>
613
<section class="comment-cook">
714
<i class="icon ion-chatbubble-working"></i>

www/templates/recipe/full-recipe.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
<!--<ion-nav-bar class="bar-assertive">
2-
<ion-nav-back-button class="button-icon ion-arrow-left-c">
3-
</ion-nav-back-button>
4-
</ion-nav-bar>-->
5-
61
<ion-view title="{{'recipe.header' | translate}}">
72
<ion-content>
83
<div class="full-recipe-container item-container" id="{{recipe._id}}">
@@ -60,7 +55,7 @@ <h1 class="recipe-title">{{recipe.title}}</h1>
6055
<button ng-click="submitComment(recipe._id)" class="button button-block button-positive">{{'recipe.recipe-comment-submit' | translate}}</button>
6156
</div>
6257
<div class="comment-title">{{'recipe.all-comment-title' | translate}}</div>
63-
<comment-box></comment-box>
58+
<comment-box comments="comments" recipe-id="recipe._id"></comment-box>
6459
</div>
6560
</div>
6661
</div>

0 commit comments

Comments
 (0)