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

Added autocomplete input field for assigning bulk default user #3250

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 37 additions & 14 deletions tcms/testplans/static/testplans/js/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export function pageTestplansGetReadyHandler () {
'perm-remove-testcase': testPlanDataElement.data('perm-remove-testcase') === 'True',
'perm-add-testcase': testPlanDataElement.data('perm-add-testcase') === 'True',
'perm-add-comment': testPlanDataElement.data('perm-add-comment') === 'True',
'perm-delete-comment': testPlanDataElement.data('perm-delete-comment') === 'True'
'perm-delete-comment': testPlanDataElement.data('perm-delete-comment') === 'True',
'perm-view-user': testPlanDataElement.data('perm-view-user') === 'True'
}

// bind everything in tags table
Expand Down Expand Up @@ -376,6 +377,26 @@ function attachEvents (testPlanId, permissions) {
})
}

if (permissions['perm-view-user']) {
$('#default-tester-input').typeahead({
minLength: 3,
highlight: true
}, {
name: 'default-tester-autocomplete',
// will display up to X results even if more were returned
limit: 100,
async: true,
display: function (element) {
return element.username
},
source: function (query, processSync, processAsync) {
jsonRPC('User.filter', { username__icontains: query }, function (data) {
return processAsync(data)
})
}
})
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few issues with how this function/modal behaves:

Issue #1

  1. Use it once to assign a default tester. I chose "alice" then
  2. Mark some test cases and trigger the default tester modal again -> the text "alice" is still present inside the input field, it should be empty field instead

Issue #2

Every time the modal opens the typeahead handler gets initialized again. Using the modal 5-6 times without reloading the page leads to a chain of User.filter RPC calls instead of having only 1 call. This visibly slows down the page. This is similar to #3281 .


// get details and draw expand area only on expand
$('.js-testcase-row').click(function (ev) {
// don't trigger row expansion when kebab menu is clicked
Expand Down Expand Up @@ -540,23 +561,25 @@ function toolbarEvents (testPlanId, permissions) {
})

$('#default-tester-button').click(function (ev) {
$(this).parents('.dropdown').toggleClass('open')
const selectedCases = getSelectedTestCases()

if (!selectedCases.length) {
if (!getSelectedTestCases().length) {
alert($('#test_plan_pk').data('trans-no-testcases-selected'))
return false
ev.stopPropagation()
} else {
$('#default-tester-modal').modal('show')
}
return false
})

const emailOrUsername = window.prompt($('#test_plan_pk').data('trans-username-email-prompt'))

if (!emailOrUsername) {
return false
$('.default-tester-form').submit(function (ev) {
ev.preventDefault()
const selectedCases = getSelectedTestCases()
const emailOrUsername = $('#default-tester-input').val()
if (emailOrUsername) {
updateTestCasesViaAPI(selectedCases, { default_tester: emailOrUsername },
testPlanId, permissions)
}

updateTestCasesViaAPI(selectedCases, { default_tester: emailOrUsername },
testPlanId, permissions)

$('#default-tester-modal').modal('hide')
$('.default-tester-form').trigger('reset')
return false
})

Expand Down
27 changes: 27 additions & 0 deletions tcms/testplans/templates/testplans/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ <h1 class="col-md-12" style="margin-top: 0">
data-perm-add-testcase="{{ perms.testcases.add_testcase }}"
data-perm-add-comment="{{ perms.django_comments.add_comment }}"
data-perm-delete-comment="{{ perms.django_comments.delete_comment }}"
data-perm-view-user="{{ perms.auth.view_user }}"
data-trans-username-email-prompt="{% trans 'Enter username, email or user ID:' %}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, needs to be removed:

Suggested change
data-trans-username-email-prompt="{% trans 'Enter username, email or user ID:' %}"

data-trans-no-testcases-selected="{% trans 'No rows selected! Please select at least one!'%}"
data-trans-are-you-sure="{% trans 'Are you sure?' %}"
Expand Down Expand Up @@ -326,6 +327,32 @@ <h2 class="card-pf-title">

</div>

<div class="modal fade" id="default-tester-modal" tabindex="-1" role="dialog" aria-labelledby="default-tester-modal" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" aria-label="Close">
<span class="pficon pficon-close"></span>
</button>
<h4 class="modal-title" id="default-tester-modal-title">{% trans "Default Tester" %}</h4>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default Tester -> Default tester to minimize variations in translation strings

Suggested change
<h4 class="modal-title" id="default-tester-modal-title">{% trans "Default Tester" %}</h4>
<h4 class="modal-title" id="default-tester-modal-title">{% trans "Default tester" %}</h4>

</div>
<form class="form-horizontal default-tester-form">
<div class="modal-body">
<div class="form-group">
<label class="col-sm-5 control-label" for="default-tester">{% trans 'Enter username, email or user ID:' %}</label>
<div class="col-sm-6">
<input type="text" name="default-tester" id="default-tester-input" class="form-control">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">{% trans "Cancel" %}</button>
<button type="submit" class="btn btn-primary default-testerk-button">{% trans "Save" %}</button>
</div>
</form>
</div>
</div>
</div>
<template id="no_test_cases">
<div class="list-group-item">
<div class="list-group-item-header">
Expand Down