cms/app-client/app/models/document.js
author Chloe Laisne <chloe.laisne@gmail.com>
Sun, 17 Jul 2016 23:58:55 +0200
changeset 243 0f29cc270f9e
parent 242 523ca6e73353
child 253 0be9770b09b4
permissions -rw-r--r--
Fix firefox focus JSLinting
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     1
import DS from 'ember-data';
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     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
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     4
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
     5
export default DS.Model.extend({
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 126
diff changeset
     6
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 126
diff changeset
     7
    uri: DS.attr('string'),
210
08ad36c693b1 Player design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 209
diff changeset
     8
    issued: DS.attr('date'),
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 126
diff changeset
     9
    title: DS.attr('string'),
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 126
diff changeset
    10
    language: DS.attr('string'),
242
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    11
    publisher: DS.attr('string'),
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    12
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    13
    publishers: DS.attr({ defaultValue: function() { return []; } }),
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    14
    contributors: DS.attr({ defaultValue: function() { return []; } }),
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    15
    geoInfo: DS.attr({ defaultValue: function() { return {}; } }),
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    16
    mediaArray: DS.attr({ defaultValue: function() { return []; } }),
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    17
229
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    18
    duration_ms: DS.attr('number', {
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    19
        defaultValue: function() {
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    20
            var self = this;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    21
            var duration = 0;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    22
            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
    23
                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
    24
                    duration = self.get('mediaArray')[key].extent_ms;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    25
                }
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    26
            });
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    27
            return duration;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    28
        }
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    29
    }),
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    30
242
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    31
    media: Ember.computed('mediaArray', function() {
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    32
        var array = [];
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    33
        _.forEach(this.get('mediaArray'), function(media) {
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    34
            var index = array.findIndex(element => element.format === media.format);
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    35
            if(index > -1) {
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    36
                if (media.master) {
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    37
                    array.splice(index, 1, media);
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    38
                }
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    39
            } else {
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    40
                array.push(media);
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 126
diff changeset
    41
            }
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 126
diff changeset
    42
        });
242
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    43
        return array;
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    44
    }),
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    45
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    46
    video: Ember.computed('media', function() {
523ca6e73353 Add video player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 229
diff changeset
    47
        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
    48
    }),
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents: 210
diff changeset
    49
229
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    50
    duration: Ember.computed('duration_ms', function() {
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    51
        return this.get('duration_ms')/1000;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    52
    }),
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    53
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    54
    publishers_disp: Ember.computed('publisher', 'publishers', function() {
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 220
diff changeset
    55
        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
    56
    })
126
e87a340711a4 improve on dataloading. add fixture management with proper interface to load data.
ymh <ymh.work@gmail.com>
parents: 125
diff changeset
    57
91
acfeddc7821d rename "sound" to "document"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
    58
});