cms/app-client/app/components/visu-chrono.js
author ymh <ymh.work@gmail.com>
Fri, 04 Nov 2016 19:03:25 +0100
changeset 392 4fbe94af93e8
parent 234 c928f6190771
child 393 5ef3bfef0bff
permissions -rw-r--r--
Improve filter service. Centralize filter management in a single point
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48
9ef0952033e0 add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     1
import Ember from 'ember';
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
     2
import _ from 'lodash/lodash';
48
9ef0952033e0 add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
     3
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
     4
export default Ember.Component.extend({
120
e5e15547ffb1 correct deprecation warning
ymh <ymh.work@gmail.com>
parents: 98
diff changeset
     5
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
     6
    range: [],
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
     7
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
     8
    decades: Ember.computed('range', function() {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
     9
        var range = this.get('range');
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    10
        return _.range(Math.floor(range[0]/10)*10, Math.floor(range[1]/10)*10, 10);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    11
    }),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    12
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
    13
    filter: Ember.inject.service(),
189
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    14
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    15
    dateObserver: Ember.observer('date', function() {
202
0446e07981db Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    16
        var self = this;
0446e07981db Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    17
        this.$('li').removeClass('highlighted');
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    18
        this.get('date').forEach(function(date) {
202
0446e07981db Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    19
            self.$('li#' + date).addClass('highlighted');
0446e07981db Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    20
        });
0446e07981db Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    21
    }),
0446e07981db Add interval to filter component
Chloe Laisne <chloe.laisne@gmail.com>
parents: 197
diff changeset
    22
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    23
    date: Ember.computed('filter.date', {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    24
        get: function() {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    25
            const dates = this.get('filter').get('date');
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    26
            console.log("get DATES", dates);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    27
            if(dates === null) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    28
                return [];
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    29
            }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    30
            const res = _.reduce(dates, function(res, d) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    31
                let m = d.match(/^(\d+)(?:-(\d+))?$/);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    32
                if(m) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    33
                    let start = parseInt(m[1]);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    34
                    let end = parseInt(m[2]);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    35
                    if(isNaN(end)) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    36
                        res.push(parseInt(m[1]));
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    37
                    } else {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    38
                        res = res.concat(_.range(start,end+1));
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    39
                    }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    40
                }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    41
                return res;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    42
            }, []).sort();
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    43
            console.log("GET DATE", res);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    44
            return res;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    45
        },
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    46
        set: function(key, values) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    47
            var srcDateList = _.clone(values).sort();
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    48
            let start = null;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    49
            let end = null;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    50
            var pushValues = function(s,e,valuesList) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    51
                if(s === e) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    52
                    valuesList.push(s.toString());
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    53
                } else {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    54
                    valuesList.push(s.toString()+"-"+e.toString());
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    55
                }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    56
            };
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    57
            let dateList = _.reduce(srcDateList, function(res, d, i) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    58
                if(start === null) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    59
                    start = end = d;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    60
                }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    61
                if(d > (end + 1)) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    62
                    pushValues(start, end, res);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    63
                    start = end = d;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    64
                } else {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    65
                    end = d;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    66
                }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    67
                if(i === (srcDateList.length - 1)) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    68
                    pushValues(start, end, res);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    69
                }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    70
                return res;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    71
          }, []);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    72
          console.log("SET DATE",key, values, dateList);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    73
          if(dateList.length === 0) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    74
              dateList = null;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    75
          }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    76
          this.get('filter').set('date', dateList);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    77
          return srcDateList;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    78
      }
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    79
    }),
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    80
195
9d083636bd99 Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    81
    elementId: "chrono-table",
9d083636bd99 Layout and style of the /chronologie endpoint
Chloe Laisne <chloe.laisne@gmail.com>
parents: 189
diff changeset
    82
