DEV: refactoring admin-logs-screened-ip-addresses (#6932)
This commit is contained in:
parent
0aa049791e
commit
bd31423137
|
@ -11,8 +11,7 @@ export default Ember.Controller.extend({
|
||||||
show: debounce(function() {
|
show: debounce(function() {
|
||||||
this.set("loading", true);
|
this.set("loading", true);
|
||||||
ScreenedIpAddress.findAll(this.get("filter")).then(result => {
|
ScreenedIpAddress.findAll(this.get("filter")).then(result => {
|
||||||
this.set("model", result);
|
this.setProperties({ model: result, loading: false });
|
||||||
this.set("loading", false);
|
|
||||||
});
|
});
|
||||||
}, 250).observes("filter"),
|
}, 250).observes("filter"),
|
||||||
|
|
||||||
|
@ -35,8 +34,9 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
cancel(record) {
|
cancel(record) {
|
||||||
if (this.get("savedIpAddress") && record.get("editing")) {
|
const savedIpAddress = this.get("savedIpAddress");
|
||||||
record.set("ip_address", this.get("savedIpAddress"));
|
if (savedIpAddress && record.get("editing")) {
|
||||||
|
record.set("ip_address", savedIpAddress);
|
||||||
}
|
}
|
||||||
record.set("editing", false);
|
record.set("editing", false);
|
||||||
},
|
},
|
||||||
|
@ -46,9 +46,7 @@ export default Ember.Controller.extend({
|
||||||
record.set("editing", false);
|
record.set("editing", false);
|
||||||
record
|
record
|
||||||
.save()
|
.save()
|
||||||
.then(() => {
|
.then(() => this.set("savedIpAddress", null))
|
||||||
this.set("savedIpAddress", null);
|
|
||||||
})
|
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {
|
||||||
bootbox.alert(
|
bootbox.alert(
|
||||||
|
@ -84,7 +82,7 @@ export default Ember.Controller.extend({
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
bootbox.alert(
|
bootbox.alert(
|
||||||
I18n.t("generic_error_with_reason", {
|
I18n.t("generic_error_with_reason", {
|
||||||
error: "http: " + e.status + " - " + e.body
|
error: `http: ${e.status} - ${e.body}`
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -98,25 +96,24 @@ export default Ember.Controller.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
rollUp() {
|
rollUp() {
|
||||||
const self = this;
|
|
||||||
return bootbox.confirm(
|
return bootbox.confirm(
|
||||||
I18n.t("admin.logs.screened_ips.roll_up_confirm"),
|
I18n.t("admin.logs.screened_ips.roll_up_confirm"),
|
||||||
I18n.t("no_value"),
|
I18n.t("no_value"),
|
||||||
I18n.t("yes_value"),
|
I18n.t("yes_value"),
|
||||||
function(confirmed) {
|
confirmed => {
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
self.set("loading", true);
|
this.set("loading", true);
|
||||||
return ScreenedIpAddress.rollUp().then(function(results) {
|
return ScreenedIpAddress.rollUp().then(results => {
|
||||||
if (results && results.subnets) {
|
if (results && results.subnets) {
|
||||||
if (results.subnets.length > 0) {
|
if (results.subnets.length > 0) {
|
||||||
self.send("show");
|
this.send("show");
|
||||||
bootbox.alert(
|
bootbox.alert(
|
||||||
I18n.t("admin.logs.screened_ips.rolled_up_some_subnets", {
|
I18n.t("admin.logs.screened_ips.rolled_up_some_subnets", {
|
||||||
subnets: results.subnets.join(", ")
|
subnets: results.subnets.join(", ")
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
self.set("loading", false);
|
this.set("loading", false);
|
||||||
bootbox.alert(
|
bootbox.alert(
|
||||||
I18n.t("admin.logs.screened_ips.rolled_up_no_subnet")
|
I18n.t("admin.logs.screened_ips.rolled_up_no_subnet")
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,26 +1,38 @@
|
||||||
<p>{{i18n 'admin.logs.screened_ips.description'}}</p>
|
<p>{{i18n "admin.logs.screened_ips.description"}}</p>
|
||||||
|
|
||||||
<div class="screened-ip-controls">
|
<div class="screened-ip-controls">
|
||||||
<div class="filter-screened-ip-address">
|
<div class="filter-screened-ip-address">
|
||||||
{{text-field value=filter class="ip-address-input" placeholderKey="admin.logs.screened_ips.form.filter" autocorrect="off" autocapitalize="off"}}
|
{{text-field
|
||||||
{{d-button class="btn-default" action=(action "rollUp") title="admin.logs.screened_ips.roll_up.title" label="admin.logs.screened_ips.roll_up.text"}}
|
value=filter
|
||||||
{{d-button class="btn-default" action=(action "exportScreenedIpList") icon="download" title="admin.export_csv.button_title.screened_ip" label="admin.export_csv.button_text"}}
|
class="ip-address-input"
|
||||||
|
placeholderKey="admin.logs.screened_ips.form.filter"
|
||||||
|
autocorrect="off"
|
||||||
|
autocapitalize="off"}}
|
||||||
|
{{d-button
|
||||||
|
class="btn-default"
|
||||||
|
action=(action "rollUp")
|
||||||
|
title="admin.logs.screened_ips.roll_up.title"
|
||||||
|
label="admin.logs.screened_ips.roll_up.text"}}
|
||||||
|
{{d-button
|
||||||
|
class="btn-default"
|
||||||
|
action=(action "exportScreenedIpList")
|
||||||
|
icon="download"
|
||||||
|
title="admin.export_csv.button_title.screened_ip"
|
||||||
|
label="admin.export_csv.button_text"}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{screened-ip-address-form action=(action "recordAdded")}}
|
{{screened-ip-address-form action=(action "recordAdded")}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{{#conditional-loading-spinner condition=loading}}
|
{{#conditional-loading-spinner condition=loading}}
|
||||||
{{#if model.length}}
|
{{#if model.length}}
|
||||||
|
<table class="admin-logs-table screened-ip-addresses grid">
|
||||||
<table class='admin-logs-table screened-ip-addresses grid'>
|
|
||||||
<thead class="heading-container">
|
<thead class="heading-container">
|
||||||
<th class="col heading first ip_address">{{i18n 'admin.logs.ip_address'}}</th>
|
<th class="col heading first ip_address">{{i18n "admin.logs.ip_address"}}</th>
|
||||||
<th class="col heading action">{{i18n 'admin.logs.action'}}</th>
|
<th class="col heading action">{{i18n "admin.logs.action"}}</th>
|
||||||
<th class="col heading match_count">{{i18n 'admin.logs.match_count'}}</th>
|
<th class="col heading match_count">{{i18n "admin.logs.match_count"}}</th>
|
||||||
<th class="col heading created_at">{{i18n 'admin.logs.created_at'}}</th>
|
<th class="col heading created_at">{{i18n "admin.logs.created_at"}}</th>
|
||||||
<th class="col heading last_match_at">{{i18n 'admin.logs.last_match_at'}}</th>
|
<th class="col heading last_match_at">{{i18n "admin.logs.last_match_at"}}</th>
|
||||||
<th class="col heading actions"></th>
|
<th class="col heading actions"></th>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -47,34 +59,64 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{item.actionName}}
|
{{item.actionName}}
|
||||||
</td>
|
</td>
|
||||||
<td class="col match_count"><div class="label">{{i18n 'admin.logs.match_count'}}</div> {{item.match_count}}</td>
|
<td class="col match_count">
|
||||||
<td class="col created_at"><div class="label">{{i18n 'admin.logs.created_at'}}</div> {{age-with-tooltip item.created_at}}</td>
|
<div class="label">{{i18n "admin.logs.match_count"}}</div>
|
||||||
|
{{item.match_count}}
|
||||||
|
</td>
|
||||||
|
<td class="col created_at">
|
||||||
|
<div class="label">{{i18n "admin.logs.created_at"}}</div>
|
||||||
|
{{age-with-tooltip item.created_at}}
|
||||||
|
</td>
|
||||||
<td class="col last_match_at">
|
<td class="col last_match_at">
|
||||||
{{#if item.last_match_at}}
|
{{#if item.last_match_at}}
|
||||||
<div class="label">{{i18n 'admin.logs.last_match_at'}} {{age-with-tooltip item.last_match_at}}</div>
|
<div class="label">
|
||||||
|
{{i18n "admin.logs.last_match_at"}}
|
||||||
|
{{age-with-tooltip item.last_match_at}}
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</td>
|
</td>
|
||||||
<td class="col actions">
|
<td class="col actions">
|
||||||
{{#unless item.editing}}
|
{{#unless item.editing}}
|
||||||
{{d-button class="btn-default" action=(action "destroy") actionParam=item icon="far-trash-alt" class="btn-danger"}}
|
{{d-button
|
||||||
{{d-button class="btn-default"action=(action "edit") actionParam=item icon="pencil-alt"}}
|
class="btn-default"
|
||||||
|
action=(action "destroy")
|
||||||
|
actionParam=item
|
||||||
|
icon="far-trash-alt"
|
||||||
|
class="btn-danger"}}
|
||||||
|
{{d-button
|
||||||
|
class="btn-default"
|
||||||
|
action=(action "edit")
|
||||||
|
actionParam=item
|
||||||
|
icon="pencil-alt"}}
|
||||||
{{#if item.isBlocked}}
|
{{#if item.isBlocked}}
|
||||||
{{d-button class="btn-default" action=(action "allow") actionParam=item icon="check" label="admin.logs.screened_ips.actions.do_nothing"}}
|
{{d-button
|
||||||
|
class="btn-default"
|
||||||
|
action=(action "allow")
|
||||||
|
actionParam=item
|
||||||
|
icon="check"
|
||||||
|
label="admin.logs.screened_ips.actions.do_nothing"}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{d-button class="btn-default" action=(action "block") actionParam=item icon="ban" label="admin.logs.screened_ips.actions.block"}}
|
{{d-button
|
||||||
|
class="btn-default"
|
||||||
|
action=(action "block")
|
||||||
|
actionParam=item
|
||||||
|
icon="ban"
|
||||||
|
label="admin.logs.screened_ips.actions.block"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{d-button class="btn-default" action=(action "save") actionParam=item label="admin.logs.save"}}
|
{{d-button
|
||||||
<a {{action "cancel" item}}>{{i18n 'cancel'}}</a>
|
class="btn-default"
|
||||||
|
action=(action "save")
|
||||||
|
actionParam=item
|
||||||
|
label="admin.logs.save"}}
|
||||||
|
<a {{action "cancel" item}}>{{i18n "cancel"}}</a>
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{{else}}
|
{{else}}
|
||||||
{{i18n 'search.no_results'}}
|
{{i18n "search.no_results"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/conditional-loading-spinner}}
|
{{/conditional-loading-spinner}}
|
||||||
|
|
Loading…
Reference in New Issue