cms/app-client/app/components/notice-component.js
author ymh <ymh.work@gmail.com>
Wed, 22 Feb 2017 07:57:05 +0100
changeset 519 ef3e4841d506
parent 513 dad9471f0d63
child 529 5d9eacbd5794
permissions -rw-r--r--
Correct bug #0026428 - in notice filter on creation date for period
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
519
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
     2
import * as commonUtils from 'corpus-common-addon/utils/utils';
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
     3
import _ from 'lodash/lodash';
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     4
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     5
export default Ember.Component.extend({
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     6
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     7
    player: Ember.inject.service(),
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
     8
    filter: Ember.inject.service(),
502
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
     9
    constants: Ember.inject.service(),
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    10
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    11
    classNames: ['notice-component'],
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    12
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    13
    item: Ember.computed('model', 'player.model', function() {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    14
        return this.get('model') || this.get('player').get('model');
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    15
    }),
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    16
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    17
    participants: Ember.computed('item.contributors', function() {
447
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    18
        let participants = [];
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    19
        const contributors = this.get('item.contributors') || [];
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    20
        let identifier;
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    21
        contributors.forEach(function(contributor) {
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    22
          identifier = contributor.name || contributor.url;
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    23
          var participant = participants.find(participant => participant.identifier === identifier);
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    24
          if(participant) {
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    25
              participant['role'].push(contributor.role.split('/').pop());
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    26
          } else {
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    27
              participants.push({ identifier: identifier, role: [ contributor.role.split('/').pop() ] });
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    28
          }
38d5789e30d0 Improce notice data display, correct m3.23
ymh <ymh.work@gmail.com>
parents: 446
diff changeset
    29
        });
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    30
        return participants;
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    31
    }),
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    32
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    33
    location: Ember.computed('item.geoInfo', function() {
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    34
        var location = '';
228
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    35
        if(this.get('item')) {
a2497a2b6224 Notice display logic and design
Chloe Laisne <chloe.laisne@gmail.com>
parents: 217
diff changeset
    36
            var meta = this.get('item').get('geoInfo').notes.find(element => element.lang);
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    37
            if(meta) {
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    38
                location = meta.value;
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    39
            }
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    40
        }
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    41
        return location;
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    42
    }),
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    43
502
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    44
    noticeCocoonPurlUrl: Ember.computed('item', function() {
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    45
      const item = this.get('item');
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    46
      return this.get('constants').COCOON_PURL_BASE_URL + item.get('cocoonId');
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    47
    }),
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    48
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    49
    actions: {
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    50
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    51
        addThemeFilter: function(id) {
446
2a93eb9f38f5 pb m3.22 - set correct filter when clicking on subject and language in notice
ymh <ymh.work@gmail.com>
parents: 338
diff changeset
    52
            this.get('filter').setFilter('theme', id);
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    53
        },
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    54
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    55
        addLanguageFilter: function(id) {
446
2a93eb9f38f5 pb m3.22 - set correct filter when clicking on subject and language in notice
ymh <ymh.work@gmail.com>
parents: 338
diff changeset
    56
            this.get('filter').setFilter('language', id);
502
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    57
        },
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    58
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    59
        addTypeFilter: function(id) {
74fba571487e Complete the notice display. add various fields to document to correctly display the notice. Correct bug #0025746
ymh <ymh.work@gmail.com>
parents: 447
diff changeset
    60
            this.get('filter').setFilter('theme', id);
513
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 502
diff changeset
    61
        },
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 502
diff changeset
    62
dad9471f0d63 add filter on created date in notice
ymh <ymh.work@gmail.com>
parents: 502
diff changeset
    63
        addCreatedFilter: function(dateStr) {
519
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    64
          const filter = this.get('filter');
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    65
          console.log("DATE LIST", this.get('filter').get('date'));
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    66
          console.log("DATE STR", dateStr);
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    67
          if(!dateStr) {
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    68
            return;
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    69
          }
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    70
          const oldDateList = filter.get('dateList');
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    71
          let newDateList = [];
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    72
          const periodMatches = commonUtils.getPeriodMatches(dateStr);
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    73
          if(periodMatches) {
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    74
            newDateList = _.range(periodMatches.start.date.getFullYear(), periodMatches.end.date.getFullYear()+1);
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    75
          } else {
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    76
            const date = new Date(dateStr);
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    77
            if (!isNaN(date.getTime())) {
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    78
              newDateList = [ date.getFullYear() ];
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    79
            }
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    80
          }
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    81
          if(newDateList.length > 0) {
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    82
            filter.set('dateList', _.union(oldDateList, newDateList));
ef3e4841d506 Correct bug #0026428 - in notice filter on creation date for period
ymh <ymh.work@gmail.com>
parents: 513
diff changeset
    83
          }
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    84
        }
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 335
diff changeset
    85
    }
217
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    86
989b9c36b849 Toolbar and Notice component styles
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
    87
});