Addition of new filters for event search
Open Event has an event search provided but it lacked two of the userful filters which will make searching for an event for a user easier than the current ecosystem. In this blog post, I describe how I implemented filtering of events on the basis of CFP status and Ticket Type.
About the issue
Addition of these two filters were subparts of improving the browse events page better. The browse events page currently functions in an optimal way but these improvements make it even better.
How the filters are added
For adding these two filters, it was required that the request sent to server to filter the event must contain ticket type and cfp so that the results from the server can be received. To achieve this, the frontend code needed the following changes:
- Passing of request variable into sidebar component present in app/templates/explore.hbs and addition of a clear filter for the same in the same file.e startDate=start_date endDate=end_date location=location ticket_type=ticket_type}
{{explore/side-bar model=model category=category sub_category=sub_category event_type=event_type startDate=start_date endDate=end_date location=location ticket_type=ticket_type}} {{#if filters.ticket_type}} <div class=”ui mini label”> {{ticket_type}} <a role=”button” {{action ‘clearFilter’ ‘ticket_type’}}> <i class=”icon close”></i> </a> </div> {{/if}} |
- Adding UI for both the filters in app/templates/components/explore/side-bar.hbs. Accordion UI is used to achieve this.
<div class=”item”> {{#ui-accordion}} <span class=”title”> <i class=”dropdown icon”></i> {{t ‘Ticket Type’ }} </span> <div class=”content menu”> <a href=”#” class=”link item {{if (eq ticket_type ‘free’) ‘active’}}” {{action ‘selectTicketType’ ‘free’}}> {{t ‘Free’}} </a> <a href=”#” class=”link item {{if (eq ticket_type ‘paid’) ‘active’}}” {{action ‘selectTicketType’ ‘paid’}}> {{t ‘Paid’}} </a> </div> {{/ui-accordion}} </div> |
- Editing the routes (app/routes/explore.js) to make sure if the request has new filter parameter then it should be sent to server.
if (params.ticket_type) { filterOptions.push({ name : ‘tickets’, op : ‘any’, val : { name : ‘type’, op : ‘eq’, val : params.ticket_type } }); } |
- Addition of new request parameter in the controller (app/controllers/explore.js)
queryParams : [‘category’, ‘sub_category’, ‘event_type’, ‘start_date’, ‘end_date’, ‘location’, ‘ticket_type’], ticket_type : null, if (filterType === ‘ticket_type’) { this.set(‘ticket_type’, null); } |
- Editing the sidebar component to set the value of request parameter when the user interacts with the filter.
hideClearFilters: computed(‘category’, ‘sub_category’, ‘event_type’, ‘startDate’, ‘endDate’, ‘location’, ‘ticket_type’, function() { return !(this.category || this.sub_category || this.event_type || this.startDate || this.endDate || this.location || this.ticket_type !== null); }), selectTicketType(ticketType) { this.set(‘ticket_type’, ticketType === this.ticket_type ? null : ticketType); }, this.set(‘ticket_type’, null); |
Sidebar after the addition of filters.
Resources:
Issue: https://github.com/fossasia/open-event-frontend/issues/3098
Pull Requests:
Ticket Type: https://github.com/fossasia/open-event-frontend/pull/3158
CFS: https://github.com/fossasia/open-event-frontend/pull/3144
Specifying Query Params: https://guides.emberjs.com/release/routing/query-params/
UI Resources for the feature: https://semantic-org.github.io/Semantic-UI-Ember/#/modules/accordion
You must be logged in to post a comment.