Skip to content

Commit

Permalink
Extract bugs table into reusable template
Browse files Browse the repository at this point in the history
  • Loading branch information
asankov committed Jun 11, 2020
1 parent 61ede13 commit 72b3591
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 68 deletions.
49 changes: 49 additions & 0 deletions tcms/static/js/bugs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const bugDetailsCache = {}

function loadBugs(selector, filter) {
$(selector).DataTable({
ajax: (data, callback, settings) => {
dataTableJsonRPC('TestExecution.get_links', filter, callback);
},
columns: [
{
data: null,
render: (data, type, full, meta) => `<a href="${data.url}" class="bug-url">${data.url}</a>`
},
{
data: null,
render: function (data, type, full, meta) {
return `<a href="#bugs" data-toggle="popover" data-html="true"
data-content="undefined" data-trigger="focus" data-placement="top">
<span class="fa fa-info-circle"></span>
</a>`;
}
},
],
dom: "t",
language: {
loadingRecords: '<div class="spinner spinner-lg"></div>',
processing: '<div class="spinner spinner-lg"></div>',
zeroRecords: "No records found"
},
order: [[0, 'asc']],
});

$(selector).on('draw.dt', () => {
$(selector).find('[data-toggle=popover]')
.popovers()
.on('show.bs.popover', (element) => {
fetchBugDetails($(element.target).parents('tr').find('.bug-url')[0],
element.target,
bugDetailsCache);
});
});

$('[data-toggle=popover]')
.popovers()
.on('show.bs.popover', (element) => {
fetchBugDetails($(element.target).parents('.list-view-pf-body').find('.bug-url')[0],
element.target,
bugDetailsCache);
});
}
21 changes: 21 additions & 0 deletions tcms/templates/include/bugs_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% load i18n %}
{% load static %}

<div class="col-xs-12 col-sm-6 col-md-4">
<div class="card-pf card-pf-accented">
<h2 class="card-pf-title">
<span class="fa fa-bug"></span>
{% trans heading %}
</h2>

<div class="card-pf-body">
<table class="table {{ class }}" data-show-hyperlinks="{% if show_hyperlinks %}true{% else %}false{% endif %}">
<thead>
<tr>
<th colspan="2">{% trans 'URL' %}</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
54 changes: 4 additions & 50 deletions tcms/testcases/static/testcases/js/get.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const bug_details_cache = {}
const plan_cache = {}


Expand Down Expand Up @@ -214,55 +213,10 @@ $(document).ready(function() {
initAddPlan(case_id, plans_table);

// bugs table
$('#bugs').DataTable({
ajax: function(data, callback, settings) {
dataTableJsonRPC('TestExecution.get_links',
{execution__case: case_id,
is_defect: true}, callback);
},
columns: [
{
data: null,
render: function (data, type, full, meta) {
return '<a href="' + data.url + '" class="bug-url">' + data.url + '</a>';
}
},
{
data: null,
render: function (data, type, full, meta) {
return '<a href="#bugs" data-toggle="popover" data-html="true" ' +
'data-content="undefined" data-trigger="focus" data-placement="top">' +
'<span class="fa fa-info-circle"></span>' +
'</a>';
}
},
],
dom: "t",
language: {
loadingRecords: '<div class="spinner spinner-lg"></div>',
processing: '<div class="spinner spinner-lg"></div>',
zeroRecords: "No records found"
},
order: [[ 0, 'asc' ]],
});

$('#bugs').on('draw.dt', function () {
$('#bugs').find('[data-toggle=popover]')
.popovers()
.on('show.bs.popover', function(element) {
fetchBugDetails($(element.target).parents('tr').find('.bug-url')[0],
element.target,
bug_details_cache);
});
});

$('[data-toggle=popover]')
.popovers()
.on('show.bs.popover', function(element) {
fetchBugDetails($(element.target).parents('.list-view-pf-body').find('.bug-url')[0],
element.target,
bug_details_cache);
});
loadBugs('.bugs', {
execution__case: case_id,
is_defect: true
})

// executions treeview
treeViewBind();
Expand Down
20 changes: 2 additions & 18 deletions tcms/testcases/templates/testcases/get.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,7 @@ <h2 class="card-pf-title" style="text-align: left">
</div>

<div class="row row-cards-pf">
<div class="col-xs-12 col-sm-6 col-md-4">
<div class="card-pf card-pf-accented">
<h2 class="card-pf-title">
<span class="fa fa-bug"></span>
{% trans 'Bugs' %}
</h2>

<div class="card-pf-body">
<table class="table" id="bugs">
<thead>
<tr>
<th colspan="2">{% trans 'Bug URL' %}</th>
</tr>
</thead>
</table>
</div>
</div>
</div>
{% include "include/bugs_table.html" with heading="Bugs" class="bugs" %}

<div class="col-xs-12 col-sm-6 col-md-8">
<div class="card-pf card-pf-accented">
Expand Down Expand Up @@ -245,5 +228,6 @@ <h2 class="card-pf-title">
<script src="{% static 'js/utils.js' %}"></script>
<script src="{% static 'js/jsonrpc.js' %}"></script>
<script src="{% static 'js/tags.js' %}"></script>
<script src="{% static 'js/bugs.js' %}"></script>
<script src="{% static 'testcases/js/get.js' %}"></script>
{% endblock %}

0 comments on commit 72b3591

Please sign in to comment.