A platform for community discussion. Free, open, simple.
DEV: refactoring admin-logs-screened-ip-addresses (#6932)
Joffrey JAFFEUXbd3142313748
diff --git a/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6 b/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6index a5eb32ae57d..595a6285720 100644--- a/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6+++ b/app/assets/javascripts/admin/controllers/admin-logs-screened-ip-addresses.js.es6@@ -11,8 +11,7 @@ export default Ember.Controller.extend({show: debounce(function() {this.set("loading", true);ScreenedIpAddress.findAll(this.get("filter")).then(result => {- this.set("model", result);- this.set("loading", false);+ this.setProperties({ model: result, loading: false });});}, 250).observes("filter"),@@ -35,8 +34,9 @@ export default Ember.Controller.extend({},cancel(record) {- if (this.get("savedIpAddress") && record.get("editing")) {- record.set("ip_address", this.get("savedIpAddress"));+ const savedIpAddress = this.get("savedIpAddress");+ if (savedIpAddress && record.get("editing")) {+ record.set("ip_address", savedIpAddress);}record.set("editing", false);},@@ -46,9 +46,7 @@ export default Ember.Controller.extend({record.set("editing", false);record.save()- .then(() => {- this.set("savedIpAddress", null);- })+ .then(() => this.set("savedIpAddress", null)).catch(e => {if (e.jqXHR.responseJSON && e.jqXHR.responseJSON.errors) {bootbox.alert(@@ -84,7 +82,7 @@ export default Ember.Controller.extend({.catch(e => {bootbox.alert(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() {- const self = this;return bootbox.confirm(I18n.t("admin.logs.screened_ips.roll_up_confirm"),I18n.t("no_value"),I18n.t("yes_value"),- function(confirmed) {+ confirmed => {if (confirmed) {- self.set("loading", true);- return ScreenedIpAddress.rollUp().then(function(results) {+ this.set("loading", true);+ return ScreenedIpAddress.rollUp().then(results => {if (results && results.subnets) {if (results.subnets.length > 0) {- self.send("show");+ this.send("show");bootbox.alert(I18n.t("admin.logs.screened_ips.rolled_up_some_subnets", {subnets: results.subnets.join(", ")}));} else {- self.set("loading", false);+ this.set("loading", false);bootbox.alert(I18n.t("admin.logs.screened_ips.rolled_up_no_subnet"));diff --git a/app/assets/javascripts/admin/templates/logs/screened-ip-addresses.hbs b/app/assets/javascripts/admin/templates/logs/screened-ip-addresses.hbsindex 4e1def35b39..c5819da7912 100644--- a/app/assets/javascripts/admin/templates/logs/screened-ip-addresses.hbs+++ b/app/assets/javascripts/admin/templates/logs/screened-ip-addresses.hbs@@ -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="filter-screened-ip-address">- {{text-field value=filter 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"}}+ {{text-field+ value=filter+ 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>- {{screened-ip-address-form action=(action "recordAdded")}}-</div>-+ {{screened-ip-address-form action=(action "recordAdded")}}+</div>{{#conditional-loading-spinner condition=loading}}{{#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">- <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 match_count">{{i18n 'admin.logs.match_count'}}</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 first ip_address">{{i18n "admin.logs.ip_address"}}</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 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 actions"></th></thead><tbody>@@ -47,34 +59,64 @@{{/if}}{{item.actionName}}</td>- <td class="col match_count"><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 match_count">+ <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">{{#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}}</td><td class="col actions">{{#unless item.editing}}- {{d-button 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"}}+ {{d-button+ 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}}- {{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}}- {{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}}{{else}}- {{d-button class="btn-default" action=(action "save") actionParam=item label="admin.logs.save"}}- <a {{action "cancel" item}}>{{i18n 'cancel'}}</a>+ {{d-button+ class="btn-default"+ action=(action "save")+ actionParam=item+ label="admin.logs.save"}}+ <a {{action "cancel" item}}>{{i18n "cancel"}}</a>{{/unless}}</td></tr>{{/each}}</tbody></table>-{{else}}- {{i18n 'search.no_results'}}+ {{i18n "search.no_results"}}{{/if}}{{/conditional-loading-spinner}}