cms/app-client/app/components/playlist-component.js
author ymh <ymh.work@gmail.com>
Fri, 09 Dec 2016 11:41:15 +0100
changeset 467 762fc0eb4946
parent 462 ebd8269781fa
permissions -rw-r--r--
Migrate d3js to v4 and correct d3js visualisations i.e. bug 3.20. Breadcrumb navigation for the language treemap has been improved
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     1
import Ember from 'ember';
415
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
     2
import SocialShareKit from 'socialsharekit';
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     3
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     4
export default Ember.Component.extend({
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
     5
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
     6
    classNames: ['playlist-component'],
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
     7
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
     8
    filter: Ember.inject.service(),
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
     9
    player: Ember.inject.service(),
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    10
404
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 347
diff changeset
    11
    isLoading: false,
0a5eef6ad2fe correction, change colors for discourse categories, add loding spinner
ymh <ymh.work@gmail.com>
parents: 347
diff changeset
    12
344
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    13
    model: [],
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    14
    documents: Ember.computed('model', 'filter.location', 'filter.language', 'filter.discourse', 'filter.date', 'filter.theme', function() {
317
e653de66f252 Remove document filtering in playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 301
diff changeset
    15
        return this.get('model');
200
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    16
    }),
a441c40f9c5e Fix playlist filtering
Chloe Laisne <chloe.laisne@gmail.com>
parents: 196
diff changeset
    17
215
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    18
    documentsLoaded: Ember.observer('documents', function() {
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    19
        this.get('player').set('items', this.get('documents').map(function(document) {
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    20
            return document.get('id');
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    21
        }));
240
aa101458cd4e Player forward and backward
Chloe Laisne <chloe.laisne@gmail.com>
parents: 233
diff changeset
    22
        if(this.get('player').get('items').length && this.get('player').get('playing') === false) {
347
9779512454af Correct jslint errors
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    23
            this.get('player').set('item', this.get('player').get('items')[0]);
216
c174124d1849 /discours and /chrono design changes
Chloe Laisne <chloe.laisne@gmail.com>
parents: 215
diff changeset
    24
        }
215
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    25
    }).on('init'),
82878d132784 Play/Pause/Reset events from player/playlist-components
Chloe Laisne <chloe.laisne@gmail.com>
parents: 212
diff changeset
    26
336
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    27
    playerItemObserver: Ember.observer('player.item', function() {
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    28
        if(this.$() && this.get('player').get('item')) {
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    29
            var ul = this.$().find('ul');
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    30
            var li = this.$().find('li#' + this.get('player').get('item').replace('.', '\\.').replace('/', '\\/'));
344
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    31
            if(li.length) {
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    32
                if(li.offset().top - ul.offset().top < 0) {
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    33
                    ul.animate({
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    34
                        'scrollTop': ul.scrollTop() + li.offset().top - ul.offset().top
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    35
                    });
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    36
                } else if(li.offset().top + li.outerHeight() - ul.offset().top > ul.outerHeight()) {
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    37
                    ul.animate({
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    38
                        'scrollTop': ul.scrollTop() + li.offset().top  + li.outerHeight() - ul.offset().top  - ul.height()
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    39
                    });
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    40
                }
336
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    41
            }
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    42
        }
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    43
    }),
f076ddd29e13 Playlist scroll to show playing track in view always
Chloe Laisne <chloe.laisne@gmail.com>
parents: 317
diff changeset
    44
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    45
    didRender: function() {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    46
        this._super(...arguments);
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    47
        this.$().find('ul').height(Ember.$('.corpus-app-wrapper').outerHeight() - (Ember.$('.filter-component').outerHeight() + this.$().find('h2').outerHeight()));
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    48
    },
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    49
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    50
    actions: {
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
    51
344
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    52
        previous: function() {
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    53
            this.sendAction('pageAction', 'previous');
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    54
        },
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    55
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    56
        next: function() {
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    57
            this.sendAction('pageAction', 'next');
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    58
        },
70451a4dc9ae Pagination playlist
Chloe Laisne <chloe.laisne@gmail.com>
parents: 342
diff changeset
    59
252
ba4fd614582a Load player with selected row
Chloe Laisne <chloe.laisne@gmail.com>
parents: 251
diff changeset
    60
        select: function(id) {
ba4fd614582a Load player with selected row
Chloe Laisne <chloe.laisne@gmail.com>
parents: 251
diff changeset
    61
            this.get('player').select(id);
342
9375b692ff22 Display transcript by default
Chloe Laisne <chloe.laisne@gmail.com>
parents: 338
diff changeset
    62
            this.get('player').displayMetadata('notice');
252
ba4fd614582a Load player with selected row
Chloe Laisne <chloe.laisne@gmail.com>
parents: 251
diff changeset
    63
        },
ba4fd614582a Load player with selected row
Chloe Laisne <chloe.laisne@gmail.com>
parents: 251
diff changeset
    64
249
e4204b1a579a Quickfix micro-cuts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    65
        play: function(id) {
e4204b1a579a Quickfix micro-cuts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    66
            this.get('player').play(id);
e4204b1a579a Quickfix micro-cuts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    67
        },
e4204b1a579a Quickfix micro-cuts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    68
257
eba9edbd8f46 Add title to annotation
Chloe Laisne <chloe.laisne@gmail.com>
parents: 254
diff changeset
    69
        pause: function() {
249
e4204b1a579a Quickfix micro-cuts
Chloe Laisne <chloe.laisne@gmail.com>
parents: 240
diff changeset
    70
            this.get('player').pause();
227
5c9250f55f4b Basic notice logic from query parameters
Chloe Laisne <chloe.laisne@gmail.com>
parents: 216
diff changeset
    71
        },
5c9250f55f4b Basic notice logic from query parameters
Chloe Laisne <chloe.laisne@gmail.com>
parents: 216
diff changeset
    72
301
29b425234094 Transcript icon in tool container + Toggle transcript action on click
Chloe Laisne <chloe.laisne@gmail.com>
parents: 257
diff changeset
    73
        displayTranscript: function() {
462
ebd8269781fa support transcript in pdf
ymh <ymh.work@gmail.com>
parents: 459
diff changeset
    74
            this.get('player').set('transcriptLoading', (this.get('player.window') !== 'transcript') && !this.get("player.transcriptIframe"));
459
6a296e92887f add a spinner when opening a transcript
ymh <ymh.work@gmail.com>
parents: 434
diff changeset
    75
6a296e92887f add a spinner when opening a transcript
ymh <ymh.work@gmail.com>
parents: 434
diff changeset
    76
            Ember.run.later(() => { this.get('player').displayAdditionalInformation('transcript'); }, 10);
301
29b425234094 Transcript icon in tool container + Toggle transcript action on click
Chloe Laisne <chloe.laisne@gmail.com>
parents: 257
diff changeset
    77
        },
29b425234094 Transcript icon in tool container + Toggle transcript action on click
Chloe Laisne <chloe.laisne@gmail.com>
parents: 257
diff changeset
    78
347
9779512454af Correct jslint errors
ymh <ymh.work@gmail.com>
parents: 344
diff changeset
    79
        displayNotice: function() {
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 336
diff changeset
    80
            if(this.get('player').get('window') !== 'notice') {
254
a7cf2887e993 Hide/Show video CSS
Chloe Laisne <chloe.laisne@gmail.com>
parents: 252
diff changeset
    81
                this.get('player').displayMetadata('notice');
227
5c9250f55f4b Basic notice logic from query parameters
Chloe Laisne <chloe.laisne@gmail.com>
parents: 216
diff changeset
    82
            } else {
338
4a3899b6a7ed Fix notice/transcript display when adding filter from notice, switching from playlist, toolbar, and player
Chloe Laisne <chloe.laisne@gmail.com>
parents: 336
diff changeset
    83
                this.get('player').displayMetadata(false);
227
5c9250f55f4b Basic notice logic from query parameters
Chloe Laisne <chloe.laisne@gmail.com>
parents: 216
diff changeset
    84
            }
415
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    85
        },
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    86
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    87
        shareLinkRender: (elemId) => {
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    88
            SocialShareKit.init({selector: "#"+elemId+" .ssk"});
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    89
            Ember.$("#"+elemId+" .playlist-share-button-close").click(function() {
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    90
                // This is done like this because I was not able to register an action directly on the button like shgown on ember-tooltips documentaion (https://github.com/sir-dunxalot/ember-tooltips#popover-on-element)
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    91
                Ember.$("#corpus-app").click();
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    92
            });
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    93
            return true;
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    94
        },
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    95
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    96
        shareLinkShow: (elemId) => {
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    97
            let input = Ember.$("#"+elemId+" input");
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    98
            input.get(0).setSelectionRange(0, input.val().length);
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
    99
            input.get(0).select(0, input.val().length);
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
   100
            return true;
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
   101
        },
0046797e0411 add share buttons
ymh <ymh.work@gmail.com>
parents: 404
diff changeset
   102
209
35cb7200bb0a Separate playlist and player component with player service as bridge
Chloe Laisne <chloe.laisne@gmail.com>
parents: 201
diff changeset
   103
    }
196
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
   104
7550cb541901 Filter as a service
Chloe Laisne <chloe.laisne@gmail.com>
parents:
diff changeset
   105
});