Change timers update strategy at operator/users.php

This commit is contained in:
Dmitriy Simushev 2013-02-08 15:01:01 +00:00
parent 3fc81ec53e
commit 7d0a71da64
12 changed files with 75 additions and 80 deletions

View File

@ -5,8 +5,8 @@
Copyright (c) 2005-2011 Mibew Messenger Community Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php License: http://mibew.org/license.php
*/ */
(function(d,h,j,k){d.Views.ThreadsCollection=h.Marionette.CompositeView.extend({template:j.templates.threads_collection,itemView:d.Views.QueuedThread,itemViewContainer:"#threads-container",emptyView:d.Views.NoThreads,className:"threads-collection",collectionEvents:{sort:"renderCollection","sort:field":"createSortField",add:"threadAdded"},itemViewOptions:function(a){return{tagName:d.Objects.Models.page.get("threadTag"),collection:a.get("controls")}},initialize:function(){window.setInterval(k.bind(this.renderCollection, (function(d,h,j,k){d.Views.ThreadsCollection=h.Marionette.CompositeView.extend({template:j.templates.threads_collection,itemView:d.Views.QueuedThread,itemViewContainer:"#threads-container",emptyView:d.Views.NoThreads,className:"threads-collection",collectionEvents:{sort:"renderCollection","sort:field":"createSortField",add:"threadAdded"},itemViewOptions:function(a){return{tagName:d.Objects.Models.page.get("threadTag"),collection:a.get("controls")}},initialize:function(){window.setInterval(k.bind(this.updateTimers,
this),2E3);this.on("itemview:before:render",this.updateStyles,this)},updateStyles:function(a){var b=this.collection,c=a.model,d=this;if(c.id){var e=this.getQueueCode(c),f=!1,g=!1,b=b.filter(function(a){return d.getQueueCode(a)==e});0<b.length&&(g=b[0].id==c.id,f=b[b.length-1].id==c.id);if(0<a.lastStyles.length){c=0;for(b=a.lastStyles.length;c<b;c++)a.$el.removeClass(a.lastStyles[c]);a.lastStyles=[]}c=(e!=this.QUEUE_BAN?"in":"")+this.queueCodeToString(e);a.lastStyles.push(c);g&&a.lastStyles.push(c+ this),2E3);this.on("itemview:before:render",this.updateStyles,this);this.on("render",this.updateTimers,this)},updateStyles:function(a){var b=this.collection,c=a.model,d=this;if(c.id){var e=this.getQueueCode(c),f=!1,g=!1,b=b.filter(function(a){return d.getQueueCode(a)==e});0<b.length&&(g=b[0].id==c.id,f=b[b.length-1].id==c.id);if(0<a.lastStyles.length){c=0;for(b=a.lastStyles.length;c<b;c++)a.$el.removeClass(a.lastStyles[c]);a.lastStyles=[]}c=(e!=this.QUEUE_BAN?"in":"")+this.queueCodeToString(e);a.lastStyles.push(c);
"-first");f&&a.lastStyles.push(c+"-last");c=0;for(b=a.lastStyles.length;c<b;c++)a.$el.addClass(a.lastStyles[c])}},createSortField:function(a,b){var c=this.getQueueCode(a)||"Z";b.field=c.toString()+"_"+a.get("waitingTime").toString()},threadAdded:function(){var a=d.Objects.Models.page.get("webimRoot");a&&d.Objects.Models.sound.play(a+"/sounds/new_user.wav");if(d.Objects.Models.page.get("showPopup"))this.once("render",function(){alert(d.Localization.get("pending.popup_notification"))})},getQueueCode:function(a){var b= g&&a.lastStyles.push(c+"-first");f&&a.lastStyles.push(c+"-last");c=0;for(b=a.lastStyles.length;c<b;c++)a.$el.addClass(a.lastStyles[c])}},updateTimers:function(){d.Utils.updateTimers(this.$el,".timesince")},createSortField:function(a,b){var c=this.getQueueCode(a)||"Z";b.field=c.toString()+"_"+a.get("waitingTime").toString()},threadAdded:function(){var a=d.Objects.Models.page.get("webimRoot");a&&d.Objects.Models.sound.play(a+"/sounds/new_user.wav");if(d.Objects.Models.page.get("showPopup"))this.once("render",
a.get("state");return!1!=a.get("ban")&&b!=a.STATE_CHATTING?this.QUEUE_BAN:b==a.STATE_QUEUE||b==a.STATE_LOADING?this.QUEUE_WAITING:b==a.STATE_CLOSED||b==a.STATE_LEFT?this.QUEUE_CLOSED:b==a.STATE_WAITING?this.QUEUE_PRIO:b==a.STATE_CHATTING?this.QUEUE_CHATTING:!1},queueCodeToString:function(a){return a==this.QUEUE_PRIO?"prio":a==this.QUEUE_WAITING?"wait":a==this.QUEUE_CHATTING?"chat":a==this.QUEUE_BAN?"ban":a==this.QUEUE_CLOSED?"closed":""},QUEUE_PRIO:1,QUEUE_WAITING:2,QUEUE_CHATTING:3,QUEUE_BAN:4,QUEUE_CLOSED:5})})(Mibew, function(){alert(d.Localization.get("pending.popup_notification"))})},getQueueCode:function(a){var b=a.get("state");return!1!=a.get("ban")&&b!=a.STATE_CHATTING?this.QUEUE_BAN:b==a.STATE_QUEUE||b==a.STATE_LOADING?this.QUEUE_WAITING:b==a.STATE_CLOSED||b==a.STATE_LEFT?this.QUEUE_CLOSED:b==a.STATE_WAITING?this.QUEUE_PRIO:b==a.STATE_CHATTING?this.QUEUE_CHATTING:!1},queueCodeToString:function(a){return a==this.QUEUE_PRIO?"prio":a==this.QUEUE_WAITING?"wait":a==this.QUEUE_CHATTING?"chat":a==this.QUEUE_BAN?
Backbone,Handlebars,_); "ban":a==this.QUEUE_CLOSED?"closed":""},QUEUE_PRIO:1,QUEUE_WAITING:2,QUEUE_CHATTING:3,QUEUE_BAN:4,QUEUE_CLOSED:5})})(Mibew,Backbone,Handlebars,_);

