--- /dev/null
+<?php
+
+use Illuminate\Support\Facades\Schema;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CommentsAddActiveCol extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('comments', function (Blueprint $table) {
+ // add column active
+ $table->boolean('active')->default(true);
+ $table->dropIndex('comments_page_id_parent_id_index');
+ $table->index(['page_id']);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('comments', function (Blueprint $table) {
+ // reversing the schema
+ $table->dropIndex('comments_page_id_index');
+ $table->dropColumn('active');
+ $table->index(['page_id', 'parent_id']);
+ });
+ }
+}
}]);
// CommentCrudController
- ngApp.controller('CommentReplyController', ['$scope', '$http', function ($scope, $http) {
+ ngApp.controller('CommentReplyController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
const MarkdownIt = require("markdown-it");
const md = new MarkdownIt({html: true});
let vm = this;
$scope.errors = {};
+
vm.saveComment = function () {
let pageId = $scope.comment.pageId || $scope.pageId;
let comment = $scope.comment.text;
if (!resp.data || resp.data.status !== 'success') {
return events.emit('error', trans('error'));
}
+ // hide the comments first, and then retrigger the refresh
if ($scope.isEdit) {
- $scope.comment.html = resp.data.comment.html;
- $scope.comment.text = resp.data.comment.text;
- $scope.comment.updated = resp.data.comment.updated;
- $scope.comment.updated_by = resp.data.comment.updated_by;
+ updateComment($scope.comment, resp.data);
$scope.$emit('evt.comment-success', $scope.comment.id);
} else {
$scope.comment.text = '';
}
$scope.$emit('evt.comment-success', null, true);
}
+ $scope.comment.is_hidden = true;
+ $timeout(function() {
+ $scope.comment.is_hidden = false;
+ });
+
events.emit('success', trans(resp.data.message));
}, checkError(errorOp));
}
}]);
+ ngApp.controller('CommentDeleteController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
+ let vm = this;
+
+ vm.delete = function(comment) {
+ $http.delete(window.baseUrl(`/ajax/comment/${comment.id}`)).then(resp => {
+ if (!resp.data || resp.data.success !== true) {
+ return;
+ }
+ updateComment(comment, resp.data, $timeout, true);
+ }, function (resp) {
+ if (!resp || !resp.data || resp.data.success !== true) {
+ events.emit('error', trans('entities.comment_delete_fail'));
+ } else {
+ events.emit('success', trans('entities.comment_delete_success'));
+ }
+ });
+ };
+ }]);
// CommentListController
ngApp.controller('CommentListController', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {
});
vm.canEdit = function (comment) {
+ if (!comment.active) {
+ return false;
+ }
if (vm.permissions.comment_update_all) {
return true;
}
return true;
}
return false;
- }
+ };
vm.canComment = function () {
return vm.permissions.comment_create;
- }
+ };
$timeout(function() {
$http.get(window.baseUrl(`/ajax/page/${$scope.pageId}/comments/`)).then(resp => {
} else if (vm.totalComments === 1) {
vm.totalCommentsStr = '1 Comments';
} else {
- vm.totalCommentsStr = vm.totalComments + ' Comments'
+ vm.totalCommentsStr = vm.totalComments + ' Comments';
}
}, checkError('app'));
});
$scope.errors[errorGroupName] = {};
return function(response) {
console.log(response);
- }
+ };
}
}]);
+ function updateComment(comment, resp, $timeout, isDelete) {
+ if (isDelete && !resp.comment.active) {
+ comment.html = trans('entities.comment_deleted');
+ }
+ comment.text = resp.comment.text;
+ comment.updated = resp.comment.updated;
+ comment.updated_by = resp.comment.updated_by;
+ comment.active = resp.comment.active;
+ if (isDelete && !resp.comment.active) {
+ comment.html = trans('entities.comment_deleted');
+ } else {
+ comment.html = resp.comment.html;
+ }
+ if (!$timeout) {
+ return;
+ }
+ comment.is_hidden = true;
+ $timeout(function() {
+ comment.is_hidden = false;
+ });
+ }
};
}]);
- ngApp.directive('commentReplyLink', ['$document', '$compile', '$http', function ($document, $compile, $http) {
+ ngApp.directive('commentReplyLink', ['$document', '$compile', function ($document, $compile) {
return {
scope: {
comment: '='
$existingElement.remove();
}
}]);
+
+ ngApp.directive('commentDeleteLink', ['$window', function ($window) {
+ return {
+ controller: 'CommentDeleteController',
+ scope: {
+ comment: '='
+ },
+ link: function (scope, element, attr, ctrl) {
+
+ element.on('click', function() {
+ var resp = $window.confirm('This will remove the content of the comment, are you sure you want to continue?');
+ if (!resp) {
+ return;
+ }
+
+ ctrl.delete(scope.comment);
+ });
+ }
+ };
+ }]);
};
<div class="comment-header">
<a href="@{{::comment.created_by.profile_url}}">@{{ ::comment.created_by.name }}</a>
</div>
- <div ng-bind-html="comment.html" class="comment-body">
+ <div ng-bind-html="comment.html" ng-if="::comment.active" class="comment-body">
+ </div>
+ <div ng-if="::!comment.active" class="comment-body">
+ {{ trans('entites.comment_deleted') }}
</div>
<div class="comment-actions">
- <ul>
+ <ul ng-if="!comment.is_hidden">
<li ng-if="::(level < 3 && vm.canComment())"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" is-reply="true">Reply</a></li>
<li ng-if="::vm.canEdit(comment)"><a href="#" comment-reply-link no-comment-reply-dupe="true" comment="comment" >Edit</a></li>
+ <li ng-if="::vm.canEdit(comment, true)"><a href="#" comment-delete-link comment="comment" >Delete</a></li>
<li>Created <a title="@{{::comment.created.day_time_str}}" href="#comment-@{{::comment.id}}-@{{::pageId}}">@{{::comment.created.diff}}</a></li>
- <li ng-if="comment.updated"><span title="@{{comment.updated.day_time_str}}">Updated @{{comment.updated.diff}} by
- <a href="@{{comment.updated_by.profile_url}}">@{{comment.updated_by.name}}</a></span></li>
+ <li ng-if="::comment.updated"><span title="@{{::comment.updated.day_time_str}}">Updated @{{::comment.updated.diff}} by
+ <a href="@{{::comment.updated_by.profile_url}}">@{{::comment.updated_by.name}}</a></span></li>
</ul>
</div>
<div class="comment-box" ng-repeat="comment in comments = comment.sub_comments track by comment.id" ng-init="level = level + 1">