Add a progress bar on the UI

This commit is contained in:
Gaël Métais
2021-01-03 01:43:46 +00:00
parent 64733d55f8
commit bd9cb2e257
10 changed files with 122 additions and 10 deletions
+4
View File
@@ -24,9 +24,13 @@ var yellowLabTools = function(url, options) {
};
var runner = new Runner(params)
.progress(deferred.notify)
.then(function(data) {
deferred.resolve(data);
})
.fail(function(err) {
deferred.reject(err);
});
+36 -1
View File
@@ -24,7 +24,29 @@ var Runner = function(params) {
// Execute Phantomas first
phantomasWrapper.execute(data)
// For the progress bar
.progress(function(event) {
if (event === 'domReady') {
deferred.notify({
estimatedProgress: 0.15,
milestone: 'domReady'
});
}
if (event === 'domComplete') {
deferred.notify({
estimatedProgress: 0.25,
milestone: 'domComplete'
});
}
})
.then(function(phantomasResults) {
// For the progress bar
deferred.notify({
estimatedProgress: 0.4,
milestone: 'phantomas'
});
data.toolsResults.phantomas = phantomasResults;
// Mix all DOM Access metrics together
@@ -37,12 +59,25 @@ var Runner = function(params) {
data = mediaQueriesChecker.analyzeMediaQueries(data);
// Redownload every file
return redownload.recheckAllFiles(data);
return redownload.recheckAllFiles(data)
.progress(function(redownloadedProgress) {
deferred.notify({
estimatedProgress: 0.4 + redownloadedProgress * 0.55,
milestone: 'phantomas'
});
});
})
.then(function(data) {
// For the progress bar
deferred.notify({
estimatedProgress: 0.99,
milestone: 'redownload'
});
// Rules checker
var policies = require('./metadata/policies');
data.rules = rulesChecker.check(data, policies);
+7 -3
View File
@@ -84,11 +84,15 @@ var ApiController = function(app) {
authPass: run.params.authPass,
blockDomain: run.params.blockDomain,
allowDomain: run.params.allowDomain,
noExternals: run.params.noExternals,
phantomasEngine: serverSettings.phantomasEngine
noExternals: run.params.noExternals
};
return ylt(run.params.url, runOptions);
return ylt(run.params.url, runOptions)
// Update the progress bar on each progress
.progress(function(progress) {
runsDatastore.updateRunProgress(run.runId, progress);
});
})
+10
View File
@@ -42,6 +42,16 @@ function RunsDatastore() {
};
// When the test is launched, set the progress bar
this.updateRunProgress = function(runId, progress) {
var run = runs[runId];
run.progress = progress;
runs[runId] = run;
};
this.markAsComplete = function(runId) {
var run = runs[runId];
+6
View File
@@ -79,6 +79,12 @@ var PhantomasWrapper = function() {
deferred.reject('Phantomas failed: ' + res.message);
});
promise.on('milestone', function(event) {
if (event === 'domReady' || event === 'domComplete') {
deferred.notify(event);
}
});
return deferred.promise;
};
};
+12 -3
View File
@@ -33,6 +33,7 @@ var Redownload = function() {
function recheckAllFiles(data) {
var startTime = Date.now();
debug('Redownload started');
var deferred = Q.defer();
var requestsOffenders = data.toolsResults.phantomas.offenders.requests;
@@ -43,6 +44,9 @@ var Redownload = function() {
var requestsList = mergeOffenders(requestsOffenders, gzipOffenders, postOffenders, notFoundOffenders, redirectOffenders);
var totalCount = requestsList.length;
var doneCount = 0;
var httpAuth = null;
if (data.params && data.params.options && data.params.options.authUser && data.params.options.authPass) {
httpAuth = {
@@ -89,6 +93,11 @@ var Redownload = function() {
.then(function(newEntry) {
debug('File %s - Redownloaded, optimized, minified, compressed, analyzed: done', entry.url);
// For the progress bar
doneCount ++;
deferred.notify(doneCount/totalCount);
callback(null, newEntry);
})
@@ -745,9 +754,9 @@ var Redownload = function() {
function detectWordPress(requests) {
// Check the first file only
if (requests[0].isHTML
&& requests[0].weightCheck.bodyBuffer
&& requests[0].weightCheck.bodyBuffer.indexOf('/wp-content/') > 0) {
if (requests[0].isHTML &&
requests[0].weightCheck.bodyBuffer &&
requests[0].weightCheck.bodyBuffer.indexOf('/wp-content/') > 0) {
return true;
}