@ -2,42 +2,37 @@
{% block title %}{{ release }}{% endblock %}
{% block content %}
< div class = "container" >
< h2 > Release {{ release }}< / h2 >
< ul >
{% for p in projects %}
< div class = "panel panel-default" id = "{{ p }}-panel" >
< h2 > Release {{ release }}< / h2 >
{% for project in projects %}
< div class = "panel panel-default project" id = "{{ project }}" >
< div class = "panel-heading" >
< h3 class = "panel-title" > {{ p }}< / h3 >
< h3 class = "panel-title" >
< a href = "{% url 'panel:project-view' release project %}" >
{{ project }}
< / a >
< / h3 >
< / div >
< div class = "project panel-body" >
< ul class = "list-group list-inline build_info" id = "{{ p }}" >
< li class = "list-group-item bi source" id = "{{ p }}-get-code" >
< div class = "status" > {{ p }}-get-source< / div >
< / li >
< li class = "list-group-item bi tests" id = "{{ p }}-source-tests" >
< div class = "status" > {{ p }}-source-tests< / div >
< / li >
< li class = "list-group-item bi debs" id = "{{ p }}-source" >
< div class = "status" > {{ p }}-source< / div >
< / li >
< li class = "list-group-item bi debs" id = "{{ p }}-binaries" >
< div class = "status" > {{ p }}-binaries< / div >
< / li >
< li class = "list-group-item bi debs" id = "{{ p }}-repos" >
< div class = "status" > {{ p }}-repos< / div >
< / li >
< / ul >
< div class = "panel-body" >
< div class = "panel panel-default hidden uuid-clone" >
< div class = "panel-heading" >
< h3 class = "panel-title" > < / h3 >
< / div >
< div class = "panel-body" >
< ul class = "list-group list-inline uuid-list" >
< li class = "list-group-item hidden job" > < / li >
< / ul >
< / div >
< / div >
< / div >
< div class = "panel-footer error"> < / div >
< div class = "panel-footer" id = "{{ project}}-error" > < / div >
< / div >
{% endfor %}
< / ul >
{% endfor %}
< / div >
{% endblock %}
{% block extrajs %}
< script type = "text/javascript" >
$.release = {failed_projects: {}, interval: 60000, };
$.release = {};
function get_class_status(base, status) {
var result = base;
@ -54,93 +49,193 @@ function get_class_status(base, status) {
return result;
}
function set_project_status(project, project_build, value) {
var _project = $('#' + project + '-panel');
function set_project_status(project, value) {
var div_project = $('#' + project);
var div_uuid = $('.uuid:first', div_project);
console.debug('set_project_status');
if (value) {
var status = value.result;
div_project.addClass(get_class_status("panel-", status));
}
else {
console.debug('uuid that counts: ' + div_uuid.attr('id'));
if (div_uuid.hasClass('panel-warning')) {
div_project.addClass('panel-warning');
}
else if (div_uuid.hasClass('panel-danger')) {
div_project.addClass('panel-danger');
}
else if (div_uuid.hasClass('panel-success')) {
div_project.addClass('panel-success');
}
}
}
function set_uuid_status(project, uuid, job, value) {
var div_uuid = $('#' + project + '-' + uuid);
var status = value.result;
var _class = get_class_status("panel-", status);
switch (status) {
case "SUCCESS":
case "UNSTABLE":
if (project_build.match(/.+-repos$/)) {
_project.removeClass('panel-warning panel-danger').addClass(_class);
console.debug(project + " OK. done");
if (job .match(/.+-repos$/)) {
div_uuid .removeClass('panel-warning panel-danger').addClass(_class);
console.debug(project + ' uuid: ' + uuid + " OK. done");
}
else {
console.debug(project_build + ' nothing to do here.');
console.debug(job + ' nothing to do here.');
}
break;
default:
_project.addClass(_class);
if(! $.release.failed_projects[project]) {
$.release.failed_projects[project] = true;
console.debug(project_build + " set failed");
div_uuid .addClass(_class);
if(! $.release[project][uuid].failed ) {
$.release[project][uuid].failed = true;
console.debug(project + ' uuid: ' + uuid + ' set failed' );
}
set_project_status(project, value);
}
}
function set_build_status(project_build, value) {
var _project_build = $('#' + project_build);
function set_job_status(project, uuid, job, value) {
var id = project + '-' + uuid + '-' + job;
var div_job = $('#' + id);
if (value) {
var div_status = $('.status', _project_build);
var _class = get_class_status("list-group-item-", value.result);
console.debug("found " + project_build);
_project_build.removeClass('disabled').addClass(_class);
_project_build.show();
div_status.html('< a href = "' + value.job_url + value.buildnumber +'" > ' + project_build + '< / a > ');
console.debug(job + ' found');
div_job.addClass(get_class_status("list-group-item-", value.result));
div_job.html('< a href = "' + value . job_url + value . buildnumber
+ '">' + job + '< / a > ');
}
else {
console.debug("not found " + project_build);
_project_build.addClass('disabled');
_project_build.hide();
console.error(job + ' not found');
// this should not happend!!
}
}
function update_view(project, project_build, data) {
function create_new_job(project, uuid, job) {
var id = project + '-' + uuid;
var div_job = $('#' + id + '-job').clone().removeClass('hidden');
div_job.attr('id', id + '-' + job).html(job);
// put it on the proper place
div_job.appendTo('#' + id + '-list');
console.debug('job ' + job + ' created for ' + project + ' uuid: ' + uuid);
}
/**
* The idea is to have a hidden blocks to clone
* be sure to create proper ids and remove the classes
* you use to select them
*/
function create_new_uuid_panel(project, uuid) {
var id = project + '-' + uuid;
var div_uuid = $('#' + project +' > .panel-body .uuid-clone').clone();
div_uuid.removeClass('hidden');
div_uuid.attr('id', id).removeClass('uuid-clone').addClass('uuid');
// rest of blocks or classes to select inside this
$('.uuid-list', div_uuid).attr('id', id + '-list').removeClass('uuid-list');
$('.job', div_uuid).attr('id', id + '-job').removeClass('job');
var div_title = $('.panel-heading > .panel-title', div_uuid);
div_title.html(uuid);
// put it on the proper place
div_uuid.appendTo('#' + project + ' > .panel-body');
console.debug('uuid ' + uuid + ' created for ' + project);
}
function update_job_view(project, uuid, job, data) {
var value = data.results[0];
set_build_status(project_build, value);
set_job_status(project, uuid, job , value);
if (data.count == 0) {
if (! $.release.failed_projects[project]) {
if (! $.release.failed_projects[project_build]) {
$.release.failed_projects[project_build] = setInterval(function() {
update_build_info(project, project_build); }, $.release.interval);
console.debug('setInterval ' + $.release.interval/1000 +
's for ' + project_build);
}
if (data.count != 0) {
if ($.release[project][uuid][job].timer) {
clearInterval($.release[project][uuid][job].timer);
console.debug("clearInterval uuid: "+ uuid + ' ' + job);
}
set_uuid_status(project, uuid, job, value);
}
else {
console.error(job + ' not found');
// this should not happend!!
}
}
function update_job_info(release, project, uuid, job) {
function successFunc(data, textStatus, jqXHR ) {
update_job_view(project, uuid, job, data);
}
function errorFunc(jqXHR, status, error) {
$('#' + project + '-error').html(error);
$.release[project][uuid][job].failed = true;
}
if (! $.release[project][uuid].failed) {
if (! $.release[project][uuid][job].failed ) {
$.ajax({
url: '/jenkinsbuildinfo/?format=json& tag=' + uuid
+ '& param_release={{ release}}& projectname=' + job,
method: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
}
else {
console.debug(project + " already failed");
clearInterval($.release.failed_projects[project_build]);
console.debug("clearInterval: " + project_build);
set_project_status(project, project_build, {result: "FAILED"});
console.debug('uuid: ' + uuid + ' job: ' + job + ' already failed');
}
}
else {
clearInterval($.release.failed_projects[project_build]);
console.debug("clearInterval: " + project_build);
set_project_status(project, project_build, value);
console.debug(project + ' uuid: ' + uuid + ' already failed');
clearInterval($.release[project][uuid][job].timer);
console.debug("clearInterval uuid:" + uuid + ' ' + job);
set_project_status(project, {result: "FAILED"});
}
}
function update_build_info(project, project_build) {
var parent = $('#' + project_build).parent();
var div_err = $('.error', parent);
function update_uuid_info(release, project, uuid) {
function successFunc(data, textStatus, jqXHR ) {
update_view(project, project_build, data);
$(data).each(function() {
var job = this.projectname;
$.release[project][uuid].jobs.add(job);
if (! $.release[project][uuid][job]) {
$.release[project][uuid][job] = { failed: false, };
create_new_job(project, uuid, job);
update_job_info(release, project, uuid, job);
}
if (! $.release[project][uuid][job].failed) {
if (! $.release[project][uuid][job].timer) {
$.release[project][uuid][job].timer = setInterval(function() {
update_job_info(release, project, uuid, job); }, $.release[project].interval);
console.debug('uuid: ' + uuid +
' new job: ' + job +' setInterval ' + $.release[project].interval);
}
}
else {
console.debug('uuid: ' + job +' already failed');
}
});
}
function errorFunc(jqXHR, status, error) {
div_err.html(error);
$.release.failed_projects[project] = true;
$('#' + project + '-error') .html(error);
$.release[project][uuid].failed = true;
}
if (! $.release.failed_projects[project]) {
if (! $.release[project][uuid].failed) {
$.ajax({
url: '/jenkinsbuildinfo/?format=json& tag={{ release}}& projectname=' + project_build,
url: '/release/{{ release }}/' + project + '/' + uuid + '/?format=json' ,
method: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
@ -149,18 +244,62 @@ function update_build_info(project, project_build) {
});
}
else {
console.debug("update_build_info: "+ project + " already failed");
clearInterval($.release.failed_projects[project_build]);
console.debug("clearInterval: " + project_build);
set_project_status(project, project_build, {result: "FAILED"});
console.debug(project + 'uuid ' + uuid +' already failed');
clearInterval($.release[project][uuid].timer);
}
}
function get_uuids_for_project(release, project) {
function successFunc(data, textStatus, jqXHR ) {
$(data).each(function() {
var uuid = this.tag;
if (uuid == null) {
console.warn(project + " skip null uuid");
return;
}
$.release[project].uuids.add(uuid);
if (! $.release[project][uuid] ) {
$.release[project][uuid] = { failed: false, jobs: new Set(),};
create_new_uuid_panel(project, uuid);
update_uuid_info(release, project, uuid);
}
if (! $.release[project][uuid].failed ) {
if (! $.release[project][uuid].timer) {
$.release[project][uuid].timer = setInterval(function() {
update_uuid_info(release, project, uuid); }, $.release[project].interval);
console.debug(project + ' new uuid: ' + uuid +
' setInterval ' + $.release[project].interval);
}
}
else {
console.debug(project + ' uuid: ' + uuid +' already failed');
clearInterval($.release[project][uuid].timer);
console.debug(project + " clearInterval: " + uuid);
set_project_status(project, {result: "FAILED"});
}
});
}
function errorFunc(jqXHR, status, error) {
$('#' + project + '-error').html(error);
$.release[project].failed = true;
}
$.ajax({
url: '/release/{{ release }}/' + project + '/?format=json',
method: 'GET',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: successFunc,
error: errorFunc
});
}
$( document ).ready(function() {
$('.project > .build_info > .bi').each(function(){
var project_build = $(this).attr('id');
var project = $(this).parent().attr('id');
update_build_info(project, project_build);
$('.project').each(function(){
var project = $(this).attr('id');
$.release[project] = {uuids: new Set(), failed: false, interval: 5000,} ;
get_uuids_for_project('{{ release }}', project );
});
});
< / script >