View File

@ -5,5 +5,5 @@
Copyright (c) 2005-2011 Mibew Messenger Community Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php License: http://mibew.org/license.php
*/ */
(function(a,b,c,d){a.Views.VisitorsCollection=b.Marionette.CompositeView.extend({template:c.templates.visitors_collection,itemView:a.Views.Visitor,itemViewContainer:"#visitors-container",emptyView:a.Views.NoVisitors,className:"visitors-collection",collectionEvents:{sort:"renderCollection"},itemViewOptions:function(b){return{tagName:a.Objects.Models.page.get("visitorTag"),collection:b.get("controls")}},initialize:function(){window.setInterval(d.bind(this.renderCollection,this),2E3);this.on("itemview:before:render", (function(a,b,c,d){a.Views.VisitorsCollection=b.Marionette.CompositeView.extend({template:c.templates.visitors_collection,itemView:a.Views.Visitor,itemViewContainer:"#visitors-container",emptyView:a.Views.NoVisitors,className:"visitors-collection",collectionEvents:{sort:"renderCollection"},itemViewOptions:function(b){return{tagName:a.Objects.Models.page.get("visitorTag"),collection:b.get("controls")}},initialize:function(){window.setInterval(d.bind(this.updateTimers,this),2E3);this.on("render",this.updateTimers,
this.updateStyles,this)}})})(Mibew,Backbone,Handlebars,_); this)},updateTimers:function(){a.Utils.updateTimers(this.$el,".timesince")}})})(Mibew,Backbone,Handlebars,_);

View File

@ -1,8 +0,0 @@
/*
This file is part of Mibew Messenger project.
http://mibew.org
Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php
*/
(function(e){e.registerHelper("formatTimeSince",function(b){var a=Math.round((new Date).getTime()/1E3)-b;b=a%60;var d=Math.floor(a/60)%60,a=Math.floor(a/3600),c=[];0<a&&c.push(a);c.push(10>d?"0"+d:d);c.push(10>b?"0"+b:b);return c.join(":")})})(Handlebars);

