cms/app-client/mirage/serializers/language.js
author ymh <ymh.work@gmail.com>
Mon, 06 Feb 2017 16:05:02 +0100
changeset 501 7b2dcd2b31c1
parent 474 245b4df137d3
child 532 1190ea937f2d
permissions -rw-r--r--
add rights, Prepare #0025746
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
import { JSONAPISerializer } from 'ember-cli-mirage';
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import _ from 'lodash/lodash';
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 JSONAPISerializer.extend({
474
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     6
    serialize(response, request) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     7
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     8
      let json = JSONAPISerializer.prototype.serialize.apply(this, arguments);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
     9
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    10
      let qParams = request.queryParams['discourse'];
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    11
      if(qParams) {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    12
        json =  { 'data': _.map(json.data.slice(0, json.data.length/Math.pow(2,qParams.length)), (lang) => {
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    13
          let resLang = _.clone(lang);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    14
          resLang.attributes.count = Math.max(Math.floor(resLang.attributes.count / 2), 1);
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    15
          return resLang;
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    16
        })};
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    17
      }
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    18
245b4df137d3 Correct themes visualisation
ymh <ymh.work@gmail.com>
parents: 319
diff changeset
    19
      return {'languages' : _(json.data).map((lang) => { return [lang.id, lang.attributes.count];}).object().value()};
173
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    }
cf7b221238fd Work on test fixtures:
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
});