Skip to content

Commit 96e034a

Browse files
Add search function for redirection
1 parent 5edb16f commit 96e034a

File tree

2 files changed

+44
-14
lines changed

2 files changed

+44
-14
lines changed

Diff for: frontend/js/app/nginx/redirection/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">Redirection Hosts</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-yellow btn-sm ml-2 add-item">Add Redirection Host</a>

Diff for: frontend/js/app/nginx/redirection/main.js

+36-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,28 @@ 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.RedirectionHosts.getAll,
23+
24+
showData: function(response) {
25+
this.showChildView('list_region', new ListView({
26+
collection: new RedirectionHostModel.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.showNginxRedirection();
36+
}
37+
}));
38+
console.error(err);
1839
},
1940

2041
regions: {
@@ -30,6 +51,17 @@ module.exports = Mn.View.extend({
3051
'click @ui.help': function (e) {
3152
e.preventDefault();
3253
App.Controller.showHelp(App.i18n('redirection-hosts', 'help-title'), App.i18n('redirection-hosts', 'help-content'));
54+
},
55+
56+
'submit @ui.search': function (e) {
57+
e.preventDefault();
58+
let query = this.ui.query.val();
59+
60+
this.fetch(['owner', 'certificate'], query)
61+
.then(response => this.showData(response))
62+
.catch(err => {
63+
this.showError(err);
64+
});
3365
}
3466
},
3567

@@ -40,13 +72,11 @@ module.exports = Mn.View.extend({
4072
onRender: function () {
4173
let view = this;
4274

43-
App.Api.Nginx.RedirectionHosts.getAll(['owner', 'certificate'])
75+
view.fetch(['owner', 'certificate'])
4476
.then(response => {
4577
if (!view.isDestroyed()) {
4678
if (response && response.length) {
47-
view.showChildView('list_region', new ListView({
48-
collection: new RedirectionHostModel.Collection(response)
49-
}));
79+
view.showData(response);
5080
} else {
5181
let manage = App.Cache.User.canManage('redirection_hosts');
5282

@@ -64,15 +94,7 @@ module.exports = Mn.View.extend({
6494
}
6595
})
6696
.catch(err => {
67-
view.showChildView('list_region', new ErrorView({
68-
code: err.code,
69-
message: err.message,
70-
retry: function () {
71-
App.Controller.showNginxRedirection();
72-
}
73-
}));
74-
75-
console.error(err);
97+
view.showError(err);
7698
})
7799
.then(() => {
78100
view.ui.dimmer.removeClass('active');

0 commit comments

Comments
 (0)