From 5582ec6989f48a46f94f6a8838738c9f9e4d3478 Mon Sep 17 00:00:00 2001 From: asankov Date: Thu, 30 Apr 2020 01:18:00 +0300 Subject: [PATCH 1/6] Add LinkReference form to be used in the modal that creates hyperlink for out-of-the-box validation --- tcms/core/contrib/linkreference/forms.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tcms/core/contrib/linkreference/forms.py diff --git a/tcms/core/contrib/linkreference/forms.py b/tcms/core/contrib/linkreference/forms.py new file mode 100644 index 0000000000..5da50ab685 --- /dev/null +++ b/tcms/core/contrib/linkreference/forms.py @@ -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 From ae0faf64471c6610606c06e19f37dfcf42de8fc8 Mon Sep 17 00:00:00 2001 From: asankov Date: Wed, 29 Apr 2020 19:25:55 +0300 Subject: [PATCH 2/6] Add 'Add link' modal For each TestExecution in TestRun page. Use LinkReference form for validation. --- tcms/testruns/static/testruns/js/get.js | 55 +++++++++++++++++++++-- tcms/testruns/templates/testruns/get.html | 45 ++++++++++++++++++- tcms/testruns/views.py | 2 + 3 files changed, 98 insertions(+), 4 deletions(-) diff --git a/tcms/testruns/static/testruns/js/get.js b/tcms/testruns/static/testruns/js/get.js index 446f129444..509a35015d 100644 --- a/tcms/testruns/static/testruns/js/get.js +++ b/tcms/testruns/static/testruns/js/get.js @@ -131,12 +131,17 @@ 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').on('click', () => addLinkToExecution(testExecution)) + + const ul = listGroupItem.find('.test-execution-hyperlinks') + links.forEach(link => ul.append(renderLink(link))) }) }) }) - } function renderTestExecutionRow(template, testExecution, testExecutionStatus) { @@ -210,3 +215,47 @@ function fileBugFromExecution(run_id, title_container, container, case_id, execu dialog.show(); } + +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 = $('.add-hyperlink-form #autoUpdateCheckbox').is(':checked') + + 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 icon = link.is_defect ? `` : '' + return `
  • ${icon} ${link.name || link.url}
  • ` +} diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 896aeafd87..7089f68ead 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -240,8 +240,10 @@
    Results

    {% trans 'Notes' %}:

    + {% trans "Bugs and hyperlinks" %}: + [ Add ]
    - {% comment %} TODO: bugs come here {% endcomment %} +
    @@ -262,6 +264,47 @@
    Results
    + + diff --git a/tcms/testruns/views.py b/tcms/testruns/views.py index 48bc313d26..b8f3d1c66b 100755 --- a/tcms/testruns/views.py +++ b/tcms/testruns/views.py @@ -21,6 +21,7 @@ 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 @@ -132,6 +133,7 @@ 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() return context def render_to_response(self, context, **response_kwargs): From 4f0fcf4cecf978416a171fc5b022b67922cea75d Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Tue, 11 Aug 2020 18:26:13 +0300 Subject: [PATCH 3/6] Make docs --- .../modules/tcms.core.contrib.linkreference.forms.rst | 7 +++++++ docs/source/modules/tcms.core.contrib.linkreference.rst | 1 + 2 files changed, 8 insertions(+) create mode 100644 docs/source/modules/tcms.core.contrib.linkreference.forms.rst diff --git a/docs/source/modules/tcms.core.contrib.linkreference.forms.rst b/docs/source/modules/tcms.core.contrib.linkreference.forms.rst new file mode 100644 index 0000000000..5b5c6f0f64 --- /dev/null +++ b/docs/source/modules/tcms.core.contrib.linkreference.forms.rst @@ -0,0 +1,7 @@ +tcms.core.contrib.linkreference.forms module +============================================ + +.. automodule:: tcms.core.contrib.linkreference.forms + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/source/modules/tcms.core.contrib.linkreference.rst b/docs/source/modules/tcms.core.contrib.linkreference.rst index d177f16c63..1d539fc307 100644 --- a/docs/source/modules/tcms.core.contrib.linkreference.rst +++ b/docs/source/modules/tcms.core.contrib.linkreference.rst @@ -12,4 +12,5 @@ Submodules .. toctree:: :maxdepth: 4 + tcms.core.contrib.linkreference.forms tcms.core.contrib.linkreference.models From e71ce802c1b5cc6c5328d0620973ca4518d5c41f Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Sat, 15 Aug 2020 18:05:45 +0300 Subject: [PATCH 4/6] Visual improvements - mark text for translation - remove 'update bug tracker' dropdown - use 'template' instead of html in js - `btn-danger`, not `btn-default` --- tcms/testruns/static/testruns/js/get.js | 13 ++++++--- tcms/testruns/templates/testruns/get.html | 33 ++++++++++++++--------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/tcms/testruns/static/testruns/js/get.js b/tcms/testruns/static/testruns/js/get.js index 509a35015d..0dcfd0d0f2 100644 --- a/tcms/testruns/static/testruns/js/get.js +++ b/tcms/testruns/static/testruns/js/get.js @@ -227,7 +227,7 @@ function addLinkToExecution(testExecution) { 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 = $('.add-hyperlink-form #autoUpdateCheckbox').is(':checked') + const updateTracker = true jsonRPC('TestExecution.add_link', [{ execution_id: testExecution.id, @@ -256,6 +256,13 @@ function addLinkToExecution(testExecution) { } function renderLink(link) { - const icon = link.is_defect ? `` : '' - return `
  • ${icon} ${link.name || link.url}
  • ` + 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 } diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 7089f68ead..32219b39d5 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -188,6 +188,17 @@
    Results
    +
    + +
    @@ -241,9 +252,11 @@
    Results
    {% trans 'Notes' %}:

    {% trans "Bugs and hyperlinks" %}: - [ Add ]
    +
    @@ -271,34 +284,30 @@
    Results
    - +
    From 30c7c0f2ea400332b4e8e56f7c051162dd5d881f Mon Sep 17 00:00:00 2001 From: Anton Sankov Date: Fri, 21 Aug 2020 21:13:26 +0300 Subject: [PATCH 5/6] Fixes - don't fail if `tracker` is None - use `.click(handler)` instead of `.on('click', handler)` - bootstrap switch allignment --- tcms/rpc/api/testexecution.py | 1 + tcms/testruns/static/testruns/js/get.js | 2 +- tcms/testruns/templates/testruns/get.html | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/tcms/rpc/api/testexecution.py b/tcms/rpc/api/testexecution.py index 9c79bf48d2..fb408d7473 100644 --- a/tcms/rpc/api/testexecution.py +++ b/tcms/rpc/api/testexecution.py @@ -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): diff --git a/tcms/testruns/static/testruns/js/get.js b/tcms/testruns/static/testruns/js/get.js index 0dcfd0d0f2..fdc39ba1f0 100644 --- a/tcms/testruns/static/testruns/js/get.js +++ b/tcms/testruns/static/testruns/js/get.js @@ -135,7 +135,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').on('click', () => addLinkToExecution(testExecution)) + listGroupItem.find('.add-link-button').click(() => addLinkToExecution(testExecution)) const ul = listGroupItem.find('.test-execution-hyperlinks') links.forEach(link => ul.append(renderLink(link))) diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 32219b39d5..6393cd7e97 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -302,7 +302,9 @@