View File

@ -5,4 +5,4 @@
Copyright (c) 2005-2011 Mibew Messenger Community Copyright (c) 2005-2011 Mibew Messenger Community
License: http://mibew.org/license.php License: http://mibew.org/license.php
*/ */
(function(a){a.Regions={};a.Popup={};a.Popup.open=function(b,a,c){b=window.open(b,a,c);b.focus();b.opener=window}})(Mibew); (function(a,e){a.Regions={};a.Popup={};a.Popup.open=function(b,a,g){b=window.open(b,a,g);b.focus();b.opener=window};a.Utils.updateTimers=function(a,f){a.find(f).each(function(){var a=e(this).data("timestamp");if(a){var c=Math.round((new Date).getTime()/1E3)-a,a=c%60,b=Math.floor(c/60)%60,c=Math.floor(c/3600),d=[];0<c&&d.push(c);d.push(10>b?"0"+b:b);d.push(10>a?"0"+a:a);e(this).html(d.join(":"))}})}})(Mibew,jQuery);

File diff suppressed because one or more lines are too long

View File

@ -64,13 +64,13 @@
/** /**
* View initializer. * View initializer.
* @todo Do something with timer. Do not render whole view!
*/ */
initialize: function() { initialize: function() {
// Rerender view to keep timers in items views working // Update time in timers
window.setInterval(_.bind(this.renderCollection, this), 2 * 1000); window.setInterval(_.bind(this.updateTimers, this), 2 * 1000);
// Register events // Register events
this.on('itemview:before:render', this.updateStyles, this); this.on('itemview:before:render', this.updateStyles, this);
this.on('render', this.updateTimers, this);
}, },
/** /**
@ -129,6 +129,13 @@
} }
}, },
/**
* Updates time in timers
*/
updateTimers: function() {
Mibew.Utils.updateTimers(this.$el, '.timesince');
},
/** /**
* This is the 'sort:field' event handler. * This is the 'sort:field' event handler.
* Make threads sort by queue code and waiting time. * Make threads sort by queue code and waiting time.

View File

@ -62,13 +62,19 @@
/** /**
* View initializer. * View initializer.
* @todo Do something with timer. Do not render whole view!
*/ */
initialize: function() { initialize: function() {
// Rerender view to keep timers in items views working // Update time in timers
window.setInterval(_.bind(this.renderCollection, this), 2 * 1000); window.setInterval(_.bind(this.updateTimers, this), 2 * 1000);
// Register events // Register events
this.on('itemview:before:render', this.updateStyles, this); this.on('render', this.updateTimers, this);
},
/**
* Updates time in timers
*/
updateTimers: function() {
Mibew.Utils.updateTimers(this.$el, '.timesince');
} }
} }
); );

View File

@ -1,33 +0,0 @@
/**
* @preserve This file is part of Mibew Messenger project.
* http://mibew.org
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* License: http://mibew.org/license.php
*/
(function(Handlebars){
/**
* Register 'formatTimeToNow' Handlebars helper.
*
* This helper takes unix timestamp as argument and return difference
* between current timestamp and passed one in "HH:MM:SS" format.
*/
Handlebars.registerHelper('formatTimeSince', function(unixTimestamp){
// Get time diff
var diff = Math.round((new Date()).getTime() / 1000) - unixTimestamp;
// Get time parts
var seconds = diff % 60;
var minutes = Math.floor(diff / 60) % 60;
var hours = Math.floor(diff / (60 * 60));
// Get result parts
var result = [];
if (hours > 0) {
result.push(hours);
}
result.push(minutes < 10 ? '0' + minutes : minutes);
result.push(seconds < 10 ? '0' + seconds : seconds);
// Build result string
return result.join(':');
});
})(Handlebars);

View File

