FEATURE: Display PMs in assigned activity and differentiate them. (#27)

approved
#1

FEATURE: Display PMs in assigned activity and differentiate them. (#27)

  • FEATURE: Display PMs in assigned activity and differentiate them.

  • FEATURE: Unassign/Re-assign tasks from the activity view

  • Remove bulkAssign. Reuse assign/unassign with a service. Change PM icon position

  • Reuse ListItemDefaults instead of duplicating code.

  • Conditionally show/hide feature if list items defaults is present in core

diff --git a/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6 b/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6
index 04fa018..ea78d64 100644
--- a/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6
+++ b/assets/javascripts/discourse-assign/connectors/topic-footer-main-buttons-before-create/assign-button.js.es6
@@ -1,5 +1,4 @@
-import showModal from "discourse/lib/show-modal";
-import { ajax } from "discourse/lib/ajax";
+import { getOwner } from "discourse-common/lib/get-owner";
 
 export default {
   shouldRender(args, component) {
@@ -11,22 +10,18 @@ export default {
     );
   },
 
+  setupComponent(args, component) {
+    const taskActions = getOwner(this).lookup("service:task-actions");
+    component.set("taskActions", taskActions);
+  },
+
   actions: {
     unassign() {
       this.set("topic.assigned_to_user", null);
-
-      return ajax("/assign/unassign", {
-        type: "PUT",
-        data: { topic_id: this.get("topic.id") }
-      });
+      this.get("taskActions").unassign(this.get("topic.id"));
     },
     assign() {
-      showModal("assign-user", {
-        model: {
-          topic: this.topic,
-          username: this.topic.get("assigned_to_user.username")
-        }
-      });
+      this.get("taskActions").assign(this.topic);
     }
   }
 };
diff --git a/assets/javascripts/discourse-assign/controllers/assign-user.js.es6 b/assets/javascripts/discourse-assign/controllers/assign-user.js.es6
index 1661570..da6bcae 100644
--- a/assets/javascripts/discourse-assign/controllers/assign-user.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/assign-user.js.es6
@@ -44,7 +44,9 @@ export default Ember.Controller.extend({
         }
       })
         .then(() => {
-          // done
+          if (this.get("model.onSuccess")) {
+            this.get("model.onSuccess")();
+          }
         })
         .catch(popupAjaxError);
     }
diff --git a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
index cd1c8aa..b87b23d 100644
--- a/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/controllers/user-activity-assigned.js.es6
@@ -1,8 +1,10 @@
 import { ajax } from "discourse/lib/ajax";
 import computed from "ember-addons/ember-computed-decorators";
+import UserTopicsList from "discourse/controllers/user-topics-list";
 
-export default Ember.Controller.extend({
+export default UserTopicsList.extend({
   user: Ember.inject.controller(),
+  taskActions: Ember.inject.service(),
 
   @computed("model.topics")
   canUnassignAll(topics) {
@@ -21,10 +23,19 @@ export default Ember.Controller.extend({
             ajax("/assign/unassign-all", {
               type: "PUT",
               data: { user_id: user.get("id") }
-            }).then(() => this.send("unassignedAll"));
+            }).then(() => this.send("changeAssigned"));
           }
         }
       );
+    },
+    unassign(topic) {
+      this.get("taskActions")
+        .unassign(topic.get("id"))
+        .then(() => this.send("changeAssigned"));
+    },
+    reassign(topic) {
+      const controller = this.get("taskActions").assign(topic);
+      controller.set("model.onSuccess", () => this.send("changeAssigned"));
     }
   }
 });
diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6 b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
index 1fddd87..7ad9b70 100644
--- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
+++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js.es6
@@ -8,6 +8,9 @@ import { iconNode } from "discourse-common/lib/icon-library";
 import { h } from "virtual-dom";
 import { iconHTML } from "discourse-common/lib/icon-library";
 
