-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathindex.html
More file actions
275 lines (260 loc) · 13.4 KB
/
index.html
File metadata and controls
275 lines (260 loc) · 13.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
{% extends "base.html" %}
{% block title %}Regression tests {{ super() }}{% endblock %}
{% block body %}
{{ super() }}
<br />
<div class="grid-x">
<div class="column medium-9">
<h1>Regression tests</h1>
{% if tests|length > 0 %}
<div class="grid-x">
<label for="category" class="column medium-4">Select a category:</label>
<select id="category" style="background-position: right 0 center" onchange="selectedCategoryChange();" class="column small-6">
{% for category in categories %}
<option value="{{ category.id }}">{{ category.name }}</option>
{% endfor %}
<option value="0">All Categories</option>
</select>
{% if user is not none and user.is_admin %}
<span class="medium-2">
<a href="{{ url_for(".category_edit", category_id=categories[0].id) }}" title="Edit category" id="category_edit"><i class="fa fa-edit"></i></a>
<a href="{{ url_for(".category_delete", category_id=categories[0].id) }}" title="Delete category" id="category_delete"><i class="fa fa-remove"></i></a>
</span>
{% endif %}
</div>
<div class="grid-x">
<label class="column medium-4">Category description:</label>
<span id="category-descriptions" class="column medium-8">
{% for category in categories %}
<span {% if not loop.first %}class="hide" {% endif %}data-category="{{ category.id }}">{{ category.description }}</span>
{% endfor %}
<span class="hide" data-category="0">{{ 'All Categories' }}</span>
</span>
</div>
<div class="grid-x">
<label class="column medium-4" for="tag">Filter Tags:</label>
<select id="tag" style="background-position: right 0 center;" class="column medium-5" onchange="selectedTagsChange('add');" >
{% if tags|length %}
<option value="0">Select Tags</option>
{% else %}
<option value="0">No Tags Available</option>
{% endif %}
{% for tag in tags %}
<option id="tag-option" value="{{ tag.id }}">{{ tag.name }}</option>
{% endfor %}
</select>
<span class="medium-2">
<button id="searchButton" class="button" onclick="searchRegressionTests();">Search</button>
</span>
<span class="medium-2">
<button id="resetButton" class="button" onclick="selectedTagsChange('reset');">Reset</button>
</span>
</div>
<div class="grid-x">
<label class="column medium-3" for="tag">Selected Tags</label>
<div id="selected_tags" class="column medium-8">
</div>
</div>
<div class="grid-x callout alert" style="display:none;" id="message"></div>
<table id="regression_tests" class="sortable tight striped">
<thead>
<tr>
<th>ID</th>
<th>Command</th>
<th>Active</th>
<th>Actions</th>
<th>Tags</th>
</tr>
</thead>
<tbody>
{% for test in tests %}
{% if test.categories|length == 0 %}
{% continue %}
{% endif %}
<tr data-category="[{{ test.categories|join(', ', attribute='id') }}]">
<td>{{ test.id }}</td>
<td>{{ test.command }}{% if test.never_worked %} <span class="label secondary" title="This test has been marked as never having produced correct output">Never worked</span>{% endif %}</td>
<td id="status-toggle-{{test.id}}">{{ test.active }}</td>
<td>
<a href="{{ url_for('.test_view', regression_id=test.id) }}" title="View details"><i class="fa fa-info-circle"></i></a>
{% if user is not none and user.has_role('contributor') %}
<a id="toggle-active-{{test.id}}" title="Toggle Active Status" onclick="toggleactive({{test.id}})"><i class="fa fa-support"></i></a>
<div id="loader-toggle-{{test.id}}" class="loader" style="display:none;"></div>
<a href="{{ url_for('.test_edit', regression_id=test.id) }}" title="Edit regression test"><i class="fa fa-edit"></i></a>
<a href="{{ url_for('.test_delete', regression_id=test.id) }}" title="Delete regression test"><i class="fa fa-remove"></i></a>
{% endif %}
</td>
<td class="tags">
{% set sample = test.sample %}
{% set visible_tags_count = 3 %}
{% for tag in sample.tags[:visible_tags_count] %}
<span class="tag regression_test_tag" title="{{tag.description or tag.name}}" data-id="{{tag.id}}">{{ tag.name }}</span>
{% endfor %}
{% if sample.tags|length > visible_tags_count %}
<a href="{{ url_for('sample.sample_by_hash', sample_hash=sample.sha) }}#tags" title="View details">
<span>+{{ sample.tags|length - visible_tags_count }} more</span>
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>There are no regression tests available</p>
{% endif %}
</div>
<div class="column medium-3">
{% if user is not none and user.has_role('contributor') %}
<h5>Regression tests</h5>
<ul class="no-bullet">
<li><i class="fa fa-plus-circle"></i> <a href="{{ url_for(".test_add") }}">Add new regression test</a></li>
{% if user.is_admin %}
<li><i class="fa fa-object-group"></i> <a href="{{ url_for(".category_add") }}">Add regression category</a></li>
{% endif %}
</ul>
{% endif %}
</div>
</div>
{% endblock %}
{% block scripts %}
{{ super() }}
<script type="text/javascript">
function selectedTagsChange(mode, id=0){
if(mode === "add"){
let tagId = $("#tag").val();
let selectedTagName = $("#tag").find("option:selected").text();
if(!selectedTagName){
$("#tag").val("0");
return;
}
let newTag = $("<span>").addClass("tag selected_tag").attr("title", selectedTagName).attr("data-id", tagId).html(`${selectedTagName} `);
let removeButton = $("<button>").html('<i class="fa fa-remove"></i>').click(function() {
$(this).parent().remove();
selectedTagsChange('remove', tagId);
});
newTag.append(removeButton);
$("#selected_tags").append(newTag);
$(`#tag option[value=${tagId}]`).prop("disabled", true);
$("#tag").val("0");
searchRegressionTests();
}
else if(mode === "remove"){
$(`#tag option[value=${id}]`).prop("disabled", false);
searchRegressionTests();
}
else if(mode === "reset"){
$("#tag option").prop("disabled", false);
$("#selected_tags").empty();
searchRegressionTests();
}
}
function areTagsPresent(search_tags, available_tags){
const elementSet = {};
available_tags.forEach(tagId => {
elementSet[tagId] = true;
});
for (const tagId of search_tags){
if(elementSet[tagId] !== true) return false;
}
return true;
}
function selectedCategoryChange(){
searchRegressionTests()
}
function updateUrlWithQueryParam(paramName, paramValue) {
const url = new URL(window.location.href);
url.searchParams.set(paramName, paramValue);
window.history.replaceState({}, "", url.toString());
}
function searchRegressionTests(){
selected_tags = []
$(".selected_tag").each(function() {
selected_tags.push($(this).data("id"))
});
var id = $("#category").val();
$("tbody tr[data-category]").each(function(idx, elm){
let array = JSON.parse(elm.getAttribute("data-category"));
category_id = parseInt(id)
let regression_test_tags = []
$(elm).find('.tags > .regression_test_tag').each(function() {
regression_test_tags.push($(this).data("id"))
})
let are_tags_present = areTagsPresent(selected_tags, regression_test_tags)
let is_element_visible = (are_tags_present && (category_id===0 || array.indexOf(category_id) > -1))
elm.setAttribute("class", is_element_visible ? "" : "hide");
});
var cat_desc = $("#category-descriptions");
cat_desc.find("span[data-category='"+id+"']").each(function(idx, elm){
elm.setAttribute("class","");
});
cat_desc.find("span[data-category!='"+id+"']").each(function(idx, elm){
elm.setAttribute("class","hide");
});
{% if user.is_admin %}
var cat_edit = $("#category_edit");
var cat_delete = $("#category_delete");
var cat_parts = cat_edit.attr("href").split("/");
cat_edit.attr("href",cat_parts[cat_parts.length-3]+"/"+id+"/"+cat_parts[cat_parts.length-1]);
cat_parts = cat_delete.attr("href").split("/");
cat_delete.attr("href",cat_parts[cat_parts.length-3]+"/"+id+"/"+cat_parts[cat_parts.length-1]);
{% endif %}
updateUrlWithQueryParam("tags", selected_tags.join(","))
updateUrlWithQueryParam("category", id)
}
$(document).ready(function(){
const urlParams = new URLSearchParams(window.location.search);
const hash = urlParams.get("category");
if(hash === "") hash = "1";
$("#category").find("option").each(function(idx, elm){
if($(elm).val() === hash){
$(elm).attr("selected",true);
}
});
query_tags = (urlParams.get("tags") || "").split(",");
query_tags.forEach(tagId => {
if(isNaN(parseInt(tagId))) return;
$("#tag").val(tagId);
selectedTagsChange('add');
})
searchRegressionTests();
});
function toggleactive(test_id) {
$.ajax({
type: "GET",
url: ("{{ url_for('.toggle_active_status', regression_id='test_id') }}").replace('test_id', test_id),
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend:function()
{
var toggle_active = "#toggle-active-" + test_id;
var toggle_loader = "#loader-toggle-" + test_id;
$(toggle_active).hide();
$(toggle_loader).show();
},
success:function(data){
var message = "#message";
var $div = $(message);
if(data.status === "success")
{
var toggle_td = "#status-toggle-" + test_id;
var toggle_active = "#toggle-active-" + test_id;
var toggle_loader = "#loader-toggle-" + test_id;
$(toggle_td).html(data.active);
$(toggle_loader).hide();
$(toggle_active).show();
$div.html("Status updated for Regression Test " + test_id);
}
else{
$div.html("Error updating status for Regression Test " + test_id);
}
$div.show();
/* hide message after 5 seconds */
setTimeout(function() {
$div.hide();
}, 5000);
}
});
}
</script>
{% endblock %}