Skip to content

Commit 14b889a

Browse files
authored
Merge pull request #1822 from ivankristianto/add-search-feature-redirection
Add Search Feature To Backend Administration
2 parents 7281ed5 + 8eb44c4 commit 14b889a

File tree

18 files changed

+490
-203
lines changed

18 files changed

+490
-203
lines changed

backend/internal/certificate.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ const internalCertificate = {
388388
zipFiles(source, out) {
389389
const archive = archiver('zip', { zlib: { level: 9 } });
390390
const stream = fs.createWriteStream(out);
391-
391+
392392
return new Promise((resolve, reject) => {
393393
source
394394
.map((fl) => {
@@ -399,7 +399,7 @@ const internalCertificate = {
399399
archive
400400
.on('error', (err) => reject(err))
401401
.pipe(stream);
402-
402+
403403
stream.on('close', () => resolve());
404404
archive.finalize();
405405
});
@@ -477,7 +477,7 @@ const internalCertificate = {
477477
// Query is used for searching
478478
if (typeof search_query === 'string') {
479479
query.where(function () {
480-
this.where('name', 'like', '%' + search_query + '%');
480+
this.where('nice_name', 'like', '%' + search_query + '%');
481481
});
482482
}
483483

@@ -1140,7 +1140,7 @@ const internalCertificate = {
11401140
if (domains.length === 0) {
11411141
throw new error.InternalValidationError('No domains provided');
11421142
}
1143-
1143+
11441144
// Create a test challenge file
11451145
const testChallengeDir = '/data/letsencrypt-acme-challenge/.well-known/acme-challenge';
11461146
const testChallengeFile = testChallengeDir + '/test-challenge';
@@ -1215,7 +1215,7 @@ const internalCertificate = {
12151215

12161216
// Remove the test challenge file
12171217
fs.unlinkSync(testChallengeFile);
1218-
1218+
12191219
return results;
12201220
}
12211221
};

frontend/js/app/audit-log/main.ejs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
<div class="card-status bg-teal"></div>
33
<div class="card-header">
44
<h3 class="card-title"><%- i18n('audit-log', 'title') %></h3>
5+
<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="<%- i18n('audit-log', 'search') %>" aria-label="<%- i18n('audit-log', 'search') %>">
12+
</div>
13+
</form>
14+
</div>
515
</div>
616
<div class="card-body no-padding min-100">
717
<div class="dimmer active">

frontend/js/app/audit-log/main.js

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,68 @@ module.exports = Mn.View.extend({
1212

1313
ui: {
1414
list_region: '.list-region',
15-
dimmer: '.dimmer'
15+
dimmer: '.dimmer',
16+
search: '.search-form',
17+
query: 'input[name="source-query"]'
18+
},
19+
20+
fetch: App.Api.AuditLog.getAll,
21+
22+
showData: function(response) {
23+
this.showChildView('list_region', new ListView({
24+
collection: new AuditLogModel.Collection(response)
25+
}));
26+
},
27+
28+
showError: function(err) {
29+
this.showChildView('list_region', new ErrorView({
30+
code: err.code,
31+
message: err.message,
32+
retry: function () {
33+
App.Controller.showAuditLog();
34+
}
35+
}));
36+
37+
console.error(err);
38+
},
39+
40+
showEmpty: function() {
41+
this.showChildView('list_region', new EmptyView({
42+
title: App.i18n('audit-log', 'empty'),
43+
subtitle: App.i18n('audit-log', 'empty-subtitle')
44+
}));
1645
},
1746

1847
regions: {
1948
list_region: '@ui.list_region'
2049
},
2150

51+
events: {
52+
'submit @ui.search': function (e) {
53+
e.preventDefault();
54+
let query = this.ui.query.val();
55+
56+
this.fetch(['user'], query)
57+
.then(response => this.showData(response))
58+
.catch(err => {
59+
this.showError(err);
60+
});
61+
}
62+
},
63+
2264
onRender: function () {
2365
let view = this;
2466

25-
App.Api.AuditLog.getAll(['user'])
67+
view.fetch(['user'])
2668
.then(response => {
2769
if (!view.isDestroyed() && response && response.length) {
28-
view.showChildView('list_region', new ListView({
29-
collection: new AuditLogModel.Collection(response)
30-
}));
70+
view.showData(response);
3171
} else {
32-
view.showChildView('list_region', new EmptyView({
33-
title: App.i18n('audit-log', 'empty'),
34-
subtitle: App.i18n('audit-log', 'empty-subtitle')
35-
}));
72+
view.showEmpty();
3673
}
3774
})
3875
.catch(err => {
39-
view.showChildView('list_region', new ErrorView({
40-
code: err.code,
41-
message: err.message,
42-
retry: function () {
43-
App.Controller.showAuditLog();
44-
}
45-
}));
46-
47-
console.error(err);
76+
view.showError(err);
4877
})
4978
.then(() => {
5079
view.ui.dimmer.removeClass('active');

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
<div class="card-header">
44
<h3 class="card-title"><%- i18n('access-lists', '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="<%- i18n('access-lists', 'search') %>" aria-label="<%- i18n('access-lists', 'search') %>">
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-teal btn-sm ml-2 add-item"><%- i18n('access-lists', 'add') %></a>

frontend/js/app/nginx/access/main.js

Lines changed: 53 additions & 26 deletions
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.AccessLists.getAll,
23+
24+
showData: function(response) {
25+
this.showChildView('list_region', new ListView({
26+
collection: new AccessListModel.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.showNginxAccess();
36+
}
37+
}));
38+
39+
console.error(err);
40+
},
41+
42+
showEmpty: function() {
43+
let manage = App.Cache.User.canManage('access_lists');
44+
45+
this.showChildView('list_region', new EmptyView({
46+
title: App.i18n('access-lists', 'empty'),
47+
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
48+
link: manage ? App.i18n('access-lists', 'add') : null,
49+
btn_color: 'teal',
50+
permission: 'access_lists',
51+
action: function () {
52+
App.Controller.showNginxAccessListForm();
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('access-lists', 'help-title'), App.i18n('access-lists', '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', 'items', 'clients'], 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.AccessLists.getAll(['owner', 'items', 'clients'])
91+
view.fetch(['owner', 'items', 'clients'])
4492
.then(response => {
4593
if (!view.isDestroyed()) {
4694
if (response && response.length) {
47-
view.showChildView('list_region', new ListView({
48-
collection: new AccessListModel.Collection(response)
49-
}));
95+
view.showData(response);
5096
} else {
51-
let manage = App.Cache.User.canManage('access_lists');
52-
53-
view.showChildView('list_region', new EmptyView({
54-
title: App.i18n('access-lists', 'empty'),
55-
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
56-
link: manage ? App.i18n('access-lists', 'add') : null,
57-
btn_color: 'teal',
58-
permission: 'access_lists',
59-
action: function () {
60-
App.Controller.showNginxAccessListForm();
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.showNginxAccess();
72-
}
73-
}));
74-
75-
console.error(err);
102+
view.showError(err);
76103
})
77104
.then(() => {
78105
view.ui.dimmer.removeClass('active');

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
<div class="card-header">
44
<h3 class="card-title"><%- i18n('certificates', '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="<%- i18n('certificates', 'search') %>" aria-label="<%- i18n('certificates', 'search') %>">
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
<div class="dropdown">

frontend/js/app/nginx/certificates/main.js

Lines changed: 53 additions & 26 deletions
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.Certificates.getAll,
23+
24+
showData: function(response) {
25+
this.showChildView('list_region', new ListView({
26+
collection: new CertificateModel.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.showNginxCertificates();
36+
}
37+
}));
38+
39+
console.error(err);
40+
},
41+
42+
showEmpty: function() {
43+
let manage = App.Cache.User.canManage('certificates');
44+
45+
this.showChildView('list_region', new EmptyView({
46+
title: App.i18n('certificates', 'empty'),
47+
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
48+
link: manage ? App.i18n('certificates', 'add') : null,
49+
btn_color: 'pink',
50+
permission: 'certificates',
51+
action: function () {
52+
App.Controller.showNginxCertificateForm();
53+
}
54+
}));
1855
},
1956

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

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

44-
App.Api.Nginx.Certificates.getAll(['owner'])
92+
view.fetch(['owner'])
4593
.then(response => {
4694
if (!view.isDestroyed()) {
4795
if (response && response.length) {
48-
view.showChildView('list_region', new ListView({
49-
collection: new CertificateModel.Collection(response)
50-
}));
96+
view.showData(response);
5197
} else {
52-
let manage = App.Cache.User.canManage('certificates');
53-
54-
view.showChildView('list_region', new EmptyView({
55-
title: App.i18n('certificates', 'empty'),
56-
subtitle: App.i18n('all-hosts', 'empty-subtitle', {manage: manage}),
57-
link: manage ? App.i18n('certificates', 'add') : null,
58-
btn_color: 'pink',
59-
permission: 'certificates',
60-
action: function () {
61-
App.Controller.showNginxCertificateForm();
62-
}
63-
}));
98+
view.showEmpty();
6499
}
65100
}
66101
})
67102
.catch(err => {
68-
view.showChildView('list_region', new ErrorView({
69-
code: err.code,
70-
message: err.message,
71-
retry: function () {
72-
App.Controller.showNginxCertificates();
73-
}
74-
}));
75-
76-
console.error(err);
103+
view.showError(err);
77104
})
78105
.then(() => {
79106
view.ui.dimmer.removeClass('active');

0 commit comments

Comments
 (0)