+// TODO: This has to be removed when 2.3 becomes the new stable version.
+import { ListItemDefaults } from "discourse/components/topic-list-item";
+
 const ACTION_ID = "assign";
 
 function modifySelectKit(api) {
@@ -138,9 +141,18 @@ function initialize(api) {
     const assignedTo = topic.get("assigned_to_user.username");
     if (assignedTo) {
       const assignedPath = topic.get("assignedToUserPath");
-      return `<a data-auto-route='true' class='assigned-to discourse-tag simple' href='${assignedPath}'>${iconHTML(
+      let assignLabels = `<a data-auto-route='true' class='assigned-to discourse-tag simple' href='${assignedPath}'>${iconHTML(
         "user-plus"
       )}${assignedTo}</a>`;
+
+      if (
+        ListItemDefaults === undefined &&
+        topic.get("archetype") === "private_message"
+      ) {
+        assignLabels += `<div>${iconHTML("envelope")} Message</div>`;
+      }
+
+      return assignLabels;
     }
   });
 
diff --git a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6 b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
index ef89462..72f43dd 100644
--- a/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
+++ b/assets/javascripts/discourse-assign/routes/user-activity-assigned.js.es6
@@ -1,4 +1,5 @@
 import UserTopicListRoute from "discourse/routes/user-topic-list";
+import { ListItemDefaults } from "discourse/components/topic-list-item";
 
 export default UserTopicListRoute.extend({
   userActionType: 16,
@@ -6,9 +7,10 @@ export default UserTopicListRoute.extend({
 
   model() {
     return this.store.findFiltered("topicList", {
-      filter: "latest",
+      filter: `topics/messages-assigned/${this.modelFor("user").get(
+        "username_lower"
+      )}`,
       params: {
-        assigned: this.modelFor("user").get("username_lower"),
         // core is a bit odd here and is not sending an array, should be fixed
         exclude_category_ids: [-1]
       }
@@ -16,8 +18,12 @@ export default UserTopicListRoute.extend({
   },
 
   renderTemplate() {
+    // TODO: This has to be removed when 2.3 becomes the new stable version.
+    const template = ListItemDefaults
+      ? "user-assigned-topics"
+      : "user-topics-list";
     this.render("user-activity-assigned");
-    this.render("user-topics-list", { into: "user-activity-assigned" });
+    this.render(template, { into: "user-activity-assigned" });
   },
 
   setupController(controller, model) {
@@ -26,7 +32,7 @@ export default UserTopicListRoute.extend({
   },
 
   actions: {
-    unassignedAll() {
+    changeAssigned() {
       this.refresh();
     }
   }
diff --git a/assets/javascripts/discourse/components/assign-actions-dropdown.js.es6 b/assets/javascripts/discourse/components/assign-actions-dropdown.js.es6
new file mode 100644
index 0000000..88ed3e4
--- /dev/null
+++ b/assets/javascripts/discourse/components/assign-actions-dropdown.js.es6
@@ -0,0 +1,39 @@
+import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
+
+export default DropdownSelectBoxComponent.extend({
+  classNames: ["assign-actions-dropdown"],
+  headerIcon: null,
+  title: "...",
+  allowInitialValueMutation: false,
+  showFullTitle: true,
+
+  computeContent() {
+    return [
+      {
+        id: "unassign",
+        icon: "user-times",
+        name: I18n.t("discourse_assign.unassign.title"),
+        description: I18n.t("discourse_assign.unassign.help")
+      },
+      {
+        id: "reassign",
+        icon: "users",
+        name: I18n.t("discourse_assign.reassign.title"),
+        description: I18n.t("discourse_assign.reassign.help")
+      }
+    ];
+  },
+
+  actions: {
+    onSelect(id) {
+      switch (id) {
+        case "unassign":
+          this.unassign(this.get("topic"), this.get("user"));
+          break;
+        case "reassign":
+          this.reassign(this.get("topic"), this.get("user"));
+          break;
+      }
+    }
+  }
+});

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

GitHub sha: e3b2e5bd

#2

I think we should add some basic client side acceptance test here.

1 Like
Follow Up #3
#5

Follow up commit here:

It was really hard to do a full interaction so I ended doing a simple smoke test. We have tested the unassign/re-assign behavior at the controller level so we should be fine.

4 Likes
Approved #6