]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+about/about-instance/about-instance.component.ts
Dependencies RHEL8 (#4337)
[github/Chocobozzz/PeerTube.git] / client / src / app / +about / about-instance / about-instance.component.ts
CommitLineData
67ed6552 1import { ViewportScroller } from '@angular/common'
8ee25e17 2import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
67ed6552 3import { ActivatedRoute } from '@angular/router'
2989628b 4import { Notifier, ServerService } from '@app/core'
67ed6552 5import { InstanceService } from '@app/shared/shared-instance'
5c16e6bc
C
6import { copyToClipboard } from '@root-helpers/utils'
7import { HTMLServerConfig } from '@shared/models/server'
b42f9c40 8import { ResolverData } from './about-instance.resolver'
5c16e6bc 9import { ContactAdminModalComponent } from './contact-admin-modal.component'
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})
45e0d669 16export class AboutInstanceComponent implements OnInit, AfterViewChecked {
8ee25e17 17 @ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
5c16e6bc 18 @ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
d3e56c0c 19
45c0fb35 20 shortDescription = ''
8ee25e17 21 descriptionContent: string
ccc00cb2
C
22
23 html = {
ccc00cb2
C
24 terms: '',
25 codeOfConduct: '',
26 moderationInformation: '',
be04c6fd 27 administrator: '',
f45c7cc7
FC
28 creationReason: '',
29 maintenanceLifetime: '',
30 businessModel: '',
be04c6fd 31 hardwareInformation: ''
ccc00cb2
C
32 }
33
ccc00cb2 34 languages: string[] = []
4402b54d 35 categories: string[] = []
36f9424f 36
12c8a463
C
37 initialized = false
38
2989628b
C
39 private serverConfig: HTMLServerConfig
40
64e0f8cf
C
41 private lastScrollHash: string
42
36f9424f 43 constructor (
45e0d669 44 private viewportScroller: ViewportScroller,
b42f9c40 45 private route: ActivatedRoute,
f3081d64 46 private notifier: Notifier,
2989628b 47 private serverService: ServerService,
b42f9c40 48 private instanceService: InstanceService
36f9424f
C
49 ) {}
50
51 get instanceName () {
ba430d75 52 return this.serverConfig.instance.name
36f9424f
C
53 }
54
d3e56c0c 55 get isContactFormEnabled () {
ba430d75 56 return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
d3e56c0c
C
57 }
58
c8000975 59 get isNSFW () {
ba430d75 60 return this.serverConfig.instance.isNSFW
c8000975
C
61 }
62
b42f9c40 63 async ngOnInit () {
2989628b 64 const { about, languages, categories }: ResolverData = this.route.snapshot.data.instanceData
ba430d75 65
2989628b 66 this.serverConfig = this.serverService.getHTMLConfig()
b42f9c40 67
5c16e6bc
C
68 this.route.data.subscribe(data => {
69 if (!data?.isContact) return
70
71 const prefill = this.route.snapshot.queryParams
72
73 this.contactAdminModal.show(prefill)
74 })
75
b42f9c40
C
76 this.languages = languages
77 this.categories = categories
78
79 this.shortDescription = about.instance.shortDescription
8ee25e17 80 this.descriptionContent = about.instance.description
b42f9c40 81
b42f9c40 82 this.html = await this.instanceService.buildHtml(about)
12c8a463
C
83
84 this.initialized = true
36f9424f
C
85 }
86
45e0d669 87 ngAfterViewChecked () {
12c8a463 88 if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
64e0f8cf
C
89 this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
90
91 this.lastScrollHash = window.location.hash
92 }
45e0d669
RK
93 }
94
f3081d64
K
95 onClickCopyLink (anchor: HTMLAnchorElement) {
96 const link = anchor.href
97 copyToClipboard(link)
9df52d66 98 this.notifier.success(link, $localize`Link copied`)
f3081d64 99 }
36f9424f 100}