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

Merge pull request #4884 from helioguardabaxo/master

Added 'next week' due date filter
Lauri Ojansivu 2 жил өмнө
parent
commit
9aeb5b4f05

+ 8 - 3
client/components/sidebar/sidebarFilters.jade

@@ -109,13 +109,18 @@ template(name="filterSidebar")
           | {{_ 'filter-due-tomorrow' }}
         if Filter.dueAt.isSelected 'tomorrow'
           i.fa.fa-check
-    li(class="{{#if Filter.dueAt.isSelected 'week'}}active{{/if}}")
+    li(class="{{#if Filter.dueAt.isSelected 'thisweek'}}active{{/if}}")
       a.name.js-toggle-due-this-week-filter
         span.sidebar-list-item-description
           | {{_ 'filter-due-this-week' }}
-        if Filter.dueAt.isSelected 'week'
+        if Filter.dueAt.isSelected 'thisweek'
+          i.fa.fa-check
+    li(class="{{#if Filter.dueAt.isSelected 'nextweek'}}active{{/if}}")
+      a.name.js-toggle-due-next-week-filter
+        span.sidebar-list-item-description
+          | {{_ 'filter-due-next-week' }}
+        if Filter.dueAt.isSelected 'nextweek'
           i.fa.fa-check
-
   hr
   h3
     i.fa.fa-list-alt

+ 5 - 0
client/components/sidebar/sidebarFilters.js

@@ -53,6 +53,11 @@ BlazeComponent.extendComponent({
           Filter.dueAt.thisWeek();
           Filter.resetExceptions();
         },
+        'click .js-toggle-due-next-week-filter'(evt) {
+          evt.preventDefault();
+          Filter.dueAt.nextWeek();
+          Filter.resetExceptions();
+        },
         'click .js-toggle-archive-filter'(evt) {
           evt.preventDefault();
           Filter.archive.toggle(this.currentData()._id);

+ 43 - 17
client/lib/filter.js

@@ -55,7 +55,12 @@ class DateFilter {
 
   // thisWeek is a convenience method for calling relativeWeek with 1
   thisWeek() {
-    this.relativeWeek(1);
+    this.relativeWeek(1, 'this')
+  }
+
+  // nextWeek is a convenience method for calling relativeWeek with 1
+  nextWeek() {
+    this.relativeWeek(1, 'next')
   }
 
   // relativeDay builds a filter starting from now and including all
@@ -83,11 +88,17 @@ class DateFilter {
     this._updateState('day');
   }
 
-  // relativeWeek builds a filter starting from today and including all
+  // relativeWeek builds a filter starting from today (for this week)
+  // or 7 days after (for next week) and including all
   // weeks up to today +/- offset. This considers the user's preferred
   // start of week day (as defined by Meteor).
-  relativeWeek(offset) {
-    if (this._filterState == 'week') {
+  relativeWeek(offset, week) {
+    if (this._filterState == 'thisweek') {
+      this.reset();
+      return;
+    }
+
+    if (this._filterState == 'nextweek') {
       this.reset();
       return;
     }
@@ -99,25 +110,40 @@ class DateFilter {
     const currentUser = Meteor.user();
     const weekStartDay = currentUser ? currentUser.getStartDayOfWeek() : 1;
 
-    // Moments are mutable so they must be cloned before modification
-    var thisWeekStart = moment()
-      .startOf('day')
-      .startOf('week')
-      .add(weekStartDay, 'days');
-    var thisWeekEnd = thisWeekStart
-      .clone()
-      .add(offset, 'week')
-      .endOf('day');
-    var startDate = thisWeekStart.toDate();
-    var endDate = thisWeekEnd.toDate();
+    if (week === 'this') {
+      // Moments are mutable so they must be cloned before modification
+      var WeekStart = moment()
+        .startOf('day')
+        .startOf('week')
+        .add(weekStartDay, 'days');
+      var WeekEnd = WeekStart
+        .clone()
+        .add(offset, 'week')
+        .endOf('day');
+
+      this._updateState('thisweek');
+    } else if (week === 'next') {
+      // Moments are mutable so they must be cloned before modification
+      var WeekStart = moment()
+        .startOf('day')
+        .startOf('week')
+        .add(weekStartDay + 7, 'days');
+      var WeekEnd = WeekStart
+        .clone()
+        .add(offset, 'week')
+        .endOf('day');
+
+     this._updateState('nextweek');
+    }
+
+    var startDate = WeekStart.toDate();
+    var endDate = WeekEnd.toDate();
 
     if (offset >= 0) {
       this._filter = { $gte: startDate, $lte: endDate };
     } else {
       this._filter = { $lte: startDate, $gte: endDate };
     }
-
-    this._updateState('week');
   }
 
   // noDate builds a filter for items where date is not set

+ 1 - 0
imports/i18n/data/en.i18n.json

@@ -404,6 +404,7 @@
   "filter-overdue": "Overdue",
   "filter-due-today": "Due today",
   "filter-due-this-week": "Due this week",
+  "filter-due-next-week": "Due next week",
   "filter-due-tomorrow": "Due tomorrow",
   "list-filter-label": "Filter List by Title",
   "filter-clear": "Clear filter",