Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bulk hyperlink button #1876

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -21,6 +21,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((_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 @@ -136,7 +154,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(() => addLinkToExecution(testExecution))
listGroupItem.find('.add-link-button').click(() => addLinkToExecutions([testExecution.id]))
listGroupItem.find('.one-click-bug-report-button').click(() => fileBugFromExecution(testExecution))

const ul = listGroupItem.find('.test-execution-hyperlinks')
Expand Down Expand Up @@ -168,6 +186,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(execution) {
return true // so that the modal is opened
}

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 = testExecutionRow.find('.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