diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f2cdb19..fc91670 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,5 +26,12 @@ repos: hooks: - id: eslint args: ['--fix'] + exclude: > + (?x)^( + .*/*min.js| + panel/static/panel/js/jquery*.js| + panel/static/panel/js/npm.js| + panel/static/panel/js/bootstrap.js| + )$ additional_dependencies: - eslint-config-jquery diff --git a/panel/static/panel/js/panel.js b/panel/static/panel/js/panel.js index 0d55e6e..b6e8069 100644 --- a/panel/static/panel/js/panel.js +++ b/panel/static/panel/js/panel.js @@ -199,6 +199,7 @@ function create_new_project_stat( project, label ) { $( "#" + id ).remove(); } var div_project = $( ".stats-project-" + label + "-clone" ).clone(); + var div_link = $( ".link", div_project ); var jobs = 0; div_project.removeClass( "hidden stats-project-" + label + "-clone" ); @@ -211,14 +212,13 @@ function create_new_project_stat( project, label ) { jobs = $.release[ project ][ uuid ].jobs.size; } } - var div_link = $( ".link", div_project ); div_link.attr( "href", "#" + project ); - div_link.text( project ); $( ".badge", div_project ).text( jobs ); } else { - div_project.text( project ); - console.debug( project + " on queue" ); + div_link.attr( "onclick", "click_build(event, \"" + project + "\")" ); + console.debug( project + " on queue" ); } + div_link.text( project ); // put it on the proper place div_project.appendTo( "#stats-list-" + label ); diff --git a/panel/static/panel/js/panel_release.js b/panel/static/panel/js/panel_release.js index d3c5b5f..6f47670 100644 --- a/panel/static/panel/js/panel_release.js +++ b/panel/static/panel/js/panel_release.js @@ -4,6 +4,21 @@ function click_retrigger( e, project ) { e.preventDefault(); } +/* eslint-disable-next-line no-unused-vars*/ // used at onClick +function click_build( e, project ) { + var div_project = $( "#stats-" + project ); + if ( $.release.release_jobs.size < $.release.release_jobs_size ) { + alert( "Not all release_jobs are done, builds are not allowed" ); + } else { + var ok = confirm( "This will build " + project + ", are you sure?" ); + if ( ok === true ) { + div_project.text( project ); + build_queued_project( project ); + } + } + e.preventDefault(); +} + /* eslint-disable-next-line no-unused-vars*/ // used at onClick function click_resume( e, id ) { resume_build( id ); @@ -90,6 +105,40 @@ function retrigger_project( project ) { } ); } +function build_queued_project( project ) { + + function successFunc( _data, _textStatus, _jqXHR ) { + console.debug( "build sent for " + project ); + } + + function errorFunc( _jqXHR, _status, error ) { + console.error( error ); + } + var csrftoken = jQuery( "[name=csrfmiddlewaretoken]" ).val(); + function csrfSafeMethod( method ) { + + // these HTTP methods do not require CSRF protection + return ( /^(GET|HEAD|OPTIONS|TRACE)$/.test( method ) ); + } + $.ajaxSetup( { + beforeSend: function( xhr, settings ) { + if ( !csrfSafeMethod( settings.type ) && !this.crossDomain ) { + xhr.setRequestHeader( "X-CSRFToken", csrftoken ); + } + } + } ); + var url = "/build/" + $.release.uuid + "/" + project + "/?format=json"; + $.ajax( { + async: true, + url: url, + method: "POST", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: successFunc, + error: errorFunc + } ); +} + function create_new_release_job( data ) { var job = data.jobname; if ( $.release.release_jobs.has( job ) ) { diff --git a/panel/templates/panel/release_stats.html b/panel/templates/panel/release_stats.html index 09a5126..dc1dd58 100644 --- a/panel/templates/panel/release_stats.html +++ b/panel/templates/panel/release_stats.html @@ -67,7 +67,7 @@