-
Notifications
You must be signed in to change notification settings - Fork 155
/
media-information.js
63 lines (56 loc) · 2.06 KB
/
media-information.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import Component from '@ember/component';
import { get, computed } from '@ember/object';
import { equal, not } from '@ember/object/computed';
import humanizeDuration from 'client/utils/humanize-duration';
import moment from 'moment';
const computedProduction = key => (
computed('media.animeProductions', function() {
const productions = get(this, 'media.animeProductions');
return productions.filterBy('role', key).mapBy('producer.name').join(', ');
}).readOnly()
);
export default Component.extend({
classNames: ['media--information'],
isExpanded: false,
producers: computedProduction('producer'),
licensors: computedProduction('licensor'),
studios: computedProduction('studio'),
isAnime: equal('media.modelType', 'anime'),
isManga: not('isAnime'),
season: computed('media.startDate', function() {
const start = get(this, 'media.startDate');
if (!start) { return null; }
const month = start.month() + 1;
if ([12, 1, 2].includes(month)) {
return 'winter';
} else if ([3, 4, 5].includes(month)) {
return 'spring';
} else if ([6, 7, 8].includes(month)) {
return 'summer';
} else if ([9, 10, 11].includes(month)) {
return 'fall';
}
}).readOnly(),
seasonYear: computed('season', function() {
const season = get(this, 'season');
if (!season) { return null; }
const start = get(this, 'media.startDate');
const year = start.year();
const month = start.month() + 1;
if (season === 'winter' && month === 12) {
return year + 1;
}
return year;
}).readOnly(),
airedLongerThanOneDay: computed('media.{startDate,endDate}', function() {
const start = get(this, 'media.startDate');
if (!start) { return false; }
return !start.isSame(get(this, 'media.endDate'));
}).readOnly(),
totalTime: computed('media.{episodeCount,episodeLength}', function() {
const count = get(this, 'media.episodeCount');
const length = get(this, 'media.episodeLength');
const time = moment.duration(count * length, 'minutes');
return humanizeDuration(time);
}).readOnly()
});