/langue endpoint: 1. Date interval 2. Delete date
authorChloe Laisne <chloe.laisne@gmail.com>
Tue, 14 Jun 2016 18:15:26 +0200
changeset 189 21b30ee23191
parent 188 d2cb39155997
child 190 226ae8f2e8e9
/langue endpoint: 1. Date interval 2. Delete date
cms/app-client/app/components/visu-chrono.js
cms/app-client/app/controllers/application.js
cms/app-client/app/controllers/tabs/chrono.js
cms/app-client/app/helpers/interval.js
cms/app-client/app/routes/tabs/chrono.js
cms/app-client/app/templates/results.hbs
cms/app-client/app/templates/tabs/chrono.hbs
cms/app-client/app/templates/tabs/langues.hbs
cms/app-client/tests/unit/helpers/interval-test.js
--- a/cms/app-client/app/components/visu-chrono.js	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/components/visu-chrono.js	Tue Jun 14 18:15:26 2016 +0200
@@ -3,45 +3,50 @@
 const { getOwner } = Ember;
 
 export default Ember.Component.extend({
-  didInsertElement: function(){
-    var _this = this;
+
+    didInsertElement: function(){
+        var self = this;
+
+        if (getOwner(self).lookup('controller:application').date !== null){
+            this.highlightQuery(getOwner(self).lookup('controller:application').date);
+        }
+
+        var isMouseDown = false,
+        isHighlighted;
 
-    if (getOwner(this).lookup('controller:application').date !== null){
-      this.highlightQuery(getOwner(this).lookup('controller:application').date);
+        Ember.$("#chrono-table li").mousedown(function () {
+            isMouseDown = true;
+            Ember.$(this).toggleClass("highlighted");
+            isHighlighted = Ember.$(this).hasClass("highlighted");
+            self.sendUpdate();
+            return false; // prevent text selection
+        }).mouseover(function () {
+            if (isMouseDown) {
+                Ember.$(this).toggleClass("highlighted", isHighlighted);
+                self.sendUpdate();
+            }
+        }).bind("selectstart", function () {
+            return false;
+        });
+
+        Ember.$(document).mouseup(function () {
+            isMouseDown = false;
+        });
+    },
+
+    sendUpdate: function(){
+        var dateQuery = [];
+        Ember.$('.highlighted').map(function(index, elt) {
+            dateQuery.push(parseInt(Ember.$(elt).parent().attr('id')) + parseInt(Ember.$(elt).html()));
+        });
+        this.sendAction('action', dateQuery);
+    },
+
+    highlightQuery: function(list){
+        list.map(function(elt){
+            var year = Math.floor(parseInt(elt)/10)*10;
+            Ember.$("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true);
+        });
     }
 
-    var isMouseDown = false,
-      isHighlighted;
-    Ember.$("#chrono-table li").mousedown(function () {
-      isMouseDown = true;
-      Ember.$(this).toggleClass("highlighted");
-      isHighlighted = Ember.$(this).hasClass("highlighted");
-      _this.sendUpdate();
-      return false; // prevent text selection
-    }).mouseover(function () {
-      if (isMouseDown) {
-        Ember.$(this).toggleClass("highlighted", isHighlighted);
-        _this.sendUpdate();
-      }
-    }).bind("selectstart", function () {
-      return false;
-    });
-
-    Ember.$(document).mouseup(function () {
-      isMouseDown = false;
-    });
-  },
-  sendUpdate: function(){
-    var dateQuery = [];
-    Ember.$('.highlighted').map(function(index, elt) {
-      dateQuery.push(parseInt(Ember.$(elt).parent().attr('id')) + parseInt(Ember.$(elt).html()));
-    });
-    this.sendAction('action', dateQuery);
-  },
-  highlightQuery: function(list){
-    list.map(function(elt){
-      var year = Math.floor(parseInt(elt)/10)*10;
-      Ember.$("#"+year+" ."+(parseInt(elt)-year)).toggleClass("highlighted", true);
-    });
-  }
 });
--- a/cms/app-client/app/controllers/application.js	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/controllers/application.js	Tue Jun 14 18:15:26 2016 +0200
@@ -9,6 +9,25 @@
   thematique: null,
   detail: null,
 
+  dateIntervals: Ember.computed('date', function() {
+    var intervals = [];
+
+    this.get('date').forEach(function(date) {
+      var intervalDate = false;
+
+      intervals.forEach(function(interval) {
+        if(interval.length && (interval.includes(date + 1) || interval.includes(date - 1))) {
+          interval.push(date);
+          intervalDate = true;
+        }
+      });
+
+      if (!intervalDate) { intervals.push([date]); }
+    });
+
+    return intervals;
+  }),
+
   currentId: null,
   currentItem: Ember.computed('currentId', function() {
     Ember.$(".result-item").toggleClass("playing", false);
@@ -53,21 +72,24 @@
     }
     return documents;
   }),
+
   actions: {
-    deleteTag: function(query, item){
-      var newParams = null;
+
+    deleteTag: function(key, value){
+      var newValue = null;
 
-      if (query === 'date'){
-        newParams = [];
-        Ember.$.each(this.get('date'), function(index, elt){
-          if (elt !== item){
-            newParams.push(elt);
+      if (key === 'date'){
+        newValue = [];
+        Ember.$.each(this.get('date'), function(index, date){
+          if(!value.includes(date)) {
+            newValue.push(date);
           }
         });
       }
 
-      this.set(query, newParams);
+      this.set(key, newValue);
     },
+
     changeDocument: function(docDirection){
       var direction = (docDirection === "next") ? 1 : -1;
       var currentObject = this.get("filteredDocuments").findBy('id', this.get("currentItem").get('id'));
--- a/cms/app-client/app/controllers/tabs/chrono.js	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/controllers/tabs/chrono.js	Tue Jun 14 18:15:26 2016 +0200
@@ -1,6 +1,7 @@
 import Ember from 'ember';
 
 export default Ember.Controller.extend({
+
   actions: {
     updateUrl: function(selection){
       this.transitionToRoute({queryParams: {date: selection}});
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cms/app-client/app/helpers/interval.js	Tue Jun 14 18:15:26 2016 +0200
@@ -0,0 +1,8 @@
+import Ember from 'ember';
+
+export function interval(params) {
+    var dates = params[0].slice();
+    return dates.shift() + ( dates.length ? '-' + dates.pop() : '' );
+}
+
+export default Ember.Helper.helper(interval);
--- a/cms/app-client/app/routes/tabs/chrono.js	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/routes/tabs/chrono.js	Tue Jun 14 18:15:26 2016 +0200
@@ -1,9 +1,11 @@
 import Ember from 'ember';
 
 export default Ember.Route.extend({
-  actions: {
-    queryParamsDidChange: function() {
-      console.log("chrono params");
-    },
-  }
+
+    actions: {
+        queryParamsDidChange: function() {
+            console.log('chrono params');
+        },
+    }
+
 });
--- a/cms/app-client/app/templates/results.hbs	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/templates/results.hbs	Tue Jun 14 18:15:26 2016 +0200
@@ -10,9 +10,9 @@
     {{#if discours}}
       <span class="filters discours">{{discours}}<span class="fa fa-times" {{action 'deleteTag' 'discours'}}></span></span>
     {{/if}}
-    {{#if date}}
-      {{#each date as |item| }}
-        <span class="filters date">{{item}}<span class="fa fa-times" {{action 'deleteTag' 'date' item }}></span></span>
+    {{#if dateIntervals}}
+      {{#each dateIntervals as |item| }}
+        <span class="filters date" data-dates="{{item}}">{{interval item}}<span class="fa fa-times" {{action 'deleteTag' 'date' item }}></span></span>
       {{/each}}
     {{/if}}
     {{#if thematique}}
@@ -20,6 +20,7 @@
     {{/if}}
   </p>
 </div>
+
 <div class='result-list'>
   {{#each filteredDocuments as |item| }}
     <div id="{{item.id}}" {{action "showMore" item}} class='result-item'>
--- a/cms/app-client/app/templates/tabs/chrono.hbs	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/templates/tabs/chrono.hbs	Tue Jun 14 18:15:26 2016 +0200
@@ -1,2 +1,2 @@
 <h2>Selectionnez une date:</h2>
-{{visu-chrono action="updateUrl" query=model}}
+{{visu-chrono action="updateUrl"}}
--- a/cms/app-client/app/templates/tabs/langues.hbs	Sun Jun 12 22:53:25 2016 +0200
+++ b/cms/app-client/app/templates/tabs/langues.hbs	Tue Jun 14 18:15:26 2016 +0200
@@ -1,1 +1,1 @@
-{{visu-langues query=model setQueryParameters=( action 'transitionTo' ) }}
+{{visu-langues setQueryParameters=( action 'transitionTo' ) }}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cms/app-client/tests/unit/helpers/interval-test.js	Tue Jun 14 18:15:26 2016 +0200
@@ -0,0 +1,10 @@
+import { interval } from 'app-client/helpers/interval';
+import { module, test } from 'qunit';
+
+module('Unit | Helper | interval');
+
+// Replace this with your real tests.
+test('it works', function(assert) {
+  let result = interval([42]);
+  assert.ok(result);
+});