correct min, max calculations when theme list change
authorymh <ymh.work@gmail.com>
Mon, 12 Dec 2016 17:37:54 +0100
changeset 468 8fe093d88efe
parent 467 762fc0eb4946
child 469 b363c6d1a73c
correct min, max calculations when theme list change
cms/app-client/app/components/sorting-component.js
cms/app-client/app/helpers/popularity.js
--- a/cms/app-client/app/components/sorting-component.js	Fri Dec 09 11:41:15 2016 +0100
+++ b/cms/app-client/app/components/sorting-component.js	Mon Dec 12 17:37:54 2016 +0100
@@ -9,8 +9,8 @@
     isAlphabetical: true,
     isPopularity: Ember.computed('isAlphabetical', function() { return !this.get('isAlphabetical'); }),
 
-    minimum: Ember.computed('themes', function() { return Math.min(...this.themes.mapBy('count')); }),
-    maximum: Ember.computed('themes', function() { return Math.max(...this.themes.mapBy('count')); }),
+    minimum: Ember.computed('themes.[]', function() { return Math.min(...this.get('themes').mapBy('count')); }),
+    maximum: Ember.computed('themes.[]', function() { return Math.max(...this.get('themes').mapBy('count')); }),
 
     more: true,
 
--- a/cms/app-client/app/helpers/popularity.js	Fri Dec 09 11:41:15 2016 +0100
+++ b/cms/app-client/app/helpers/popularity.js	Mon Dec 12 17:37:54 2016 +0100
@@ -2,12 +2,9 @@
 
 export function popularity([target, minimum, maximum]) {
     var classname = ['not-popular', 'popular', 'very-popular'];
-    var interval = ( maximum - minimum ) / classname.length;
+    var interval = ( maximum + 1 - minimum ) / classname.length;
 
-    var i = 0;
-    while( target > minimum + ( interval * ( i + 1 ) ) ) {
-        i ++;
-    }
+    var i = Math.floor((target-minimum)/interval);
 
     return classname[i];
 }