diff --git a/modules/core/client/app/trans-string-cn.js b/modules/core/client/app/trans-string-cn.js index 50268436..3d52b2a5 100644 --- a/modules/core/client/app/trans-string-cn.js +++ b/modules/core/client/app/trans-string-cn.js @@ -142,13 +142,24 @@ TORRENT_SEED_USERS: '做种用户列表', TORRENT_LEECHER_USERS: '下载用户列表', TORRENT_FINISHED_USERS: '完成用户列表', + + //comment USER_COMMENT_LIST: '用户评论', POST_NEW_COMMENT: '发表新评论', + EDIT_COMMENT: '编辑评论', SUBMIT_COMMENT: '提交评论', + SUBMIT_CANCEL: '取消', MARKDOWN_LINK: '排版支持 Markdown 全部格式', COMMENT_REPLY_BUTTON: '@ 楼主并回复', - COMMENT_REPLY_DELETE: '删除回复', - COMMENT_REPLY_EDIT: '编辑回复', + COMMENT_REPLY_DELETE: '删除', + COMMENT_REPLY_EDIT: '编辑', + COMMENT_EDITED_INFO: '编辑于', + COMMENT_CONFIRM_OK: '删除', + COMMENT_CONFIRM_CANCEL: '取消', + COMMENT_CONFIRM_HEADER_TEXT: '删除确认', + COMMENT_CONFIRM_BODY_TEXT: '你确定要删除这条评论吗?', + COMMENT_EDIT_ICON_TITLE: '编辑回复', + COMMENT_DELETE_ICON_TITLE: '删除回复', //TorrentsUploadsController TORRENTS_UPLOAD_SUCCESSFULLY: '文件上传成功', diff --git a/modules/core/client/app/trans-string-en.js b/modules/core/client/app/trans-string-en.js index 5082d4ba..d858310b 100644 --- a/modules/core/client/app/trans-string-en.js +++ b/modules/core/client/app/trans-string-en.js @@ -142,13 +142,25 @@ TORRENT_SEED_USERS: 'Seed Users', TORRENT_LEECHER_USERS: 'Leecher Users', TORRENT_FINISHED_USERS: 'Finished Users', + + //comment USER_COMMENT_LIST: 'User Comments List', POST_NEW_COMMENT: 'Post New Comment', + EDIT_COMMENT: 'Edit Comment', SUBMIT_COMMENT: 'Submit Comment', + SUBMIT_CANCEL: 'Cancel', MARKDOWN_LINK: 'Styling with Markdown is supported', COMMENT_REPLY_BUTTON: '@ & reply', - COMMENT_REPLY_DELETE: 'Delete reply', - COMMENT_REPLY_EDIT: 'Edit reply', + COMMENT_REPLY_DELETE: 'Delete', + COMMENT_REPLY_EDIT: 'Edit', + COMMENT_EDITED_INFO: 'Edit at', + COMMENT_CONFIRM_OK: 'Delete', + COMMENT_CONFIRM_CANCEL: 'Cancel', + COMMENT_CONFIRM_HEADER_TEXT: 'Delete Confirm', + COMMENT_CONFIRM_BODY_TEXT: 'Are you sure want to delete this comment?', + COMMENT_CONFIRM_BODY_TEXT_REPLY: 'Are you sure want to delete this comment reply?', + COMMENT_EDIT_ICON_TITLE: 'Edit this reply', + COMMENT_DELETE_ICON_TITLE: 'Delete this reply', //TorrentsUploadsController & views TORRENTS_UPLOAD_SUCCESSFULLY: 'Successfully uploads file', diff --git a/modules/core/client/directives/scrollIf.client.directive.js b/modules/core/client/directives/scrollIf.client.directive.js index 4cee884b..98b0c9e3 100644 --- a/modules/core/client/directives/scrollIf.client.directive.js +++ b/modules/core/client/directives/scrollIf.client.directive.js @@ -19,7 +19,7 @@ if (value) { //element[0].scrollIntoView({block: 'end', behavior: 'smooth'}); //$uiViewScroll(element); - window.scrollTo(0, element[0].offsetTop - 60) + window.scrollTo(0, element[0].offsetTop - 60); } }); } diff --git a/modules/core/client/less/comment.less b/modules/core/client/less/comment.less index 54247bdd..a5644c2b 100644 --- a/modules/core/client/less/comment.less +++ b/modules/core/client/less/comment.less @@ -101,7 +101,11 @@ min-height: 42px; .timeline-comment-body-text { padding-top: 10px; - padding-bottom: 10px; + } + .timeline-comment-body-edited-text { + font-size: 12px; + color: lighten(@gray-base, 60%); + margin-right: 15px; } .timeline-comment-sub-list { border-top: 1px solid #d1d5da; @@ -114,6 +118,24 @@ p { margin: 5px 0; } + .edit-button { + font-size: 12px; + margin-left: 10px; + cursor: pointer; + color: @brand-primary; + &:hover { + color: @brand-danger; + } + } + .delete-button { + font-size: 12px; + margin-left: 5px; + cursor: pointer; + color: @brand-primary; + &:hover { + color: @brand-danger; + } + } } .timeline-comment-sub-avatar { img { diff --git a/modules/torrents/client/controllers/torrent-info.client.controller.js b/modules/torrents/client/controllers/torrent-info.client.controller.js index 884a55c7..9471d84c 100644 --- a/modules/torrents/client/controllers/torrent-info.client.controller.js +++ b/modules/torrents/client/controllers/torrent-info.client.controller.js @@ -6,10 +6,10 @@ .controller('TorrentsInfoController', TorrentsInfoController); TorrentsInfoController.$inject = ['$scope', '$state', '$stateParams', '$translate', 'Authentication', 'Notification', 'TorrentsService', - 'MeanTorrentConfig', 'DownloadService', '$sce', '$filter', 'CommentsService']; + 'MeanTorrentConfig', 'DownloadService', '$sce', '$filter', 'CommentsService', 'ModalConfirmService']; function TorrentsInfoController($scope, $state, $stateParams, $translate, Authentication, Notification, TorrentsService, MeanTorrentConfig, - DownloadService, $sce, $filter, CommentsService) { + DownloadService, $sce, $filter, CommentsService, ModalConfirmService) { var vm = this; vm.user = Authentication.user; vm.announce = MeanTorrentConfig.meanTorrentConfig.announce; @@ -191,6 +191,11 @@ * submitComment */ vm.submitComment = function () { + if (vm.reply_action === 'edit') { + vm.submitEditComment(); + return; + } + var comment = new CommentsService({ _torrentId: vm.torrentLocalInfo._id, _commentId: vm.comment_to_id, @@ -209,17 +214,60 @@ if (vm.comment_to_id) { vm.scrollToId = vm.comment_to_id; } - vm.new_comment_content = ''; - vm.comment_to_id = undefined; - vm.comment_to_at = undefined; + vm.submitInit(); vm.torrentLocalInfo = res; } function errorCallback(res) { + vm.submitInit(); vm.error_msg = res.data.message; Notification.error({message: res.data.message, title: ' Comment created error!'}); } + }; + /** + * submitEditComment + */ + vm.submitEditComment = function () { + var comment = new CommentsService({ + _torrentId: vm.torrentLocalInfo._id, + _commentId: vm.comment_to_id, + _subCommentId: vm.comment_to_sub_id, + comment: vm.new_comment_content + }); + + comment.$update(function (response) { + successCallback(response); + }, function (errorResponse) { + errorCallback(errorResponse); + }); + + function successCallback(res) { + Notification.success({message: ' Comment edited successfully!'}); + + if (vm.comment_to_id) { + vm.scrollToId = vm.comment_to_id; + } + vm.submitInit(); + vm.torrentLocalInfo = res; + } + + function errorCallback(res) { + vm.submitInit(); + vm.error_msg = res.data.message; + Notification.error({message: res.data.message, title: ' Comment edited error!'}); + } + }; + + /** + * submitCancel + */ + vm.submitInit = function () { + vm.new_comment_content = ''; + vm.comment_to_id = undefined; + vm.comment_to_sub_id = undefined; + vm.comment_to_at = undefined; + vm.reply_action = undefined; }; /** @@ -251,11 +299,18 @@ */ vm.getSubMarkdown = function (sitem) { var mk = ' ' + '- [@' + sitem.user.displayName + '](@' + sitem.user.displayName + ') '; - mk += '' + $filter('date')(sitem.createdat, 'yyyy-MM-dd hh:mm:ss') + ''; + mk += '' + $filter('date')(sitem.createdat, 'yyyy-MM-dd HH:mm:ss') + ''; + mk += ''; + mk += ''; return mk; }; + /** + * markLinkClick + * @param evt + * @param citem + */ vm.markLinkClick = function (evt, citem) { if (evt.originalEvent.srcElement.innerText[0] === '@') { evt.preventDefault(); @@ -267,5 +322,110 @@ } }; + + /** + * editComment + * @param citem + */ + vm.editComment = function (citem) { + vm.comment_to_id = citem._id; + vm.reply_action = 'edit'; + + vm.new_comment_content = citem.comment; + angular.element('.new_comment_textarea').trigger('focus'); + }; + + /** + * editSubComment + * @param citem + * @param sitem + */ + vm.editSubComment = function (citem, sitem) { + vm.comment_to_id = citem._id; + vm.comment_to_sub_id = sitem._id; + vm.reply_action = 'edit'; + + vm.new_comment_content = sitem.comment; + angular.element('.new_comment_textarea').trigger('focus'); + }; + + /** + * deleteComment + * @param citem + */ + vm.deleteComment = function (citem) { + var modalOptions = { + closeButtonText: $translate.instant('COMMENT_CONFIRM_CANCEL'), + actionButtonText: $translate.instant('COMMENT_CONFIRM_OK'), + headerText: $translate.instant('COMMENT_CONFIRM_HEADER_TEXT'), + bodyText: $translate.instant('COMMENT_CONFIRM_BODY_TEXT') + }; + + ModalConfirmService.showModal({}, modalOptions) + .then(function (result) { + var comment = new CommentsService({ + _torrentId: vm.torrentLocalInfo._id, + _commentId: citem._id + }); + + comment.$remove(function (response) { + successCallback(response); + }, function (errorResponse) { + errorCallback(errorResponse); + }); + + function successCallback(res) { + Notification.success({message: ' Comment deleted successfully!'}); + + vm.submitInit(); + vm.torrentLocalInfo = res; + } + + function errorCallback(res) { + vm.error_msg = res.data.message; + Notification.error({message: res.data.message, title: ' Comment deleted error!'}); + } + }); + }; + + /** + * deleteSubComment + * @param citem + */ + vm.deleteSubComment = function (citem, sitem) { + var modalOptions = { + closeButtonText: $translate.instant('COMMENT_CONFIRM_CANCEL'), + actionButtonText: $translate.instant('COMMENT_CONFIRM_OK'), + headerText: $translate.instant('COMMENT_CONFIRM_HEADER_TEXT'), + bodyText: $translate.instant('COMMENT_CONFIRM_BODY_TEXT_REPLY') + }; + + ModalConfirmService.showModal({}, modalOptions) + .then(function (result) { + var comment = new CommentsService({ + _torrentId: vm.torrentLocalInfo._id, + _commentId: citem._id, + _subCommentId: sitem._id + }); + + comment.$remove(function (response) { + successCallback(response); + }, function (errorResponse) { + errorCallback(errorResponse); + }); + + function successCallback(res) { + Notification.success({message: ' Comment reply deleted successfully!'}); + + vm.submitInit(); + vm.torrentLocalInfo = res; + } + + function errorCallback(res) { + vm.error_msg = res.data.message; + Notification.error({message: res.data.message, title: ' Comment reply deleted error!'}); + } + }); + }; } }()); diff --git a/modules/torrents/client/views/view-torrent.client.view.html b/modules/torrents/client/views/view-torrent.client.view.html index 9c505e78..75f59e7a 100644 --- a/modules/torrents/client/views/view-torrent.client.view.html +++ b/modules/torrents/client/views/view-torrent.client.view.html @@ -169,10 +169,13 @@ ) - {{item.createdat | date:'yyyy-MM-dd hh:mm:ss'}} + {{item.createdat | date:'yyyy-MM-dd HH:mm:ss'}}
[ {{item.editedby}} {{ 'COMMENT_EDITED_INFO' | translate}} {{item.editedat | date:'yyyy-MM-dd HH:mm:ss'}} ]
+