REFACTOR: various refactoring applied to group pages (#9440)

REFACTOR: various refactoring applied to group pages (#9440)

diff --git a/app/assets/javascripts/discourse/controllers/group-add-members.js b/app/assets/javascripts/discourse/controllers/group-add-members.js
index 9b1f888..0637ac7 100644
--- a/app/assets/javascripts/discourse/controllers/group-add-members.js
+++ b/app/assets/javascripts/discourse/controllers/group-add-members.js
@@ -3,6 +3,7 @@ import { isEmpty } from "@ember/utils";
 import Controller from "@ember/controller";
 import { extractError } from "discourse/lib/ajax-error";
 import ModalFunctionality from "discourse/mixins/modal-functionality";
+import { action } from "@ember/object";
 
 export default Controller.extend(ModalFunctionality, {
   loading: false,
@@ -13,36 +14,32 @@ export default Controller.extend(ModalFunctionality, {
     return loading || !usernames || !(usernames.length > 0);
   },
 
-  actions: {
-    addMembers() {
-      this.set("loading", true);
+  @action
+  addMembers() {
+    this.set("loading", true);
 
-      const model = this.model;
-      const usernames = model.get("usernames");
-      if (isEmpty(usernames)) {
-        return;
-      }
-      let promise;
+    const usernames = this.model.usernames;
+    if (isEmpty(usernames)) {
+      return;
+    }
+    let promise;
 
-      if (this.setAsOwner) {
-        promise = model.addOwners(usernames, true);
-      } else {
-        promise = model.addMembers(usernames, true);
-      }
+    if (this.setAsOwner) {
+      promise = this.model.addOwners(usernames, true);
+    } else {
+      promise = this.model.addMembers(usernames, true);
+    }
 
-      promise
-        .then(() => {
-          this.transitionToRoute("group.members", this.get("model.name"), {
-            queryParams: { filter: usernames }
-          });
+    promise
+      .then(() => {
+        this.transitionToRoute("group.members", this.get("model.name"), {
+          queryParams: { filter: usernames }
+        });
 
-          model.set("usernames", null);
-          this.send("closeModal");
-        })
-        .catch(error => {
-          this.flash(extractError(error), "error");
-        })
-        .finally(() => this.set("loading", false));
-    }
+        this.model.set("usernames", null);
+        this.send("closeModal");
+      })
+      .catch(error => this.flash(extractError(error), "error"))
+      .finally(() => this.set("loading", false));
   }
 });
diff --git a/app/assets/javascripts/discourse/controllers/group-index.js b/app/assets/javascripts/discourse/controllers/group-index.js
index b4168ba..6d66189 100644
--- a/app/assets/javascripts/discourse/controllers/group-index.js
+++ b/app/assets/javascripts/discourse/controllers/group-index.js
@@ -1,8 +1,9 @@
 import Controller, { inject as controller } from "@ember/controller";
-import { alias } from "@ember/object/computed";
+import { gt, readOnly } from "@ember/object/computed";
 import discourseComputed, { observes } from "discourse-common/utils/decorators";
 import { popupAjaxError } from "discourse/lib/ajax-error";
 import discourseDebounce from "discourse/lib/debounce";
+import { action } from "@ember/object";
 
 export default Controller.extend({
   application: controller(),
@@ -15,7 +16,7 @@ export default Controller.extend({
   filterInput: null,
 
   loading: false,
-  isOwner: alias("model.is_group_owner"),
+  isOwner: readOnly("model.is_group_owner"),
   showActions: false,
 
   @observes("filterInput")
@@ -29,27 +30,22 @@ export default Controller.extend({
   },
 
   findMembers(refresh) {
-    if (this.loading) {
+    if (this.loading || !this.model) {
       return;
     }
 
-    const model = this.model;
-    if (!model) {
-      return;
-    }
-
-    if (!refresh && model.members.length >= model.user_count) {
+    if (!refresh && this.model.members.length >= this.model.user_count) {
       this.set("application.showFooter", true);
       return;
     }
 
     this.set("loading", true);
-    model.findMembers(this.memberParams, refresh).finally(() => {
-      this.set(
-        "application.showFooter",
-        model.members.length >= model.user_count
-      );
-      this.set("loading", false);
+    this.model.findMembers(this.memberParams, refresh).finally(() => {
+      this.setProperties({
+        "application.showFooter":
+          this.model.members.length >= this.model.user_count,
+        loading: false
+      });
     });
   },
 
@@ -58,10 +54,7 @@ export default Controller.extend({
     return { order, desc, filter };
   },
 
-  @discourseComputed("model.members.[]")
-  hasMembers(members) {
-    return members && members.length > 0;
-  },
+  hasMembers: gt("model.members.length", 0),
 
   @discourseComputed("model")
   canManageGroup(model) {
@@ -77,49 +70,53 @@ export default Controller.extend({
     }
   },
 
-  actions: {
-    loadMore() {
-      this.findMembers();
-    },
-
-    toggleActions() {
-      this.toggleProperty("showActions");
-    },
-
-    actOnGroup(member, actionId) {
-      switch (actionId) {
-        case "removeMember":
-          this.send("removeMember", member);
-          break;
-        case "makeOwner":
-          this.send("makeOwner", member.username);
-          break;
-        case "removeOwner":
-          this.send("removeOwner", member);
-          break;
-      }
-    },
-
-    removeMember(user) {
-      this.model.removeMember(user, this.memberParams);
-    },
-
-    makeOwner(username) {
-      this.model.addOwners(username);
-    },
-
-    removeOwner(user) {
-      this.model.removeOwner(user);
-    },
-
-    addMembers() {
-      const usernames = this.usernames;
-      if (usernames && usernames.length > 0) {
-        this.model
-          .addMembers(usernames)
-          .then(() => this.set("usernames", []))
-          .catch(popupAjaxError);
-      }
+  @action
+  loadMore() {
+    this.findMembers();
+  },
+
+  @action
+  toggleActions() {
+    this.toggleProperty("showActions");
+  },
+
+  @action
+  actOnGroup(member, actionId) {
+    switch (actionId) {
+      case "removeMember":
+        this.removeMember(member);
+        break;
+      case "makeOwner":
+        this.makeOwner(member.username);
+        break;
+      case "removeOwner":
+        this.removeOwner(member);
+        break;
+    }
+  },
+
+  @action
+  removeMember(user) {
+    this.model.removeMember(user, this.memberParams);
+  },
+
+  @action
+  makeOwner(username) {
+    this.model.addOwners(username);
+  },
+
+  @action
+  removeOwner(user) {
+    this.model.removeOwner(user);
+  },
+
+  @action
+  addMembers() {
+    if (this.usernames && this.usernames.length > 0) {
+      this.model
+        .addMembers(this.usernames)
+        .then(() => this.set("usernames", []))
+        .catch(popupAjaxError);
     }
   }
 });
diff --git a/app/assets/javascripts/discourse/controllers/group-manage-logs.js b/app/assets/javascripts/discourse/controllers/group-manage-logs.js
index 80947cb..ab3ff8e 100644
--- a/app/assets/javascripts/discourse/controllers/group-manage-logs.js
+++ b/app/assets/javascripts/discourse/controllers/group-manage-logs.js
@@ -1,5 +1,5 @@
 import Controller, { inject as controller } from "@ember/controller";
-import EmberObject from "@ember/object";
+import EmberObject, { action } from "@ember/object";
 import discourseComputed, { observes } from "discourse-common/utils/decorators";
 
 export default Controller.extend({
@@ -19,8 +19,8 @@ export default Controller.extend({
     "filters.target_user",
     "filters.subject"
   )
-  filterParams(action, acting_user, target_user, subject) {
-    return { action, acting_user, target_user, subject };
+  filterParams(filtersAction, acting_user, target_user, subject) {
+    return { action: filtersAction, acting_user, target_user, subject };
   },
 
   @observes(
@@ -54,28 +54,26 @@ export default Controller.extend({
     });
   },
 
-  actions: {
-    loadMore() {
-      if (this.get("model.all_loaded")) return;
+  @action
+  loadMore() {
+    if (this.get("model.all_loaded")) return;
 
-      this.set("loading", true);

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

GitHub sha: 0a9f283e

This commit appears in #9440 which was approved by eviltrout. It was merged by jjaffeux.