MDL-43682 loglive: Rewrite loglive to use new logging stores

AMOS BEGIN
 CPY [eventcomponent,report_log],[eventcomponent,report_loglive]
 CPY [eventcontext,report_log],[eventcontext,report_loglive]
 CPY [eventloggedas,report_log],[eventloggedas,report_loglive]
 CPY [eventorigin,report_log],[eventorigin,report_loglive]
 CPY [eventrelatedfullnameuser,report_log],[eventrelatedfullnameuser,report_loglive]
 CPY [nologreaderenabled,report_log],[nologreaderenabled,report_loglive]
 CPY [selectlogreader,report_log],[selectlogreader,report_loglive]
AMOS END
This commit is contained in:
Ankit Agarwal 2014-04-04 14:42:19 +08:00
parent 1a727e121e
commit 5991eb80cd
19 changed files with 1759 additions and 76 deletions

View file

@ -0,0 +1,245 @@
YUI.add('moodle-report_loglive-fetchlogs', function (Y, NAME) {
/**
* A module to manage ajax requests.
*
* @module moodle-report_loglive-fetchlogs
*/
/**
* A module to manage ajax requests.
*
* @class moodle-report_loglive.fetchlogs
* @extends Base
* @constructor
*/
function FetchLogs() {
FetchLogs.superclass.constructor.apply(this, arguments);
}
var CSS = {
NEWROW: 'newrow',
SPINNER: 'spinner',
ICONSMALL: 'iconsmall'
},
SELECTORS = {
NEWROW: '.' + CSS.NEWROW,
TBODY: '.flexible tbody',
PAUSEBUTTON: '#livelogs-pause-button',
SPINNER: '.' + CSS.SPINNER
};
Y.extend(FetchLogs, Y.Base, {
/**
* Reference to the callBack object generated by Y.later
*
* @property callBack
* @type Object
* @default {}
* @protected
*/
callBack: {},
/**
* Reference to the spinner node.
*
* @property callBack
* @type Object
* @default {}
* @protected
*/
spinner: {},
/**
* Reference to the toggleButton node.
*
* @property pauseButton
* @type Object
* @default {}
* @protected
*/
pauseButton: {},
/**
* Initializer.
* Basic setup and delegations.
*
* @method initializer
*/
initializer: function() {
// We don't want the pages to be updated when viewing a specific page in the chain.
if (this.get('page') === 0) {
this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true);
}
this.spinner = Y.one(SELECTORS.SPINNER);
this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON);
this.spinner.hide();
Y.delegate('click', this.toggleUpdate, 'button', SELECTORS.PAUSEBUTTON, this);
},
/**
* Method to fetch recent logs.
*
* @method fetchRecentLogs
*/
fetchRecentLogs: function() {
this.spinner.show(); // Show a loading icon.
var data = {
logreader: this.get('logreader'),
since: this.get('since'),
page: this.get('page'),
id: this.get('courseid')
};
var cfg = {
method: 'get',
context: this,
on: {
complete: this.updateLogTable
},
data: data
};
var url = M.cfg.wwwroot + '/report/loglive/loglive_ajax.php';
Y.io(url, cfg);
},
/**
* Method to update the log table, populate the table with new entries and remove old entries if needed.
*
* @method updateLogTable
*/
updateLogTable: function(tid, response) {
Y.later(600, this, 'hideLoadingIcon'); // Hide loading icon, give sometime to people to actually see it. We should do it, event in case of an error.
var responseobject;
// Attempt to parse the response into an object.
try {
responseobject = Y.JSON.parse(response.responseText);
if (responseobject.error) {
Y.use('moodle-core-notification-ajaxexception', function() {
return new M.core.ajaxException(responseobject);
});
return this;
}
} catch (error) {
Y.use('moodle-core-notification-exception', function() {
return new M.core.exception(error);
});
return this;
}
this.set('since' , responseobject.until);
var logs = responseobject.logs;
var tbody = Y.one(SELECTORS.TBODY);
var firstTr = null;
if (tbody && logs) {
firstTr = tbody.get('firstChild');
if (firstTr) {
tbody.insertBefore(logs, firstTr);
} else {
// @Todo, when no data is present our library should generate an empty table. so data can be added dynamically (MDL-44525).
}
// Let us chop off some data from end of table to prevent really long pages.
var oldChildren = tbody.get('children').slice(this.get('perpage'));
oldChildren.remove();
Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows.
}
},
/**
* Remove background highlight from the newly added rows.
*
* @method removeHighlight
*/
removeHighlight: function(timeStamp) {
Y.all('.time' + timeStamp).removeClass(CSS.NEWROW);
},
/**
* Hide the spinning icon.
*
* @method hideLoadingIcon
*/
hideLoadingIcon: function() {
this.spinner.hide();
},
/**
* Toggle live update.
*
* @method toggleUpdate
*/
toggleUpdate: function() {
if (this.callBack) {
this.callBack.cancel();
this.callBack = '';
this.pauseButton.setContent(M.util.get_string('resume', 'report_loglive'));
} else {
this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true);
this.pauseButton.setContent(M.util.get_string('pause', 'report_loglive'));
}
}
}, {
NAME: 'fetchLogs',
ATTRS: {
/**
* time stamp from where the new logs needs to be fetched.
*
* @attribute since
* @default null
* @type String
*/
since: null,
/**
* courseid for which the logs are shown.
*
* @attribute courseid
* @default 0
* @type int
*/
courseid: 0,
/**
* Page number shown to user.
*
* @attribute page
* @default 0
* @type int
*/
page: 0,
/**
* Items to show per page.
*
* @attribute perpage
* @default 100
* @type int
*/
perpage: 100,
/**
* Refresh interval.
*
* @attribute interval
* @default 60
* @type int
*/
interval: 60,
/**
* Which logstore is being used.
*
* @attribute logreader
* @default logstore_standard
* @type String
*/
logreader: 'logstore_standard'
}
});
Y.namespace('M.report_loglive.FetchLogs').init = function(config) {
return new FetchLogs(config);
};
}, '@VERSION@', {"requires": ["base", "event", "node", "io", "node-event-delegate"]});

