cms/app-client/mirage/config.js
changeset 466 a8effb60ccb6
parent 447 38d5789e30d0
child 467 762fc0eb4946
--- a/cms/app-client/mirage/config.js	Sun Dec 04 00:23:52 2016 +0100
+++ b/cms/app-client/mirage/config.js	Sun Dec 04 13:49:44 2016 +0100
@@ -1,6 +1,7 @@
 import ENV from 'app-client/config/environment';
 import _ from 'lodash/lodash';
 import * as constants from 'corpus-common-addon/utils/constants';
+import Collection from 'ember-cli-mirage/orm/collection';
 
 export default function() {
 
@@ -36,7 +37,33 @@
 
     this.get('/stats/themes', 'themes');
 
-    this.get('/stats/discourses', 'discourses');
+    this.get('/stats/discourses', ({discourses}, request) => {
+      console.log("DISCOURSES", request.queryParams, discourses.all(), discourses.all().models);
+
+      if(request.queryParams['discourse']) {
+        var res = [];
+        request.queryParams.discourse.forEach( did => {
+          let d = discourses.find(did);
+          if(d) {
+            res.push(d);
+          }
+        });
+        let allDiscourses = discourses.all().models;
+        let i=0;
+        while(i<allDiscourses.length && res.length < (allDiscourses.length/2)) {
+          let d = allDiscourses[i++];
+          if(!_.contains(request.queryParams.discourse, d.id)) {
+            d.count = Math.floor(d.count / 2);
+            res.push(d);
+          }
+        }
+        console.log("DISCOURSES", request.queryParams, { modelName: "discourse", models: res });
+        //return discourses.all();
+        return new Collection('discourse', res);
+      } else {
+        return discourses.all();
+      }
+    });
 
     this.get('/stats/datestats', 'datestats');