From 584542f226ab28d35019551ca7a7191170458682 Mon Sep 17 00:00:00 2001 From: "andreea.moraru" Date: Sat, 3 Apr 2021 13:06:18 +0200 Subject: [PATCH] Update how the start date and stop date of the TestRun is set Fixes #2323 : - the start_date in the TestRun is not set automatically when the Test Run is created - a toggle button is added for setting the start date and stop date, when the date is set for start or finish, the toggle disappears and only the timestamp is visible on the page --- .../0014_remove_auto_setting_start_date.py | 23 ++++++++++ tcms/testruns/models.py | 2 +- tcms/testruns/static/testruns/js/get.js | 44 ++++++++++++------- tcms/testruns/templates/testruns/get.html | 31 +++++++------ 4 files changed, 69 insertions(+), 31 deletions(-) create mode 100644 tcms/testruns/migrations/0014_remove_auto_setting_start_date.py diff --git a/tcms/testruns/migrations/0014_remove_auto_setting_start_date.py b/tcms/testruns/migrations/0014_remove_auto_setting_start_date.py new file mode 100644 index 0000000000..754d0b7403 --- /dev/null +++ b/tcms/testruns/migrations/0014_remove_auto_setting_start_date.py @@ -0,0 +1,23 @@ +# Generated by Django 3.1.6 on 2021-04-03 10:29 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("testruns", "0013_remove_product_version"), + ] + + operations = [ + migrations.AlterField( + model_name="historicaltestrun", + name="start_date", + field=models.DateTimeField(blank=True, db_index=True, null=True), + ), + migrations.AlterField( + model_name="testrun", + name="start_date", + field=models.DateTimeField(blank=True, db_index=True, null=True), + ), + ] diff --git a/tcms/testruns/models.py b/tcms/testruns/models.py index a23c02f0e2..b64cb85f4e 100755 --- a/tcms/testruns/models.py +++ b/tcms/testruns/models.py @@ -26,7 +26,7 @@ class TestRun(models.Model, UrlMixin): history = KiwiHistoricalRecords() - start_date = models.DateTimeField(auto_now_add=True, db_index=True) + start_date = models.DateTimeField(db_index=True, null=True, blank=True) stop_date = models.DateTimeField(null=True, blank=True, db_index=True) planned_start = models.DateTimeField(db_index=True, null=True, blank=True) planned_stop = models.DateTimeField(db_index=True, null=True, blank=True) diff --git a/tcms/testruns/static/testruns/js/get.js b/tcms/testruns/static/testruns/js/get.js index d908db97ea..741039bc03 100644 --- a/tcms/testruns/static/testruns/js/get.js +++ b/tcms/testruns/static/testruns/js/get.js @@ -10,6 +10,10 @@ const allExecutionStatuses = {}, $(document).ready(() => { + $('[data-toggle="tooltip"]').tooltip({ + trigger: 'hover' + }); + permissions.removeTag = $('#test_run_pk').data('perm-remove-tag') === 'True' permissions.addComment = $('#test_run_pk').data('perm-add-comment') === 'True' permissions.removeComment = $('#test_run_pk').data('perm-remove-comment') === 'True' @@ -19,23 +23,29 @@ $(document).ready(() => { const testRunId = $('#test_run_pk').data('pk') - $('#status_button').on('switchChange.bootstrapSwitch', (_event, state) => { - if (state) { - jsonRPC('TestRun.update', [testRunId, { 'stop_date': null }], () => { - $('.stop-date').html('-') - $('#test_run_pk').parent('h1').css({ 'text-decoration': 'none' }) - }) - } else { - const timeZone = $('#clock').data('time-zone') - const now = currentTimeWithTimezone(timeZone) - - jsonRPC('TestRun.update', [testRunId, { 'stop_date': now }], testRun => { - const stopDate = moment(testRun.stop_date).format("DD MMM YYYY, HH:mm a") - $('.stop-date').html(stopDate) - $('#test_run_pk').parent('h1').css({ 'text-decoration': 'line-through' }) - }) - } - }) + $('#start-button').on('click', function () { + const timeZone = $('#clock').data('time-zone') + const now = currentTimeWithTimezone(timeZone) + + jsonRPC('TestRun.update', [testRunId, { 'start_date': now }], testRun => { + const startDate = moment(testRun.start_date).format("DD MMM YYYY, HH:mm a") + $('.start-date').html(startDate); + $(this).hide(); + }) + }); + + $('#stop-button').on('click', function () { + const timeZone = $('#clock').data('time-zone') + const now = currentTimeWithTimezone(timeZone) + + jsonRPC('TestRun.update', [testRunId, { 'stop_date': now }], testRun => { + const stopDate = moment(testRun.stop_date).format("DD MMM YYYY, HH:mm a") + $('.stop-date').html(stopDate); + $(this).hide(); + $('#test_run_pk').parent('h1').css({ 'text-decoration': 'line-through' }) + }) + }); + $('.add-comment-bulk').click(function () { $(this).parents('.dropdown').toggleClass('open') diff --git a/tcms/testruns/templates/testruns/get.html b/tcms/testruns/templates/testruns/get.html index fa2260bc8a..8a928e69df 100644 --- a/tcms/testruns/templates/testruns/get.html +++ b/tcms/testruns/templates/testruns/get.html @@ -63,13 +63,6 @@

{% endif %} -

- {% trans 'Status' %}: - -

{% trans 'Planned start' %}: @@ -79,6 +72,16 @@

{% trans 'Started at' %}: {{ object.start_date }} + + {{ object.start_date|default:'-' }} + + {% if not object.start_date %} + + {% endif %}

@@ -86,15 +89,17 @@

{{ object.planned_stop|default:'-' }}

-

+

{% trans 'Finished at' %}: - {% if object.stop_date %} - {{ object.stop_date }} - {% else %} - - - {% endif %} + {{ object.stop_date|default:'-' }} + {% if not object.stop_date %} + + {% endif %}