# HG changeset patch # User ymh # Date 1467807744 -7200 # Node ID 7443794512199cd10475c3e3435c64ba06678a0a # Parent a2497a2b622463ef8f275ed19198967cae6f5064 add publisher and duration_ms to model diff -r a2497a2b6224 -r 744379451219 cms/app-client/app/models/document.js --- a/cms/app-client/app/models/document.js Tue Jul 05 16:53:04 2016 +0200 +++ b/cms/app-client/app/models/document.js Wed Jul 06 14:22:24 2016 +0200 @@ -8,6 +8,19 @@ issued: DS.attr('date'), title: DS.attr('string'), language: DS.attr('string'), + duration_ms: DS.attr('number', { + defaultValue: function() { + var self = this; + var duration = 0; + Object.keys(this.get('mediaArray')).forEach(function(key) { + if (!duration && self.get('mediaArray')[key].extent_ms) { + duration = self.get('mediaArray')[key].extent_ms; + } + }); + return duration; + } + }), + publisher: DS.attr('string'), publishers: DS.attr({ defaultValue: function() { return []; } }), contributors: DS.attr({ defaultValue: function() { return []; } }), geoInfo: DS.attr({ defaultValue: function() { return {}; } }), @@ -29,15 +42,12 @@ return res; }), - duration: Ember.computed('mediaArray', function() { - var self = this; - var duration = 0; - Object.keys(this.get('mediaArray')).forEach(function(key) { - if (!duration && self.get('mediaArray')[key].extent_ms) { - duration = self.get('mediaArray')[key].extent_ms; - } - }); - return duration / 1000; + duration: Ember.computed('duration_ms', function() { + return this.get('duration_ms')/1000; + }), + + publishers_disp: Ember.computed('publisher', 'publishers', function() { + return this.get('publisher')?this.get('publisher'):this.get('publishers').join(', '); }) }); diff -r a2497a2b6224 -r 744379451219 cms/app-client/app/templates/components/player-component.hbs --- a/cms/app-client/app/templates/components/player-component.hbs Tue Jul 05 16:53:04 2016 +0200 +++ b/cms/app-client/app/templates/components/player-component.hbs Wed Jul 06 14:22:24 2016 +0200 @@ -19,7 +19,7 @@ {{doc-language class="language" url=item.language}}

- {{author item.publishers}} + {{item.publishers_disp}} {{short-date item.issued}}

diff -r a2497a2b6224 -r 744379451219 cms/app-client/app/templates/components/playlist-component.hbs --- a/cms/app-client/app/templates/components/playlist-component.hbs Tue Jul 05 16:53:04 2016 +0200 +++ b/cms/app-client/app/templates/components/playlist-component.hbs Wed Jul 06 14:22:24 2016 +0200 @@ -2,7 +2,7 @@ \ No newline at end of file + diff -r a2497a2b6224 -r 744379451219 cms/app-client/app/templates/tabs/detail.hbs --- a/cms/app-client/app/templates/tabs/detail.hbs Tue Jul 05 16:53:04 2016 +0200 +++ b/cms/app-client/app/templates/tabs/detail.hbs Wed Jul 06 14:22:24 2016 +0200 @@ -6,7 +6,7 @@

Titre {{model.title}}

Langue {{doc-language url=model.language}}

Enregistré le {{model.modified}}

-

Interviewer {{model.publishers}}

+

Interviewer {{model.publishers_disp}}

Description {{model.description}}

Type de Discours {{model.type}}

Localisation {{model.spatial}}

diff -r a2497a2b6224 -r 744379451219 cms/app-client/mirage/serializers/sparse-document.js --- a/cms/app-client/mirage/serializers/sparse-document.js Tue Jul 05 16:53:04 2016 +0200 +++ b/cms/app-client/mirage/serializers/sparse-document.js Wed Jul 06 14:22:24 2016 +0200 @@ -1,6 +1,24 @@ // mirage/serializers/blog-post.js import BaseSerializer from './application'; +import _ from 'lodash'; export default BaseSerializer.extend({ - attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray'] + attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray'], + + serialize(response, request) { + + console.log(request, response); + // This is how to call super, as Mirage borrows [Backbone's implementation of extend](http://backbonejs.org/#Model-extend) + let json = BaseSerializer.prototype.serialize.apply(this, arguments); + + json['documents'] = _.map(json['documents'], function(doc) { + let res = _.omit(doc, ['publishers', 'mediaArray']); + res['publisher'] = doc['publishers'].join(', '); + res['duration_ms'] = doc['mediaArray']?doc['mediaArray'][_(Object.keys(doc['mediaArray'])).first()]['extent_ms']:0; + return res; + }); + + return json; + } + });