FEATURE: Assignments summary tab for groups (#70)

FEATURE: Assignments summary tab for groups (#70)

diff --git a/assets/javascripts/discourse-assign/assigned-group-route-map.js.es6 b/assets/javascripts/discourse-assign/assigned-group-route-map.js.es6
new file mode 100644
index 0000000..7080da8
--- /dev/null
+++ b/assets/javascripts/discourse-assign/assigned-group-route-map.js.es6
@@ -0,0 +1,8 @@
+export default {
+  resource: "group",
+  map() {
+    this.route("assignments", function() {
+      this.route("show", { path: "/:filter" });
+    });
+  }
+};
diff --git a/assets/javascripts/discourse-assign/connectors/group-reports-nav-item/assigned-topic-list.hbs b/assets/javascripts/discourse-assign/connectors/group-reports-nav-item/assigned-topic-list.hbs
new file mode 100644
index 0000000..bdae640
--- /dev/null
+++ b/assets/javascripts/discourse-assign/connectors/group-reports-nav-item/assigned-topic-list.hbs
@@ -0,0 +1 @@
+{{group-assignments-menu-item group = group}}
\ No newline at end of file
diff --git a/assets/javascripts/discourse-assign/controllers/group-assignments-show.js.es6 b/assets/javascripts/discourse-assign/controllers/group-assignments-show.js.es6
new file mode 100644
index 0000000..7ca8c5f
--- /dev/null
+++ b/assets/javascripts/discourse-assign/controllers/group-assignments-show.js.es6
@@ -0,0 +1,18 @@
+import UserTopicsList from "discourse/controllers/user-topics-list";
+
+export default UserTopicsList.extend({
+  user: Ember.inject.controller(),
+  taskActions: Ember.inject.service(),
+
+  actions: {
+    unassign(topic) {
+      this.taskActions
+        .unassign(topic.get("id"))
+        .then(() => this.send("changeAssigned"));
+    },
+    reassign(topic) {
+      const controller = this.taskActions.assign(topic);
+      controller.set("model.onSuccess", () => this.send("changeAssigned"));
+    }
+  }
+});
diff --git a/assets/javascripts/discourse-assign/controllers/group-assignments.js.es6 b/assets/javascripts/discourse-assign/controllers/group-assignments.js.es6
new file mode 100644
index 0000000..a328734
--- /dev/null
+++ b/assets/javascripts/discourse-assign/controllers/group-assignments.js.es6
@@ -0,0 +1,34 @@
+import Controller, { inject as controller } from "@ember/controller";
+
+export default Controller.extend({
+  application: controller(),
+  loading: false,
+
+  findMembers(refresh) {
+    if (this.loading || !this.model) {
+      return;
+    }
+
+    if (!refresh && this.model.members.length >= this.model.user_count) {
+      this.set("application.showFooter", true);
+      return;
+    }
+
+    this.set("loading", true);
+    this.model
+      .findMembers({ order: "", asc: true, filter: null }, refresh)
+      .finally(() => {
+        this.setProperties({
+          "application.showFooter":
+            this.model.members.length >= this.model.user_count,
+          loading: false
+        });
+      });
+  },
+
+  actions: {
+    loadMore: function() {
+      this.findMembers();
+    }
+  }
+});
diff --git a/assets/javascripts/discourse-assign/routes/group-assignments-show.js.es6 b/assets/javascripts/discourse-assign/routes/group-assignments-show.js.es6
new file mode 100644
index 0000000..c1d8f1e
--- /dev/null
+++ b/assets/javascripts/discourse-assign/routes/group-assignments-show.js.es6
@@ -0,0 +1,27 @@
+import DiscourseRoute from "discourse/routes/discourse";
+
+export default DiscourseRoute.extend({
+  model(params) {
+    let filter = null;
+    if (params.filter !== "everyone") {
+      filter = `topics/messages-assigned/${params.filter}`;
+    } else {
+      filter = `topics/group-topics-assigned/${this.modelFor("group").get(
+        "name"
+      )}`;
+    }
+    return this.store.findFiltered("topicList", {
+      filter: filter
+    });
+  },
+
+  renderTemplate() {
+    this.render("group-topics-list");
+  },
+
+  actions: {
+    changeAssigned() {
+      this.refresh();
+    }
+  }
+});
diff --git a/assets/javascripts/discourse-assign/routes/group-assignments.js.es6 b/assets/javascripts/discourse-assign/routes/group-assignments.js.es6
new file mode 100644
index 0000000..c70a634
--- /dev/null
+++ b/assets/javascripts/discourse-assign/routes/group-assignments.js.es6
@@ -0,0 +1,24 @@
+import Route from "@ember/routing/route";
+
+export default Route.extend({
+  model() {
+    return this.modelFor("group");
+  },
+
+  setupController(controller, model) {
+    controller.setProperties({
+      model,
+      showing: "members"
+    });
+
+    controller.findMembers(true);
+  },
+
+  redirect(model, transition) {
+    if (transition.to.params.hasOwnProperty("filter")) {
+      this.transitionTo("group.assignments.show", transition.to.params.filter);
+    } else {
+      this.transitionTo("group.assignments.show", "everyone");
+    }
+  }
+});
diff --git a/assets/javascripts/discourse/components/group-assignments-filter.js.es6 b/assets/javascripts/discourse/components/group-assignments-filter.js.es6
new file mode 100644
index 0000000..e0188e1
--- /dev/null
+++ b/assets/javascripts/discourse/components/group-assignments-filter.js.es6
@@ -0,0 +1,5 @@
+import Component from "@ember/component";
+
+export default Component.extend({
+  tagName: "li"
+});
diff --git a/assets/javascripts/discourse/components/group-assignments-menu-item.js.es6 b/assets/javascripts/discourse/components/group-assignments-menu-item.js.es6
new file mode 100644
index 0000000..0c46d45
--- /dev/null
+++ b/assets/javascripts/discourse/components/group-assignments-menu-item.js.es6
@@ -0,0 +1,8 @@
+export default Ember.Component.extend({
+  canAssign: false,
+
+  init() {
+    this._super(...arguments);
+    this.set("canAssign", this.currentUser.can_assign);
+  }
+});
diff --git a/assets/javascripts/discourse/templates/components/group-assignments-filter.hbs b/assets/javascripts/discourse/templates/components/group-assignments-filter.hbs
new file mode 100644
index 0000000..fb1e704
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/group-assignments-filter.hbs
@@ -0,0 +1,9 @@
+{{#if show-avatar}}
+  {{#link-to "group.assignments.show" filter.username_lower}}
+    {{avatar filter avatarTemplatePath="avatar_template" usernamePath="username" imageSize="small"}} {{filter.username}}
+  {{/link-to}}
+{{else}}
+  {{#link-to "group.assignments.show" filter}}
+    {{i18n 'discourse_assign.group_everyone'}}
+  {{/link-to}}
+{{/if}}
diff --git a/assets/javascripts/discourse/templates/components/group-assignments-menu-item.hbs b/assets/javascripts/discourse/templates/components/group-assignments-menu-item.hbs
new file mode 100644
index 0000000..0d1b27e
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/group-assignments-menu-item.hbs
@@ -0,0 +1,9 @@
+{{#if canAssign}}
+  <ul class ='nav-pills'>
+    <li>
+      {{#link-to 'group.assignments' group}}
+        {{d-icon "user-plus" class="glyph"}}{{i18n 'discourse_assign.group_assignments'}}{{concat ' (' group.assignment_count concat ')'}}
+      {{/link-to}}
+    </li>
+  </ul>
+{{/if}}
diff --git a/assets/javascripts/discourse/templates/group-topics-list.hbs b/assets/javascripts/discourse/templates/group-topics-list.hbs
new file mode 100644
index 0000000..8d177d2
--- /dev/null
+++ b/assets/javascripts/discourse/templates/group-topics-list.hbs
@@ -0,0 +1,18 @@
+{{#load-more class="paginated-topics-list" selector=".paginated-topics-list .topic-list tr" action=(action "loadMore")}}
+  {{basic-assigned-topic-list topicList=model
+                              hideCategory=hideCategory
+                              showPosters=showPosters
+                              bulkSelectEnabled=bulkSelectEnabled
+                              selected=selected
+                              hasIncoming=hasIncoming
+                              incomingCount=incomingCount
+                              showInserted=(action "showInserted")
+                              tagsForUser=tagsForUser
+                              unassign=(action 'unassign')
+                              reassign=(action 'reassign')}}
+

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

GitHub sha: ae83f70e

1 Like

This commit appears in #70 which was merged by davidtaylorhq.

This should use @action

@action also please

{ filter }

do we net .get here ?

do we want to transition to this if filter is null or undefined?

Should we put most of this (not the icon) into a locale with count ?