189
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    83
    didInsertElement: function(){
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    84
        var self = this;
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    85
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    86
        if (this.get('date') !== null){
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    87
            this.highlightQuery(this.get('date'));
189
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    88
        }
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    89
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
    90
        var isMouseDown = false,
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    91
            isHighlighted,
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    92
            didHighlight,
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    93
            previousElement;
77
0889740f79c2 on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents: 72
diff changeset
    94
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    95
        Ember.$("#chrono-table li").mousedown(function (event) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    96
            // Prevent right click selection.
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    97
            if(event.button === 0) {
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
    98
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
    99
                isMouseDown = true;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   100
                var element = parseInt(Ember.$(this).attr('id'));
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   101
                var elements = [element];
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   102
                if(event.shiftKey) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   103
                    while(previousElement !== element) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   104
                        elements.push(previousElement);
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   105
                        if(previousElement < element) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   106
                            previousElement = previousElement + 1;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   107
                        } else if(previousElement > element) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   108
                            previousElement = previousElement - 1;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   109
                        } else {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   110
                            break;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   111
                        }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   112
                    }
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   113
                }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   114
                var dates = self.get('date');
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   115
                var index = dates.indexOf(element);
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   116
                if((!event.shiftKey && index === -1) || (event.shiftKey && didHighlight)) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   117
                    dates = dates.concat(elements);
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   118
                    isHighlighted = true;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   119
                } else {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   120
                    elements.forEach(function(el) {
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   121
                        var id = dates.indexOf(el);
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   122
                        if((!event.shiftKey && index !== -1) || (event.shiftKey && id !== -1)) {
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   123
                            dates.splice(id, 1);
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   124
                        }
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   125
                    });
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   126
                    isHighlighted = false;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   127
                }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   128
                self.set('date', dates);
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   129
                didHighlight = isHighlighted;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   130
                previousElement = element;
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   131
                // Prevent text selection.
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   132
                return false;
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   133
            }
189
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   134
        }).mouseover(function () {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   135
            if (isMouseDown) {
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   136
                var element = parseInt(Ember.$(this).attr('id'));
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   137
                if(Ember.$(this).hasClass("highlighted") !== isHighlighted) {
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   138
                    var dates = self.get('date');
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   139
                    var index = dates.indexOf(element);
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   140
                    if(index === -1) {
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   141
                        dates.push(element);
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   142
                    } else {
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   143
                        dates.splice(index, 1);
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   144
                    }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   145
                    self.set('date', dates);
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   146
                }
233
0ff47a9c5da2 Keyboard events on chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 202
diff changeset
   147
                previousElement = element;
189
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   148
            }
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   149
        }).bind("selectstart", function () {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   150
            return false;
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   151
        });
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   152
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   153
        Ember.$(document).mouseup(function () {
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   154
            isMouseDown = false;
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   155
        });
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   156
    },
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   157
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   158
    highlightQuery: function(dates){
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   159
        console.log("highlightQuery", dates);
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   160
        if(dates === null) {
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   161
            return;
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   162
        }
197
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   163
        dates.map(function(date){
7b266ccf6d3d Setup filter service
Chloe Laisne <chloe.laisne@gmail.com>
parents: 195
diff changeset
   164
            Ember.$("#" + date).toggleClass("highlighted", true);
189
21b30ee23191 /langue endpoint: 1. Date interval 2. Delete date
Chloe Laisne <chloe.laisne@gmail.com>
parents: 120
diff changeset
   165
        });
234
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   166
    },
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   167
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   168
    actions : {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   169
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   170
        selectDecade: function(decade) {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   171
            var array = [];
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   172
            var next = decade + 10;
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   173
            var dates = this.get('date');
234
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   174
            while(decade < next) {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   175
                array.push(decade);
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   176
                decade ++;
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   177
            }
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   178
            if(array.find(function(date){ return dates.indexOf(date) === -1; })) {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   179
                array = array.filter(function(value) {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   180
                    return dates.indexOf(value) === -1;
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   181
                });
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   182
                array = dates.concat(array);
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   183
            } else {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   184
                array = dates.filter(function(value) {
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   185
                    return array.indexOf(value) === -1;
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   186
                });
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   187
            }
392
4fbe94af93e8 Improve filter service. Centralize filter management in a single point
ymh <ymh.work@gmail.com>
parents: 234
diff changeset
   188
            this.set('date', array);
234
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   189
        }
c928f6190771 Select row in chronology
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
   190
77
0889740f79c2 on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents: 72
diff changeset
   191
    }
0889740f79c2 on page load, hilight the objects corresponding to the query params
nowmad@23.1.168.192.in-addr.arpa
parents: 72
diff changeset
   192
48
9ef0952033e0 add example of visualisation for "chonologie"
nowmad@nowmads-macbook-pro.local
parents:
diff changeset
   193
});