From c499030a1d93c2e3fafbbfee5076f976f362cdf2 Mon Sep 17 00:00:00 2001 From: asankov Date: Fri, 21 Feb 2020 17:49:45 +0200 Subject: [PATCH 1/4] Add status bar to Test Run page --- tcms/testruns/static/testruns/js/get.js | 79 +++++++++++++++++++++++ tcms/testruns/templates/testruns/get.html | 19 ++++++ 2 files changed, 98 insertions(+) diff --git a/tcms/testruns/static/testruns/js/get.js b/tcms/testruns/static/testruns/js/get.js index b413298d51..0be21f7208 100644 --- a/tcms/testruns/static/testruns/js/get.js +++ b/tcms/testruns/static/testruns/js/get.js @@ -1,3 +1,5 @@ +let executionStatuses; + $(document).ready(() => { $('.bootstrap-switch').bootstrapSwitch(); @@ -18,4 +20,81 @@ $(document).ready(() => { // bind everything in tags table tagsCard('TestRun', testRunId, { run: testRunId }, permRemoveTag); + + jsonRPC('TestExecutionStatus.filter', {}, data => { + executionStatuses = data + drawPercentBar(testRunId) + }) }) + +function drawPercentBar(testRunId) { + + jsonRPC('TestExecution.filter', { 'run_id': testRunId }, testExecutions => { + + let positiveCount = 0; + let negativeCount = 0; + let allCount = testExecutions.length; + let statusCount = {} + executionStatuses.forEach(s => statusCount[s.name] = { count: 0, id: s.id }) + + testExecutions.forEach(testExecution => { + const executionStatus = executionStatuses.find(s => s.id === testExecution.status_id) + + if (executionStatus.weight > 0) { + positiveCount++ + } else if (executionStatus.weight < 0) { + negativeCount++ + } + + statusCount[executionStatus.name].count++ + }) + + renderProgressBars(positiveCount, negativeCount, allCount) + renderCountPerStatusList(statusCount) + }) +} + +function renderProgressBars(positiveCount, negativeCount, allCount) { + + const positivePercent = +(positiveCount / allCount * 100).toFixed(2) + const positiveBar = $(".progress > .progress-completed") + if (positivePercent) { + positiveBar.text(`${positivePercent}%`) + } + positiveBar.css('width', `${positivePercent}%`) + positiveBar.attr('aria-valuenow', `${positivePercent}`) + + const negativePercent = +(negativeCount / allCount * 100).toFixed(2) + const negativeBar = $('.progress > .progress-failed') + if (negativePercent) { + negativeBar.text(`${negativePercent}%`) + } + negativeBar.css('width', `${negativePercent}%`) + negativeBar.attr('aria-valuenow', `${negativePercent}`) + + const neutralPercent = +(100 - (negativePercent + positivePercent)).toFixed(2) + const neutralBar = $('.progress > .progress-bar-remaining') + if (neutralPercent) { + neutralBar.text(`${neutralPercent}%`) + } + neutralBar.css('width', `${neutralPercent}%`) + neutralBar.attr('aria-valuenow', `${neutralPercent}`) + + $(".total-execution-count").text(allCount) +} + +function renderCountPerStatusList(statusCount) { + $(".count-per-status-list").remove() + $(".count-per-status-container").prepend('') + + for (var status in statusCount) { + const count = statusCount[status].count + const element = count ? `${count}` : '0' + + $(".count-per-status-list").append(` +
  • + - ${element} +
  • + `) + } +} diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 5644e341f1..9aa3830c6c 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -19,6 +19,25 @@

    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
      +
    +
  • + - +
  • +
    +
    +
    +
    +
    From 2330b4a7fbce4335700d04ef1503d45e20fd1bd9 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Wed, 15 Apr 2020 13:45:20 +0300 Subject: [PATCH 2/4] Move the card around and adjust column sizes --- tcms/testruns/templates/testruns/get.html | 41 ++++++++++++----------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 9aa3830c6c..60ebd1e591 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -19,25 +19,6 @@

    -
    -
    -
    -
    -
    -
    -
    -
    -
    -
      -
    -
  • - - -
  • -
    -
    -
    -
    -
    @@ -97,10 +78,32 @@

    + +
    +
    +
    +
    +
    +
    +
    +
    +
    +
      +
    +
  • + - +
  • +
    +
    +
    +
    +
    {% include 'include/tags_card.html' with add_perm=perms.testruns.add_testruntag %}
    +
    +
    {% include 'include/attachments.html' %}
    From 610d12080e61726e8a80241a4b8b4ad7b6b7617d Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Wed, 15 Apr 2020 14:09:20 +0300 Subject: [PATCH 3/4] Render status placeholders outside JavaScript removes HTML mangling inside JavaScript --- tcms/testruns/static/testruns/js/get.js | 15 ++++----------- tcms/testruns/templates/testruns/get.html | 6 ++++++ tcms/testruns/views.py | 7 ++++++- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tcms/testruns/static/testruns/js/get.js b/tcms/testruns/static/testruns/js/get.js index 0be21f7208..eec06cecfe 100644 --- a/tcms/testruns/static/testruns/js/get.js +++ b/tcms/testruns/static/testruns/js/get.js @@ -84,17 +84,10 @@ function renderProgressBars(positiveCount, negativeCount, allCount) { } function renderCountPerStatusList(statusCount) { - $(".count-per-status-list").remove() - $(".count-per-status-container").prepend('') - for (var status in statusCount) { - const count = statusCount[status].count - const element = count ? `${count}` : '0' - - $(".count-per-status-list").append(` -
  • - - ${element} -
  • - `) + const status_id = statusCount[status].id; + + $(`#count-for-status-${status_id}`).attr('href', `?status_id=${status_id}`); + $(`#count-for-status-${status_id}`).text(statusCount[status].count); } } diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 60ebd1e591..2fe0ce7b47 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -89,7 +89,13 @@

      + {% for status in execution_statuses%} +
    • + - +
    • + {% endfor %}
    +
  • -
  • diff --git a/tcms/testruns/views.py b/tcms/testruns/views.py index 9448ba9ab9..706cbe6097 100755 --- a/tcms/testruns/views.py +++ b/tcms/testruns/views.py @@ -22,7 +22,7 @@ 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 TestExecution, TestRun +from tcms.testruns.models import TestExecution, TestExecutionStatus, TestRun User = get_user_model() # pylint: disable=invalid-name @@ -131,6 +131,11 @@ class GetTestRunView(DetailView): # pylint: disable=missing-permission-required model = TestRun response_class = ModifySettingsTemplateResponse + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['execution_statuses'] = TestExecutionStatus.objects.order_by('-weight', 'name') + return context + def render_to_response(self, context, **response_kwargs): self.response_class.modify_settings = modify_settings( MENU_ITEMS={'append': [ From 7fe98df79ba76d4d025ebc7d61ce5e09d14dc752 Mon Sep 17 00:00:00 2001 From: "Mr. Senko" Date: Wed, 15 Apr 2020 14:13:25 +0300 Subject: [PATCH 4/4] Patch the TOTAL execution count widget b/c it was incorrect - can't have
  • elements outside of
      - spacing between label & number was missing - inconsistent with the labels above - point the URL explicitly to the current TR instead of using '#' Note: when using '#' for the URL and filtering by status the resulting URL was '/runs/123/?status_id=x#', now it is '/runs/123/'! --- tcms/testruns/templates/testruns/get.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index 2fe0ce7b47..2571303232 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -96,9 +96,9 @@

      {% endfor %}

    -
  • - - -
  • +
    + - +