View file

@ -0,0 +1 @@
YUI.add("moodle-report_loglive-fetchlogs",function(e,t){function n(){n.superclass.constructor.apply(this,arguments)}var r={NEWROW:"newrow",SPINNER:"spinner",ICONSMALL:"iconsmall"},i={NEWROW:"."+r.NEWROW,TBODY:".flexible tbody",PAUSEBUTTON:"#livelogs-pause-button",SPINNER:"."+r.SPINNER};e.extend(n,e.Base,{callBack:{},spinner:{},pauseButton:{},initializer:function(){this.get("page")===0&&(this.callBack=e.later(this.get("interval")*1e3,this,this.fetchRecentLogs,null,!0)),this.spinner=e.one(i.SPINNER),this.pauseButton=e.one(i.PAUSEBUTTON),this.spinner.hide(),e.delegate("click",this.toggleUpdate,"button",i.PAUSEBUTTON,this)},fetchRecentLogs:function(){this.spinner.show();var t={logreader:this.get("logreader"),since:this.get("since"),page:this.get("page"),id:this.get("courseid")},n={method:"get",context:this,on:{complete:this.updateLogTable},data:t},r=M.cfg.wwwroot+"/report/loglive/loglive_ajax.php";e.io(r,n)},updateLogTable:function(t,n){e.later(600,this,"hideLoadingIcon");var r;try{r=e.JSON.parse(n.responseText);if(r.error)return e.use("moodle-core-notification-ajaxexception",function(){return new M.core.ajaxException(r)}),this}catch(s){return e.use("moodle-core-notification-exception",function(){return new M.core.exception(s)}),this}this.set("since",r.until);var o=r.logs,u=e.one(i.TBODY),a=null;if(u&&o){a=u.get("firstChild"),a&&u.insertBefore(o,a);var f=u.get("children").slice(this.get("perpage"));f.remove(),e.later(5e3,this,"removeHighlight",r.until)}},removeHighlight:function(t){e.all(".time"+t).removeClass(r.NEWROW)},hideLoadingIcon:function(){this.spinner.hide()},toggleUpdate:function(){this.callBack?(this.callBack.cancel(),this.callBack="",this.pauseButton.setContent(M.util.get_string("resume","report_loglive"))):(this.callBack=e.later(this.get("interval")*1e3,this,this.fetchRecentLogs,null,!0),this.pauseButton.setContent(M.util.get_string("pause","report_loglive")))}},{NAME:"fetchLogs",ATTRS:{since:null,courseid:0,page:0,perpage:100,interval:60,logreader:"logstore_standard"}}),e.namespace("M.report_loglive.FetchLogs").init=function(e){return new n(e)}},"@VERSION@",{requires:["base","event","node","io","node-event-delegate"]});

