Skip to content

Commit 49f350f

Browse files
Add search feature to 404 hosts
1 parent e141b5f commit 49f350f

File tree

2 files changed

+61
-26
lines changed

2 files changed

+61
-26
lines changed

frontend/js/app/nginx/dead/main.ejs

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
<div class="card-header">
44
<h3 class="card-title"><%- i18n('dead-hosts', 'title') %></h3>
55
<div class="card-options">
6+
<form class="search-form" role="search">
7+
<div class="input-icon">
8+
<span class="input-icon-addon">
9+
<i class="fe fe-search"></i>
10+
</span>
11+
<input name="source-query" type="text" value="" class="form-control form-control-sm" placeholder="Search Host…" aria-label="Search in Hosts">
12+
</div>
13+
</form>
614
<a href="#" class="btn btn-outline-secondary btn-sm ml-2 help"><i class="fe fe-help-circle"></i></a>
715
<% if (showAddButton) { %>
816
<a href="#" class="btn btn-outline-danger btn-sm ml-2 add-item"><%- i18n('dead-hosts', 'add') %></a>

frontend/js/app/nginx/dead/main.js

+53-26
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,44 @@ module.exports = Mn.View.extend({
1414
list_region: '.list-region',
1515
add: '.add-item',
1616
help: '.help',
17-
dimmer: '.dimmer'
17+
dimmer: '.dimmer',
18+
search: '.search-form',
19+
query: 'input[name="source-query"]'
20+
},
21+
22+
fetch: App.Api.Nginx.DeadHosts.getAll,
23+
24+
showData: function(response) {
25+
this.showChildView('list_region', new ListView({
26+
collection: new DeadHostModel.Collection(response)
27+
}));
28+
},
29+
30+
showError: function(err) {
31+
this.showChildView('list_region', new ErrorView({
32+
code: err.code,
33+
message: err.message,
34+
retry: function () {
35+
App.Controller.showNginxDead();
36+
}
37+
}));
38+
39+
console.error(err);
40+
},
41+
42+
showEmpty: function() {
43+
let manage = App.Cache.User.canManage('dead_hosts');
44+
45+
this.showChildView('list_region', new EmptyView({
46+
title: App.i18n('dead-hosts', 'empty'),
47+
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
48+
link: manage ? App.i18n('dead-hosts', 'add') : null,
49+
btn_color: 'danger',
50+
permission: 'dead_hosts',
51+
action: function () {
52+
App.Controller.showNginxDeadForm();
53+
}
54+
}));
1855
},
1956

2057
regions: {
@@ -30,6 +67,17 @@ module.exports = Mn.View.extend({
3067
'click @ui.help': function (e) {
3168
e.preventDefault();
3269
App.Controller.showHelp(App.i18n('dead-hosts', 'help-title'), App.i18n('dead-hosts', 'help-content'));
70+
},
71+
72+
'submit @ui.search': function (e) {
73+
e.preventDefault();
74+
let query = this.ui.query.val();
75+
76+
this.fetch(['owner', 'certificate'], query)
77+
.then(response => this.showData(response))
78+
.catch(err => {
79+
this.showError(err);
80+
});
3381
}
3482
},
3583

@@ -40,39 +88,18 @@ module.exports = Mn.View.extend({
4088
onRender: function () {
4189
let view = this;
4290

43-
App.Api.Nginx.DeadHosts.getAll(['owner', 'certificate'])
91+
view.fetch(['owner', 'certificate'])
4492
.then(response => {
4593
if (!view.isDestroyed()) {
4694
if (response && response.length) {
47-
view.showChildView('list_region', new ListView({
48-
collection: new DeadHostModel.Collection(response)
49-
}));
95+
view.showData(response);
5096
} else {
51-
let manage = App.Cache.User.canManage('dead_hosts');
52-
53-
view.showChildView('list_region', new EmptyView({
54-
title: App.i18n('dead-hosts', 'empty'),
55-
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
56-
link: manage ? App.i18n('dead-hosts', 'add') : null,
57-
btn_color: 'danger',
58-
permission: 'dead_hosts',
59-
action: function () {
60-
App.Controller.showNginxDeadForm();
61-
}
62-
}));
97+
view.showEmpty();
6398
}
6499
}
65100
})
66101
.catch(err => {
67-
view.showChildView('list_region', new ErrorView({
68-
code: err.code,
69-
message: err.message,
70-
retry: function () {
71-
App.Controller.showNginxDead();
72-
}
73-
}));
74-
75-
console.error(err);
102+
view.showError(err);
76103
})
77104
.then(() => {
78105
view.ui.dimmer.removeClass('active');

0 commit comments

Comments
 (0)