feat(messages): delete selected messages

This commit is contained in:
OldHawk
2017-06-17 19:33:30 +08:00
parent 7ee46bd860
commit 2b2b6c0ced
6 changed files with 90 additions and 11 deletions

View File

@@ -495,6 +495,14 @@
MESSAGE_TYPE_NOTICE: 'Notice message',
MESSAGE_SEND_SUCCESSFULLY: 'Message send successfully',
MESSAGE_SEND_FAILED: 'Message send failed',
MESSAGE_DELETED_SUCCESSFULLY: 'Message deleted successfully',
MESSAGE_DELETED_ERROR: 'Message deleted failed',
MESSAGE_DELETE_CONFIRM_OK: 'Delete',
MESSAGE_DELETE_CONFIRM_CANCEL: 'Cancel',
MESSAGE_DELETE_CONFIRM_HEADER_TEXT: 'Delete Confirm',
MESSAGE_DELETE_CONFIRM_BODY_TEXT_MANY: 'Are you sure want to delete these messages?',
MESSAGE_DELETE_CONFIRM_BODY_TEXT: 'Are you sure want to delete this message?',
//chat view
CHAT_USERS_LIST: 'Users List',

View File

@@ -495,6 +495,14 @@
MESSAGE_TYPE_NOTICE: '系统通知',
MESSAGE_SEND_SUCCESSFULLY: '消息发送成功',
MESSAGE_SEND_FAILED: '消息发送失败',
MESSAGE_DELETED_SUCCESSFULLY: '消息删除成功',
MESSAGE_DELETED_ERROR: '消息删除失败',
MESSAGE_DELETE_CONFIRM_OK: '删除',
MESSAGE_DELETE_CONFIRM_CANCEL: '取消',
MESSAGE_DELETE_CONFIRM_HEADER_TEXT: '删除确认',
MESSAGE_DELETE_CONFIRM_BODY_TEXT_MANY: '您确定要删除选中的这些消息?',
MESSAGE_DELETE_CONFIRM_BODY_TEXT: '您确定要删除该消息?',
//chat view
CHAT_USERS_LIST: '用户列表',

View File

@@ -6,14 +6,15 @@
.controller('MessageController', MessageController);
MessageController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$filter', 'NotifycationService', '$stateParams', 'MessagesService',
'MeanTorrentConfig'];
'MeanTorrentConfig', 'ModalConfirmService'];
function MessageController($scope, $state, $translate, $timeout, Authentication, $filter, NotifycationService, $stateParams, MessagesService,
MeanTorrentConfig) {
MeanTorrentConfig, ModalConfirmService) {
var vm = this;
vm.messageConfig = MeanTorrentConfig.meanTorrentConfig.messages;
vm.user = Authentication.user;
vm.messageFields = {};
vm.deleteList = [];
/**
* If user is not signed in then redirect back home
@@ -83,7 +84,7 @@
*/
vm.buildPager = function () {
vm.pagedItems = [];
vm.itemsPerPage = 15;
vm.itemsPerPage = 10;
vm.currentPage = 1;
vm.figureOutItemsToDisplay();
};
@@ -112,9 +113,45 @@
* deleteSelected
*/
vm.deleteSelected = function () {
vm.deleteList = [];
var modalOptions = {
closeButtonText: $translate.instant('MESSAGE_DELETE_CONFIRM_CANCEL'),
actionButtonText: $translate.instant('MESSAGE_DELETE_CONFIRM_OK'),
headerText: $translate.instant('MESSAGE_DELETE_CONFIRM_HEADER_TEXT'),
bodyText: $translate.instant('MESSAGE_DELETE_CONFIRM_BODY_TEXT')
};
angular.forEach(vm.selected, function (item, id) {
console.log(id + '-' + item);
if (item) {
vm.deleteList.push(id);
}
});
if (vm.deleteList.length > 0) {
ModalConfirmService.showModal({}, modalOptions)
.then(function (result) {
MessagesService.remove({
ids: vm.deleteList
}, function (res) {
//$state.reload();
var s = [];
angular.forEach(vm.messages, function (m) {
if (vm.deleteList.indexOf(m._id) !== -1) {
s.push(m);
}
});
angular.forEach(s, function (m) {
vm.messages.splice(vm.messages.indexOf(m), 1);
});
vm.figureOutItemsToDisplay();
NotifycationService.showSuccessNotify('MESSAGE_DELETED_SUCCESSFULLY');
}, function (res) {
NotifycationService.showErrorNotify(res.data.message, 'MESSAGE_DELETED_ERROR');
});
});
}
};
}
}());

View File

@@ -1,18 +1,15 @@
<section ng-controller="MessageController as vm" ng-init="vm.getMessageList()">
<div class="row margin-top-20">
<div class="col-md-10 col-md-offset-1 messages-list" id="top_of_messages_list">
<div class="messages-list">
<div class="row margin-bottom-20">
<div class="col-xs-12 col-md-3">
<div class="col-xs-8 col-md-9">
<h4>{{'MESSAGES_BOX' | translate}}</h4>
</div>
<div class="col-xs-7 col-md-3 col-md-offset-4">
<div class="col-xs-4 col-md-3">
<input class="form-control" type="text" ng-model="vm.search" placeholder="Search"
ng-change="vm.figureOutItemsToDisplay()"/>
</div>
<div class="col-xs-5 col-md-2">
<button class="btn btn-success btn-block" ng-click="vm.figureOutItemsToDisplay()">{{ 'BUTTON_SEARCH' | translate }}</button>
</div>
</div>
<div class="pagination-div-top">

View File

@@ -79,7 +79,35 @@ exports.update = function (req, res) {
* @param res
*/
exports.delete = function (req, res) {
if (req.params.messageId) {
var message = req.message;
message.remove(function (err) {
if (err) {
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
res.json(message);
}
});
} else {
if (req.query.ids) {
Message.remove({
_id: {$in: req.query.ids}
}, function (err) {
if (err) {
return res.status(422).send({
message: errorHandler.getErrorMessage(err)
});
} else {
return res.status(200).send({
message: 'delete successfully'
});
}
});
}
}
};
/**

View File

@@ -9,7 +9,8 @@ var messagesPolicy = require('../policies/messages.server.policy'),
module.exports = function (app) {
app.route('/api/messages').all(messagesPolicy.isAllowed)
.get(messages.list)
.post(messages.create);
.post(messages.create)
.delete(messages.delete);
app.route('/api/messages/:messageId').all(messagesPolicy.isAllowed)
.get(messages.listReply)