cms/app-client/app/models/document.js
changeset 487 514dc9b6f875
parent 445 b1e5ad6b2a29
child 488 0161e028afb7
equal deleted inserted replaced
486:44a5801ed246 487:514dc9b6f875
     1 import DS from 'ember-data';
     1 import DS from 'ember-data';
     2 import Ember from 'ember';
     2 import Ember from 'ember';
     3 import _ from 'lodash/lodash';
     3 import _ from 'lodash/lodash';
     4 
     4 
     5 export default DS.Model.extend({
     5 export default DS.Model.extend({
       
     6     constants: Ember.inject.service(),
     6 
     7 
     7     uri: DS.attr('string'),
     8     uri: DS.attr('string'),
     8     issued: DS.attr('date'),
     9     issued: DS.attr('date'),
     9     created: DS.attr('string'),
    10     created: DS.attr('string'),
    10     title: DS.attr('string'),
    11     title: DS.attr('string'),
    32         }
    33         }
    33     }),
    34     }),
    34 
    35 
    35     media: Ember.computed('mediaArray', function() {
    36     media: Ember.computed('mediaArray', function() {
    36         var array = [];
    37         var array = [];
       
    38         var master = null;
    37         _.forEach(this.get('mediaArray'), function(media) {
    39         _.forEach(this.get('mediaArray'), function(media) {
    38             var index = array.findIndex(element => element.format === media.format);
    40             var index = array.findIndex(element => element.format === media.format);
    39             if(index > -1) {
    41             if(media.master) {
    40                 if (media.master) {
    42               master = media;
    41                     array.splice(index, 1, media);
    43             }
    42                 }
    44             if(index === -1 && !media.master) {
    43             } else {
       
    44                 array.push(media);
    45                 array.push(media);
    45             }
    46             }
    46         });
    47         });
       
    48         array.sort((m1, m2) => {
       
    49 
       
    50           const f1 = m1.format;
       
    51           const f2 = m2.format;
       
    52           const w1 = this.get('constants').MEDIA_TYPE_WEIGHT[f1] || 0;
       
    53           const w2 = this.get('constants').MEDIA_TYPE_WEIGHT[f2] || 0;
       
    54 
       
    55           return w1-w2;
       
    56         });
       
    57         if(array.length === 0 && master) {
       
    58           array.push(master);
       
    59         }
    47         return array;
    60         return array;
    48     }),
    61     }),
    49 
    62 
    50     video: Ember.computed('media', function() {
    63     video: Ember.computed('media', function() {
    51         return this.get('media').findIndex(element => element.format.match(new RegExp('^video/'))) > -1;
    64         return this.get('media').findIndex(element => element.format.match(new RegExp('^video/'))) > -1;