Implementing Sessions API for the event in Open Event Frontend
This article will illustrate how the sessions are displayed and updated on the events/{event_id}/sessions route to display the sessions available for a particular event using the sessions API in Open Event Frontend. The primary end point of Open Event API with which we are concerned with for fetching the sessions is GET /v1/sessions/{session_id} First, we need to create a model for the sessions, which will have the fields corresponding to the API, so we proceed with the ember CLI command: ember g model session Next, we need to define the model according to the requirements. The model needs to extend the base model class. As a session can have multiple speakers and a session always belongs to an event, so we have to use ember data relationships “hasMany” and “belongsTo”. Hence, the model will have the following format. import ModelBase from 'open-event-frontend/models/base'; import { belongsTo, hasMany } from 'ember-data/relationships'; export default ModelBase.extend({ title : attr('string'), subtitle : attr('string'), speakers : hasMany('speaker'), event : belongsTo('event') }); Complete code for the model can be seen here Now, we need to load the data from the API using the above model, so we will send a GET request to the API to fetch the sessions corresponding to a particular event. This can be easily achieved using this. return this.modelFor('events.view').query('sessions'); The above line is asking for getting the current model that is on the route events.view and query for the sessions property from that model. Now we need to filter the sessions based on their sessions whether they have been accepted or confirmed or pending or rejected and display them on different pages. For this purpose, we need to pass filter and pages to the query which will tell what type and now of sessions to be loaded at once. Also, we need to display the speakers associated with session and event details. For this case, the above query will be formatted like this. return this.modelFor('events.view').query('sessions', { include : 'event,speakers', filter : filterOptions, 'page[size]' : 10 }); In the above query, the filterOptions are designed in such a way which check for what type of sessions user is querying for. The code can be found here. The next thing we need to do is to display the above data fetched from the API into an ember table. For this, we need to have a controller class which will help in letting the table know what all columns will be required to display and the attribute values they correspond in the API. We can also define the template for each column. The code for the controller class looks like this. export default Controller.extend({ columns: [ { propertyName : 'state', title : 'State', disableSorting : true, template : 'components/ui-table/cell/events/view/sessions/cell-session-state' }, { propertyName : 'title', title : 'Title' }, { propertyName : 'speakers', template : 'components/ui-table/cell/cell-speakers', title : 'Speakers', disableSorting : true }] }); In the above code, we can see a field called ‘disableSorting’ which is true if we don’t want to sort the table based…
