瀏覽代碼

Add support for clicking label names and board titles

John R. Supplee 4 年之前
父節點
當前提交
61c691a267
共有 4 個文件被更改,包括 82 次插入11 次删除
  1. 17 4
      client/components/main/globalSearch.jade
  2. 44 6
      client/components/main/globalSearch.js
  3. 20 0
      models/boards.js
  4. 1 1
      models/lists.js

+ 17 - 4
client/components/main/globalSearch.jade

@@ -32,15 +32,28 @@ template(name="globalSearch")
               +resultCard(card)
       else
         .global-search-instructions
-          h2 Label Colors
-          .palette-colors: each label in labelColors
-            span.card-label.palette-color.js-palette-color(class="card-label-{{label.color}}")
-              = label.name
+          h2 Boards
+          .lists-wrapper
+            each title in myBoardNames.get
+              span.card-label.list-title.js-board-title
+                = title
           h2 Lists
           .lists-wrapper
             each title in myLists.get
               span.card-label.list-title.js-list-title
                 = title
+          h2 Label Colors
+          .palette-colors: each label in labelColors
+            span.card-label.palette-color.js-label-color(class="card-label-{{label.color}}")
+              = label.name
+          if myLabelNames.get.length
+            h2 Label Names
+            .lists-wrapper
+              each name in myLabelNames.get
+                span.card-label.list-title.js-label-name
+                  = name
+          +viewer
+            = searchInstructions
 
 template(name="globalSearchViewChangePopup")
   if currentUser

+ 44 - 6
client/components/main/globalSearch.js

@@ -43,6 +43,8 @@ BlazeComponent.extendComponent({
     this.resultsHeading = new ReactiveVar('');
     this.searchLink = new ReactiveVar(null);
     this.myLists = new ReactiveVar([]);
+    this.myLabelNames = new ReactiveVar([]);
+    this.myBoardNames = new ReactiveVar([]);
     this.queryParams = null;
     this.parsingErrors = [];
     this.resultsCount = 0;
@@ -63,6 +65,18 @@ BlazeComponent.extendComponent({
       }
     });
 
+    Meteor.call('myLabelNames', (err, data) => {
+      if (!err) {
+        this.myLabelNames.set(data);
+      }
+    });
+
+    Meteor.call('myBoardNames', (err, data) => {
+      if (!err) {
+        this.myBoardNames.set(data);
+      }
+    });
+
     Meteor.subscribe('setting');
     if (Session.get('globalQuery')) {
       this.searchAllBoards(Session.get('globalQuery'));
@@ -119,11 +133,13 @@ BlazeComponent.extendComponent({
         messages.push({ tag: 'list-title-not-found', value: list });
       });
       this.queryErrors.notFound.labels.forEach(label => {
-        const color = TAPi18n.__(`color-${label}`);
-        if (color) {
+        const color = Object.entries(this.colorMap)
+          .filter(value => value[1] === label)
+          .map(value => value[0]);
+        if (color.length) {
           messages.push({
             tag: 'label-color-not-found',
-            value: color,
+            value: color[0],
           });
         } else {
           messages.push({ tag: 'label-not-found', value: label });
@@ -378,14 +394,36 @@ BlazeComponent.extendComponent({
           evt.preventDefault();
           this.searchAllBoards(evt.target.searchQuery.value);
         },
-        'click .js-palette-color'(evt) {
+        'click .js-label-color'(evt) {
+          evt.preventDefault();
+          this.query.set(
+            `${this.query.get()} ${TAPi18n.__('operator-label')}:"${
+              evt.currentTarget.textContent
+            }"`,
+          );
+        },
+        'click .js-board-title'(evt) {
+          evt.preventDefault();
           this.query.set(
-            `${this.query.get()} label:"${evt.currentTarget.textContent}"`,
+            `${this.query.get()} ${TAPi18n.__('operator-board')}:"${
+              evt.currentTarget.textContent
+            }"`,
           );
         },
         'click .js-list-title'(evt) {
+          evt.preventDefault();
+          this.query.set(
+            `${this.query.get()} ${TAPi18n.__('operator-list')}:"${
+              evt.currentTarget.textContent
+            }"`,
+          );
+        },
+        'click .js-label-name'(evt) {
+          evt.preventDefault();
           this.query.set(
-            `${this.query.get()} list:"${evt.currentTarget.textContent}"`,
+            `${this.query.get()} ${TAPi18n.__('operator-label')}:"${
+              evt.currentTarget.textContent
+            }"`,
           );
         },
       },

+ 20 - 0
models/boards.js

@@ -1324,6 +1324,26 @@ if (Meteor.isServer) {
         },
       });
     },
+    myLabelNames() {
+      let names = [];
+      Boards.userBoards(Meteor.userId()).forEach(board => {
+        names = names.concat(
+          board.labels
+            .filter(label => !!label.name)
+            .map(label => {
+              return label.name;
+            }),
+        );
+      });
+      return _.uniq(names).sort();
+    },
+    myBoardNames() {
+      return _.uniq(
+        Boards.userBoards(Meteor.userId()).map(board => {
+          return board.title;
+        }),
+      ).sort();
+    },
   });
 
   Meteor.methods({

+ 1 - 1
models/lists.js

@@ -374,7 +374,7 @@ Meteor.methods({
         .map(list => {
           return list.title;
         }),
-    );
+    ).sort();
   },
 });