Merge pull request #5337 from RocketChat/livechat-fix-current-chats

Fix livechat current chats screen
pull/5344/merge
Gabriel Engel 9 years ago committed by GitHub
commit c60e3789e2
  1. 2
      packages/rocketchat-i18n/i18n/en.i18n.json
  2. 2
      packages/rocketchat-i18n/i18n/pt.i18n.json
  3. 17
      packages/rocketchat-livechat/client/views/app/livechatCurrentChats.html
  4. 24
      packages/rocketchat-livechat/client/views/app/livechatCurrentChats.js
  5. 43
      packages/rocketchat-livechat/server/publications/livechatRooms.js

@ -332,6 +332,8 @@
"Custom_Translations_Description": "Should be a valid JSON where keys are languages containing a dictionary of key and translations. Example:</br><code>{\n\t\"en\": {\n\t\t\"key\": \"translation\"\n\t},\n\t\"pt\": {\n\t\t\"key\": \"tradução\"\n\t}\n}</code> ",
"Dashboard": "Dashboard",
"Date": "Date",
"Date_From": "From",
"Date_to": "to",
"days": "days",
"DB_Migration": "Database Migration",
"DB_Migration_Date": "Database Migration Date",

@ -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",

@ -24,16 +24,13 @@
<option value="closed">{{_ "Closed"}}</option>
</select>
</div>
<!--Added by Deepankar-->
<div class="input-group input-daterange" data-date-autoclose="true" data-date-todayHighlight="true" data-provide="datepicker" >
<span class="input-group-addon">From</span>
<input type="text" class="form-control" id="from" name="from" >
<span class="input-group-addon">to</span>
<input type="text" class="form-control" id="to" name="to">
<button class="button">{{_ "Filter"}}</button>
</div>
<!--Added by Deepankar-->
<div class="form-group input-daterange">
<span class="input-group-addon">{{_ "Date_From"}}</span>
<input type="text" class="form-control" id="from" name="from" >
<span class="input-group-addon">{{_ "Date_to"}}</span>
<input type="text" class="form-control" id="to" name="to">
</div>
<button class="button">{{_ "Filter"}}</button>
</form>
</fieldset>
<div class="list">

@ -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()
});
});

@ -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();
});
});

Loading…
Cancel
Save