Skip to content

Commit

Permalink
Remove duplicate runs search result templates (Nitrate#699)
Browse files Browse the repository at this point in the history
Signed-off-by: Chenxiong Qi <qcxhome@gmail.com>
  • Loading branch information
tkdchen committed Aug 25, 2020
1 parent 1ee9f6f commit 2811155
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 135 deletions.
56 changes: 16 additions & 40 deletions src/static/js/testrun_actions.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Nitrate.TestRuns = {};
Nitrate.TestRuns.Search = {};
Nitrate.TestRuns.List = {};
Nitrate.TestRuns.Details = {};
Nitrate.TestRuns.New = {};
Expand Down Expand Up @@ -93,23 +94,24 @@ function cloneRunsClickHandler() {
postToURL(jQ(this).data('param'), Nitrate.Utils.formSerialize(this.form), 'get');
}

Nitrate.TestRuns.AdvancedSearch.on_load = function () {

jQ('.js-clone-testruns').on('click', cloneRunsClickHandler);

/**
* Initialize the test runs search result table and associated action buttons.
* @param {stirng} searchEndpoint - the endpoint to search test runs.
*/
Nitrate.TestRuns.Search.initializeSearchResult = function (searchEndpoint) {
let runsSearchResultTableSettings = Object.assign({}, Nitrate.DataTable.commonSettings, {
aaSorting: [[1, 'desc']],
sAjaxSource: '/advance-search/' + this.window.location.search,
sAjaxSource: searchEndpoint + window.location.search,

iDeferLoading: Nitrate.TestRuns.AdvancedSearch.numberOfRuns,
iDeferLoading: Nitrate.TestRuns.Search.numberOfRuns,

aoColumns: [
{'bSortable': false}, // Select checker
{'sType': 'numeric'}, // ID
{'sType': 'html'}, // Summary
{'sType': 'html'}, // Manager
{'sType': 'html'}, // Default Tester
{'bVisible': false}, // ?
null, // Product
null, // Product Version
null, // Environment
Expand All @@ -122,6 +124,10 @@ Nitrate.TestRuns.AdvancedSearch.on_load = function () {
sEmptyTable: 'No run was found.'
},

fnInitComplete: function () {
jQ('.js-clone-testruns').on('click', cloneRunsClickHandler);
},

fnDrawCallback: function () {
jQ('#testruns_table tbody tr td:nth-child(1)').shiftcheckbox({
checkboxSelector: ':checkbox',
Expand All @@ -142,7 +148,10 @@ Nitrate.TestRuns.AdvancedSearch.on_load = function () {
});

jQ('#testruns_table').dataTable(runsSearchResultTableSettings);
};

Nitrate.TestRuns.AdvancedSearch.on_load = function () {
Nitrate.TestRuns.Search.initializeSearchResult('/advance-search/');
};

Nitrate.TestRuns.List.on_load = function () {
Expand Down Expand Up @@ -184,40 +193,7 @@ Nitrate.TestRuns.List.on_load = function () {
});
}

jQ('#testruns_table').dataTable({
'iDisplayLength': 20,
'sPaginationType': 'full_numbers',
'bFilter': false,
'bLengthChange': false,
'aaSorting': [[ 1, 'desc' ]],
'bProcessing': true,
'bServerSide': true,
'iDeferLoading': Nitrate.TestRuns.List.numberOfRuns,
'sAjaxSource': '/runs/' + window.location.search,
'aoColumns': [
{'bSortable': false},
{'sType': 'numeric'},
{'sType': 'html'},
{'sType': 'html'},
{'sType': 'html'},
{'bVisible': false},
null,
null,
{'bSortable': false},
{'sType': 'numeric'},
null,
{'bSortable': false}
],
'oLanguage': {'sEmptyTable': 'No run was found.'},
'fnDrawCallback': function () {
jQ('#testruns_table tbody tr td:nth-child(1)').shiftcheckbox({
checkboxSelector: ':checkbox',
selectAll: '#testruns_table .js-select-all'
});
}
});

jQ('.js-clone-testruns').on('click', cloneRunsClickHandler);
Nitrate.TestRuns.Search.initializeSearchResult('/runs/');
};


Expand Down
7 changes: 4 additions & 3 deletions src/tcms/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ def advance_search(request, tmpl='search/advanced_search.html'):
),
'run': SearchInfo(
column_names=[
'', 'run_id', 'summary', 'manager__username', 'default_tester__username',
'', 'plan__product__name', 'product_version__value', '',
'cases_count', 'stop_date', ''
'', 'run_id', 'summary', 'manager__username',
'default_tester__username', 'build__product__name',
'product_version__value', 'env_groups', 'cases_count',
'stop_date', 'completed'
],
template_file='run/common/json_runs.txt'
)
Expand Down
25 changes: 15 additions & 10 deletions src/tcms/testruns/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,23 @@ def search_runs(request):
runs = TestRun.objects.none()

if search_form.is_valid():
runs = (TestRun
.list(search_form.cleaned_data)
.select_related('manager', 'default_tester', 'build', 'plan', 'build__product')
.only('run_id', 'summary', 'manager__username', 'default_tester__id',
'default_tester__username', 'plan__name', 'build__product__name',
'stop_date', 'product_version__value')
.extra(select={'cases_count': RawSQL.total_num_caseruns}))
runs = (
TestRun
.list(search_form.cleaned_data)
.select_related('manager', 'default_tester', 'build', 'plan',
'build__product')
.only('run_id', 'summary', 'manager__username',
'default_tester__id', 'default_tester__username',
'plan__name', 'build__product__name',
'stop_date', 'product_version__value')
.extra(select={'cases_count': RawSQL.total_num_caseruns})
)

column_names = [
'', 'run_id', 'summary', 'manager__username', 'default_tester__username',
'plan', 'build__product__name', 'product_version', 'env_groups',
'cases_count', 'stop_date', 'completed',
'', 'run_id', 'summary', 'manager__username',
'default_tester__username', 'build__product__name',
'product_version__value', 'env_groups', 'cases_count', 'stop_date',
'completed',
]

dt = DataTableResult(request.GET, runs, column_names,
Expand Down
10 changes: 2 additions & 8 deletions src/templates/run/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script type="text/javascript" src="{% static "js/testrun_actions.js" %}"></script>
<script type="text/javascript" src="{% static "js/management_actions.js" %}"></script>
<script type="text/javascript">
Nitrate.TestRuns.List.numberOfRuns = {{ total_count }};
Nitrate.TestRuns.Search.numberOfRuns = {{ total_count }};
Nitrate.Utils.after_page_load(Nitrate.TestRuns.List.on_load);
</script>
{% endblock %}
Expand Down Expand Up @@ -48,12 +48,6 @@ <h2>Search Run</h2>
<div class="clear"></div>
</div>
</form>
<form id="runs_form">
<div id="contentTab" class="mixbar">
<span class="tit"><a href="{% url "runs-all" %}?case_run__assignee={{ user.email }}">View My Assigned Runs</a></span>
<input type="button" value="Clone" title="clone selected test runs" class="js-clone-testruns" data-param='{% url "runs-clone" %}' />
</div>
{% include "run/common/run_filtered.html" %}
</form>
{% include "run/search_result.html" %}
</div>
{% endblock %}
1 change: 0 additions & 1 deletion src/templates/run/common/json_runs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
{% else %}
"{{ run.default_tester }}"
{% endif %},
"{{ run.plan }}",
"{{ run.build.product }}",
"{{ run.product_version }}",
"{{ run.associated_data.env_group }}",
Expand Down
99 changes: 52 additions & 47 deletions src/templates/run/common/run_filtered.html
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
<table id="testruns_table" class="list border-bottom" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="nosort" width="30">
<input id="id_check_all_runs" class="js-select-all" type="checkbox" title="Select all/Select none" />
</th>
<th class="number nosort widthID">ID</th>
<th class="text nosort">Summary</th>
<th class="text nosort" width="80">Manager</th>
<th class="text nosort" width="100">Default Tester</th>
<th class="text nosort" style="display:none" id="col_plan_head" >Plan</th>
<th class="text nosort" width="130">Product</th>
<th class="sortable nosort" width="120">Product Version</th>
<th class="text nosort" width="100" title='Plan Environment Group'>Environment</th>
<th class="number nosort" width="40">Cases</th>
<th class="text nosort" width="80">Status</th>
<th class="number nosort" width="110">Completed</th>
</tr>
</thead>
<tbody>
{% for test_run in object_list %}
<tr id="run_{{test_run.run_id}}">
<td><input type='checkbox' name="run" value="{{ test_run.pk }}" class="run_selector" /></td>
<td><a href="{% url "run-get" test_run.run_id %}">{{ test_run.run_id }}</a></td>
<td><a href="{% url "run-get" test_run.run_id %}">{{ test_run.summary }}</a></td>
<td><a href="{% url "user-profile" test_run.manager.username %}">{{ test_run.manager }}</a></td>
<td>{% if test_run.default_tester_id %}<a href="{% url "user-profile" test_run.default_tester.username %}">{% endif %}{{ test_run.default_tester }}{% if test_run.default_tester_id %}</a>{% endif %}</td>
<td style="display:none" class="col_plan_content"><a href="{{ test_run.plan.get_absolute_url }}">{{ test_run.plan }}</a></td>
<td>{{ test_run.build.product }}</td>
<td>{{ test_run.product_version }}</td>
<td>{{ test_run.associated_data.env_group }}</td>
<td>{{ test_run.cases_count }}</td>
<td>
<form id="runs_form">
<div id="contentTab" class="mixbar">
<span class="tit"><a href="{% url "runs-all" %}?case_run__assignee={{ user.email }}">View My Assigned Runs</a></span>
<input type="button" value="Clone" title="clone selected test runs"
class="js-clone-testruns" data-param="{% url "runs-clone" %}" disabled />
</div>
<table id="testruns_table" class="list border-bottom" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th class="nosort" width="30">
<input id="id_check_all_runs" class="js-select-all" type="checkbox" title="Select all/Select none" />
</th>
<th class="number nosort widthID">ID</th>
<th class="text nosort">Summary</th>
<th class="text nosort" width="80">Manager</th>
<th class="text nosort" width="100">Default Tester</th>
<th class="text nosort" width="130">Product</th>
<th class="sortable nosort" width="120">Product Version</th>
<th class="text nosort" width="100" title='Plan Environment Group'>Environment</th>
<th class="number nosort" width="40">Cases</th>
<th class="text nosort" width="80">Status</th>
<th class="number nosort" width="110">Completed</th>
</tr>
</thead>
<tbody>
{% for test_run in object_list %}
<tr id="run_{{test_run.run_id}}">
<td><input type='checkbox' name="run" value="{{ test_run.pk }}" class="run_selector" /></td>
<td><a href="{% url "run-get" test_run.run_id %}">{{ test_run.run_id }}</a></td>
<td><a href="{% url "run-get" test_run.run_id %}">{{ test_run.summary }}</a></td>
<td><a href="{% url "user-profile" test_run.manager.username %}">{{ test_run.manager }}</a></td>
<td>{% if test_run.default_tester_id %}<a href="{% url "user-profile" test_run.default_tester.username %}">{% endif %}{{ test_run.default_tester }}{% if test_run.default_tester_id %}</a>{% endif %}</td>
<td>{{ test_run.build.product }}</td>
<td>{{ test_run.product_version }}</td>
<td>{{ test_run.associated_data.env_group }}</td>
<td>{{ test_run.cases_count }}</td>
<td>
{% if test_run.stop_date %}
<span class="pauselink">Finished</span>
{% else %}
<span class="runninglink">Running</span>
{% endif %}
</td>
<td>
<div class='progress-bar'>
<div class='progress-inner' style='width: {{ test_run.associated_data.stats.completed_percent|floatformat:2 }}px;'>
<div class='progress-failed' style='width: {{ test_run.associated_data.stats.failed_percent|floatformat:2 }}px;'>
</td>
<td>
<div class='progress-bar'>
<div class='progress-inner' style='width: {{ test_run.associated_data.stats.completed_percent|floatformat:2 }}px;'>
<div class='progress-failed' style='width: {{ test_run.associated_data.stats.failed_percent|floatformat:2 }}px;'>
</div>
</div>
<div class='percent'>
{{ test_run.associated_data.stats.completed_percent|floatformat:2 }}%
</div>
</div>
<div class='percent'>
{{ test_run.associated_data.stats.completed_percent|floatformat:2 }}%
</div>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<form id='runs_form'>
<div id="contentTab" class="mixbar">
<span class="tit"><a href="{% url "runs-all" %}?case_run__assignee={{ user.email }}">View My Assigned Runs</a></span>
<input type="button" value="Clone" title="clone selected test runs" class="js-clone-testruns" disabled data-param="{% url "runs-clone" %}" />
<input type="button" value="Clone" title="clone selected test runs"
class="js-clone-testruns" data-param="{% url "runs-clone" %}" disabled />
</div>
<table id="testruns_table" class="list border-bottom js-advance-search-runs" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr >
<th width="30">
<input id='id_check_all_runs' class="js-select-all" type="checkbox" title="Select all/Select none" />
</th>
<th class="widthID"><a href="{{query_url}}&order_by=run_id" title="Sort by Run ID">ID</a></th>
<th><a href="{{query_url}}&order_by=summary" title="Sort by Summary">Summary</a></th>
<th class="widthID" title="Sort by Run ID">ID</th>
<th title="Sort by Summary">Summary</th>
<th width="80" title="Sort by Manager Name">Manager</th>
<th width="100" title="Sort by Default Tester">Default Tester</th>
<th class="text" title="Sort by Plan" style="display:none" id="col_plan_head">Plan</th>
<th width="130" title="Sort by Product">Product</th>
<th width="120" title="Sort by Product Version">Product version</th>
<th width="100" title='Plan Environment Group'>Environment</th>
Expand All @@ -23,38 +23,24 @@
</tr>
</thead>
<tbody>
{% for test_run in object_list %}
{% for test_run in object_list %}
<tr id="run_{{test_run.run_id}}">
<td><input type='checkbox' name="run" value="{{ test_run.pk }}" class="run_selector" /></td>
<td><a href="{% url "run-get" test_run.run_id %}">{{ test_run.run_id }}</a></td>
<td><a href="{% url "run-get" test_run.run_id %}">{{ test_run.summary }}</a></td>
<td><a href="{% url "user-profile" test_run.manager.username %}">{{ test_run.manager }}</a></td>
<td>{% if test_run.default_tester_id %}<a href="{% url "user-profile" test_run.default_tester.username %}">{% endif %}{{ test_run.default_tester }}{% if test_run.default_tester_id %}</a>{% endif %}</td>
<td style="display:none" class="col_plan_content"><a href="{{ test_run.plan.get_absolute_url }}">{{ test_run.plan }}</a></td>
<td>{{ test_run.build.product }}</td>
<td>{{ test_run.product_version }}</td>
<td>{{ test_run.associated_data.env_group }}</td>
<td>{{ test_run.cases_count }}</td>
<td>
{% if test_run.stop_date %}
{% if test_run.stop_date %}
<span class="pauselink">Finished</span>
{% else %}
{% else %}
<span class="runninglink">Running</span>
{% endif %}
{% endif %}
</td>

{% comment %}
<td>
<div class="progress-bar" title="failed:{{ test_run.failed_case_run_percent|default:"0" }}%">
<div class="progress-inner" style="width:{{ test_run.completed_case_run_percent|default:"0" }}%;">
<div class="progress-failed" style="width:{{ test_run.failed_case_run_percent|default:"0" }}%;">
</div>
</div>
<div class="percent">{{ test_run.completed_case_run_percent|default:"0" }}%</div>
</div>
</td>
{% endcomment %}

<td>
<div class='progress-bar'>
<div class='progress-inner' style='width: {{ test_run.associated_data.stats.completed_percent|floatformat:2 }}px;'>
Expand All @@ -67,7 +53,7 @@
</div>
</td>
</tr>
{% endfor %}
{% endfor %}
</tbody>
</table>
</form>
4 changes: 2 additions & 2 deletions src/templates/search/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ <h2 class="clear">

<script type="text/javascript" src="{% static "js/testrun_actions.js" %}"></script>
<script type="text/javascript">
Nitrate.TestRuns.AdvancedSearch.numberOfRuns = {{ total_count }};
Nitrate.TestRuns.Search.numberOfRuns = {{ total_count }};
Nitrate.Utils.after_page_load(Nitrate.TestRuns.AdvancedSearch.on_load);
</script>
{% include "run/common/run_advance_filtered.html" %}
{% include "run/search_result.html" %}

{% endif %}

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_basic_search_runs(self):
# Collect data from env_group (Environment) column
env_group_names = []
for tr in bs.find(id='testruns_table').find_all('tr')[1:]:
env_group_names.append(tr.find_all('td')[8].text.strip())
env_group_names.append(tr.find_all('td')[7].text.strip())

self.assertListEqual(['db', 'None', 'None'], env_group_names)

Expand Down

0 comments on commit 2811155

Please sign in to comment.