|
1 | 1 | import Controller from '@ember/controller'; |
2 | | -import {computed} from '@ember/object'; |
3 | | -import createGraph from 'cats-client/utils/create-graph'; |
4 | | -import { A as emberA } from '@ember/array'; |
5 | | -import { inject as service } from '@ember/service'; |
6 | | - |
7 | | -export const ALL_MONTHS = 0; |
8 | | - |
9 | 2 | export default Controller.extend({ |
10 | | - store: service(), |
11 | | - fastboot: service(), |
12 | | - |
13 | | - allMonths: ALL_MONTHS, |
14 | | - |
15 | | - showCTA: computed({ |
16 | | - get() { |
17 | | - if (this.get('fastboot.isFastBoot')) { |
18 | | - return; |
19 | | - } |
20 | | - return !localStorage.getItem('seenCTA'); |
21 | | - }, |
22 | | - set(key, value) { |
23 | | - localStorage.setItem('seenCTA', !value); |
24 | | - return value; |
25 | | - } |
26 | | - }), |
27 | | - |
28 | | - selectedArtist: computed('artist', { |
29 | | - get() { |
30 | | - let artist = this.get('artist'); |
31 | | - if (artist) { |
32 | | - return this.get('store').peekRecord('artist', artist); |
33 | | - } |
34 | | - |
35 | | - return null; |
36 | | - }, |
37 | | - set(key, value) { |
38 | | - this.set('showCTA', false); |
39 | | - this.set('artist', value && value.get('id')); |
40 | | - return value; |
41 | | - } |
42 | | - }), |
43 | | - |
44 | | - sortDef: Object.freeze(['startTime:desc']), |
45 | | - sortedEvents: computed.sort('events', 'sortDef'), |
46 | | - |
47 | | - includeBandmates: true, |
48 | | - month: ALL_MONTHS, |
49 | | - year: null, |
50 | | - |
51 | | - artist: null, |
52 | | - |
53 | | - queryParams: Object.freeze([ 'month', 'year', 'includeBandmates', 'artist' ]), |
54 | | - |
55 | | - // converter query-string month input "1"-"12" |
56 | | - // do 0 based int 0-11 so that getMonth() works. |
57 | | - monthInt: computed('month', function() { |
58 | | - let month = this.get('month'); |
59 | | - if (month === ALL_MONTHS || month === null) { |
60 | | - return null; |
61 | | - } |
62 | | - |
63 | | - return parseInt(month, 10) - 1; |
64 | | - }), |
65 | | - |
66 | | - // Filter on month and/or selectedArtist |
67 | | - events: computed('monthInt', 'selectedArtist', 'includeBandmates', function() { |
68 | | - let month = this.get('monthInt'); |
69 | | - let events; |
70 | | - |
71 | | - let selectedArtist = this.get('selectedArtist'); |
72 | | - if (selectedArtist) { |
73 | | - events = emberA(); |
74 | | - |
75 | | - let pushEvents = function(artist) { |
76 | | - events.pushObjects(artist.get('events').filter(event => { |
77 | | - if (month === null) { |
78 | | - return true; |
79 | | - } |
80 | | - |
81 | | - return event.get('startTime').getMonth() === month; |
82 | | - })); |
83 | | - }; |
84 | | - |
85 | | - pushEvents(selectedArtist); |
86 | | - |
87 | | - if (this.get('includeBandmates')) { |
88 | | - let bandMates = emberA(); |
89 | | - events.forEach(event => { |
90 | | - bandMates.pushObjects(event.get('artists').toArray()); |
91 | | - }); |
92 | | - |
93 | | - bandMates = bandMates.uniq().removeObject(selectedArtist); |
94 | | - |
95 | | - bandMates.forEach(bandMate => pushEvents(bandMate)); |
96 | | - } |
97 | | - |
98 | | - return events.uniq(); |
99 | | - } |
100 | | - |
101 | | - // if (month !== null) { |
102 | | - // return this.get('model').filter(event => { |
103 | | - // return event.get('startTime').getMonth() === month; |
104 | | - // }); |
105 | | - // } |
106 | | - |
107 | | - return this.get('model'); |
108 | | - }), |
109 | | - |
110 | | - graph: computed('events.[]', function() { |
111 | | - let events = this.get('events'); |
112 | | - return createGraph(events); |
113 | | - }) |
114 | 3 | }); |
0 commit comments