]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.component.ts
Add categories and languages to about page
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
1 import { Component, OnInit, ViewChild } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { I18n } from '@ngx-translate/i18n-polyfill'
4 import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component'
5 import { InstanceService } from '@app/shared/instance/instance.service'
6 import { MarkdownService } from '@app/shared/renderer'
7 import { forkJoin } from 'rxjs'
8 import { first } from 'rxjs/operators'
9 import { peertubeTranslate } from '@shared/models'
10
11 @Component({
12 selector: 'my-about-instance',
13 templateUrl: './about-instance.component.html',
14 styleUrls: [ './about-instance.component.scss' ]
15 })
16 export class AboutInstanceComponent implements OnInit {
17 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
18
19 shortDescription = ''
20
21 html = {
22 description: '',
23 terms: '',
24 codeOfConduct: '',
25 moderationInformation: '',
26 administrator: ''
27 }
28
29 maintenanceLifetime = ''
30 businessModel = ''
31
32 languages: string[] = []
33 categories: string[] = []
34
35 constructor (
36 private notifier: Notifier,
37 private serverService: ServerService,
38 private instanceService: InstanceService,
39 private markdownService: MarkdownService,
40 private i18n: I18n
41 ) {}
42
43 get instanceName () {
44 return this.serverService.getConfig().instance.name
45 }
46
47 get isContactFormEnabled () {
48 return this.serverService.getConfig().email.enabled && this.serverService.getConfig().contactForm.enabled
49 }
50
51 get isNSFW () {
52 return this.serverService.getConfig().instance.isNSFW
53 }
54
55 ngOnInit () {
56 forkJoin([
57 this.instanceService.getAbout(),
58 this.serverService.localeObservable.pipe(first()),
59 this.serverService.videoLanguagesLoaded.pipe(first()),
60 this.serverService.videoCategoriesLoaded.pipe(first())
61 ]).subscribe(
62 async ([ res, translations ]) => {
63 this.shortDescription = res.instance.shortDescription
64
65 this.maintenanceLifetime = res.instance.maintenanceLifetime
66 this.businessModel = res.instance.businessModel
67
68 for (const key of [ 'description', 'terms', 'codeOfConduct', 'moderationInformation', 'administrator' ]) {
69 this.html[ key ] = await this.markdownService.textMarkdownToHTML(res.instance[ key ])
70 }
71
72 const languagesArray = this.serverService.getVideoLanguages()
73 const categoriesArray = this.serverService.getVideoCategories()
74
75 this.languages = res.instance.languages
76 .map(l => {
77 const languageObj = languagesArray.find(la => la.id === l)
78
79 return peertubeTranslate(languageObj.label, translations)
80 })
81
82 this.categories = res.instance.categories
83 .map(c => {
84 const categoryObj = categoriesArray.find(ca => ca.id === c)
85
86 return peertubeTranslate(categoryObj.label, translations)
87 })
88 },
89
90 () => this.notifier.error(this.i18n('Cannot get about information from server'))
91 )
92 }
93
94 openContactModal () {
95 return this.contactAdminModal.show()
96 }
97 }