Skip to content

Commit

Permalink
Add bulk action for changing default tester
Browse files Browse the repository at this point in the history
  • Loading branch information
RMadjev authored and atodorov committed Oct 8, 2020
1 parent 56ae26f commit 950c35a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
50 changes: 45 additions & 5 deletions tcms/testplans/static/testplans/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $(document).ready(function() {
});

toolbarDropdowns();
toolbarEvents(testPlanId);
toolbarEvents(testPlanId, permissions);

collapseDocumentText();
});
Expand Down Expand Up @@ -90,6 +90,15 @@ function drawTestCases(testCases, testPlanId, permissions) {
}
}

function redrawSingleRow(testCaseId, testPlanId, permissions) {
var testCaseRowDocumentFragment = $('#test_case_row')[0].content,
newRow = getTestCaseRowContent(testCaseRowDocumentFragment.cloneNode(true), allTestCases[testCaseId], permissions);

// replace the element in the dom
$(`[data-testcase-pk=${testCaseId}]`).replaceWith(newRow);
attachEvents(allTestCases[testCaseId], testPlanId, permissions);
}

function getTestCaseRowContent(rowContent, testCase, permissions) {
var row = $(rowContent);

Expand Down Expand Up @@ -183,13 +192,13 @@ function attachEvents(testCases, testPlanId, permissions) {
if (permissions['perm-change-testcase']) {
// update default tester
$('.js-test-case-menu-tester').click(function(ev) {
var email_or_username = window.prompt($('#test_plan_pk').data('trans-default-tester-prompt-message'));
if (!email_or_username) {
var emailOrUsername = window.prompt($('#test_plan_pk').data('trans-default-tester-prompt-message'));
if (!emailOrUsername) {
return;
}
const testCaseId = getCaseIdFromEvent(ev);

jsonRPC('TestCase.update', [testCaseId, {'default_tester': email_or_username}], function(tc) {
jsonRPC('TestCase.update', [testCaseId, {'default_tester': emailOrUsername}], function(tc) {
const testCaseRow = $(ev.target).closest(`[data-testcase-pk=${testCaseId}]`);
animate(testCaseRow, function() {
testCaseRow.find('.js-test-case-tester').html(tc.default_tester);
Expand Down Expand Up @@ -268,7 +277,7 @@ function attachEvents(testCases, testPlanId, permissions) {
}
}

function toolbarEvents(testPlanId) {
function toolbarEvents(testPlanId, permissions) {

$('.js-checkbox-toolbar').click(function(ev) {
const isChecked = ev.target.checked;
Expand Down Expand Up @@ -381,6 +390,37 @@ function toolbarEvents(testPlanId) {
}
}
});

$('#default-tester-button').click(function(ev) {
let selectedCases = getSelectedTestCases();

if (!selectedCases.length) {
alert($('#test_plan_pk').data('trans-no-testcases-selected'));
return;
}

var emailOrUsername = window.prompt($('#test_plan_pk').data('trans-default-tester-prompt-message'));

if (!emailOrUsername) {
return;
}

for (let i = 0; i < selectedCases.length; i++) {
let testCaseId = selectedCases[i];

jsonRPC('TestCase.update', [testCaseId, {'default_tester': emailOrUsername}], function(tc) {
const testCaseRow = $(`[data-testcase-pk=${testCaseId}]`);

//update the data
allTestCases[testCaseId].default_tester = tc.default_tester;

animate(testCaseRow, function() {
redrawSingleRow(testCaseId, testPlanId, permissions);
});
});
}

});
}

function toolbarDropdowns() {
Expand Down
2 changes: 1 addition & 1 deletion tcms/testplans/templates/testplans/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ <h2 class="card-pf-title">
</ul>
</div>
<button class="btn btn-default"
type="button"
type="button" id="default-tester-button"
{% if not perms.testcases.change_testcase %}
disabled
{% endif %}>{% trans 'Default tester' %}</button>
Expand Down

0 comments on commit 950c35a

Please sign in to comment.