cms/app-client/mirage/serializers/sparse-document.js
author Chloe Laisne <chloe.laisne@gmail.com>
Tue, 27 Sep 2016 01:40:19 +0200
changeset 302 973df1349591
parent 275 a4d8618c2f1b
child 324 92fc9d077f95
permissions -rw-r--r--
Animate player text-overflow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
// mirage/serializers/blog-post.js
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
import BaseSerializer from './application';
229
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
     3
import _ from 'lodash';
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
export default BaseSerializer.extend({
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 229
diff changeset
     6
    attrs: ['id', 'title', 'language', 'url', 'issued', 'modified', 'publishers', 'mediaArray', 'transcript'],
229
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
     7
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
     8
    serialize(response, request) {
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
     9
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    10
        console.log(request, response);
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    11
        // This is how to call super, as Mirage borrows [Backbone's implementation of extend](http://backbonejs.org/#Model-extend)
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    12
        let json = BaseSerializer.prototype.serialize.apply(this, arguments);
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    13
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    14
        json['documents'] = _.map(json['documents'], function(doc) {
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 229
diff changeset
    15
            let res = _.omit(doc, ['publishers', 'mediaArray', 'transcript']);
229
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    16
            res['publisher'] = doc['publishers'].join(', ');
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    17
            res['duration_ms'] = doc['mediaArray']?doc['mediaArray'][_(Object.keys(doc['mediaArray'])).first()]['extent_ms']:0;
275
a4d8618c2f1b add transcript_url property on document list results
ymh <ymh.work@gmail.com>
parents: 229
diff changeset
    18
            res['transcript_url'] = (doc['transcript'] && doc['transcript']['url'])?doc['transcript']['url']:null;
229
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    19
            return res;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    20
        });
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    21
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    22
        return json;
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    23
    }
744379451219 add publisher and duration_ms to model
ymh <ymh.work@gmail.com>
parents: 222
diff changeset
    24
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
});