]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+about/about-instance/about-instance.component.ts
15841be74e34339636530a11a6cc1cf038392506
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
1 import { Component, OnInit, ViewChild, AfterViewChecked } from '@angular/core'
2 import { Notifier, ServerService } from '@app/core'
3 import { ContactAdminModalComponent } from '@app/+about/about-instance/contact-admin-modal.component'
4 import { InstanceService } from '@app/shared/instance/instance.service'
5 import { ServerConfig } from '@shared/models'
6 import { ActivatedRoute } from '@angular/router'
7 import { ResolverData } from './about-instance.resolver'
8 import { ViewportScroller } from '@angular/common'
9
10 @Component({
11 selector: 'my-about-instance',
12 templateUrl: './about-instance.component.html',
13 styleUrls: [ './about-instance.component.scss' ]
14 })
15 export class AboutInstanceComponent implements OnInit, AfterViewChecked {
16 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
17
18 shortDescription = ''
19
20 html = {
21 description: '',
22 terms: '',
23 codeOfConduct: '',
24 moderationInformation: '',
25 administrator: '',
26 hardwareInformation: ''
27 }
28
29 creationReason = ''
30 maintenanceLifetime = ''
31 businessModel = ''
32
33 languages: string[] = []
34 categories: string[] = []
35
36 serverConfig: ServerConfig
37
38 private lastScrollHash: string
39
40 constructor (
41 private viewportScroller: ViewportScroller,
42 private route: ActivatedRoute,
43 private serverService: ServerService,
44 private instanceService: InstanceService
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 async ngOnInit () {
60 this.serverConfig = this.serverService.getTmpConfig()
61 this.serverService.getConfig()
62 .subscribe(config => this.serverConfig = config)
63
64 const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
65
66 this.languages = languages
67 this.categories = categories
68
69 this.shortDescription = about.instance.shortDescription
70
71 this.creationReason = about.instance.creationReason
72 this.maintenanceLifetime = about.instance.maintenanceLifetime
73 this.businessModel = about.instance.businessModel
74
75 this.html = await this.instanceService.buildHtml(about)
76 }
77
78 ngAfterViewChecked () {
79 if (window.location.hash && window.location.hash !== this.lastScrollHash) {
80 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
81
82 this.lastScrollHash = window.location.hash
83 }
84 }
85
86 openContactModal () {
87 return this.contactAdminModal.show()
88 }
89 }