author | ymh <ymh.work@gmail.com> |
Tue, 08 Nov 2016 15:48:01 +0100 | |
changeset 404 | 0a5eef6ad2fe |
parent 394 | 48458e099b05 |
child 424 | feb0d3e0fef9 |
permissions | -rw-r--r-- |
393 | 1 |
import Ember from 'ember'; |
2 |
import _ from 'lodash/lodash'; |
|
3 |
||
4 |
export default Ember.Component.extend({ |
|
5 |
||
6 |
colors: Ember.inject.service(), |
|
7 |
filter: Ember.inject.service(), |
|
8 |
||
9 |
tagName: 'li', |
|
10 |
classNameBindings: ['isDisabled:disabled', 'isDark:light-color', 'isHighlighted:highlighted'], |
|
11 |
attributeBindings: ['style', 'title', 'id'], |
|
12 |
||
13 |
isDisabled: Ember.computed('range', 'year', 'count', function() { |
|
14 |
let year = parseInt(this.get('year')); |
|
15 |
let count = this.get('count'); |
|
16 |
return (!_.inRange(year, this.get('range')[0], this.get('range')[1]+1)) || count === 0; |
|
17 |
}), |
|
18 |
||
19 |
isHighlighted: Ember.computed('filter.dateList.[]', function() { |
|
20 |
return _.contains(this.get('filter.dateList'), this.get('year')); |
|
21 |
}), |
|
22 |
isDark: Ember.computed('backgroundColor', 'isDisabled', function() { |
|
23 |
let backgroundColor = this.get('backgroundColor'); |
|
24 |
if(this.get('isDisabled')) { |
|
25 |
return false; |
|
26 |
} |
|
394
48458e099b05
make dynamic filters for all route and do some code pruning and cleaning
ymh <ymh.work@gmail.com>
parents:
393
diff
changeset
|
27 |
return this.get('colors').getPerceptiveLuminance(backgroundColor) >= 0.5; |
393 | 28 |
}), |
29 |
||
30 |
backgroundColor: Ember.computed('count', 'maxCount', 'minCount', function() { |
|
31 |
return this.get('colors').shadeLinear(this.get('count'), this.get('minCount'), this.get('maxCount')); |
|
32 |
}), |
|
33 |
||
34 |
style: Ember.computed('backgroundColor', 'isDisabled', 'isHighlighted', function() { |
|
35 |
let backgroundColor = this.get('backgroundColor'); |
|
36 |
if(this.get('isDisabled') || this.get('isHighlighted')) { |
|
37 |
return null; |
|
38 |
} |
|
39 |
return Ember.String.htmlSafe(`background-color: ${backgroundColor};`); |
|
40 |
}), |
|
41 |
id: Ember.computed.alias('year'), |
|
42 |
count: Ember.computed('datestats.[]', function() { |
|
43 |
let year = this.get('year'); |
|
44 |
let count = this.get('datestats').get(`${year}`); |
|
45 |
return count?count:0; |
|
46 |
}), |
|
47 |
title: Ember.computed('count', 'isDsabled', function() { |
|
48 |
if(this.get('isDisabled')) { |
|
49 |
return null; |
|
50 |
} |
|
51 |
let year = this.get('year'); |
|
52 |
let count = this.get('count'); |
|
53 |
return `${year} (${count})`; |
|
54 |
}), |
|
55 |
||
56 |
year: null, |
|
57 |
datestats: null, |
|
58 |
range: null, |
|
59 |
maxCount: null, |
|
60 |
minCount: null, |
|
61 |
}); |