Skip to content

Commit 61b25e1

Browse files
Add search feature to Audit Logs
1 parent d3a5a3d commit 61b25e1

File tree

2 files changed

+57
-18
lines changed

2 files changed

+57
-18
lines changed

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

+10
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="Search Log…" aria-label="Search in Audit Logs">
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

+47-18
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');

0 commit comments

Comments
 (0)