Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jenkins@backuity: Fix strict mode errors #1993

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 22 additions & 30 deletions jenkins@backuity.org/files/jenkins@backuity.org/applet.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ MyApplet.prototype = {

let applet = this;
_httpSession.connect("authenticate",function(session,message,auth,retrying) {
log("Authenticating with " + applet._jenkinsUsername);
global.log("Authenticating with " + applet._jenkinsUsername);
auth.authenticate(applet._jenkinsUsername, applet._jenkinsPassword);
});
});

// PopupMenu
//----------------------------------
Expand All @@ -102,7 +102,8 @@ MyApplet.prototype = {
this.menu = new Applet.AppletPopupMenu(this, orientation);
this.menuManager.addMenu(this.menu);

this.menu.addMenuItem(new PopupMenu.PopupMenuItem(_('Loading jobs...')));
this.initialMenuItem = new PopupMenu.PopupMenuItem(_('Loading jobs...'));
this.menu.addMenuItem(this.initialMenuItem);
}

, assignMessageSource: function() {
Expand Down Expand Up @@ -148,16 +149,15 @@ MyApplet.prototype = {
return;
}

log("Loading " + this.jenkinsUrl());
let applet = this;
this.loadJsonAsync(this.jenkinsUrl(), function(json) {
applet.destroyMenu();
this.loadJsonAsync(this.jenkinsUrl(), function(json) {
applet.destroyMenu();
try {
let maxJobs = applet._maxNumberOfJobs;
let jobs = json.get_array_member('jobs').get_elements();
let displayedJobs = 0;
let filteredJobs = [];

let filteredJobs = [];
for (let i = 0; i < jobs.length && displayedJobs < maxJobs; i++) {
let job = jobs[i].get_object();

Expand All @@ -177,7 +177,7 @@ MyApplet.prototype = {

let jobName = job.get_string_member('name');
let url = job.get_string_member('url');

var regex = RegExp(this._jenkinsFilter);
if(regex.exec(jobName)) {
filteredJobs.push(jobs[i]);
Expand All @@ -195,14 +195,14 @@ MyApplet.prototype = {
} else {
applet.set_applet_icon_name('jenkins-green');
}


applet.displayNewlyFailedJobs(filteredJobs);

} catch(error) {
applet.set_applet_icon_name('jenkins-grey');
applet.set_applet_label('!');
logError(error.message)
applet.set_applet_label('!');
global.logError(error.message)
applet.menu.addMenuItem(new PopupMenu.PopupMenuItem(error.message));
}
})
Expand Down Expand Up @@ -278,7 +278,7 @@ MyApplet.prototype = {
this.menu.removeAll();
}

, jenkinsUrl: function() {
, jenkinsUrl: function() {
let output = this._jenkinsUrl + '/api/json';
return output;
}
Expand All @@ -291,11 +291,16 @@ MyApplet.prototype = {
message.request_headers.append('Authorization', 'Basic ' + encoded);
}
_httpSession.ssl_strict = this._sslStrict;
if (!message) {
if (this.initialMenuItem) this.initialMenuItem.label.set_text(_('No jobs'));
return;
}
_httpSession.queue_message(message, function soupQueue(session, message) {

if( message.status_code != 200 ) {
logError("Got status " + message.status_code + " " + message.response_body.data);
global.logError("Got status " + message.status_code + " " + message.response_body.data);
applet.destroyMenu();
this.initialMenuItem = null;
applet.set_applet_label('!');
applet.set_applet_icon_name('jenkins-grey');

Expand Down Expand Up @@ -340,7 +345,7 @@ JobMenuItem.prototype = {
this.connect('activate', Lang.bind(this, function (menuItem, event) {
Util.spawnCommandLine("xdg-open " + url);
}));
}
}
};


Expand Down Expand Up @@ -379,19 +384,6 @@ Helpers.prototype = {

}


// Logging
//----------------------------------------------------------------------

function log(message) {
global.log(UUID + "#" + log.caller.name + ": " + message)
}

function logError(error) {
global.logError(UUID + "#" + logError.caller.name + ": " + error)
}


// Entry point
//----------------------------------------------------------------------

Expand Down