# HG changeset patch # User Chloe Laisne # Date 1476696030 -19800 # Node ID 70451a4dc9ae8385ee014c1b4e48135b2bb1cbc6 # Parent 3b2e76f5f3cac4819f5f5b45ad7667ed87d3b896 Pagination playlist diff -r 3b2e76f5f3ca -r 70451a4dc9ae cms/app-client/app/components/playlist-component.js --- a/cms/app-client/app/components/playlist-component.js Mon Oct 17 00:33:28 2016 +0530 +++ b/cms/app-client/app/components/playlist-component.js Mon Oct 17 14:50:30 2016 +0530 @@ -7,6 +7,7 @@ filter: Ember.inject.service(), player: Ember.inject.service(), + model: [], documents: Ember.computed('model', 'filter.location', 'filter.language', 'filter.discourse', 'filter.date', 'filter.theme', function() { return this.get('model'); }), @@ -24,22 +25,20 @@ if(this.$() && this.get('player').get('item')) { var ul = this.$().find('ul'); var li = this.$().find('li#' + this.get('player').get('item').replace('.', '\\.').replace('/', '\\/')); - if(li.offset().top - ul.offset().top < 0) { - ul.animate({ - 'scrollTop': ul.scrollTop() + li.offset().top - ul.offset().top - }); - } else if(li.offset().top + li.outerHeight() - ul.offset().top > ul.outerHeight()) { - ul.animate({ - 'scrollTop': ul.scrollTop() + li.offset().top + li.outerHeight() - ul.offset().top - ul.height() - }); + if(li.length) { + if(li.offset().top - ul.offset().top < 0) { + ul.animate({ + 'scrollTop': ul.scrollTop() + li.offset().top - ul.offset().top + }); + } else if(li.offset().top + li.outerHeight() - ul.offset().top > ul.outerHeight()) { + ul.animate({ + 'scrollTop': ul.scrollTop() + li.offset().top + li.outerHeight() - ul.offset().top - ul.height() + }); + } } } }), - init: function() { - this._super(...arguments); - }, - didRender: function() { this._super(...arguments); this.$().find('ul').height(Ember.$('.corpus-app-wrapper').outerHeight() - (Ember.$('.filter-component').outerHeight() + this.$().find('h2').outerHeight())); @@ -47,6 +46,14 @@ actions: { + previous: function() { + this.sendAction('pageAction', 'previous'); + }, + + next: function() { + this.sendAction('pageAction', 'next'); + }, + select: function(id) { this.get('player').select(id); this.get('player').displayMetadata('notice'); diff -r 3b2e76f5f3ca -r 70451a4dc9ae cms/app-client/app/components/visu-langues.js --- a/cms/app-client/app/components/visu-langues.js Mon Oct 17 00:33:28 2016 +0530 +++ b/cms/app-client/app/components/visu-langues.js Mon Oct 17 14:50:30 2016 +0530 @@ -47,6 +47,7 @@ }) .round(false); + console.log('width', width, Ember.$('#' + self.get('elementId')).parent().width(), Ember.$('#' + self.get('elementId')).parent().parent().width(), Ember.$('#' + self.get('elementId')).parent().parent().parent().width()); var element = d3.select('#' + self.get('elementId')) .style("width", width + margin.left + margin.right + 'px') .style("height", height + margin.bottom + margin.top + 'px') diff -r 3b2e76f5f3ca -r 70451a4dc9ae cms/app-client/app/routes/application.js --- a/cms/app-client/app/routes/application.js Mon Oct 17 00:33:28 2016 +0530 +++ b/cms/app-client/app/routes/application.js Mon Oct 17 14:50:30 2016 +0530 @@ -2,9 +2,25 @@ export default Ember.Route.extend({ - model: function() { - return this.store.findAll('document'); - }, + page: 1, + limit: 10, + + documents: [], + model: Ember.observer('page', function() { + var self = this; + var promise = this.store.query('document', { + page: this.get('page'), + perpage: this.get('limit') + }); + promise.then(function(value) { + if(self.controller) { + self.controller.set('page', self.get('page')); + self.controller.set('documents', self.get('documents')); + } + self.set('documents', value); + }); + return promise; + }), serializeQueryParam: function(value, urlKey) { if (urlKey === 'date') { @@ -13,6 +29,13 @@ return '' + value; }, + setupController: function(controller) { + this._super(...arguments); + controller.set('page', this.get('page')); + controller.set('limit', this.get('limit')); + controller.set('documents', this.get('documents')); + }, + deserializeQueryParam: function(value, urlKey) { if (urlKey === 'date') { var array = []; @@ -26,6 +49,18 @@ actions: { + setPageQueryparams: function(type) { + var page = this.get('page'); + if(type === 'previous') { + page = page - 1; + } else if(type === 'next') { + page = page + 1; + } + this.propertyWillChange('page'); + this.set('page', page); + this.propertyDidChange('page'); + }, + willTransition: function() { // Prevent navigation from removing query parameters var _this = this, diff -r 3b2e76f5f3ca -r 70451a4dc9ae cms/app-client/app/styles/components/playlist-component.scss --- a/cms/app-client/app/styles/components/playlist-component.scss Mon Oct 17 00:33:28 2016 +0530 +++ b/cms/app-client/app/styles/components/playlist-component.scss Mon Oct 17 14:50:30 2016 +0530 @@ -2,13 +2,40 @@ background-color: $dark-blue; } -.playlist-component h2 { +.playlist-component .header { line-height: 40px; + height: 40px; + width: 100%; text-transform: none; padding: 0px 15px; text-align: left; color: $light-white; font-size: 13px; + display: block; + margin: 0; + border: none; + box-sizing: border-box; +} + +.playlist-component .header h2 { + line-height: 40px; + color: $light-white; + font-size: 13px; + display: inline-block; +} + +.playlist-component .header .pagination { + float: right; +} + +.playlist-component .header .pagination .fa.disabled { + pointer-events: none; + opacity: 0.3; +} + +.playlist-component .header .pagination .span { + display: inline-block; + margin: 0 10px; } .playlist-component ul { diff -r 3b2e76f5f3ca -r 70451a4dc9ae cms/app-client/app/templates/application.hbs --- a/cms/app-client/app/templates/application.hbs Mon Oct 17 00:33:28 2016 +0530 +++ b/cms/app-client/app/templates/application.hbs Mon Oct 17 14:50:30 2016 +0530 @@ -19,7 +19,7 @@
{{ filter-component }} - {{ playlist-component notice=notice model=model }} + {{ playlist-component model=documents page=page limit=limit pageAction='setPageQueryparams' }}
\ No newline at end of file diff -r 3b2e76f5f3ca -r 70451a4dc9ae cms/app-client/app/templates/components/playlist-component.hbs --- a/cms/app-client/app/templates/components/playlist-component.hbs Mon Oct 17 00:33:28 2016 +0530 +++ b/cms/app-client/app/templates/components/playlist-component.hbs Mon Oct 17 14:50:30 2016 +0530 @@ -1,4 +1,11 @@ -

Résultat ({{ documents.length }})

+
+

Résultat ({{ model.meta.total }})

+ +