FEATURE: Add custom theme for code review categories (#26)

FEATURE: Add custom theme for code review categories (#26)

diff --git a/assets/javascripts/discourse/components/review-topic-list-item.js.es6 b/assets/javascripts/discourse/components/review-topic-list-item.js.es6
new file mode 100644
index 0000000..31ca665
--- /dev/null
+++ b/assets/javascripts/discourse/components/review-topic-list-item.js.es6
@@ -0,0 +1,13 @@
+import { findRawTemplate } from "discourse-common/lib/raw-templates";
+import { observes } from "discourse-common/utils/decorators";
+import TopicListItem from "discourse/components/topic-list-item";
+
+export default TopicListItem.extend({
+  @observes("topic.pinned")
+  renderTopicListItem() {
+    const template = findRawTemplate("list/review-topic-list-item");
+    if (template) {
+      this.set("topicListItemContents", template(this).htmlSafe());
+    }
+  }
+});
diff --git a/assets/javascripts/discourse/initializers/theme.js.es6 b/assets/javascripts/discourse/initializers/theme.js.es6
new file mode 100644
index 0000000..2fa5cd2
--- /dev/null
+++ b/assets/javascripts/discourse/initializers/theme.js.es6
@@ -0,0 +1,61 @@
+import discourseComputed from "discourse-common/utils/decorators";
+import TopicListComponent from "discourse/components/topic-list";
+import { withPluginApi } from "discourse/lib/plugin-api";
+
+export default {
+  name: "discourse-code-review-theme",
+
+  initialize(container) {
+    const siteSettings = container.lookup("site-settings:main");
+    if (!siteSettings.code_review_theme) {
+      return;
+    }
+
+    withPluginApi("0.8.28", () => {
+      TopicListComponent.reopen({
+        @discourseComputed("filteredTopics.[]")
+        filteredTopicsByDate(filteredTopics) {
+          if (
+            !this.category ||
+            !this.category.custom_fields["GitHub Repo Name"]
+          ) {
+            return;
+          }
+
+          const topicsByDate = {};
+          filteredTopics.forEach(topic => {
+            topic.setProperties({
+              approved: topic.tags.includes(
+                this.siteSettings.code_review_approved_tag
+              ),
+              followup: topic.tags.includes(
+                this.siteSettings.code_review_followup_tag
+              ),
+              pending: topic.tags.includes(
+                this.siteSettings.code_review_pending_tag
+              )
+            });
+
+            const date = moment(topic.created_at).format("YYYY-MM-DD");
+            if (!topicsByDate[date]) {
+              topicsByDate[date] = [];
+            }
+            topicsByDate[date].push(topic);
+          });
+
+          const filteredTopicsByDate = [];
+          Object.keys(topicsByDate)
+            .sort()
+            .reverse()
+            .forEach(date => {
+              filteredTopicsByDate.push({
+                date: moment(date).format("MMMM D, YYYY"),
+                topics: topicsByDate[date]
+              });
+            });
+          return filteredTopicsByDate;
+        }
+      });
+    });
+  }
+};
diff --git a/assets/javascripts/discourse/templates/components/review-topic-list-item.hbs b/assets/javascripts/discourse/templates/components/review-topic-list-item.hbs
new file mode 100644
index 0000000..556c017
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/review-topic-list-item.hbs
@@ -0,0 +1 @@
+{{topicListItemContents}}
diff --git a/assets/javascripts/discourse/templates/components/topic-list.hbs b/assets/javascripts/discourse/templates/components/topic-list.hbs
new file mode 100644
index 0000000..73e0321
--- /dev/null
+++ b/assets/javascripts/discourse/templates/components/topic-list.hbs
@@ -0,0 +1,101 @@
+{{#if filteredTopicsByDate}}
+  {{#each filteredTopicsByDate as |topicsByDate|}}
+    {{#unless skipHeader}}
+      <thead class="code-review">
+        {{raw "review-topic-list-header"
+          topicsDate=topicsByDate.date
+          canBulkSelect=canBulkSelect
+          toggleInTitle=toggleInTitle
+          hideCategory=hideCategory
+          showPosters=showPosters
+          showLikes=showLikes
+          showOpLikes=showOpLikes
+          order=order
+          ascending=ascending
+          sortable=sortable
+          listTitle=listTitle
+          bulkSelectEnabled=bulkSelectEnabled}}
+      </thead>
+    {{/unless}}
+
+    {{plugin-outlet
+      name="before-topic-list-body"
+      args=(hash
+        topics=topics
+        selected=selected
+        bulkSelectEnabled=bulkSelectEnabled
+        lastVisitedTopic=lastVisitedTopic
+        discoveryList=discoveryList
+        hideCategory=hideCategory)
+      tagName=""
+      connectorTagName=""}}
+
+    <tbody class="code-review">
+      {{#each topicsByDate.topics as |topic|}}
+        {{review-topic-list-item topic=topic
+                                bulkSelectEnabled=bulkSelectEnabled
+                                showTopicPostBadges=showTopicPostBadges
+                                hideCategory=hideCategory
+                                showPosters=showPosters
+                                showLikes=showLikes
+                                showOpLikes=showOpLikes
+                                expandGloballyPinned=expandGloballyPinned
+                                expandAllPinned=expandAllPinned
+                                lastVisitedTopic=lastVisitedTopic
+                                selected=selected
+                                tagsForUser=tagsForUser}}
+        {{raw "list/visited-line" lastVisitedTopic=lastVisitedTopic topic=topic}}
+      {{/each}}
+    </tbody>
+  {{/each}}
+{{else}}
+
+{{! original app/templates/components/topic-list.hbs }}
+{{#unless skipHeader}}
+  <thead>
+    {{raw "topic-list-header"
+      canBulkSelect=canBulkSelect
+      toggleInTitle=toggleInTitle
+      hideCategory=hideCategory
+      showPosters=showPosters
+      showLikes=showLikes
+      showOpLikes=showOpLikes
+      order=order
+      ascending=ascending
+      sortable=sortable
+      listTitle=listTitle
+      bulkSelectEnabled=bulkSelectEnabled}}
+  </thead>
+{{/unless}}
+
+{{plugin-outlet
+  name="before-topic-list-body"
+  args=(hash
+    topics=topics
+    selected=selected
+    bulkSelectEnabled=bulkSelectEnabled
+    lastVisitedTopic=lastVisitedTopic
+    discoveryList=discoveryList
+    hideCategory=hideCategory)
+  tagName=""
+  connectorTagName=""}}
+
+<tbody>
+  {{#each filteredTopics as |topic|}}
+    {{topic-list-item topic=topic
+                      bulkSelectEnabled=bulkSelectEnabled
+                      showTopicPostBadges=showTopicPostBadges
+                      hideCategory=hideCategory
+                      showPosters=showPosters
+                      showLikes=showLikes
+                      showOpLikes=showOpLikes
+                      expandGloballyPinned=expandGloballyPinned
+                      expandAllPinned=expandAllPinned
+                      lastVisitedTopic=lastVisitedTopic
+                      selected=selected
+                      tagsForUser=tagsForUser}}
+    {{raw "list/visited-line" lastVisitedTopic=lastVisitedTopic topic=topic}}
+  {{/each}}
+</tbody>
+
+{{/if}}
\ No newline at end of file
diff --git a/assets/javascripts/discourse/templates/list/review-topic-list-item.hbr b/assets/javascripts/discourse/templates/list/review-topic-list-item.hbr
new file mode 100644
index 0000000..f91f248
--- /dev/null
+++ b/assets/javascripts/discourse/templates/list/review-topic-list-item.hbr
@@ -0,0 +1,83 @@
+{{~raw-plugin-outlet name="topic-list-before-columns"}}
+
+{{#if bulkSelectEnabled}}
+  <td class="bulk-select">
+    <input type="checkbox" class="bulk-select">
+  </td>
+{{/if}}
+
+{{!--
+  The `~` syntax strip spaces between the elements, making it produce
+  `<a class=topic-post-badges>Some text</a><span class=topic-post-badges>`,
+  with no space between them.
+  This causes the topic-post-badge to be considered the same word as "text"
+  at the end of the link, preventing it from line wrapping onto its own line.
+--}}
+<td class='main-link clearfix' colspan="1">

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

GitHub sha: 5a88bc29

2 Likes

This commit appears in #26 which was approved by danielwaterworth. It was merged by nbianca.