2
0
Эх сурвалжийг харах

Global search development

* Add translation tags
* Use translation tags for showing result count
* Add logic for selecting cards by labels
* Readd code for searching card text that was mistakenly deleted
John R. Supplee 4 жил өмнө
parent
commit
25dc779a73

+ 6 - 2
client/components/main/globalSearch.jade

@@ -17,8 +17,12 @@ template(name="globalSearch")
     else if hasResults.get
     else if hasResults.get
       .global-search-dueat-list-wrapper
       .global-search-dueat-list-wrapper
         h1
         h1
-          = resultsCount.get
-          | Results
+          if $eq resultCount.get 0
+            | {{_ 'no-results' }}
+          else if $eq resultCount.get 1
+            | {{_ 'one-result' }}
+          else
+            | {{_ 'n-results' resultsCount.get }}
         if queryErrors.get
         if queryErrors.get
           div
           div
             each msg in errorMessages
             each msg in errorMessages

+ 1 - 1
client/components/main/globalSearch.js

@@ -104,7 +104,7 @@ BlazeComponent.extendComponent({
           const reLabel = /^#(?<label>[\w:-]+)(\s+|$)/;
           const reLabel = /^#(?<label>[\w:-]+)(\s+|$)/;
           const reOperator1 = /^(?<operator>\w+):(?<value>\w+)(\s+|$)/;
           const reOperator1 = /^(?<operator>\w+):(?<value>\w+)(\s+|$)/;
           const reOperator2 = /^(?<operator>\w+):(?<quote>["']*)(?<value>.*?)\k<quote>(\s+|$)/;
           const reOperator2 = /^(?<operator>\w+):(?<quote>["']*)(?<value>.*?)\k<quote>(\s+|$)/;
-          const reText = /^(?<text>[^:@#\s]+)(\s+|$)/;
+          const reText = /^(?<text>\S+)(\s+|$)/;
           const reQuotedText = /^(?<quote>["'])(?<text>\w+)\k<quote>(\s+|$)/;
           const reQuotedText = /^(?<quote>["'])(?<text>\w+)\k<quote>(\s+|$)/;
           const operatorMap = {
           const operatorMap = {
             board: 'boards',
             board: 'boards',

+ 4 - 1
i18n/en.i18n.json

@@ -868,5 +868,8 @@
   "board-title-not-found": "Board '%s' not found.",
   "board-title-not-found": "Board '%s' not found.",
   "swimlane-title-not-found": "Swimlane '%s' not found.",
   "swimlane-title-not-found": "Swimlane '%s' not found.",
   "list-title-not-found": "List '%s' not found.",
   "list-title-not-found": "List '%s' not found.",
-  "user-username-not-found": "Username '%s' not found."
+  "user-username-not-found": "Username '%s' not found.",
+  "globalSearch-title": "Search All Boards",
+  "one-results": "One Result",
+  "n-results": "%s Results"
 }
 }

+ 8 - 5
models/boards.js

@@ -1208,18 +1208,21 @@ function boardRemover(userId, doc) {
   );
   );
 }
 }
 
 
-Boards.userSearch = (userId, includeArchived = false, selector = {}) => {
+Boards.userSearch = (
+  userId,
+  selector = {},
+  projection = {},
+  includeArchived = false,
+) => {
   if (!includeArchived) {
   if (!includeArchived) {
-    selector = {
-      archived: false,
-    };
+    selector.archived = false;
   }
   }
   selector.$or = [
   selector.$or = [
     { permission: 'public' },
     { permission: 'public' },
     { members: { $elemMatch: { userId, isActive: true } } },
     { members: { $elemMatch: { userId, isActive: true } } },
   ];
   ];
 
 
-  return Boards.find(selector);
+  return Boards.find(selector, projection);
 };
 };
 
 
 Boards.userBoards = (userId, includeArchived = false, selector = {}) => {
 Boards.userBoards = (userId, includeArchived = false, selector = {}) => {

+ 58 - 0
models/cards.js

@@ -1827,6 +1827,63 @@ Cards.globalSearch = queryParams => {
     ];
     ];
   }
   }
 
 
+  if (queryParams.labels.length) {
+    queryParams.labels.forEach(label => {
+      const queryLabels = [];
+
+      let boards = Boards.userSearch(userId, {
+        labels: { $elemMatch: { color: label.toLowerCase() } },
+      });
+
+      if (boards.count()) {
+        boards.forEach(board => {
+          // eslint-disable-next-line no-console
+          console.log('board:', board);
+          // eslint-disable-next-line no-console
+          console.log('board.labels:', board.labels);
+          board.labels
+            .filter(boardLabel => {
+              return boardLabel.color === label.toLowerCase();
+            })
+            .forEach(boardLabel => {
+              queryLabels.push(boardLabel._id);
+            });
+        });
+      } else {
+        const reLabel = new RegExp(label, 'i');
+        boards = Boards.userSearch(userId, {
+          labels: { $elemMatch: { name: reLabel } },
+        });
+
+        if (boards.count()) {
+          boards.forEach(board => {
+            board.labels
+              .filter(boardLabel => {
+                return boardLabel.name.match(reLabel);
+              })
+              .forEach(boardLabel => {
+                queryLabels.push(boardLabel._id);
+              });
+          });
+        } else {
+          errors.notFound.labels.push({ tag: 'label', value: label });
+        }
+      }
+
+      selector.labelIds = { $in: queryLabels };
+    });
+  }
+
+  if (queryParams.text) {
+    const regex = new RegExp(queryParams.text, 'i');
+
+    selector.$or = [
+      { title: regex },
+      { description: regex },
+      { customFields: { $elemMatch: { value: regex } } },
+    ];
+  }
+
   // eslint-disable-next-line no-console
   // eslint-disable-next-line no-console
   console.log('selector:', selector);
   console.log('selector:', selector);
   const cards = Cards.find(selector, {
   const cards = Cards.find(selector, {
@@ -1843,6 +1900,7 @@ Cards.globalSearch = queryParams => {
       assignees: 1,
       assignees: 1,
       colors: 1,
       colors: 1,
       dueAt: 1,
       dueAt: 1,
+      labelIds: 1,
     },
     },
     limit: 50,
     limit: 50,
   });
   });