Browse Source

Merge branch 'ednamaeG-sort-feature'

Lauri Ojansivu 4 năm trước cách đây
mục cha
commit
a195b52d34

+ 19 - 0
client/components/boards/boardHeader.jade

@@ -31,6 +31,9 @@ template(name="boardHeaderBar")
             if $eq watchLevel "muted"
               i.fa.fa-bell-slash
             span {{_ watchLevel}}
+          a.board-header-btn.js-sort-cards(title="{{_ 'sort-cards'}}")
+            i.fa.fa-sort
+            | {{_ 'sort-cards'}} {{sortCardsBy.get}}
 
         else
           a.board-header-btn.js-log-in(
@@ -247,3 +250,19 @@ template(name="boardChangeTitlePopup")
 template(name="boardCreateRulePopup")
   p {{_ 'close-board-pop'}}
   button.js-confirm.negate.full(type="submit") {{_ 'archive'}}
+
+
+template(name="cardsSortPopup")
+  ul.pop-over-list
+    li
+      a.js-sort-due {{_ 'due-date'}}
+      hr
+    li
+      a.js-sort-title {{_ 'title-alphabetically'}}
+      hr
+    li
+      a.js-sort-created-desc {{_ 'created-at-newest-first'}}
+      hr
+    li
+      a.js-sort-created-asc {{_ 'created-at-oldest-first'}}
+

+ 51 - 0
client/components/boards/boardHeader.js

@@ -2,6 +2,7 @@
 const DOWNCLS = 'fa-sort-down';
 const UPCLS = 'fa-sort-up';
 */
+const sortCardsBy = new ReactiveVar('');
 Template.boardMenuPopup.events({
   'click .js-rename-board': Popup.open('boardChangeTitle'),
   'click .js-custom-fields'() {
@@ -110,6 +111,7 @@ BlazeComponent.extendComponent({
         'click .js-open-filter-view'() {
           Sidebar.setView('filter');
         },
+        'click .js-sort-cards': Popup.open('cardsSort'),
         /*
         'click .js-open-sort-view'(evt) {
           const target = evt.target;
@@ -368,3 +370,52 @@ BlazeComponent.extendComponent({
   },
 }).register('listsortPopup');
 */
+
+BlazeComponent.extendComponent({
+  events() {
+    return [
+      {
+        'click .js-sort-due'() {
+          const sortBy = {
+            dueAt: 1,
+          };
+          Session.set('sortBy', sortBy);
+          sortCardsBy.set(TAPi18n.__('due-date'));
+          Popup.close();
+        },
+        'click .js-sort-title'() {
+          const sortBy = {
+            title: 1,
+          };
+          Session.set('sortBy', sortBy);
+          sortCardsBy.set(TAPi18n.__('title'));
+          Popup.close();
+        },
+        'click .js-sort-created-asc'() {
+          const sortBy = {
+            createdAt: 1,
+          };
+          Session.set('sortBy', sortBy);
+          sortCardsBy.set(TAPi18n.__('date-created-newest-first'));
+          Popup.close();
+        },
+        'click .js-sort-created-desc'() {
+          const sortBy = {
+            createdAt: -1,
+          };
+          Session.set('sortBy', sortBy);
+          sortCardsBy.set(TAPi18n.__('date-created-oldest-first'));
+          Popup.close();
+        },
+        'click .js-sort-default'() {
+          const sortBy = {
+            sort: 1,
+          };
+          Session.set('sortBy', sortBy);
+          sortCardsBy.set(TAPi18n.__('default'));
+          Popup.close();
+        },
+      },
+    ];
+  },
+}).register('cardsSortPopup');

+ 4 - 1
client/components/lists/listBody.js

@@ -168,13 +168,16 @@ BlazeComponent.extendComponent({
 
   cardsWithLimit(swimlaneId) {
     const limit = this.cardlimit.get();
+    const defaultSort = { sort: 1 };
+    const sortBy = Session.get('sortBy') ? Session.get('sortBy') : defaultSort;
     const selector = {
       listId: this.currentData()._id,
       archived: false,
     };
     if (swimlaneId) selector.swimlaneId = swimlaneId;
     return Cards.find(Filter.mongoSelector(selector), {
-      sort: ['sort'],
+      // sort: ['sort'],
+      sort: sortBy,
       limit,
     });
   },

+ 7 - 1
i18n/en.i18n.json

@@ -964,5 +964,11 @@
   "number": "Number",
   "label-colors": "Label Colors",
   "label-names": "Label Names",
-  "archived-at": "archived at"
+  "archived-at": "archived at",
+  "sort-cards": "Sort Cards",
+  "cardsSortPopup-title": "Sort Cards",
+  "due-date": "Due Date",
+  "title-alphabetically": "Title (Alphabetically)",
+  "created-at-newest-first": "Created At (Newest First)",
+  "created-at-oldest-first": "Created At (Oldest First)"
 }