Skip to content

Commit

Permalink
Merge 00e05e3 into 86c3605
Browse files Browse the repository at this point in the history
  • Loading branch information
asankov committed Aug 23, 2020
2 parents 86c3605 + 00e05e3 commit 9302439
Show file tree
Hide file tree
Showing 7 changed files with 196 additions and 28 deletions.
7 changes: 7 additions & 0 deletions docs/source/modules/tcms.core.contrib.linkreference.forms.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tcms.core.contrib.linkreference.forms module
============================================

.. automodule:: tcms.core.contrib.linkreference.forms
:members:
:undoc-members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/source/modules/tcms.core.contrib.linkreference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ Submodules
.. toctree::
:maxdepth: 4

tcms.core.contrib.linkreference.forms
tcms.core.contrib.linkreference.models
9 changes: 9 additions & 0 deletions tcms/core/contrib/linkreference/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django import forms

from tcms.core.contrib.linkreference.models import LinkReference


class LinkReferenceForm(forms.ModelForm):
class Meta:
model = LinkReference
exclude = ['created_on'] # pylint: disable=modelform-uses-exclude
1 change: 1 addition & 0 deletions tcms/rpc/api/testexecution.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def add_link(values, update_tracker=False):
tracker = tracker_from_url(link.url)

if (link.is_defect and
tracker is not None and
update_tracker and
not tracker.is_adding_testcase_to_issue_disabled()) or \
isinstance(tracker, KiwiTCMS):
Expand Down
112 changes: 86 additions & 26 deletions tcms/testruns/static/testruns/js/get.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
$(document).ready(() => {

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

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

Expand Down Expand Up @@ -131,12 +132,18 @@ function renderAdditionalInformation(testExecutions, testExecutionCaseIds) {
isAutomatedElement.addClass(isAutomatedIcon)
isAutomatedElement.attr('title', isAutomatedAttr)

jsonRPC('TestExecution.get_links', { 'execution_id': testExecution.id, 'is_defect': true }, bugs => {
listGroupItem.find('.test-execution-bugs-count').html(bugs.length)
jsonRPC('TestExecution.get_links', { 'execution_id': testExecution.id }, links => {
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('.one-click-bug-report-button').click(() => fileBugFromExecution(testExecution))

const ul = listGroupItem.find('.test-execution-hyperlinks')
links.forEach(link => ul.append(renderLink(link)))
})
})
})

}

function renderTestExecutionRow(template, testExecution, testExecutionStatus) {
Expand Down Expand Up @@ -185,28 +192,81 @@ 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 => {

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

// close the modal
$('#one-click-bug-report-modal button.close').click()
})

return false
})

return true // so that the modal is opened
}

function addLinkToExecution(testExecution) {

// remove all previous event handlers
$('.add-hyperlink-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.
$('.add-hyperlink-form').submit(() => {
const url = $('.add-hyperlink-form #id_url').val()
const name = $('.add-hyperlink-form #id_name').val()
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 ul = $(`.test-execution-${testExecution.id} .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)

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

return false;
})

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

function renderLink(link) {
const linkEntryTemplate = $('#link-entry')[0].content
const template = $(linkEntryTemplate.cloneNode(true))
if (link.is_defect) {
template.find('.link-icon').addClass('fa fa-bug')
}

template.find('.link-url').html(link.name || link.url)

return template
}
89 changes: 88 additions & 1 deletion tcms/testruns/templates/testruns/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,18 @@ <h5><span class="test-executions-count"></span> Results</h5>
<div class="list-view-pf-checkbox" style="margin-top: 0; margin-bottom: 0">
<input type="checkbox">
</div>
<div class="list-view-pf-actions" style="margin-top: 0; margin-bottom: 0;">
<div class="dropdown pull-right dropdown-kebab-pf">
<button class="btn btn-link dropdown-toggle" type="button" id="dropdownKebabRight9"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
<span class="fa fa-ellipsis-v"></span>
</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>
<div class="list-view-pf-body">
<div class="list-view-pf-description" style="flex: 1 0 30%;">
<div class="list-group-item-text">
Expand Down Expand Up @@ -240,8 +252,12 @@ <h5><span class="test-executions-count"></span> Results</h5>
<p class="test-execution-notes">
<strong>{% trans 'Notes' %}:</strong>
</p>
<strong>{% trans "Bugs and hyperlinks" %}: </strong>
<div>
{% comment %} TODO: bugs come here {% endcomment %}
<ul class="test-execution-hyperlinks"></ul>
<template id="link-entry">
<li><span class="link-icon"></span><a class="link-url" href="${link.url}">${link.name || link.url}</a></li>
</template>
</div>
</div>
</div>
Expand All @@ -262,8 +278,79 @@ <h5><span class="test-executions-count"></span> Results</h5>
</div> <!-- /row -->
</div>

<div class="modal fade" id="add-link-modal" tabindex="-1" role="dialog" aria-labelledby="add-hyperlink-modal-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="add-hyperlink-modal-title">{% trans "Add hyperlink" %}</h4>
</div>
<form class="form-horizontal add-hyperlink-form">
<div class="modal-body">
<div class="form-group">
<label class="col-sm-3 control-label" for="{{ link_form.url.id_for_label }}">{% trans "URL" %}</label>
<div class="col-sm-9">
<input type="url" name="{{ link_form.url.name }}" maxlength="{{ link_form.url.field.max_length }}" {% if link_form.url.field.required %}required{% endif %} id="{{ link_form.url.id_for_label }}" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="{{ link_form.name.id_for_label }}">{% trans "Name" %}</label>
<div class="col-sm-9">
<input type="text" name="{{ link_form.name.name }}" maxlength="{{ link_form.name.field.max_length }}" {% if link_form.name.field.required %}required{% endif %} id="{{ link_form.name.id_for_label }}" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-md-3 col-lg-3 col-sm-3 control-label" for="defectCheckbox">{% trans "Is a defect" %}</label>
<div class="col-md-3 col-lg-3">
<input class="bootstrap-switch" type="checkbox" id="defectCheckbox" data-on-text="{% trans 'Yes' %}" data-off-text="{% trans 'No' %}"/>
</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 add-hyperlink-button">{% trans "Save" %}</button>
</div>
</form>
</div>
</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" %}</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
5 changes: 4 additions & 1 deletion tcms/testruns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

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
from tcms.testruns.models import TestExecutionStatus, TestRun
from tcms.core.contrib.linkreference.forms import LinkReferenceForm

User = get_user_model() # pylint: disable=invalid-name

Expand Down Expand Up @@ -132,6 +133,8 @@ class GetTestRunView(DetailView): # pylint: disable=missing-permission-required
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 9302439

Please sign in to comment.