@ -6,7 +6,7 @@
* License: http://mibew.org/license.php * License: http://mibew.org/license.php
*/ */
(function(Mibew){ (function(Mibew, $){
/** /**
* @namespace Holds application region constructors * @namespace Holds application region constructors
@ -30,4 +30,34 @@
newWindow.opener = window; newWindow.opener = window;
} }
})(Mibew); /**
* Update time in timers
* @param {Object} $el jQuery DOM object
* @param {String} selector Selector string
*/
Mibew.Utils.updateTimers = function($el, selector) {
$el.find(selector).each(function(){
// Get timestamp
var timestamp = $(this).data('timestamp');
if (! timestamp) {
return;
}
// Get time diff
var diff = Math.round((new Date()).getTime() / 1000) - timestamp;
// Get time parts
var seconds = diff % 60;
var minutes = Math.floor(diff / 60) % 60;
var hours = Math.floor(diff / (60 * 60));
// Get result parts
var result = [];
if (hours > 0) {
result.push(hours);
}
result.push(minutes < 10 ? '0' + minutes : minutes);
result.push(seconds < 10 ? '0' + seconds : seconds);
// Build result string
$(this).html(result.join(':'));
});
}
})(Mibew, jQuery);

File diff suppressed because one or more lines are too long

View File

@ -22,6 +22,6 @@
<td class="visitor">{{#if userIp}}<a href="javascript:void(0);" class="geo-link" title="GeoLocation">{{remote}}</a>{{else}}{{remote}}{{/if}}</td> <td class="visitor">{{#if userIp}}<a href="javascript:void(0);" class="geo-link" title="GeoLocation">{{remote}}</a>{{else}}{{remote}}{{/if}}</td>
<td class="visitor">{{stateDesc}}</td> <td class="visitor">{{stateDesc}}</td>
<td class="visitor">{{agentName}}</td> <td class="visitor">{{agentName}}</td>
<td class="visitor">{{formatTimeSince totalTime}}</td> <td class="visitor"><span class="timesince" data-timestamp="{{totalTime}}"></span></td>
<td class="visitor">{{#unless chatting}}{{formatTimeSince waitingTime}}{{else}}-{{/unless}}</td> <td class="visitor">{{#unless chatting}}<span class="timesince" data-timestamp="{{waitingTime}}"></span>{{else}}-{{/unless}}</td>
<td class="visitor">{{#if ban}}{{ban.reason}}{{else}}{{userAgent}}{{/if}}</td> <td class="visitor">{{#if ban}}{{ban.reason}}{{else}}{{userAgent}}{{/if}}</td>

View File

@ -8,9 +8,9 @@
<div class="visitor-controls inline-block"></div> <div class="visitor-controls inline-block"></div>
</td> </td>
<td class="visitor">{{#if userIp}}<a href="javascript:void(0);" class="geo-link" title="GeoLocation">{{remote}}</a>{{else}}{{remote}}{{/if}}</td> <td class="visitor">{{#if userIp}}<a href="javascript:void(0);" class="geo-link" title="GeoLocation">{{remote}}</a>{{else}}{{remote}}{{/if}}</td>
<td class="visitor">{{formatTimeSince firstTime}}</td> <td class="visitor"><span class="timesince" data-timestamp="{{firstTime}}"></span></td>
<td class="visitor">{{formatTimeSince lastTime}}</td> <td class="visitor"><span class="timesince" data-timestamp="{{lastTime}}"></span></td>
<td class="visitor">{{#if invitationInfo}}{{invitationInfo.agentName}}{{else}}-{{/if}}</td> <td class="visitor">{{#if invitationInfo}}{{invitationInfo.agentName}}{{else}}-{{/if}}</td>
<td class="visitor">{{#if invitationInfo}}{{formatTimeSince invitationInfo.time}}{{else}}-{{/if}}</td> <td class="visitor">{{#if invitationInfo}}<span class="timesince" data-timestamp="{{invitationInfo.time}}"></span>{{else}}-{{/if}}</td>
<td class="visitor">{{invitations}} / {{chats}}</td> <td class="visitor">{{invitations}} / {{chats}}</td>
<td class="visitor">{{userAgent}}</td> <td class="visitor">{{userAgent}}</td>