]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.component.ts
Lazy load static objects
[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 { map, switchMap } from 'rxjs/operators'
9 import { ServerConfig } 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 hardwareInformation: ''
28 }
29
30 creationReason = ''
31 maintenanceLifetime = ''
32 businessModel = ''
33
34 languages: string[] = []
35 categories: string[] = []
36
37 serverConfig: ServerConfig
38
39 constructor (
40 private notifier: Notifier,
41 private serverService: ServerService,
42 private instanceService: InstanceService,
43 private markdownService: MarkdownService,
44 private i18n: I18n
45 ) {}
46
47 get instanceName () {
48 return this.serverConfig.instance.name
49 }
50
51 get isContactFormEnabled () {
52 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
53 }
54
55 get isNSFW () {
56 return this.serverConfig.instance.isNSFW
57 }
58
59 ngOnInit () {
60 this.serverConfig = this.serverService.getTmpConfig()
61 this.serverService.getConfig()
62 .subscribe(config => this.serverConfig = config)
63
64 this.instanceService.getAbout()
65 .pipe(
66 switchMap(about => {
67 return forkJoin([
68 this.instanceService.buildTranslatedLanguages(about),
69 this.instanceService.buildTranslatedCategories(about)
70 ]).pipe(map(([ languages, categories ]) => ({ about, languages, categories })))
71 })
72 ).subscribe(
73 async ({ about, languages, categories }) => {
74 this.languages = languages
75 this.categories = categories
76
77 this.shortDescription = about.instance.shortDescription
78
79 this.creationReason = about.instance.creationReason
80 this.maintenanceLifetime = about.instance.maintenanceLifetime
81 this.businessModel = about.instance.businessModel
82
83 this.html = await this.instanceService.buildHtml(about)
84 },
85
86 () => this.notifier.error(this.i18n('Cannot get about information from server'))
87 )
88 }
89
90 openContactModal () {
91 return this.contactAdminModal.show()
92 }
93 }