]>
Commit | Line | Data |
---|---|---|
d3e56c0c | 1 | import { Component, OnInit, ViewChild } from '@angular/core' |
f8b2c1b4 | 2 | import { Notifier, ServerService } from '@app/core' |
b1d40cff | 3 | import { I18n } from '@ngx-translate/i18n-polyfill' |
d3e56c0c C |
4 | import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component' |
5 | import { InstanceService } from '@app/shared/instance/instance.service' | |
1506307f | 6 | import { MarkdownService } from '@app/shared/renderer' |
4402b54d C |
7 | import { forkJoin } from 'rxjs' |
8 | import { first } from 'rxjs/operators' | |
9 | import { peertubeTranslate } from '@shared/models' | |
36f9424f C |
10 | |
11 | @Component({ | |
78f912ed C |
12 | selector: 'my-about-instance', |
13 | templateUrl: './about-instance.component.html', | |
14 | styleUrls: [ './about-instance.component.scss' ] | |
36f9424f | 15 | }) |
78f912ed | 16 | export class AboutInstanceComponent implements OnInit { |
f36da21e | 17 | @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent |
d3e56c0c | 18 | |
45c0fb35 | 19 | shortDescription = '' |
ccc00cb2 C |
20 | |
21 | html = { | |
22 | description: '', | |
23 | terms: '', | |
24 | codeOfConduct: '', | |
25 | moderationInformation: '', | |
26 | administrator: '' | |
27 | } | |
28 | ||
29 | maintenanceLifetime = '' | |
30 | businessModel = '' | |
31 | ||
32 | languages: string[] = [] | |
4402b54d | 33 | categories: string[] = [] |
36f9424f C |
34 | |
35 | constructor ( | |
f8b2c1b4 | 36 | private notifier: Notifier, |
36f9424f | 37 | private serverService: ServerService, |
d3e56c0c | 38 | private instanceService: InstanceService, |
b1d40cff C |
39 | private markdownService: MarkdownService, |
40 | private i18n: I18n | |
36f9424f C |
41 | ) {} |
42 | ||
43 | get instanceName () { | |
44 | return this.serverService.getConfig().instance.name | |
45 | } | |
46 | ||
d3e56c0c C |
47 | get isContactFormEnabled () { |
48 | return this.serverService.getConfig().email.enabled && this.serverService.getConfig().contactForm.enabled | |
49 | } | |
50 | ||
c8000975 C |
51 | get isNSFW () { |
52 | return this.serverService.getConfig().instance.isNSFW | |
53 | } | |
54 | ||
36f9424f | 55 | ngOnInit () { |
4402b54d C |
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 | ) | |
36f9424f C |
92 | } |
93 | ||
d3e56c0c C |
94 | openContactModal () { |
95 | return this.contactAdminModal.show() | |
96 | } | |
36f9424f | 97 | } |