|
| 1 | +import classic from 'ember-classic-decorator'; |
| 2 | +import { orderBy } from 'lodash-es'; |
| 3 | +import { action } from '@ember/object'; |
| 4 | +import Component from '@ember/component'; |
| 5 | +import { tracked } from '@glimmer/tracking'; |
| 6 | +import { levels } from 'open-event-frontend/utils/dictionary/levels'; |
| 7 | + |
| 8 | +@classic |
| 9 | +export default class ScheduleMenuFilter extends Component { |
| 10 | + |
| 11 | + @tracked activeSession = this.router.currentRoute.queryParams.sessionType ? this.router.currentRoute.queryParams.sessionType.split(',') : []; |
| 12 | + |
| 13 | + @tracked activeSessionLevel = this.router.currentRoute.queryParams.level ? this.router.currentRoute.queryParams.level.split(',') : []; |
| 14 | + |
| 15 | + @tracked activeRoom = this.router.currentRoute.queryParams.room ? this.router.currentRoute.queryParams.room.split(',') : []; |
| 16 | + |
| 17 | + @tracked activeTrack = this.router.currentRoute.queryParams.track ? this.router.currentRoute.queryParams.track.split(',') : []; |
| 18 | + |
| 19 | + @tracked levels = orderBy(levels, 'position'); |
| 20 | + |
| 21 | + |
| 22 | + @action |
| 23 | + removeActiveSession() { |
| 24 | + this.activeSession = []; |
| 25 | + } |
| 26 | + |
| 27 | + @action |
| 28 | + removeActiveSessionLevel() { |
| 29 | + this.activeSessionLevel = []; |
| 30 | + } |
| 31 | + |
| 32 | + @action |
| 33 | + removeActiveRoom() { |
| 34 | + this.activeRoom = []; |
| 35 | + } |
| 36 | + |
| 37 | + @action |
| 38 | + removeActiveTrack() { |
| 39 | + this.activeTrack = []; |
| 40 | + } |
| 41 | + |
| 42 | + removeActiveClass(name) { |
| 43 | + const activeEls = document.querySelectorAll(`.${name}.link-item.active`); |
| 44 | + activeEls.forEach(el => { |
| 45 | + el.classList.remove('active'); |
| 46 | + }); |
| 47 | + } |
| 48 | + |
| 49 | + @action |
| 50 | + sessionFilter(name) { |
| 51 | + this.activeSession = this.router.currentRoute.queryParams.sessionType ? this.router.currentRoute.queryParams.sessionType.split(',') : []; |
| 52 | + if (this.activeSession.includes(name)) { |
| 53 | + this.activeSession = this.activeSession.filter(session => session !== name); |
| 54 | + } else { |
| 55 | + this.activeSession = [...this.activeSession, name]; |
| 56 | + } |
| 57 | + this.router.transitionTo('public.sessions', { queryParams: { 'sessionType': this.activeSession } }); |
| 58 | + } |
| 59 | + |
| 60 | + @action |
| 61 | + sessionLevelFilter(level) { |
| 62 | + this.activeSessionLevel = this.router.currentRoute.queryParams.level ? this.router.currentRoute.queryParams.level.split(',') : []; |
| 63 | + if (this.activeSessionLevel.includes(level)) { |
| 64 | + this.activeSessionLevel = this.activeSessionLevel.filter(val => val !== level); |
| 65 | + } else { |
| 66 | + this.activeSessionLevel = [...this.activeSessionLevel, level]; |
| 67 | + } |
| 68 | + this.router.transitionTo('public.sessions', { queryParams: { 'level': this.activeSessionLevel } }); |
| 69 | + } |
| 70 | + |
| 71 | + @action |
| 72 | + roomFilter(name) { |
| 73 | + this.activeRoom = this.router.currentRoute.queryParams.room ? this.router.currentRoute.queryParams.room.split(',') : []; |
| 74 | + if (this.activeRoom.includes(name)) { |
| 75 | + this.activeRoom = this.activeRoom.filter(room => room !== name); |
| 76 | + } else { |
| 77 | + this.activeRoom = [...this.activeRoom, name]; |
| 78 | + } |
| 79 | + this.router.transitionTo('public.sessions', { queryParams: { 'room': this.activeRoom } }); |
| 80 | + } |
| 81 | + |
| 82 | + @action |
| 83 | + trackFilter(name) { |
| 84 | + this.activeTrack = this.router.currentRoute.queryParams.track ? this.router.currentRoute.queryParams.track.split(',') : []; |
| 85 | + if (this.activeTrack.includes(name)) { |
| 86 | + this.activeTrack = this.activeTrack.filter(track => track !== name); |
| 87 | + } else { |
| 88 | + this.activeTrack = [...this.activeTrack, name]; |
| 89 | + } |
| 90 | + this.router.transitionTo('public.sessions', { queryParams: { 'track': this.activeTrack } }); |
| 91 | + } |
| 92 | + |
| 93 | + @action |
| 94 | + applyFilter(value, filterType) { |
| 95 | + const params = this.router.currentRoute.queryParams; |
| 96 | + if (!params.track) { |
| 97 | + this.activeTrack = []; |
| 98 | + } |
| 99 | + if (!params.room) { |
| 100 | + this.activeRoom = []; |
| 101 | + } |
| 102 | + if (!params.sessionType) { |
| 103 | + this.activeSession = []; |
| 104 | + } |
| 105 | + value = value + ':'; |
| 106 | + if (filterType === 'room') { |
| 107 | + if (this.activeRoom.includes(value)) { |
| 108 | + this.activeRoom = this.activeRoom.filter(room => room !== value); |
| 109 | + } else { |
| 110 | + this.activeRoom = [...this.activeRoom, value]; |
| 111 | + } |
| 112 | + this.router.transitionTo('public.sessions', { queryParams: { 'room': this.activeRoom } }); |
| 113 | + } else { |
| 114 | + if (this.activeTrack.includes(value)) { |
| 115 | + this.activeTrack = this.activeTrack.filter(track => track !== value); |
| 116 | + } else { |
| 117 | + this.activeTrack = [...this.activeTrack, value]; |
| 118 | + } |
| 119 | + this.router.transitionTo('public.sessions', { queryParams: { 'track': this.activeTrack } }); |
| 120 | + } |
| 121 | + } |
| 122 | +} |
0 commit comments