View file

@ -0,0 +1,245 @@
YUI.add('moodle-report_loglive-fetchlogs', function (Y, NAME) {
/**
* A module to manage ajax requests.
*
* @module moodle-report_loglive-fetchlogs
*/
/**
* A module to manage ajax requests.
*
* @class moodle-report_loglive.fetchlogs
* @extends Base
* @constructor
*/
function FetchLogs() {
FetchLogs.superclass.constructor.apply(this, arguments);
}
var CSS = {
NEWROW: 'newrow',
SPINNER: 'spinner',
ICONSMALL: 'iconsmall'
},
SELECTORS = {
NEWROW: '.' + CSS.NEWROW,
TBODY: '.flexible tbody',
PAUSEBUTTON: '#livelogs-pause-button',
SPINNER: '.' + CSS.SPINNER
};
Y.extend(FetchLogs, Y.Base, {
/**
* Reference to the callBack object generated by Y.later
*
* @property callBack
* @type Object
* @default {}
* @protected
*/
callBack: {},
/**
* Reference to the spinner node.
*
* @property callBack
* @type Object
* @default {}
* @protected
*/
spinner: {},
/**
* Reference to the toggleButton node.
*
* @property pauseButton
* @type Object
* @default {}
* @protected
*/
pauseButton: {},
/**
* Initializer.
* Basic setup and delegations.
*
* @method initializer
*/
initializer: function() {
// We don't want the pages to be updated when viewing a specific page in the chain.
if (this.get('page') === 0) {
this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true);
}
this.spinner = Y.one(SELECTORS.SPINNER);
this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON);
this.spinner.hide();
Y.delegate('click', this.toggleUpdate, 'button', SELECTORS.PAUSEBUTTON, this);
},
/**
* Method to fetch recent logs.
*
* @method fetchRecentLogs
*/
fetchRecentLogs: function() {
this.spinner.show(); // Show a loading icon.
var data = {
logreader: this.get('logreader'),
since: this.get('since'),
page: this.get('page'),
id: this.get('courseid')
};
var cfg = {
method: 'get',
context: this,
on: {
complete: this.updateLogTable
},
data: data
};
var url = M.cfg.wwwroot + '/report/loglive/loglive_ajax.php';
Y.io(url, cfg);
},
/**
* Method to update the log table, populate the table with new entries and remove old entries if needed.
*
* @method updateLogTable
*/
updateLogTable: function(tid, response) {
Y.later(600, this, 'hideLoadingIcon'); // Hide loading icon, give sometime to people to actually see it. We should do it, event in case of an error.
var responseobject;
// Attempt to parse the response into an object.
try {
responseobject = Y.JSON.parse(response.responseText);
if (responseobject.error) {
Y.use('moodle-core-notification-ajaxexception', function() {
return new M.core.ajaxException(responseobject);
});
return this;
}
} catch (error) {
Y.use('moodle-core-notification-exception', function() {
return new M.core.exception(error);
});
return this;
}
this.set('since' , responseobject.until);
var logs = responseobject.logs;
var tbody = Y.one(SELECTORS.TBODY);
var firstTr = null;
if (tbody && logs) {
firstTr = tbody.get('firstChild');
if (firstTr) {
tbody.insertBefore(logs, firstTr);
} else {
// @Todo, when no data is present our library should generate an empty table. so data can be added dynamically (MDL-44525).
}
// Let us chop off some data from end of table to prevent really long pages.
var oldChildren = tbody.get('children').slice(this.get('perpage'));
oldChildren.remove();
Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows.
}
},
/**
* Remove background highlight from the newly added rows.
*
* @method removeHighlight
*/
removeHighlight: function(timeStamp) {
Y.all('.time' + timeStamp).removeClass(CSS.NEWROW);
},
/**
* Hide the spinning icon.
*
* @method hideLoadingIcon
*/
hideLoadingIcon: function() {
this.spinner.hide();
},
/**
* Toggle live update.
*
* @method toggleUpdate
*/
toggleUpdate: function() {
if (this.callBack) {
this.callBack.cancel();
this.callBack = '';
this.pauseButton.setContent(M.util.get_string('resume', 'report_loglive'));
} else {
this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true);
this.pauseButton.setContent(M.util.get_string('pause', 'report_loglive'));
}
}
}, {
NAME: 'fetchLogs',
ATTRS: {
/**
* time stamp from where the new logs needs to be fetched.
*
* @attribute since
* @default null
* @type String
*/
since: null,
/**
* courseid for which the logs are shown.
*
* @attribute courseid
* @default 0
* @type int
*/
courseid: 0,
/**
* Page number shown to user.
*
* @attribute page
* @default 0
* @type int
*/
page: 0,
/**
* Items to show per page.
*
* @attribute perpage
* @default 100
* @type int
*/
perpage: 100,
/**
* Refresh interval.
*
* @attribute interval
* @default 60
* @type int
*/
interval: 60,
/**
* Which logstore is being used.
*
* @attribute logreader
* @default logstore_standard
* @type String
*/
logreader: 'logstore_standard'
}
});
Y.namespace('M.report_loglive.FetchLogs').init = function(config) {
return new FetchLogs(config);
};
}, '@VERSION@', {"requires": ["base", "event", "node", "io", "node-event-delegate"]});

