]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-instance/instance-about-accordion.component.ts
Fix terms/code of conduct link toggle
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-instance / instance-about-accordion.component.ts
1 import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
2 import { HooksService, Notifier } from '@app/core'
3 import { NgbAccordionDirective } from '@ng-bootstrap/ng-bootstrap'
4 import { ClientFilterHookName, PluginClientScope } from '@shared/models/plugins'
5 import { About } from '@shared/models/server'
6 import { InstanceService } from './instance.service'
7
8 @Component({
9 selector: 'my-instance-about-accordion',
10 templateUrl: './instance-about-accordion.component.html',
11 styleUrls: [ './instance-about-accordion.component.scss' ]
12 })
13 export class InstanceAboutAccordionComponent implements OnInit {
14 @ViewChild('accordion', { static: true }) accordion: NgbAccordionDirective
15
16 @Output() init: EventEmitter<InstanceAboutAccordionComponent> = new EventEmitter<InstanceAboutAccordionComponent>()
17
18 @Input() displayInstanceName = true
19 @Input() displayInstanceShortDescription = true
20
21 @Input() pluginScope: PluginClientScope
22 @Input() pluginHook: ClientFilterHookName
23
24 @Input() panels = {
25 features: true,
26 administrators: true,
27 moderation: true,
28 codeOfConduct: true,
29 terms: true
30 }
31
32 about: About
33 aboutHtml = {
34 terms: '',
35 codeOfConduct: '',
36 moderationInformation: '',
37 administrator: ''
38 }
39
40 pluginPanels: { id: string, title: string, html: string }[] = []
41
42 constructor (
43 private instanceService: InstanceService,
44 private notifier: Notifier,
45 private hookService: HooksService
46 ) { }
47
48 async ngOnInit () {
49 this.instanceService.getAbout()
50 .subscribe({
51 next: async about => {
52 this.about = about
53
54 this.aboutHtml = await this.instanceService.buildHtml(about)
55
56 this.init.emit(this)
57 },
58
59 error: err => this.notifier.error(err.message)
60 })
61
62 this.pluginPanels = await this.hookService.wrapObject([], this.pluginScope, this.pluginHook)
63 }
64
65 expandTerms () {
66 this.accordion.expand('terms')
67 }
68
69 expandCodeOfConduct () {
70 this.accordion.expand('code-of-conduct')
71 }
72
73 getAdministratorsPanel () {
74 if (!this.about) return false
75 if (!this.panels.administrators) return false
76
77 return !!(this.aboutHtml?.administrator || this.about?.instance.maintenanceLifetime || this.about?.instance.businessModel)
78 }
79
80 getTermsTitle () {
81 return $localize`Terms of ${this.about.instance.name}`
82 }
83
84 get moderationPanel () {
85 return this.panels.moderation && !!this.aboutHtml.moderationInformation
86 }
87
88 get codeOfConductPanel () {
89 return this.panels.codeOfConduct && !!this.aboutHtml.codeOfConduct
90 }
91
92 get termsPanel () {
93 return this.panels.terms && !!this.aboutHtml.terms
94 }
95 }