Skip to content

Commit

Permalink
Add 'Report bug'
Browse files Browse the repository at this point in the history
via one-click to new Test Run page
  • Loading branch information
asankov authored and atodorov committed Sep 9, 2020
1 parent 14f1861 commit c548207
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
49 changes: 24 additions & 25 deletions tcms/testruns/static/testruns/js/get.js
@@ -1,6 +1,7 @@
$(document).ready(() => {

$('.bootstrap-switch').bootstrapSwitch();
$('.selectpicker').selectpicker();

const testRunId = $('#test_run_pk').data('pk')

Expand Down Expand Up @@ -135,7 +136,8 @@ 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(() => addLinkToExecution(testExecution))
listGroupItem.find('.one-click-bug-report-button').click(() => fileBugFromExecution(testExecution))

const ul = listGroupItem.find('.test-execution-hyperlinks')
links.forEach(link => ul.append(renderLink(link)))
Expand Down Expand Up @@ -211,30 +213,28 @@ function updateExecutionText() {
window.location.reload(true);
}

function fileBugFromExecution(run_id, title_container, container, case_id, execution_id) {
// todo: this dialog needs to be reimplemented with a Patternfly modal
var dialog = new AddIssueDialog({
'action': 'Report',
'onSubmit': function (e, dialog) {
e.stopPropagation();
e.preventDefault();

var tracker_id = dialog.get_data()['bug_system_id'];
jsonRPC('Bug.report', [execution_id, tracker_id], function (result) {
$('#dialog').hide();

if (result.rc === 0) {
// unescape b/c Issue #1533
const target_url = result.response.replace(/&/g, '&')
window.open(target_url, '_blank');
} else {
window.alert(result.response);
}
});
}
});
function fileBugFromExecution(execution) {

// remove all previous event handlers
$('.one-click-bug-report-form').off('submit')

// this handler must be here, because if we bind it when the page is loaded.
// we have no way of knowing for what execution ID the form is submitted for.
$('.one-click-bug-report-form').submit(() => {
const trackerId = $('.one-click-bug-report-form #id-issue-tracker').val()
jsonRPC('Bug.report', [execution.id, trackerId], result => {

// unescape b/c Issue #1533
const targetUrl = result.response.replace(/&/g, '&')
window.open(targetUrl, '_blank')

dialog.show();
// close the modal
$('#one-click-bug-report-modal button.close').click()
})
return false
})

return true // so that the modal is opened
}

function addLinkToExecution(event, testExecution) {
Expand Down Expand Up @@ -276,7 +276,6 @@ function addLinkToExecution(event, testExecution) {
return false;
})


return true; // so that the modal is opened
}

Expand Down
33 changes: 33 additions & 0 deletions tcms/testruns/templates/testruns/get.html
Expand Up @@ -196,6 +196,7 @@ <h5><span class="test-executions-count"></span> Results</h5>
</button>
<ul class="dropdown-menu dropdown-menu-right" aria-labelledby="dropdownKebabRight9">
<li><a href="#" class="add-link-button" data-toggle="modal" data-target="#add-link-modal">{% trans 'Add hyperlink' %}</a></li>
<li><a href="#" class="one-click-bug-report-button" data-toggle="modal" data-target="#one-click-bug-report-modal">{% trans 'Report bug' %}</a></li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -327,8 +328,40 @@ <h4 class="modal-title" id="add-hyperlink-modal-title">{% trans "Add hyperlink"
</div>
</div>

<div class="modal fade" id="one-click-bug-report-modal" tabindex="-1" role="dialog" aria-labelledby="one-click-bug-report-title" 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="one-click-bug-report-title">{% trans "Report bug" %}</h4>
</div>
<form class="form-horizontal one-click-bug-report-form">
<div class="modal-body">
<div class="form-group">
<label class="col-sm-3 control-label" for="issue-tracker-select">{% trans "Issue Tracker" %}</label>
<div class="col-sm-9">
<select name="issue-tracker" id="id-issue-tracker" class="form-control selectpicker">
{% for btr in bug_trackers %}
<option value="{{ btr.pk }}">{{ btr.name }}</option>
{% endfor %}
</select>
</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 one-click-bug-report-button">{% trans "Report Bug" %}</button>
</div>
</form>
</div>
</div>
</div>

<script src="{% static 'typeahead.js/dist/typeahead.jquery.min.js' %}"></script>
<script src="{% static 'bootstrap-switch/dist/js/bootstrap-switch.min.js' %}"></script>
<script src="{% static 'bootstrap-select/dist/js/bootstrap-select.min.js' %}"></script>
<script src="{% static 'moment/min/moment.min.js' %}"></script>
<script src="{% static 'moment-timezone/builds/moment-timezone-with-data.min.js' %}"></script>

Expand Down
3 changes: 2 additions & 1 deletion tcms/testruns/views.py
Expand Up @@ -16,7 +16,7 @@

from tcms.core.response import ModifySettingsTemplateResponse
from tcms.management.models import Build
from tcms.testcases.models import TestCasePlan, TestCaseStatus
from tcms.testcases.models import BugSystem, TestCasePlan, TestCaseStatus
from tcms.testcases.views import get_selected_testcases
from tcms.testplans.models import TestPlan
from tcms.testruns.forms import BaseRunForm, NewRunForm, SearchRunForm
Expand Down Expand Up @@ -136,6 +136,7 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['execution_statuses'] = TestExecutionStatus.objects.order_by('-weight', 'name')
context['link_form'] = LinkReferenceForm()
context['bug_trackers'] = BugSystem.objects.all()
return context

def render_to_response(self, context, **response_kwargs):
Expand Down

0 comments on commit c548207

Please sign in to comment.