author | ymh <ymh.work@gmail.com> |
Tue, 17 Jan 2017 18:57:25 +0100 | |
changeset 488 | 0161e028afb7 |
parent 487 | 514dc9b6f875 |
child 502 | 74fba571487e |
permissions | -rw-r--r-- |
91 | 1 |
import DS from 'ember-data'; |
2 |
import Ember from 'ember'; |
|
94
62984937a062
- add params when modal appear so we can come back right on this document modal
nowmad@23.1.168.192.in-addr.arpa
parents:
91
diff
changeset
|
3 |
import _ from 'lodash/lodash'; |
91 | 4 |
|
217
989b9c36b849
Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
210
diff
changeset
|
5 |
export default DS.Model.extend({ |
487
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
6 |
constants: Ember.inject.service(), |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
7 |
|
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
8 |
uri: DS.attr('string'), |
210 | 9 |
issued: DS.attr('date'), |
445
b1e5ad6b2a29
Display created date instead of issued
ymh <ymh.work@gmail.com>
parents:
414
diff
changeset
|
10 |
created: DS.attr('string'), |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
11 |
title: DS.attr('string'), |
327
13564bb13ccc
In the serialized document the lan files id 'languages' and not 'language'
ymh <ymh.work@gmail.com>
parents:
326
diff
changeset
|
12 |
languages: DS.attr({ defaultValue: function() { return []; } }), |
242 | 13 |
publisher: DS.attr('string'), |
289
7cae80e5748c
Add transcript icon to playlist items
Chloe Laisne <chloe.laisne@gmail.com>
parents:
270
diff
changeset
|
14 |
transcript_url: DS.attr('string'), |
253
0be9770b09b4
Hide/show transcript button in the player - Do not request transscript when property is null in the document request
Chloe Laisne <chloe.laisne@gmail.com>
parents:
243
diff
changeset
|
15 |
transcript: DS.attr({ defaultValue: function() { return {}; } }), |
242 | 16 |
|
17 |
publishers: DS.attr({ defaultValue: function() { return []; } }), |
|
18 |
contributors: DS.attr({ defaultValue: function() { return []; } }), |
|
19 |
geoInfo: DS.attr({ defaultValue: function() { return {}; } }), |
|
20 |
mediaArray: DS.attr({ defaultValue: function() { return []; } }), |
|
269
9659e91242e1
Add subjects to notice + Background color two notice type + Remove empty notice fields
Chloe Laisne <chloe.laisne@gmail.com>
parents:
253
diff
changeset
|
21 |
subjects: DS.attr({ defaultValue: function() { return []; } }), |
9659e91242e1
Add subjects to notice + Background color two notice type + Remove empty notice fields
Chloe Laisne <chloe.laisne@gmail.com>
parents:
253
diff
changeset
|
22 |
|
229
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
23 |
duration_ms: DS.attr('number', { |
414
5c6c526a7fc1
Display for single notice, preparation for share link
ymh <ymh.work@gmail.com>
parents:
327
diff
changeset
|
24 |
defaultValue: () => { |
229
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
25 |
var self = this; |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
26 |
var duration = 0; |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
27 |
Object.keys(this.get('mediaArray')).forEach(function(key) { |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
28 |
if (!duration && self.get('mediaArray')[key].extent_ms) { |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
29 |
duration = self.get('mediaArray')[key].extent_ms; |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
30 |
} |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
31 |
}); |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
32 |
return duration; |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
33 |
} |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
34 |
}), |
91 | 35 |
|
242 | 36 |
media: Ember.computed('mediaArray', function() { |
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
37 |
var arrayMedia = []; |
487
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
38 |
var master = null; |
242 | 39 |
_.forEach(this.get('mediaArray'), function(media) { |
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
40 |
var index = arrayMedia.findIndex(element => element.format === media.format); |
487
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
41 |
if(media.master) { |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
42 |
master = media; |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
43 |
} |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
44 |
if(index === -1 && !media.master) { |
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
45 |
arrayMedia.push(media); |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
46 |
} |
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
47 |
}); |
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
48 |
arrayMedia.sort((m1, m2) => { |
487
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
49 |
|
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
50 |
const f1 = m1.format; |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
51 |
const f2 = m2.format; |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
52 |
const w1 = this.get('constants').MEDIA_TYPE_WEIGHT[f1] || 0; |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
53 |
const w2 = this.get('constants').MEDIA_TYPE_WEIGHT[f2] || 0; |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
54 |
|
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
55 |
return w1-w2; |
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
56 |
}); |
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
57 |
if(arrayMedia.length === 0 && master) { |
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
58 |
arrayMedia.push(master); |
487
514dc9b6f875
Reorder media files for notice. Make the most compressed one (mp3, mp4) the default. Closes #0025878
ymh <ymh.work@gmail.com>
parents:
445
diff
changeset
|
59 |
} |
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
60 |
return arrayMedia; |
242 | 61 |
}), |
62 |
||
63 |
video: Ember.computed('media', function() { |
|
64 |
return this.get('media').findIndex(element => element.format.match(new RegExp('^video/'))) > -1; |
|
217
989b9c36b849
Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
210
diff
changeset
|
65 |
}), |
989b9c36b849
Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
210
diff
changeset
|
66 |
|
488
0161e028afb7
Correct bug on display of notices on permalinks. Correct bug #0025750
ymh <ymh.work@gmail.com>
parents:
487
diff
changeset
|
67 |
duration: Ember.computed( 'duration_ms', function() { |
229
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
68 |
return this.get('duration_ms')/1000; |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
69 |
}), |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
70 |
|
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
71 |
publishers_disp: Ember.computed('publisher', 'publishers', function() { |
744379451219
add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents:
220
diff
changeset
|
72 |
return this.get('publisher')?this.get('publisher'):this.get('publishers').join(', '); |
209
35cb7200bb0a
Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents:
126
diff
changeset
|
73 |
}) |
126
e87a340711a4
improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents:
125
diff
changeset
|
74 |
|
91 | 75 |
}); |