# HG changeset patch # User Chloe Laisne # Date 1465920926 -7200 # Node ID 21b30ee231918573829b68a5973b3f695fc3d56b # Parent d2cb391559979c8aa4da911270a1f66c2d431947 /langue endpoint: 1. Date interval 2. Delete date diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/components/visu-chrono.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); - }); - } }); diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/controllers/application.js --- 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')); diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/controllers/tabs/chrono.js --- 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}}); diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/helpers/interval.js --- /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); diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/routes/tabs/chrono.js --- 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'); + }, + } + }); diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/templates/results.hbs --- 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}} {{discours}} {{/if}} - {{#if date}} - {{#each date as |item| }} - {{item}} + {{#if dateIntervals}} + {{#each dateIntervals as |item| }} + {{interval item}} {{/each}} {{/if}} {{#if thematique}} @@ -20,6 +20,7 @@ {{/if}}

+
{{#each filteredDocuments as |item| }}
diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/templates/tabs/chrono.hbs --- 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 @@

Selectionnez une date:

-{{visu-chrono action="updateUrl" query=model}} +{{visu-chrono action="updateUrl"}} diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/app/templates/tabs/langues.hbs --- 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' ) }} diff -r d2cb39155997 -r 21b30ee23191 cms/app-client/tests/unit/helpers/interval-test.js --- /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); +});