cms/app-client/mirage/config.js
changeset 466 a8effb60ccb6
parent 447 38d5789e30d0
child 467 762fc0eb4946
equal deleted inserted replaced
465:9df336529b2f 466:a8effb60ccb6
     1 import ENV from 'app-client/config/environment';
     1 import ENV from 'app-client/config/environment';
     2 import _ from 'lodash/lodash';
     2 import _ from 'lodash/lodash';
     3 import * as constants from 'corpus-common-addon/utils/constants';
     3 import * as constants from 'corpus-common-addon/utils/constants';
       
     4 import Collection from 'ember-cli-mirage/orm/collection';
     4 
     5 
     5 export default function() {
     6 export default function() {
     6 
     7 
     7     // These comments are here to help you get started. Feel free to delete them.
     8     // These comments are here to help you get started. Feel free to delete them.
     8 
     9 
    34 
    35 
    35     this.get('/stats/geostats', 'geostats');
    36     this.get('/stats/geostats', 'geostats');
    36 
    37 
    37     this.get('/stats/themes', 'themes');
    38     this.get('/stats/themes', 'themes');
    38 
    39 
    39     this.get('/stats/discourses', 'discourses');
    40     this.get('/stats/discourses', ({discourses}, request) => {
       
    41       console.log("DISCOURSES", request.queryParams, discourses.all(), discourses.all().models);
       
    42 
       
    43       if(request.queryParams['discourse']) {
       
    44         var res = [];
       
    45         request.queryParams.discourse.forEach( did => {
       
    46           let d = discourses.find(did);
       
    47           if(d) {
       
    48             res.push(d);
       
    49           }
       
    50         });
       
    51         let allDiscourses = discourses.all().models;
       
    52         let i=0;
       
    53         while(i<allDiscourses.length && res.length < (allDiscourses.length/2)) {
       
    54           let d = allDiscourses[i++];
       
    55           if(!_.contains(request.queryParams.discourse, d.id)) {
       
    56             d.count = Math.floor(d.count / 2);
       
    57             res.push(d);
       
    58           }
       
    59         }
       
    60         console.log("DISCOURSES", request.queryParams, { modelName: "discourse", models: res });
       
    61         //return discourses.all();
       
    62         return new Collection('discourse', res);
       
    63       } else {
       
    64         return discourses.all();
       
    65       }
       
    66     });
    40 
    67 
    41     this.get('/stats/datestats', 'datestats');
    68     this.get('/stats/datestats', 'datestats');
    42 
    69 
    43     this.get('/stats/dateminmax', 'dateminmax');
    70     this.get('/stats/dateminmax', 'dateminmax');
    44 
    71