From bf2e360e301b5f77e1a94abe8db099a9b1f01e67 Mon Sep 17 00:00:00 2001 From: knrt10 Date: Wed, 3 Apr 2019 19:28:03 +0530 Subject: [PATCH 1/8] Added feature close multiple rooms --- app/livechat/client/views/app/livechatCurrentChats.html | 1 - app/livechat/client/views/app/livechatCurrentChats.js | 4 +++- packages/rocketchat-i18n/i18n/en.i18n.json | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/livechat/client/views/app/livechatCurrentChats.html b/app/livechat/client/views/app/livechatCurrentChats.html index c546543f7e4b6..7b935dfae3df2 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.html +++ b/app/livechat/client/views/app/livechatCurrentChats.html @@ -111,7 +111,6 @@ -
diff --git a/app/livechat/client/views/app/livechatCurrentChats.js b/app/livechat/client/views/app/livechatCurrentChats.js index 0ce180ad5c01f..425895575b9fc 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.js +++ b/app/livechat/client/views/app/livechatCurrentChats.js @@ -20,7 +20,7 @@ Template.livechatCurrentChats.helpers({ return Template.instance().ready.get(); }, livechatRoom() { - return LivechatRoom.find({ t: 'l' }, { sort: { ts: -1 } }); + return Template.instance().livechatRoom.get(); }, startedAt() { return moment(this.ts).format('L LTS'); @@ -275,6 +275,8 @@ Template.livechatCurrentChats.onCreated(function() { this.customFields.set(customFields); } }); + + this.livechatRoom.set(LivechatRoom.find({ t: 'l' }, { sort: { ts: -1 } })); }); Template.livechatCurrentChats.onRendered(function() { diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 97b906c016e5b..f62a81c978992 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -1038,6 +1038,7 @@ "Decode_Key": "Decode Key", "Default": "Default", "Delete": "Delete", + "Delete_all_closed_chats": "Delete all closed chats", "delete-c": "Delete Public Channels", "delete-c_description": "Permission to delete public channels", "delete-d": "Delete Direct Messages", From 9a5cdd1042193e40071d3df89319d548490b63d7 Mon Sep 17 00:00:00 2001 From: knrt10 Date: Fri, 4 Oct 2019 18:00:34 +0530 Subject: [PATCH 2/8] Fixed and rebased code Signed-off-by: knrt10 --- .../views/app/livechatCurrentChats.html | 8 ++++- .../client/views/app/livechatCurrentChats.js | 35 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/livechat/client/views/app/livechatCurrentChats.html b/app/livechat/client/views/app/livechatCurrentChats.html index 7b935dfae3df2..6124c0f0d0f64 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.html +++ b/app/livechat/client/views/app/livechatCurrentChats.html @@ -107,7 +107,13 @@
- + +
+ {{#if closedChats}} + + {{else}} +   + {{/if}}
diff --git a/app/livechat/client/views/app/livechatCurrentChats.js b/app/livechat/client/views/app/livechatCurrentChats.js index 425895575b9fc..21626b24e3342 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.js +++ b/app/livechat/client/views/app/livechatCurrentChats.js @@ -5,9 +5,10 @@ import { FlowRouter } from 'meteor/kadira:flow-router'; import { Template } from 'meteor/templating'; import { Meteor } from 'meteor/meteor'; import { Random } from 'meteor/random'; +import toastr from 'toastr'; import { modal, call, popover } from '../../../../ui-utils'; -import { t } from '../../../../utils/client'; +import { t, handleError } from '../../../../utils/client'; import { LivechatDepartment } from '../../collections/LivechatDepartment'; import { LivechatRoom } from '../../collections/LivechatRoom'; import './livechatCurrentChats.html'; @@ -64,6 +65,10 @@ Template.livechatCurrentChats.helpers({ tagId() { return this; }, + closedChats() { + const anyClosedRoom = Template.instance().livechatRoom.get().map((room) => !room.open); + return anyClosedRoom.includes(true); + }, }); Template.livechatCurrentChats.events({ @@ -73,6 +78,33 @@ Template.livechatCurrentChats.events({ 'click .js-load-more'(event, instance) { instance.limit.set(instance.limit.get() + 20); }, + 'click .delete-all-closed-chats'(event, instance) { + event.preventDefault(); + event.stopPropagation(); + + modal.open({ + title: t('Are_you_sure'), + type: 'warning', + showCancelButton: true, + confirmButtonColor: '#DD6B55', + confirmButtonText: t('Yes'), + cancelButtonText: t('Cancel'), + closeOnConfirm: true, + html: false, + }, () => { + instance.livechatRoom.get().forEach((room) => { + if (!room.open) { + Meteor.call('livechat:removeRoom', room._id, function(error/* , result*/) { + if (error) { + return handleError(error); + } + }); + } + }); + // Now all rooms Deleted, show success message + toastr.success(t('All closed rooms deleted')); + }); + }, 'click .add-filter-button'(event, instance) { event.preventDefault(); @@ -251,6 +283,7 @@ Template.livechatCurrentChats.onCreated(function() { this.ready = new ReactiveVar(false); this.limit = new ReactiveVar(20); this.filter = new ReactiveVar({}); + this.livechatRoom = new ReactiveVar([]); this.selectedAgents = new ReactiveVar([]); this.customFilters = new ReactiveVar([]); this.customFields = new ReactiveVar([]); From 33255d53e8f4edac779917741baaea0246cb158e Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 11 Oct 2019 18:29:38 -0300 Subject: [PATCH 3/8] Improvements on the new option to remove all closed livechat rooms. --- app/livechat/client/views/app/livechatCurrentChats.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/livechat/client/views/app/livechatCurrentChats.js b/app/livechat/client/views/app/livechatCurrentChats.js index 96aa0085c809b..919cb14cef8c2 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.js +++ b/app/livechat/client/views/app/livechatCurrentChats.js @@ -178,7 +178,8 @@ Template.livechatCurrentChats.events({ return; } - return instance.departments.get(); + const departments = instance.departments.get(); + return departments && departments.map((d) => d._id); } const config = { From dacf18f352ef5cc7d76ddacdedfb1fea43e10a0a Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 11 Oct 2019 18:31:45 -0300 Subject: [PATCH 4/8] Add missing semicolon. --- app/livechat/client/views/app/livechatCurrentChats.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/livechat/client/views/app/livechatCurrentChats.js b/app/livechat/client/views/app/livechatCurrentChats.js index 919cb14cef8c2..93e096b47cce5 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.js +++ b/app/livechat/client/views/app/livechatCurrentChats.js @@ -180,7 +180,7 @@ Template.livechatCurrentChats.events({ const departments = instance.departments.get(); return departments && departments.map((d) => d._id); - } + }; const config = { popoverClass: 'livechat-current-chats-add-filter', From c8037e0b313a0f3b66460eeddd104febec79260a Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 11 Oct 2019 18:36:54 -0300 Subject: [PATCH 5/8] Fix translations. --- app/livechat/client/views/app/livechatCurrentChats.html | 2 +- app/livechat/client/views/app/livechatCurrentChats.js | 6 +----- packages/rocketchat-i18n/i18n/en.i18n.json | 2 +- packages/rocketchat-i18n/i18n/pt-BR.i18n.json | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/livechat/client/views/app/livechatCurrentChats.html b/app/livechat/client/views/app/livechatCurrentChats.html index 5550da0148058..5c65baace00a4 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.html +++ b/app/livechat/client/views/app/livechatCurrentChats.html @@ -109,7 +109,7 @@
{{#if hasPopoverPermissions}} - {{/if}} diff --git a/app/livechat/client/views/app/livechatCurrentChats.js b/app/livechat/client/views/app/livechatCurrentChats.js index 93e096b47cce5..c22992743e82d 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.js +++ b/app/livechat/client/views/app/livechatCurrentChats.js @@ -66,10 +66,6 @@ Template.livechatCurrentChats.helpers({ tagId() { return this; }, - closedChats() { - const anyClosedRoom = Template.instance().livechatRoom.get().map((room) => !room.open); - return anyClosedRoom.includes(true); - }, hasPopoverPermissions() { return hasAtLeastOnePermission(['remove-closed-livechat-rooms']); }, @@ -210,7 +206,7 @@ Template.livechatCurrentChats.events({ } if (result) { - toastr.success(TAPi18n.__('All_closed_rooms_have_been_removed')); + toastr.success(TAPi18n.__('All_closed_chats_have_been_removed')); } }); }); diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 58e4a9e838e8e..9fc955cd59ab8 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -251,7 +251,7 @@ "All": "All", "All_added_tokens_will_be_required_by_the_user": "All added tokens will be required by the user", "All_channels": "All channels", - "All_closed_rooms_have_been_removed": "All closed rooms have been removed", + "All_closed_chats_have_been_removed": "All closed rooms have been removed", "All_logs": "All logs", "All_messages": "All messages", "All_users": "All users", diff --git a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json index 7b6cbfd53126f..e352bb0d5a234 100644 --- a/packages/rocketchat-i18n/i18n/pt-BR.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt-BR.i18n.json @@ -242,7 +242,7 @@ "All": "Todos", "All_added_tokens_will_be_required_by_the_user": "Todos os tokens adicionados ser exigidos ao usuário", "All_channels": "Todos os canais", - "All_closed_rooms_have_been_removed": "Todas as salas fechadas foram removidas", + "All_closed_chats_have_been_removed": "Todas as salas fechadas foram removidas", "All_logs": "Todos os logs", "All_messages": "Todas as mensagens", "All_users": "Todos usuários", From 1065b595e07c81aec0e15e93e75897085bc0e365 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 11 Oct 2019 18:40:33 -0300 Subject: [PATCH 6/8] Fix translations. --- packages/rocketchat-i18n/i18n/en.i18n.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index 9fc955cd59ab8..2277df3b3d23f 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -251,7 +251,7 @@ "All": "All", "All_added_tokens_will_be_required_by_the_user": "All added tokens will be required by the user", "All_channels": "All channels", - "All_closed_chats_have_been_removed": "All closed rooms have been removed", + "All_closed_chats_have_been_removed": "All closed chats have been removed", "All_logs": "All logs", "All_messages": "All messages", "All_users": "All users", From 7faff789f506ff9357e5f0b417b060d1df35dbd9 Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 11 Oct 2019 18:50:14 -0300 Subject: [PATCH 7/8] Remove console.log. --- app/models/server/models/LivechatRooms.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/app/models/server/models/LivechatRooms.js b/app/models/server/models/LivechatRooms.js index 9613bdbe246cc..94deba0930841 100644 --- a/app/models/server/models/LivechatRooms.js +++ b/app/models/server/models/LivechatRooms.js @@ -241,9 +241,6 @@ export class LivechatRooms extends Base { ...Array.isArray(departmentIds) && departmentIds.length > 0 && { departmentId: { $in: departmentIds } }, }; - console.log('query findClosedRooms'); - console.log(query); - return this.find(query, options); } From d18220577b95aeb2e8c6842bc8a59cfceda1212d Mon Sep 17 00:00:00 2001 From: Renato Becker Date: Fri, 11 Oct 2019 18:53:15 -0300 Subject: [PATCH 8/8] Remove unused method. --- .../client/views/app/livechatCurrentChats.js | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/app/livechat/client/views/app/livechatCurrentChats.js b/app/livechat/client/views/app/livechatCurrentChats.js index c22992743e82d..17988b1ded0d2 100644 --- a/app/livechat/client/views/app/livechatCurrentChats.js +++ b/app/livechat/client/views/app/livechatCurrentChats.js @@ -78,33 +78,6 @@ Template.livechatCurrentChats.events({ 'click .js-load-more'(event, instance) { instance.limit.set(instance.limit.get() + 20); }, - 'click .delete-all-closed-chats'(event, instance) { - event.preventDefault(); - event.stopPropagation(); - - modal.open({ - title: t('Are_you_sure'), - type: 'warning', - showCancelButton: true, - confirmButtonColor: '#DD6B55', - confirmButtonText: t('Yes'), - cancelButtonText: t('Cancel'), - closeOnConfirm: true, - html: false, - }, () => { - instance.livechatRoom.get().forEach((room) => { - if (!room.open) { - Meteor.call('livechat:removeRoom', room._id, function(error/* , result*/) { - if (error) { - return handleError(error); - } - }); - } - }); - // Now all rooms Deleted, show success message - toastr.success(t('All closed rooms deleted')); - }); - }, 'click .add-filter-button'(event, instance) { event.preventDefault();