Updating UI plugins to fix memory leak reported in #394

This commit is contained in:
Dan Cryer 2014-05-09 15:34:14 +01:00
parent 68a92e4682
commit 8418208863
7 changed files with 44 additions and 24 deletions

View file

@ -4,6 +4,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
title: 'Lines of Code',
lastData: null,
displayOnUpdate: false,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
self.displayOnUpdate = true;
if (data.queryData.status > 1 && !self.rendered) {
query();
}
});
@ -29,10 +29,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
onUpdate: function(e) {
this.lastData = e.queryData;
if (this.displayOnUpdate) {
this.displayChart();
}
this.displayChart();
},
displayChart: function() {
@ -42,6 +39,8 @@ var locPlugin = PHPCI.UiPlugin.extend({
return;
}
this.rendered = true;
$('#phploc-lines').empty().animate({height: '275px'});
var titles = ['Build', 'Lines', 'Comment Lines', 'Non-Comment Lines', 'Logical Lines'];

View file

@ -3,8 +3,8 @@ var phpcsPlugin = PHPCI.UiPlugin.extend({
css: 'col-lg-12 col-md-12 col-sm-12 col-xs-12',
title: 'PHP Code Sniffer',
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,16 +14,14 @@ var phpcsPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
self.displayOnUpdate = true;
$(window).on('build-updated', function() {
if (!self.rendered) {
query();
}
});
},
render: function() {
return $('<table class="table table-striped" id="phpcs-data">' +
'<thead>' +
'<tr>' +
@ -35,10 +33,11 @@ var phpcsPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;

View file

@ -5,6 +5,7 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,8 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
@ -23,7 +24,6 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
},
render: function() {
return $('<table class="table table-striped" id="phpdoccheck-data">' +
'<thead>' +
'<tr>' +
@ -37,10 +37,11 @@ var phpdoccheckPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;

View file

@ -5,6 +5,7 @@ var phpmdPlugin = PHPCI.UiPlugin.extend({
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,8 @@ var phpmdPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
@ -36,10 +37,11 @@ var phpmdPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var errors = this.lastData[0].meta_value;

View file

@ -5,6 +5,7 @@ var phpunitPlugin = PHPCI.UiPlugin.extend({
lastData: null,
displayOnUpdate: false,
box: true,
rendered: false,
register: function() {
var self = this;
@ -14,8 +15,8 @@ var phpunitPlugin = PHPCI.UiPlugin.extend({
self.onUpdate(data);
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
$(window).on('build-updated', function() {
if (!self.rendered) {
self.displayOnUpdate = true;
query();
}
@ -33,10 +34,11 @@ var phpunitPlugin = PHPCI.UiPlugin.extend({
},
onUpdate: function(e) {
if (this.lastData && this.lastData[0]) {
if (!e.queryData) {
return;
}
this.rendered = true;
this.lastData = e.queryData;
var tests = this.lastData[0].meta_value;

View file

@ -12,6 +12,7 @@ var warningsPlugin = PHPCI.UiPlugin.extend({
},
data: {},
displayOnUpdate: false,
rendered: false,
register: function() {
var self = this;
@ -26,7 +27,7 @@ var warningsPlugin = PHPCI.UiPlugin.extend({
});
$(window).on('build-updated', function(data) {
if (data.queryData.status > 1) {
if (!self.rendered && data.queryData.status > 1) {
self.displayOnUpdate = true;
for (var query in queries) {
queries[query]();
@ -68,6 +69,7 @@ var warningsPlugin = PHPCI.UiPlugin.extend({
displayChart: function() {
var self = this;
self.rendered = true;
$('#build-warnings').empty().animate({height: '275px'});

View file

@ -317,8 +317,19 @@ var PHPCIObject = Class.extend({
updateInterval: null,
init: function(build) {
var self = this;
this.buildId = build;
this.registerQuery('build-updated', 10);
$(window).on('build-updated', function(data) {
// If the build has finished, stop updating every 10 seconds:
if (data.queryData.status > 1) {
self.cancelQuery('build-updated');
$(window).trigger({type: 'build-complete'});
}
});
},
registerQuery: function(name, seconds, query) {
@ -337,12 +348,16 @@ var PHPCIObject = Class.extend({
};
if (seconds != -1) {
setInterval(cb, seconds * 1000);
self.queries[name] = setInterval(cb, seconds * 1000);
}
return cb;
},
cancelQuery: function (name) {
clearInterval(this.queries[name]);
},
registerPlugin: function(plugin) {
this.plugins[plugin.id] = plugin;
plugin.register();