correct discourse display and update
authorymh <ymh.work@gmail.com>
Sun, 04 Dec 2016 13:49:44 +0100
changeset 466 a8effb60ccb6
parent 465 9df336529b2f
child 467 762fc0eb4946
correct discourse display and update
cms/app-client/app/components/discourses-component.js
cms/app-client/app/templates/components/discourses-component.hbs
cms/app-client/mirage/config.js
--- a/cms/app-client/app/components/discourses-component.js	Sun Dec 04 00:23:52 2016 +0100
+++ b/cms/app-client/app/components/discourses-component.js	Sun Dec 04 13:49:44 2016 +0100
@@ -20,6 +20,7 @@
     }).on('init'),
 
     didRender: function() {
+        var previousDiv = d3.selectAll(".discourses");
         var self = this;
 
         var discourses = this.get('discourses');
@@ -42,7 +43,11 @@
             })
             .padding(10);
 
-        var element = d3.select('#' + self.get('elementId'));
+        var element = d3.select('#' + self.get('elementId'))
+          .append('div')
+          .attr('class','discourses')
+          .style('position','absolute')
+          .style('left', -100000);
 
         var bubbles = bubble.nodes(self.createNodes());
 
@@ -71,6 +76,9 @@
             .style("margin-left", function() { return ( Ember.$(this).width() > Ember.$(this).parent().width() ? - ( Ember.$(this).width() / 2 ) + ( Ember.$(this).parent().width() / 2 ) : 0 ) + 'px'; })
             .style("margin-top", function() { return Ember.$(this).parent().height() / 2 - Ember.$(this).height() / 2 + 'px'; });
 
+        previousDiv.remove();
+        element.style('position',null).style('left',null);
+
         this._super(...arguments);
     },
 
--- a/cms/app-client/app/templates/components/discourses-component.hbs	Sun Dec 04 00:23:52 2016 +0100
+++ b/cms/app-client/app/templates/components/discourses-component.hbs	Sun Dec 04 13:49:44 2016 +0100
@@ -1,1 +1,1 @@
-{{yield}}
+
--- 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');