DEV: refactoring admin-backups-index (#6933)

DEV: refactoring admin-backups-index (#6933)

diff --git a/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6 b/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6
index 6448c25..07cd082 100644
--- a/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6
+++ b/app/assets/javascripts/admin/controllers/admin-backups-index.js.es6
@@ -1,41 +1,36 @@
 import { ajax } from "discourse/lib/ajax";
-import computed from "ember-addons/ember-computed-decorators";
+import { default as computed } from "ember-addons/ember-computed-decorators";
+import { setting, i18n } from "discourse/lib/computed";
 
 export default Ember.Controller.extend({
   adminBackups: Ember.inject.controller(),
   status: Ember.computed.alias("adminBackups.model"),
+  uploadLabel: i18n("admin.backups.upload.label"),
+  backupLocation: setting("backup_location"),
+  localBackupStorage: Ember.computed.equal("backupLocation", "local"),
 
-  @computed
-  localBackupStorage() {
-    return this.siteSettings.backup_location === "local";
-  },
-
-  uploadLabel: function() {
-    return I18n.t("admin.backups.upload.label");
-  }.property(),
-
-  restoreTitle: function() {
-    if (!this.get("status.allowRestore")) {
+  @computed("status.allowRestore", "status.isOperationRunning")
+  restoreTitle(allowRestore, isOperationRunning) {
+    if (!allowRestore) {
       return "admin.backups.operations.restore.is_disabled";
-    } else if (this.get("status.isOperationRunning")) {
+    } else if (isOperationRunning) {
       return "admin.backups.operations.is_running";
     } else {
       return "admin.backups.operations.restore.title";
     }
-  }.property("status.{allowRestore,isOperationRunning}"),
+  },
 
   actions: {
     toggleReadOnlyMode() {
-      var self = this;
       if (!this.site.get("isReadOnly")) {
         bootbox.confirm(
           I18n.t("admin.backups.read_only.enable.confirm"),
           I18n.t("no_value"),
           I18n.t("yes_value"),
-          function(confirmed) {
+          confirmed => {
             if (confirmed) {
               Discourse.User.currentProp("hideReadOnlyAlert", true);
-              self._toggleReadOnlyMode(true);
+              this._toggleReadOnlyMode(true);
             }
           }
         );
@@ -45,20 +40,17 @@ export default Ember.Controller.extend({
     },
 
     download(backup) {
-      let link = backup.get("filename");
-      ajax("/admin/backups/" + link, { type: "PUT" }).then(() => {
-        bootbox.alert(I18n.t("admin.backups.operations.download.alert"));
-      });
+      const link = backup.get("filename");
+      ajax(`/admin/backups/${link}`, { type: "PUT" }).then(() =>
+        bootbox.alert(I18n.t("admin.backups.operations.download.alert"))
+      );
     }
   },
 
   _toggleReadOnlyMode(enable) {
-    var site = this.site;
     ajax("/admin/backups/readonly", {
       type: "PUT",
-      data: { enable: enable }
-    }).then(() => {
-      site.set("isReadOnly", enable);
-    });
+      data: { enable }
+    }).then(() => this.site.set("isReadOnly", enable));
   }
 });
diff --git a/app/assets/javascripts/admin/routes/admin-backups.js.es6 b/app/assets/javascripts/admin/routes/admin-backups.js.es6
index 28ec187..b06b3e8 100644
--- a/app/assets/javascripts/admin/routes/admin-backups.js.es6
+++ b/app/assets/javascripts/admin/routes/admin-backups.js.es6
@@ -47,15 +47,15 @@ export default Discourse.Route.extend({
   },
 
   model() {
-    return PreloadStore.getAndRemove("operations_status", function() {
-      return ajax("/admin/backups/status.json");
-    }).then(status => {
-      return BackupStatus.create({
+    return PreloadStore.getAndRemove("operations_status", () =>
+      ajax("/admin/backups/status.json")
+    ).then(status =>
+      BackupStatus.create({
         isOperationRunning: status.is_operation_running,
         canRollback: status.can_rollback,
         allowRestore: status.allow_restore
-      });
-    });
+      })
+    );
   },
 
   deactivate() {
@@ -74,33 +74,30 @@ export default Discourse.Route.extend({
     },
 
     destroyBackup(backup) {
-      const self = this;
       bootbox.confirm(
         I18n.t("admin.backups.operations.destroy.confirm"),
         I18n.t("no_value"),
         I18n.t("yes_value"),
-        function(confirmed) {
+        confirmed => {
           if (confirmed) {
-            backup.destroy().then(function() {
-              self
-                .controllerFor("adminBackupsIndex")
+            backup.destroy().then(() =>
+              this.controllerFor("adminBackupsIndex")
                 .get("model")
-                .removeObject(backup);
-            });
+                .removeObject(backup)
+            );
           }
         }
       );
     },
 
     startRestore(backup) {
-      const self = this;
       bootbox.confirm(
         I18n.t("admin.backups.operations.restore.confirm"),
         I18n.t("no_value"),
         I18n.t("yes_value"),
-        function(confirmed) {
+        confirmed => {
           if (confirmed) {
-            self.transitionTo("admin.backups.logs");
+            this.transitionTo("admin.backups.logs");
             backup.restore();
           }
         }
@@ -108,17 +105,17 @@ export default Discourse.Route.extend({
     },
 
     cancelOperation() {
-      const self = this;
       bootbox.confirm(
         I18n.t("admin.backups.operations.cancel.confirm"),
         I18n.t("no_value"),
         I18n.t("yes_value"),
-        function(confirmed) {
+        confirmed => {
           if (confirmed) {
-            Backup.cancel().then(function() {
-              self
-                .controllerFor("adminBackups")
-                .set("model.isOperationRunning", false);
+            Backup.cancel().then(() => {
+              this.controllerFor("adminBackups").set(
+                "model.isOperationRunning",
+                false
+              );
             });
           }
         }
@@ -130,7 +127,7 @@ export default Discourse.Route.extend({
         I18n.t("admin.backups.operations.rollback.confirm"),
         I18n.t("no_value"),
         I18n.t("yes_value"),
-        function(confirmed) {
+        confirmed => {
           if (confirmed) {
             Backup.rollback();
           }
@@ -139,17 +136,12 @@ export default Discourse.Route.extend({
     },
 
     uploadSuccess(filename) {
-      bootbox.alert(
-        I18n.t("admin.backups.upload.success", { filename: filename })
-      );
+      bootbox.alert(I18n.t("admin.backups.upload.success", { filename }));
     },
 
     uploadError(filename, message) {
       bootbox.alert(
-        I18n.t("admin.backups.upload.error", {
-          filename: filename,
-          message: message
-        })
+        I18n.t("admin.backups.upload.error", { filename, message })
       );
     },
 
diff --git a/app/assets/javascripts/admin/templates/backups-index.hbs b/app/assets/javascripts/admin/templates/backups-index.hbs
index 46a0daf..ee7abc5 100644
--- a/app/assets/javascripts/admin/templates/backups-index.hbs
+++ b/app/assets/javascripts/admin/templates/backups-index.hbs
@@ -1,20 +1,38 @@
-     <div class="backup-options">
-        {{#if localBackupStorage}}
-        {{resumable-upload target="/admin/backups/upload" success=(route-action "uploadSuccess") error=(route-action "uploadError") uploadText=uploadLabel title="admin.backups.upload.title" class="btn-default"}}
-        {{else}}
-          {{backup-uploader done=(route-action "remoteUploadSuccess")}}
-        {{/if}}
+<div class="backup-options">
+  {{#if localBackupStorage}}
+    {{resumable-upload
+      target="/admin/backups/upload"
+      success=(route-action "uploadSuccess")
+      error=(route-action "uploadError")
+      uploadText=uploadLabel
+      title="admin.backups.upload.title"
+      class="btn-default"}}
+  {{else}}
+    {{backup-uploader done=(route-action "remoteUploadSuccess")}}
+  {{/if}}
 
-        {{#if site.isReadOnly}}

[... diff too long, it was truncated ...]

GitHub sha: 0aa04979

2 Likes