Default sorting
authorChloe Laisne <chloe.laisne@gmail.com>
Sat, 11 Jun 2016 01:07:57 +0200
changeset 187 ca479ef64fb4
parent 186 36e5a67656e6
child 188 d2cb39155997
Default sorting
cms/app-client/app/components/sorting-component.js
cms/app-client/app/styles/components/sorting-component.scss
cms/app-client/app/templates/components/sorting-component.hbs
--- a/cms/app-client/app/components/sorting-component.js	Fri Jun 10 23:42:11 2016 +0200
+++ b/cms/app-client/app/components/sorting-component.js	Sat Jun 11 01:07:57 2016 +0200
@@ -3,11 +3,14 @@
 export default Ember.Component.extend({
 
     classNames: ['sorting-component'],
-    sorting: [],
+
+    sorting: ['label'],
     sortedThemes: Ember.computed.sort('themes', 'sorting'),
 
+    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')); }),
 
     actions: {
@@ -18,10 +21,16 @@
         },
 
         sortBy: function (type) {
-            this.set('sorting', type === 'popularity' ? ['count:desc'] : ['label']);
+            if(type === 'alphabetical') {
+                this.set('isAlphabetical', true);
+                this.set('sorting', ['label']);
+            } else {
+                this.set('isAlphabetical', false);
+                this.set('sorting', ['count:desc']);
+            }
             this.get('sortedThemes');
         }
 
     }
 
-});
+});
\ No newline at end of file
--- a/cms/app-client/app/styles/components/sorting-component.scss	Fri Jun 10 23:42:11 2016 +0200
+++ b/cms/app-client/app/styles/components/sorting-component.scss	Sat Jun 11 01:07:57 2016 +0200
@@ -48,3 +48,7 @@
 ul.tags li.very-popular{
   font-size: 24px;
 }
+
+ul.options li.active {
+    font-weight: bold;
+}
\ No newline at end of file
--- a/cms/app-client/app/templates/components/sorting-component.hbs	Fri Jun 10 23:42:11 2016 +0200
+++ b/cms/app-client/app/templates/components/sorting-component.hbs	Sat Jun 11 01:07:57 2016 +0200
@@ -5,8 +5,8 @@
     Trier par :
 
     <ul class="options">
-        <li {{ action 'sortBy' 'alphabetical' }}>Ordre alphabétique</li>
-        <li {{ action 'sortBy' 'popularity' }}>Popularité</li>
+        <li {{ action 'sortBy' 'alphabetical' }} class="{{if isAlphabetical "active"}}">Ordre alphabétique</li>
+        <li {{ action 'sortBy' 'popularity' }} class="{{if isPopularity "active"}}">Popularité</li>
     </ul>
 
 </div>