]>
Commit | Line | Data |
---|---|---|
22a16e36 C |
1 | import { Component, OnInit } from '@angular/core' |
2 | import { NotificationsService } from 'angular2-notifications' | |
3 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
4 | import { I18n } from '@ngx-translate/i18n-polyfill' | |
5 | import { UserSubscriptionService } from '@app/shared/user-subscription' | |
aa55a4da | 6 | import { ComponentPagination } from '@app/shared/rest/component-pagination.model' |
22a16e36 C |
7 | |
8 | @Component({ | |
9 | selector: 'my-account-subscriptions', | |
10 | templateUrl: './my-account-subscriptions.component.html', | |
11 | styleUrls: [ './my-account-subscriptions.component.scss' ] | |
12 | }) | |
13 | export class MyAccountSubscriptionsComponent implements OnInit { | |
14 | videoChannels: VideoChannel[] = [] | |
15 | ||
aa55a4da C |
16 | pagination: ComponentPagination = { |
17 | currentPage: 1, | |
18 | itemsPerPage: 10, | |
19 | totalItems: null | |
20 | } | |
21 | ||
22a16e36 C |
22 | constructor ( |
23 | private userSubscriptionService: UserSubscriptionService, | |
24 | private notificationsService: NotificationsService, | |
25 | private i18n: I18n | |
26 | ) {} | |
27 | ||
28 | ngOnInit () { | |
aa55a4da C |
29 | this.loadSubscriptions() |
30 | } | |
31 | ||
32 | loadSubscriptions () { | |
33 | this.userSubscriptionService.listSubscriptions(this.pagination) | |
34 | .subscribe( | |
35 | res => { | |
36 | this.videoChannels = this.videoChannels.concat(res.data) | |
37 | this.pagination.totalItems = res.total | |
38 | }, | |
39 | ||
40 | error => this.notificationsService.error(this.i18n('Error'), error.message) | |
41 | ) | |
42 | } | |
43 | ||
44 | onNearOfBottom () { | |
45 | // Last page | |
46 | if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return | |
22a16e36 | 47 | |
aa55a4da C |
48 | this.pagination.currentPage += 1 |
49 | this.loadSubscriptions() | |
22a16e36 C |
50 | } |
51 | ||
52 | } |