Skip to content

Commit 786d210

Browse files
committed
Persist chosen filters via cookies
As with the current date and view configuration, we should also persist the chosen filters for 7 days via the config cookie. This will work on the company and allocations calendars.
1 parent 5104b95 commit 786d210

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

app/assets/javascripts/modules/calendar.es6

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ class Calendar extends TapBase {
128128
this.config.cookieName,
129129
JSON.stringify({
130130
defaultView: view.name,
131-
defaultDate: view.calendar.getDate()
131+
defaultDate: view.calendar.getDate(),
132+
filterList: this.config.filterList
132133
}),
133134
{
134135
days: 7

app/assets/javascripts/modules/calendars/company.es6

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ class CompanyCalendar extends Calendar {
5959

6060
super.start(el);
6161

62+
this.config.filterList = this.config.filterList || [];
6263
this.isFullscreen = false;
6364
this.hideCancelledAppointments = false;
64-
this.filterList = [];
6565
this.$filterButton = $('.fc-filter-button');
6666
this.filterButtonLabel = this.$filterButton.text();
6767
this.$filterPanel = $('.resource-calendar-filter');
@@ -94,7 +94,7 @@ class CompanyCalendar extends Calendar {
9494
}
9595

9696
filterResources(resource) {
97-
return $.inArray(resource.id, this.filterList) > -1;
97+
return $.inArray(resource.id, this.config.filterList) > -1;
9898
}
9999

100100
bindEvents() {
@@ -104,6 +104,10 @@ class CompanyCalendar extends Calendar {
104104
this.$hideCancelledToggle.on('change', this.handleHideCancelledToggle.bind(this));
105105

106106
$(document).click(this.hideFilterPanel.bind(this));
107+
108+
if (this.config.filterList.length) {
109+
this.refreshFilterButtonLabel();
110+
}
107111
}
108112

109113
handleBookingSlotToggle(event) {
@@ -119,7 +123,7 @@ class CompanyCalendar extends Calendar {
119123
}
120124

121125
setFilterList(event) {
122-
this.filterList = $.map($(event.currentTarget).val(), (id) => {
126+
this.config.filterList = $.map($(event.currentTarget).val(), (id) => {
123127
return parseInt(id);
124128
});
125129

@@ -130,8 +134,8 @@ class CompanyCalendar extends Calendar {
130134
refreshFilterButtonLabel() {
131135
let filterButtonLabel = this.filterButtonLabel;
132136

133-
if (this.filterList.length) {
134-
filterButtonLabel += ` (${this.filterList.length})`;
137+
if (this.config.filterList.length) {
138+
filterButtonLabel += ` (${this.config.filterList.length})`;
135139
}
136140

137141
this.$filterButton.text(filterButtonLabel);

app/helpers/user_helper.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,22 @@ def guider_options(user)
2727
groups = Group.for_user(user).includes(:users)
2828

2929
{
30+
'Reset' => reset_options,
3031
'Groups' => group_options(groups),
3132
'Users' => user_options(user)
3233
}
3334
end
3435

36+
def reset_options
37+
[
38+
[
39+
'Reset all filters',
40+
'Reset all filters',
41+
{ data: { icon: 'glyphicon-remove', children_to_select: [] } }
42+
]
43+
]
44+
end
45+
3546
def group_options(groups)
3647
groups.map do |group|
3748
[

0 commit comments

Comments
 (0)