Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filter for running jobs in test overview #855

Merged
merged 3 commits into from Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 39 additions & 7 deletions assets/javascripts/overview.js
Expand Up @@ -42,17 +42,33 @@ function setupOverview() {
// find specified results
var varPairs = window.location.search.substring(1).split('&');
var results = {};
var states = {};

var currentFilter = [];
var formatFilter = function(filter) {
return filter.replace(/_/g, ' ');
};

for (var j = 0; j < varPairs.length; ++j) {
var pair = varPairs[j].split('=');
if(pair.length > 1) {
var key = pair[0];
var val = pair[1];
if(val.length < 1) {
continue;
}
if (key === 'result') {
results[val] = true;
currentFilter.push(formatFilter(val));
} else if (key === 'state') {
states[val] = true;
currentFilter.push(formatFilter(val));
} else if (key === 'todo') {
$('#filter-todo').prop('checked', val !== '0');
currentFilter.push('TODO');
} else if (key === 'arch') {
$('#filter-arch').prop('value', val);
currentFilter.push(val);
} else {
var input = $('<input/>');
input.attr('value', val);
Expand All @@ -62,14 +78,30 @@ function setupOverview() {
}
}
}


// make filter form expandable
var filterHeading = $('#filter-panel .panel-heading');
filterHeading.on('click', function() {
$('#filter-panel .panel-body').toggle(200);
});

// set enabled/disabled state of checkboxes (according to current filter)
var badges = ['passed', 'incomplete', 'softfailed', 'failed', 'scheduled', 'running', 'none', 'unknown'];
for(var i = 0; i < badges.length; ++i) {
var badge = badges[i];
var filterEnabled = results[badge];
var badgeElement = $('#filter-' + badge);
badgeElement.prop('checked', filterEnabled);
if(currentFilter.length > 0) {
$('#filter-results input').each(function(index, element) {
element.checked = results[element.id.substr(7)];
});
$('#filter-states input').each(function(index, element) {
element.checked = states[element.id.substr(7)];
});
filterHeading.find('span').text('current: ' + currentFilter.join(', '));
}

// don't add empty architecture to query parameters
$('#filter-form').on('submit', function() {
var archFilterElement = $('#filter-arch');
if(archFilterElement.val() === '') {
archFilterElement.remove();
}
});
}

39 changes: 26 additions & 13 deletions assets/stylesheets/overview.scss
Expand Up @@ -22,22 +22,35 @@
margin-right: 8px;
}

#filter-form {
strong {
display: block;
}
#filter-panel {
.panel-heading {
cursor: pointer;

.form-group {
label {
margin-left: 0px;
padding-left: 0px;
margin-right: 20px;
font-weight: normal;
span {
float: right;
color: #555;
font-weight: 500;
}
}
.panel-body {
display: none;
}

input {
margin-right: 2px;
padding-right: 0px;
#filter-form {
strong {
display: block;
}
.form-group {
label {
margin-left: 0px;
padding-left: 0px;
margin-right: 20px;
font-weight: normal;
}
input {
margin-right: 2px;
padding-right: 0px;
}
}
}
}
11 changes: 6 additions & 5 deletions t/ui/10-tests_overview.t
Expand Up @@ -157,11 +157,12 @@ my $baseurl = $driver->get_current_url();

# Test initial state of form and applying changes
$driver->get($baseurl . 'tests/overview?distri=opensuse&version=Factory&build=0048&todo=1&result=passed');
$driver->find_element('#filter-todo', 'css')->click();
$driver->find_element('#filter-passed', 'css')->click();
$driver->find_element('#filter-failed', 'css')->click();
$driver->find_element('#filter-form button', 'css')->click();
$driver->find_element('#res_DVD_x86_64_doc', 'css');
$driver->find_element('#filter-panel .panel-heading', 'css')->click();
$driver->find_element('#filter-todo', 'css')->click();
$driver->find_element('#filter-passed', 'css')->click();
$driver->find_element('#filter-failed', 'css')->click();
$driver->find_element('#filter-form button', 'css')->click();
$driver->find_element('#res_DVD_x86_64_doc', 'css');
my @filtered_out = $driver->find_elements('#res_DVD_x86_64_kde', 'css');
is(scalar @filtered_out, 0, 'result filter not correctly applied');

Expand Down
53 changes: 29 additions & 24 deletions templates/test/overview.html.ep
@@ -1,5 +1,6 @@
% layout 'bootstrap';
% title 'Test summary';
% use OpenQA::Schema::Result::Jobs;

% content_for 'ready_function' => begin
setupOverview();
Expand Down Expand Up @@ -49,6 +50,34 @@
% }
</div>
</div>
<div class="panel panel-default" id="filter-panel">
<div class="panel-heading"><strong>Filter</strong> <span>no filter present, click to toggle filter form<span></div>
<div class="panel-body">
<form action="#" type="get" id="filter-form">
<div class="form-group" id="filter-results">
<strong>Result</strong>
% for my $result (OpenQA::Schema::Result::Jobs::RESULTS) {
<label><input value="<%= $result %>" name="result" type="checkbox" id="filter-<%= $result %>"> <%= ucfirst $result =~ s/_/ /r %></label>
% }
</div>
<div class="form-group" id="filter-states">
<strong>State</strong>
% for my $state (OpenQA::Schema::Result::Jobs::STATES) {
<label><input value="<%= $state %>" name="state" type="checkbox" id="filter-<%= $state %>"> <%= ucfirst $state =~ s/_/ /r %></label>
% }
</div>
<div class="form-group">
<strong>Architecture</strong>
<input type="text" class="form-control" name="arch" placeholder="any" id="filter-arch">
</div>
<div class="form-group">
<strong>Misc</strong>
<label><input value="1" name="todo" type="checkbox" id="filter-todo"> TODO</label>
</div>
<button type="submit" class="btn btn-default">Apply</button>
</form>
</div>
</div>
% my $failedid;
% for my $type (@$types) {
<h3>Flavor: <%= $type %></h3>
Expand Down Expand Up @@ -83,28 +112,4 @@
</tbody>
</table>
% }
<div class="panel panel-default">
<div class="panel-heading">Filter</div>
<div class="panel-body">
<form action="#" type="get" id="filter-form">
<div class="form-group">
<strong>Result</strong>
<label><input value="passed" name="result" type="checkbox" id="filter-passed"> Passed</label>
<label><input value="incomplete" name="result" type="checkbox" id="filter-incomplete"> Incomplete</label>
<label><input value="softfailed" name="result" type="checkbox" id="filter-softfailed"> Softfailed</label>
<label><input value="failed" name="result" type="checkbox" id="filter-failed"> Failed</label>
<label><input value="running" name="result" type="checkbox" id="filter-running"> Running</label>
</div>
<div class="form-group">
<strong>Architecture</strong>
<input type="text" class="form-control" name="arch" placeholder="any" id="filter-arch">
</div>
<div class="form-group">
<strong>Misc</strong>
<label><input value="1" name="todo" type="checkbox" id="filter-todo"> TODO</label>
</div>
<button type="submit" class="btn btn-default">Apply</button>
</form>
</div>
</div>
</div>