REFACTOR: tags-show (#7079)

REFACTOR: tags-show (#7079)

diff --git a/app/assets/javascripts/discourse/controllers/tags-show.js.es6 b/app/assets/javascripts/discourse/controllers/tags-show.js.es6
index 59ad9db..65062df 100644
--- a/app/assets/javascripts/discourse/controllers/tags-show.js.es6
+++ b/app/assets/javascripts/discourse/controllers/tags-show.js.es6
@@ -1,4 +1,7 @@
-import { default as computed } from "ember-addons/ember-computed-decorators";
+import {
+  default as computed,
+  observes
+} from "ember-addons/ember-computed-decorators";
 import BulkTopicSelection from "discourse/mixins/bulk-topic-selection";
 import {
   default as NavItem,
@@ -19,14 +22,14 @@ if (extraNavItemProperties) {
 if (customNavItemHref) {
   customNavItemHref(function(navItem) {
     if (navItem.get("tagId")) {
-      var name = navItem.get("name");
+      const name = navItem.get("name");
 
       if (!Discourse.Site.currentProp("filters").includes(name)) {
         return null;
       }
 
-      var path = "/tags/",
-        category = navItem.get("category");
+      let path = "/tags/";
+      const category = navItem.get("category");
 
       if (category) {
         path += "c/";
@@ -37,8 +40,8 @@ if (customNavItemHref) {
         path += "/";
       }
 
-      path += navItem.get("tagId") + "/l/";
-      return path + name.replace(" ", "-");
+      path += `${navItem.get("tagId")}/l/`;
+      return `${path}${name.replace(" ", "-")}`;
     } else {
       return null;
     }
@@ -66,9 +69,10 @@ export default Ember.Controller.extend(BulkTopicSelection, {
 
   categories: Ember.computed.alias("site.categoriesList"),
 
-  createTopicLabel: function() {
-    return this.get("list.draft") ? "topic.open_draft" : "topic.create";
-  }.property("list", "list.draft"),
+  @computed("list", "list.draft")
+  createTopicLabel(list, listDraft) {
+    return listDraft ? "topic.open_draft" : "topic.create";
+  },
 
   @computed("canCreateTopic", "category", "canCreateTopicOnCategory")
   createTopicDisabled(canCreateTopic, category, canCreateTopicOnCategory) {
@@ -85,92 +89,87 @@ export default Ember.Controller.extend(BulkTopicSelection, {
     "q"
   ],
 
-  navItems: function() {
-    return NavItem.buildList(this.get("category"), {
-      tagId: this.get("tag.id"),
-      filterMode: this.get("filterMode")
+  @computed("category", "tag.id", "filterMode")
+  navItems(category, tagId, filterMode) {
+    return NavItem.buildList(category, {
+      tagId,
+      filterMode
     });
-  }.property("category", "tag.id", "filterMode"),
+  },
 
-  showTagFilter: function() {
+  @computed("category")
+  showTagFilter() {
     return Discourse.SiteSettings.show_filter_by_tag;
-  }.property("category"),
+  },
 
-  showAdminControls: function() {
-    return (
-      !this.get("additionalTags") &&
-      this.get("canAdminTag") &&
-      !this.get("category")
-    );
-  }.property("additionalTags", "canAdminTag", "category"),
+  @computed("additionalTags", "canAdminTag", "category")
+  showAdminControls(additionalTags, canAdminTag, category) {
+    return !additionalTags && canAdminTag && !category;
+  },
 
   loadMoreTopics() {
     return this.get("list").loadMore();
   },
 
-  _showFooter: function() {
+  @observes("list.canLoadMore")
+  _showFooter() {
     this.set("application.showFooter", !this.get("list.canLoadMore"));
-  }.observes("list.canLoadMore"),
+  },
 
-  footerMessage: function() {
-    if (this.get("loading") || this.get("list.topics.length") !== 0) {
+  @computed("navMode", "list.topics.length", "loading")
+  footerMessage(navMode, listTopicsLength, loading) {
+    if (loading || listTopicsLength !== 0) {
       return;
     }
 
-    if (this.get("list.topics.length") === 0) {
-      return I18n.t("tagging.topics.none." + this.get("navMode"), {
+    if (listTopicsLength === 0) {
+      return I18n.t(`tagging.topics.none.${navMode}`, {
         tag: this.get("tag.id")
       });
     } else {
-      return I18n.t("tagging.topics.bottom." + this.get("navMode"), {
+      return I18n.t(`tagging.topics.bottom.${navMode}`, {
         tag: this.get("tag.id")
       });
     }
-  }.property("navMode", "list.topics.length", "loading"),
+  },
 
   actions: {
-    changeSort(sortBy) {
-      if (sortBy === this.get("order")) {
+    changeSort(order) {
+      if (order === this.get("order")) {
         this.toggleProperty("ascending");
       } else {
-        this.setProperties({ order: sortBy, ascending: false });
+        this.setProperties({ order, ascending: false });
       }
+
       this.send("invalidateModel");
     },
 
     refresh() {
-      const self = this;
       // TODO: this probably doesn't work anymore
       return this.store
         .findFiltered("topicList", { filter: "tags/" + this.get("tag.id") })
-        .then(function(list) {
-          self.set("list", list);
-          self.resetSelected();
+        .then(list => {
+          this.set("list", list);
+          this.resetSelected();
         });
     },
 
     deleteTag() {
-      const self = this;
       const numTopics =
         this.get("list.topic_list.tags.firstObject.topic_count") || 0;
+
       const confirmText =
         numTopics === 0
           ? I18n.t("tagging.delete_confirm_no_topics")
           : I18n.t("tagging.delete_confirm", { count: numTopics });
-      bootbox.confirm(confirmText, function(result) {
-        if (!result) {
-          return;
-        }
 
-        self
-          .get("tag")
+      bootbox.confirm(confirmText, result => {
+        if (!result) return;
+
+        this.get("tag")
           .destroyRecord()
-          .then(function() {
-            self.transitionToRoute("tags.index");
-          })
-          .catch(function() {
-            bootbox.alert(I18n.t("generic_error"));
-          });
+          .then(() => this.transitionToRoute("tags.index"))
+          .catch(() => bootbox.alert(I18n.t("generic_error")));
       });
     },
 
diff --git a/app/assets/javascripts/discourse/routes/tags-show.js.es6 b/app/assets/javascripts/discourse/routes/tags-show.js.es6
index 73e992a..88ec2a0 100644
--- a/app/assets/javascripts/discourse/routes/tags-show.js.es6
+++ b/app/assets/javascripts/discourse/routes/tags-show.js.es6
@@ -17,10 +17,10 @@ export default Discourse.Route.extend({
   },
 
   model(params) {
-    var tag = this.store.createRecord("tag", {
-        id: Handlebars.Utils.escapeExpression(params.tag_id)
-      }),
-      f = "";
+    const tag = this.store.createRecord("tag", {
+      id: Handlebars.Utils.escapeExpression(params.tag_id)
+    });
+    let f = "";
 
     if (params.additional_tags) {
       this.set(
@@ -38,9 +38,9 @@ export default Discourse.Route.extend({
     if (params.category) {
       f = "c/";
       if (params.parent_category) {
-        f += params.parent_category + "/";
+        f += `${params.parent_category}/`;
       }
-      f += params.category + "/l/";
+      f += `${params.category}/l/`;
     }
     f += this.get("navMode");
     this.set("filterMode", f);
@@ -76,29 +76,29 @@ export default Discourse.Route.extend({
     const categorySlug = this.get("categorySlug");
     const parentCategorySlug = this.get("parentCategorySlug");
     const filter = this.get("navMode");
-    const tag_id = tag ? tag.id.toLowerCase() : "none";
+    const tagId = tag ? tag.id.toLowerCase() : "none";
 
     if (categorySlug) {
-      var category = Discourse.Category.findBySlug(
+      const category = Discourse.Category.findBySlug(
         categorySlug,
         parentCategorySlug
       );
       if (parentCategorySlug) {
-        params.filter = `tags/c/${parentCategorySlug}/${categorySlug}/${tag_id}/l/${filter}`;
+        params.filter = `tags/c/${parentCategorySlug}/${categorySlug}/${tagId}/l/${filter}`;
       } else {
-        params.filter = `tags/c/${categorySlug}/${tag_id}/l/${filter}`;
+        params.filter = `tags/c/${categorySlug}/${tagId}/l/${filter}`;
       }
       if (category) {
         category.setupGroupsAndPermissions();
         this.set("category", category);
       }

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

GitHub sha: 8ff3fc20