Skip to content

Commit

Permalink
services: Enable filtering by autostart
Browse files Browse the repository at this point in the history
Fixes: #11237
  • Loading branch information
marusak authored and martinpitt committed Mar 1, 2019
1 parent 4aaec70 commit 9e5a8b7
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/systemd/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,14 @@ $(function() {

unit.CombinedState = active_state;
unit.AutomaticStartup = _("Static");
if (unit.UnitFileState && startsWith(unit.UnitFileState, 'enabled'))
unit.AutomaticStartupIndex = 3;
if (unit.UnitFileState && startsWith(unit.UnitFileState, 'enabled')) {
unit.AutomaticStartup = _("Enabled");
else if (unit.UnitFileState && startsWith(unit.UnitFileState, 'disabled'))
unit.AutomaticStartupIndex = 1;
} else if (unit.UnitFileState && startsWith(unit.UnitFileState, 'disabled')) {
unit.AutomaticStartup = _("Disabled");
unit.AutomaticStartupIndex = 2;
}

if (unit.Id.slice(-5) == "timer") {
unit.is_timer = true;
Expand Down Expand Up @@ -266,6 +270,7 @@ $(function() {
var pattern = $('#services-filter button.active').attr('data-pattern');
var current_text_filter = $('#services-text-filter').val()
.toLowerCase();
var current_type_filter = parseInt($('#current-service-type').attr("data-num"));

function cmp_path(a, b) { return units_by_path[a].Id.localeCompare(units_by_path[b].Id) }
var sorted_keys = Object.keys(units_by_path).sort(cmp_path);
Expand All @@ -292,6 +297,8 @@ $(function() {
if (current_text_filter && unit.Description.toLowerCase().indexOf(current_text_filter) == -1 &&
unit.Id.indexOf(current_text_filter) == -1)
return;
if (current_type_filter !== 0 && current_type_filter !== unit.AutomaticStartupIndex)
return;
units.push(unit);
});

Expand Down Expand Up @@ -328,6 +335,8 @@ $(function() {

function clear_filters() {
$("#services-text-filter").val("");
$('#current-service-type').attr("data-num", 0);
$('#current-service-type').text(_("All"));
render();
}

Expand Down Expand Up @@ -490,6 +499,13 @@ $(function() {
render();
});

$('#services-dropdown .dropdown-menu li').on('click', function() {
var selected = $(this).children(":first");
$("#current-service-type").text(selected.text());
$("#current-service-type").attr("data-num", selected.attr("data-num"));
render();
});

update_all();
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/systemd/services.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ table.systemd-unit-relationship-table td:first-child {
background-color: initial;
border: initial;
}

#services-dropdown {
display: inline;
}

#service-type {
min-width: 10rem;
}

#services-dropdown .dropdown-menu {
margin-top: 4px;
left: auto;
right: 0;
}

.caret {
margin-top: 6px;
}
13 changes: 13 additions & 0 deletions pkg/systemd/services.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@
<div class="filter-group">
<button id="create-timer" data-toggle="#timer-dialog" data-target="#timer-dialog" class="btn btn-primary" translate>Create Timer</button>
<input type="search" id="services-text-filter" class="form-control" aria-label="Filter" placeholder="Filter by Id or description..." translate="placeholder"/>
<div class="dropdown" id="services-dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="service-type" data-toggle="dropdown">
<span id="current-service-type" class="pull-left" data-num=0 translatable="yes">All</span>
<span class="caret pull-right"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="service-type">
<li role="presentation"><a role="menuitem" data-num=0 translatable="yes">All</a></li>
<li role="presentation" class="divider"></li>
<li role="presentation"><a role="menuitem" data-num=1 translatable="yes">Enabled</a></li>
<li role="presentation"><a role="menuitem" data-num=2 translatable="yes">Disabled</a></li>
<li role="presentation"><a role="menuitem" data-num=3 translatable="yes">Static</a></li>
</ul>
</div>
</div>
</div>

Expand Down
36 changes: 36 additions & 0 deletions test/verify/check-services
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ Unit=test.service
if m.image == "rhel-7-6-distropkg": # Introduced in #11241
return

def select_from_dropdown(value):
button_text_selector = "#services-dropdown button span:nth-of-type(1)"
item_selector = "#services-dropdown ul li a:contains({0})".format(value)
b.click("#services-dropdown button")
b.wait_present(item_selector)
b.wait_visible(item_selector)
b.click(item_selector)
b.wait_in_text(button_text_selector, value)

def wait_service_present(service):
b.wait_present(svc_sel(service))
b.wait_visible(svc_sel(service))
Expand All @@ -222,6 +231,7 @@ Unit=test.service
b.set_input_text("#services-text-filter", "")
wait_service_present("test.service")
wait_service_present("test-fail.service")
select_from_dropdown("All")

b.go("#/")

Expand All @@ -237,6 +247,32 @@ Unit=test.service
wait_service_not_present("test.service")
wait_service_present("test-fail.service")

# Select only static services
init_filter_state()
select_from_dropdown("Static")
wait_service_not_present("test.service")
wait_service_present("test-fail.service")

# Select only disabled services
select_from_dropdown("Disabled")
wait_service_present("test.service")
wait_service_not_present("test-fail.service")

# Check filtering and selecting together - empty state
b.set_input_text("#services-text-filter", "failing")
wait_service_not_present("test.service")
b.wait_present("#empty-search")
b.wait_visible("#empty-search")

# Check resetting filter
b.wait_present("#clear-all-filters")
b.wait_visible("#clear-all-filters")
b.click("#clear-all-filters")
wait_service_present("test.service")
wait_service_present("test-fail.service")
self.assertEqual(b.val("#services-text-filter"), "")
self.assertEqual(b.text("#services-dropdown button span:nth-of-type(1)"), "All")

def testApi(self):
m = self.machine
b = self.browser
Expand Down

0 comments on commit 9e5a8b7

Please sign in to comment.