diff --git a/packages/rocketchat-i18n/i18n/en.i18n.json b/packages/rocketchat-i18n/i18n/en.i18n.json index a83fa55f540..0179dcfd64b 100644 --- a/packages/rocketchat-i18n/i18n/en.i18n.json +++ b/packages/rocketchat-i18n/i18n/en.i18n.json @@ -332,6 +332,8 @@ "Custom_Translations_Description": "Should be a valid JSON where keys are languages containing a dictionary of key and translations. Example:
{\n\t\"en\": {\n\t\t\"key\": \"translation\"\n\t},\n\t\"pt\": {\n\t\t\"key\": \"tradução\"\n\t}\n} ", "Dashboard": "Dashboard", "Date": "Date", + "Date_From": "From", + "Date_to": "to", "days": "days", "DB_Migration": "Database Migration", "DB_Migration_Date": "Database Migration Date", diff --git a/packages/rocketchat-i18n/i18n/pt.i18n.json b/packages/rocketchat-i18n/i18n/pt.i18n.json index f3fa0c3400b..697693242b1 100644 --- a/packages/rocketchat-i18n/i18n/pt.i18n.json +++ b/packages/rocketchat-i18n/i18n/pt.i18n.json @@ -307,6 +307,8 @@ "Custom_Script_Logged_Out": "Script Personalizado para usuários não logados", "Dashboard": "Dashboard", "Date": "Data", + "Date_From": "De", + "Date_to": "até", "days": "dias", "DB_Migration": "Migração de banco de dados", "DB_Migration_Date": "Data da migração do banco de dados", diff --git a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html index 090ff0e7d14..9b66c52ac3f 100644 --- a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html +++ b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html @@ -24,16 +24,13 @@ - -
- From - - to - - - -
- +
+ {{_ "Date_From"}} + + {{_ "Date_to"}} + +
+
diff --git a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js index 57bcdbd87b9..810391ba94b 100644 --- a/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js +++ b/packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js @@ -1,8 +1,10 @@ import moment from 'moment'; +const LivechatRoom = new Mongo.Collection('livechatRoom'); + Template.livechatCurrentChats.helpers({ livechatRoom() { - return ChatRoom.find({ t: 'l' }, { sort: { ts: -1 } }); + return LivechatRoom.find({ t: 'l' }, { sort: { ts: -1 } }); }, startedAt() { return moment(this.ts).format('L LTS'); @@ -38,6 +40,18 @@ Template.livechatCurrentChats.events({ } }); + if (!_.isEmpty(filter.from)) { + filter.from = moment(filter.from, moment.localeData().longDateFormat('L')).toDate(); + } else { + delete filter.from; + } + + if (!_.isEmpty(filter.to)) { + filter.to = moment(filter.to, moment.localeData().longDateFormat('L')).toDate(); + } else { + delete filter.to; + } + instance.filter.set(filter); instance.limit.set(20); } @@ -53,3 +67,11 @@ Template.livechatCurrentChats.onCreated(function() { this.subscribe('livechat:rooms', this.filter.get(), 0, this.limit.get()); }); }); + +Template.livechatCurrentChats.onRendered(function() { + this.$('.input-daterange').datepicker({ + autoclose: true, + todayHighlight: true, + format: moment.localeData().longDateFormat('L').toLowerCase() + }); +}); diff --git a/packages/rocketchat-livechat/server/publications/livechatRooms.js b/packages/rocketchat-livechat/server/publications/livechatRooms.js index 143bf8d431c..b05e442fa9c 100644 --- a/packages/rocketchat-livechat/server/publications/livechatRooms.js +++ b/packages/rocketchat-livechat/server/publications/livechatRooms.js @@ -11,8 +11,8 @@ Meteor.publish('livechat:rooms', function(filter = {}, offset = 0, limit = 20) { name: Match.Maybe(String), // room name to filter agent: Match.Maybe(String), // agent _id who is serving status: Match.Maybe(String), // either 'opened' or 'closed' - from: Match.Maybe(String), - to: Match.Maybe(String) + from: Match.Maybe(Date), + to: Match.Maybe(Date) }); let query = {}; @@ -29,13 +29,38 @@ Meteor.publish('livechat:rooms', function(filter = {}, offset = 0, limit = 20) { query.open = { $exists: false }; } } - if (filter.from && filter.to) { - var StartDate = new Date(filter.from); - var ToDate = new Date(filter.to); - ToDate.setDate(ToDate.getDate() + 1); - query['ts'] = { $gt: StartDate, $lt: ToDate }; + if (filter.from) { + query.ts = { + $gte: filter.from + }; } + if (filter.to) { + filter.to.setDate(filter.to.getDate() + 1); + filter.to.setSeconds(filter.to.getSeconds() - 1); - // CACHE: can we stop using publications here? - return RocketChat.models.Rooms.findLivechat(query, offset, limit); + if (!query.ts) { + query.ts = {}; + } + query.ts.$lte = filter.to; + } + + let self = this; + + let handle = RocketChat.models.Rooms.findLivechat(query, offset, limit).observeChanges({ + added(id, fields) { + self.added('livechatRoom', id, fields); + }, + changed(id, fields) { + self.changed('livechatRoom', id, fields); + }, + removed(id) { + self.removed('livechatRoom', id); + } + }); + + this.ready(); + + this.onStop(() => { + handle.stop(); + }); });