PeerTube/client/src/app/+my-account/my-account.component.ts

59 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-09-05 10:18:13 -05:00
import { Component, OnDestroy, OnInit } from '@angular/core'
2018-08-03 04:10:31 -05:00
import { ServerService } from '@app/core'
import { NavigationStart, Router } from '@angular/router'
import { filter } from 'rxjs/operators'
import { I18n } from '@ngx-translate/i18n-polyfill'
2018-09-05 10:18:13 -05:00
import { Subscription } from 'rxjs'
2018-04-23 09:16:05 -05:00
@Component({
2018-04-24 08:10:54 -05:00
selector: 'my-my-account',
templateUrl: './my-account.component.html',
styleUrls: [ './my-account.component.scss' ]
2018-04-23 09:16:05 -05:00
})
2018-09-05 10:18:13 -05:00
export class MyAccountComponent implements OnInit, OnDestroy {
libraryLabel = ''
2018-08-03 04:10:31 -05:00
2018-09-05 10:18:13 -05:00
private routeSub: Subscription
2018-08-03 04:10:31 -05:00
constructor (
private serverService: ServerService,
private router: Router,
private i18n: I18n
2018-08-03 04:10:31 -05:00
) {}
ngOnInit () {
this.updateLibraryLabel(this.router.url)
2018-09-05 10:18:13 -05:00
this.routeSub = this.router.events
.pipe(filter(event => event instanceof NavigationStart))
.subscribe((event: NavigationStart) => this.updateLibraryLabel(event.url))
}
2018-09-05 10:18:13 -05:00
ngOnDestroy () {
if (this.routeSub) this.routeSub.unsubscribe()
}
2018-08-03 04:10:31 -05:00
isVideoImportEnabled () {
2018-09-05 07:59:15 -05:00
const importConfig = this.serverService.getConfig().import.videos
return importConfig.http.enabled || importConfig.torrent.enabled
2018-08-03 04:10:31 -05:00
}
private updateLibraryLabel (url: string) {
const [ path ] = url.split('?')
2018-10-01 02:02:27 -05:00
if (path.startsWith('/my-account/video-channels')) {
this.libraryLabel = this.i18n('Channels')
2018-10-01 02:02:27 -05:00
} else if (path.startsWith('/my-account/videos')) {
this.libraryLabel = this.i18n('Videos')
2018-10-01 02:02:27 -05:00
} else if (path.startsWith('/my-account/subscriptions')) {
this.libraryLabel = this.i18n('Subscriptions')
2018-10-01 02:02:27 -05:00
} else if (path.startsWith('/my-account/video-imports')) {
this.libraryLabel = this.i18n('Video imports')
} else {
this.libraryLabel = ''
}
}
2018-08-03 04:10:31 -05:00
}