Skip to content

Commit

Permalink
Add bulk hyperlink button
Browse files Browse the repository at this point in the history
  • Loading branch information
asankov committed Aug 27, 2020
1 parent 46caed8 commit 9cf704b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 24 deletions.
63 changes: 41 additions & 22 deletions tcms/testruns/static/testruns/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ $(document).ready(() => {
}
});

$('.add-hyperlink-bulk').click(() => {
const testExecutionIds = []
const allChecked = $('.test-execution-checkbox:checked')

if (!allChecked.length) {
const warningText = $('#test_run_pk').data('trans-no-executions-selected')
alert(warningText)
return false
}

allChecked.each(function (_index, checkbox) {
const testExecutionId = $(checkbox).data('test-execution-id')
testExecutionIds.push(testExecutionId)
})

addLinkToExecutions(testExecutionIds)
})

const permRemoveTag = $('#test_run_pk').data('perm-remove-tag') === 'True';

// bind everything in tags table
Expand Down Expand Up @@ -135,7 +153,7 @@ function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
const bugCount = links.filter(link => link.is_defect).length;
listGroupItem.find('.test-execution-bugs-count').html(bugCount)

listGroupItem.find('.add-link-button').click(event => addLinkToExecution(event, testExecution))
listGroupItem.find('.add-link-button').click(() => addLinkToExecutions([testExecution.id]))

const ul = listGroupItem.find('.test-execution-hyperlinks')
links.forEach(link => ul.append(renderLink(link)))
Expand Down Expand Up @@ -166,6 +184,7 @@ function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
}

function renderTestExecutionRow(template, testExecution, testExecutionStatus) {
template.find('.test-execution-checkbox').data('test-execution-id', testExecution.id)
template.find('.list-group-item').addClass(`test-execution-${testExecution.id}`)
template.find('.test-execution-info').html(`TE-${testExecution.id}`)
template.find('.test-execution-info-link').html(testExecution.case)
Expand Down Expand Up @@ -237,8 +256,7 @@ function fileBugFromExecution(run_id, title_container, container, case_id, execu
dialog.show();
}

function addLinkToExecution(event, testExecution) {

function addLinkToExecutions(testExecutionIDs) {
// remove all previous event handlers
$('.add-hyperlink-form').off('submit')

Expand All @@ -250,28 +268,29 @@ function addLinkToExecution(event, testExecution) {
const isDefect = $('.add-hyperlink-form #defectCheckbox').is(':checked')
const updateTracker = true

jsonRPC('TestExecution.add_link', [{
execution_id: testExecution.id,
url: url,
name: name,
is_defect: isDefect,
}, updateTracker], link => {
const testExecutionRow = $(event.target).closest(`.test-execution-${testExecution.id}`);
animate(testExecutionRow, () => {
const ul = $(`.test-execution-${testExecution.id} .test-execution-hyperlinks`)
ul.append(renderLink(link))
testExecutionIDs.forEach(testExecutionId => {
jsonRPC('TestExecution.add_link', [{
execution_id: testExecutionId,
url: url,
name: name,
is_defect: isDefect,
}, updateTracker], link => {
const testExecutionRow = $(`div.list-group-item.test-execution-${testExecutionId}`);
animate(testExecutionRow, () => {
const ul = $(`.test-execution-${testExecutionId} .test-execution-hyperlinks`)
ul.append(renderLink(link))
})
})
})

// clean the values
$('.add-hyperlink-form #id_url').val('')
$('.add-hyperlink-form #id_name').val('')
$('.add-hyperlink-form #defectCheckbox').bootstrapSwitch('state', false)
$('.add-hyperlink-form #autoUpdateCheckbox').bootstrapSwitch('state', false)

// clean the values
$('.add-hyperlink-form #id_url').val('')
$('.add-hyperlink-form #id_name').val('')
$('.add-hyperlink-form #defectCheckbox').bootstrapSwitch('state', false)
$('.add-hyperlink-form #autoUpdateCheckbox').bootstrapSwitch('state', false)

// close the modal
$('#add-link-modal button.close').click()
})
// close the modal
$('#add-link-modal button.close').click()

return false;
})
Expand Down
5 changes: 3 additions & 2 deletions tcms/testruns/templates/testruns/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h1 class="col-md-12" style="margin-top: 0">
<span id="test_run_pk"
data-pk="{{ object.pk }}"
data-perm-remove-tag="{{ perms.testruns.delete_testruntag }}"
data-trans-no-executions-selected="{% trans 'No executions selected! Please select at least one execution!'%}"
>TR-{{ object.pk }}:</span> {{ object.summary }}
</h1>

Expand Down Expand Up @@ -161,7 +162,7 @@ <h2 class="card-pf-title">
</ul>
</div>
<button type="button" class="btn btn-default">{% trans "Add comment" %}</button>
<button type="button" class="btn btn-default">{% trans "Add hyperlink" %}</button>
<button type="button" class="btn btn-default add-hyperlink-bulk " data-toggle="modal" data-target="#add-link-modal">{% trans "Add hyperlink" %}</button>
</div>
</form>
<div class="row toolbar-pf-results">
Expand All @@ -186,7 +187,7 @@ <h5><span class="test-executions-count"></span> Results</h5>
<span class="fa fa-angle-right"></span>
</div>
<div class="list-view-pf-checkbox" style="margin-top: 0; margin-bottom: 0">
<input type="checkbox">
<input type="checkbox" class="test-execution-checkbox">
</div>
<div class="list-view-pf-actions" style="margin-top: 0; margin-bottom: 0;">
<div class="dropdown pull-right dropdown-kebab-pf">
Expand Down

0 comments on commit 9cf704b

Please sign in to comment.