]>
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 | 7 | import { forkJoin } from 'rxjs' |
ba430d75 C |
8 | import { map, switchMap } from 'rxjs/operators' |
9 | import { ServerConfig } 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: '', | |
be04c6fd C |
26 | administrator: '', |
27 | hardwareInformation: '' | |
ccc00cb2 C |
28 | } |
29 | ||
8ae03c37 | 30 | creationReason = '' |
ccc00cb2 C |
31 | maintenanceLifetime = '' |
32 | businessModel = '' | |
33 | ||
34 | languages: string[] = [] | |
4402b54d | 35 | categories: string[] = [] |
36f9424f | 36 | |
ba430d75 C |
37 | serverConfig: ServerConfig |
38 | ||
36f9424f | 39 | constructor ( |
f8b2c1b4 | 40 | private notifier: Notifier, |
36f9424f | 41 | private serverService: ServerService, |
d3e56c0c | 42 | private instanceService: InstanceService, |
b1d40cff C |
43 | private markdownService: MarkdownService, |
44 | private i18n: I18n | |
36f9424f C |
45 | ) {} |
46 | ||
47 | get instanceName () { | |
ba430d75 | 48 | return this.serverConfig.instance.name |
36f9424f C |
49 | } |
50 | ||
d3e56c0c | 51 | get isContactFormEnabled () { |
ba430d75 | 52 | return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled |
d3e56c0c C |
53 | } |
54 | ||
c8000975 | 55 | get isNSFW () { |
ba430d75 | 56 | return this.serverConfig.instance.isNSFW |
c8000975 C |
57 | } |
58 | ||
36f9424f | 59 | ngOnInit () { |
ba430d75 C |
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 | ||
421d935d | 77 | this.shortDescription = about.instance.shortDescription |
4402b54d | 78 | |
8ae03c37 | 79 | this.creationReason = about.instance.creationReason |
421d935d C |
80 | this.maintenanceLifetime = about.instance.maintenanceLifetime |
81 | this.businessModel = about.instance.businessModel | |
4402b54d | 82 | |
421d935d | 83 | this.html = await this.instanceService.buildHtml(about) |
4402b54d C |
84 | }, |
85 | ||
86 | () => this.notifier.error(this.i18n('Cannot get about information from server')) | |
87 | ) | |
36f9424f C |
88 | } |
89 | ||
d3e56c0c C |
90 | openContactModal () { |
91 | return this.contactAdminModal.show() | |
92 | } | |
36f9424f | 93 | } |