2016-04-06 11:31:22 -05:00
|
|
|
// Copyright 2016 Tim Shannon. All rights reserved.
|
|
|
|
// Use of this source code is governed by the MIT license
|
|
|
|
// that can be found in the LICENSE file.
|
|
|
|
/* jshint strict: true */
|
|
|
|
|
2016-04-17 20:43:27 -05:00
|
|
|
Ractive.DEBUG = false;
|
|
|
|
|
2016-04-06 11:31:22 -05:00
|
|
|
(function() {
|
|
|
|
"use strict";
|
|
|
|
|
2016-04-13 16:59:28 -05:00
|
|
|
var r = new Ractive({
|
2016-04-06 11:31:22 -05:00
|
|
|
el: "body",
|
|
|
|
template: "#tMain",
|
2016-04-13 16:59:28 -05:00
|
|
|
data: function() {
|
|
|
|
return {
|
2016-04-14 11:29:56 -05:00
|
|
|
project: null,
|
|
|
|
version: null,
|
|
|
|
stage: null,
|
2016-04-13 16:59:28 -05:00
|
|
|
projects: [],
|
2016-04-15 16:57:59 -05:00
|
|
|
error: null,
|
2016-04-13 16:59:28 -05:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2016-04-06 11:31:22 -05:00
|
|
|
|
2016-04-15 16:57:59 -05:00
|
|
|
setPaths();
|
|
|
|
|
|
|
|
|
|
|
|
function setPaths() {
|
|
|
|
var paths = window.location.pathname.split("/");
|
|
|
|
|
|
|
|
if (paths.length <= 1) {
|
|
|
|
getProjects();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!paths[1]) {
|
|
|
|
getProjects();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (paths[1] == "project") {
|
|
|
|
if (paths[2]) {
|
|
|
|
getProject(paths[2]);
|
|
|
|
if (paths[3]) {
|
2016-04-17 20:43:27 -05:00
|
|
|
getVersion(paths[2], paths[3]);
|
2016-04-15 16:57:59 -05:00
|
|
|
if (paths[4]) {
|
2016-04-17 20:43:27 -05:00
|
|
|
getStage(paths[2], paths[3], paths[4]);
|
2016-04-15 16:57:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getProjects();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
r.set("error", "Path Not found!");
|
|
|
|
}
|
2016-04-13 16:59:28 -05:00
|
|
|
|
|
|
|
|
|
|
|
function getProjects() {
|
|
|
|
get("/log/",
|
|
|
|
function(result) {
|
2016-04-15 16:57:59 -05:00
|
|
|
for (var i = 0; i < result.data.length; i++) {
|
|
|
|
setStatus(result.data[i]);
|
|
|
|
}
|
|
|
|
|
2016-04-13 16:59:28 -05:00
|
|
|
r.set("projects", result.data);
|
|
|
|
},
|
|
|
|
function(result) {
|
2016-04-15 16:57:59 -05:00
|
|
|
r.set("error", err(result).message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getProject(id) {
|
|
|
|
get("/log/" + id,
|
|
|
|
function(result) {
|
|
|
|
r.set("project", result.data);
|
|
|
|
},
|
|
|
|
function(result) {
|
|
|
|
r.set("error", err(result).message);
|
2016-04-13 16:59:28 -05:00
|
|
|
});
|
|
|
|
}
|
2016-04-06 11:31:22 -05:00
|
|
|
|
2016-04-17 20:43:27 -05:00
|
|
|
function getVersion(id, version) {
|
|
|
|
get("/log/" + id + "/" + version,
|
|
|
|
function(result) {
|
|
|
|
r.set("version", result.data);
|
|
|
|
},
|
|
|
|
function(result) {
|
|
|
|
r.set("error", err(result).message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getStage(id, version, stage) {
|
|
|
|
get("/log/" + id + "/" + version + "/" + stage,
|
|
|
|
function(result) {
|
|
|
|
r.set("stage", result.data);
|
|
|
|
},
|
|
|
|
function(result) {
|
|
|
|
r.set("error", err(result).message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-15 16:57:59 -05:00
|
|
|
function setStatus(project) {
|
|
|
|
//statuses
|
2016-04-17 20:43:27 -05:00
|
|
|
if (project.lastLog.version.trim() == project.releaseVersion.trim()) {
|
2016-04-15 16:57:59 -05:00
|
|
|
project.status = "Success";
|
|
|
|
} else {
|
|
|
|
if (project.lastLog.stage == "loading") {
|
|
|
|
project.status = "Load Failing";
|
|
|
|
} else if (project.lastLog.stage == "fetching") {
|
|
|
|
project.status = "Fetch Failing";
|
|
|
|
} else if (project.lastLog.stage == "building") {
|
|
|
|
project.status = "Build Failing";
|
|
|
|
} else if (project.lastLog.stage == "testing") {
|
|
|
|
project.status = "Tests Failing";
|
|
|
|
} else if (project.lastLog.stage == "releasing") {
|
|
|
|
project.status = "Release Failing";
|
|
|
|
} else {
|
|
|
|
project.status = "Failing";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 11:31:22 -05:00
|
|
|
})();
|
2016-04-13 16:59:28 -05:00
|
|
|
|
|
|
|
function ajax(type, url, data, success, error) {
|
|
|
|
"use strict";
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open(type, url);
|
|
|
|
|
|
|
|
if (success || error) {
|
|
|
|
req.onload = function() {
|
|
|
|
if (req.status >= 200 && req.status < 400) {
|
|
|
|
if (success && typeof success === 'function') {
|
|
|
|
success(JSON.parse(req.responseText));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//failed
|
|
|
|
if (error && typeof error === 'function') {
|
|
|
|
error(req);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
req.onerror = function() {
|
|
|
|
if (error && typeof error === 'function') {
|
|
|
|
error(req);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type != "get") {
|
|
|
|
req.setRequestHeader("Content-Type", "application/json");
|
|
|
|
}
|
|
|
|
|
|
|
|
req.send(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
function get(url, success, error) {
|
|
|
|
"use strict";
|
|
|
|
ajax("GET", url, null, success, error);
|
|
|
|
}
|
2016-04-14 11:29:56 -05:00
|
|
|
|
2016-04-15 16:57:59 -05:00
|
|
|
function err(response) {
|
|
|
|
"use strict";
|
|
|
|
var error = {
|
|
|
|
message: "An error occurred and has been logged",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof response === "string") {
|
|
|
|
error.message = response;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|