View file

@ -0,0 +1,10 @@
{
"name": "moodle-report_loglive-fetchlogs",
"builds": {
"moodle-report_loglive-fetchlogs": {
"jsfiles": [
"fetchlogs.js"
]
}
}
}

View file

@ -0,0 +1,240 @@
/**
* A module to manage ajax requests.
*
* @module moodle-report_loglive-fetchlogs
*/
/**
* A module to manage ajax requests.
*
* @class moodle-report_loglive.fetchlogs
* @extends Base
* @constructor
*/
function FetchLogs() {
FetchLogs.superclass.constructor.apply(this, arguments);
}
var CSS = {
NEWROW: 'newrow',
SPINNER: 'spinner',
ICONSMALL: 'iconsmall'
},
SELECTORS = {
NEWROW: '.' + CSS.NEWROW,
TBODY: '.flexible tbody',
PAUSEBUTTON: '#livelogs-pause-button',
SPINNER: '.' + CSS.SPINNER
};
Y.extend(FetchLogs, Y.Base, {
/**
* Reference to the callBack object generated by Y.later
*
* @property callBack
* @type Object
* @default {}
* @protected
*/
callBack: {},
/**
* Reference to the spinner node.
*
* @property callBack
* @type Object
* @default {}
* @protected
*/
spinner: {},
/**
* Reference to the toggleButton node.
*
* @property pauseButton
* @type Object
* @default {}
* @protected
*/
pauseButton: {},
/**
* Initializer.
* Basic setup and delegations.
*
* @method initializer
*/
initializer: function() {
// We don't want the pages to be updated when viewing a specific page in the chain.
if (this.get('page') === 0) {
this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true);
}
this.spinner = Y.one(SELECTORS.SPINNER);
this.pauseButton = Y.one(SELECTORS.PAUSEBUTTON);
this.spinner.hide();
Y.delegate('click', this.toggleUpdate, 'button', SELECTORS.PAUSEBUTTON, this);
},
/**
* Method to fetch recent logs.
*
* @method fetchRecentLogs
*/
fetchRecentLogs: function() {
this.spinner.show(); // Show a loading icon.
var data = {
logreader: this.get('logreader'),
since: this.get('since'),
page: this.get('page'),
id: this.get('courseid')
};
var cfg = {
method: 'get',
context: this,
on: {
complete: this.updateLogTable
},
data: data
};
var url = M.cfg.wwwroot + '/report/loglive/loglive_ajax.php';
Y.io(url, cfg);
},
/**
* Method to update the log table, populate the table with new entries and remove old entries if needed.
*
* @method updateLogTable
*/
updateLogTable: function(tid, response) {
Y.later(600, this, 'hideLoadingIcon'); // Hide loading icon, give sometime to people to actually see it. We should do it, event in case of an error.
var responseobject;
// Attempt to parse the response into an object.
try {
responseobject = Y.JSON.parse(response.responseText);
if (responseobject.error) {
Y.use('moodle-core-notification-ajaxexception', function() {
return new M.core.ajaxException(responseobject);
});
return this;
}
} catch (error) {
Y.use('moodle-core-notification-exception', function() {
return new M.core.exception(error);
});
return this;
}
this.set('since' , responseobject.until);
var logs = responseobject.logs;
var tbody = Y.one(SELECTORS.TBODY);
var firstTr = null;
if (tbody && logs) {
firstTr = tbody.get('firstChild');
if (firstTr) {
tbody.insertBefore(logs, firstTr);
} else {
// @Todo, when no data is present our library should generate an empty table. so data can be added dynamically (MDL-44525).
}
// Let us chop off some data from end of table to prevent really long pages.
var oldChildren = tbody.get('children').slice(this.get('perpage'));
oldChildren.remove();
Y.later(5000, this, 'removeHighlight', responseobject.until); // Remove highlighting from new rows.
}
},
/**
* Remove background highlight from the newly added rows.
*
* @method removeHighlight
*/
removeHighlight: function(timeStamp) {
Y.all('.time' + timeStamp).removeClass(CSS.NEWROW);
},
/**
* Hide the spinning icon.
*
* @method hideLoadingIcon
*/
hideLoadingIcon: function() {
this.spinner.hide();
},
/**
* Toggle live update.
*
* @method toggleUpdate
*/
toggleUpdate: function() {
if (this.callBack) {
this.callBack.cancel();
this.callBack = '';
this.pauseButton.setContent(M.util.get_string('resume', 'report_loglive'));
} else {
this.callBack = Y.later(this.get('interval') * 1000, this, this.fetchRecentLogs, null, true);
this.pauseButton.setContent(M.util.get_string('pause', 'report_loglive'));
}
}
}, {
NAME: 'fetchLogs',
ATTRS: {
/**
* time stamp from where the new logs needs to be fetched.
*
* @attribute since
* @default null
* @type String
*/
since: null,
/**
* courseid for which the logs are shown.
*
* @attribute courseid
* @default 0
* @type int
*/
courseid: 0,
/**
* Page number shown to user.
*
* @attribute page
* @default 0
* @type int
*/
page: 0,
/**
* Items to show per page.
*
* @attribute perpage
* @default 100
* @type int
*/
perpage: 100,
/**
* Refresh interval.
*
* @attribute interval
* @default 60
* @type int
*/
interval: 60,
/**
* Which logstore is being used.
*
* @attribute logreader
* @default logstore_standard
* @type String
*/
logreader: 'logstore_standard'
}
});
Y.namespace('M.report_loglive.FetchLogs').init = function(config) {
return new FetchLogs(config);
};

View file

@ -0,0 +1,11 @@
{
"moodle-report_loglive-fetchlogs": {
"requires": [
"base",
"event",
"node",
"io",
"node-event-delegate"
]
}
}