Last active
November 22, 2017 12:58
-
-
Save Buthrakaur/406487f4ba47f017f271c0a6d6305986 to your computer and use it in GitHub Desktop.
Nevercode Cancel All Builds CJS script - adds "Cancel All" button to NC Project detail page (https://app.nevercode.io/#/project/xxx)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var cookies; | |
function readCookie(name,c,C,i){ | |
if(cookies){ return cookies[name]; } | |
c = document.cookie.split('; '); | |
cookies = {}; | |
for(i=c.length-1; i>=0; i--){ | |
C = c[i].split('='); | |
cookies[C[0]] = C[1]; | |
} | |
return cookies[name]; | |
} | |
window.readCookie = readCookie; | |
var projectId = window.location.href.match(/project\/([a-z|0-9|-]+)/)[1]; | |
$.ajax({ | |
url: `/api/projects/${projectId}`, | |
type: 'GET', | |
headers: {'X-CSRFToken': window.readCookie('live_csrftoken')} | |
}) | |
.done(function(data){ | |
window.defaultWorkflow = data.workflows[0].id; | |
}); | |
})(); | |
$('builds-list').append('<button>Cancel All</button>'); | |
$('builds-list').on('click', 'button', function(){ | |
alert('all running builds will be canceled'); | |
//debugger; | |
var projectId = window.location.href.match(/project\/([a-z|0-9|-]+)/)[1]; | |
var workflowId = window.defaultWorkflow; | |
$(this).closest('builds-list').find('.table-builds .column-version a') | |
.each(function(){ | |
var buildStatus = $(this).closest('tr').find('.status-circle').attr('title'); | |
if (buildStatus !== 'queued' && buildStatus !== 'building' && buildStatus !== 'fetching') return; | |
var buildUrl = $(this).attr('href'); | |
var buildId = buildUrl.match(/build\/(.+)/)[1]; | |
//alert(buildId); | |
$.ajax({ | |
url: `/api/projects/${projectId}/workflows/${workflowId}/builds/${buildId}/cancel`, | |
type: 'PUT', | |
headers: {'X-CSRFToken': window.readCookie('live_csrftoken')} | |
}); | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment