]>
Commit | Line | Data |
---|---|---|
40360c17 | 1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
071f3e51 | 2 | import { HooksService, Notifier } from '@app/core' |
431ebbd5 | 3 | import { NgbAccordionDirective } from '@ng-bootstrap/ng-bootstrap' |
071f3e51 | 4 | import { ClientFilterHookName, PluginClientScope } from '@shared/models/plugins' |
40360c17 | 5 | import { About } from '@shared/models/server' |
071f3e51 | 6 | import { InstanceService } from './instance.service' |
40360c17 K |
7 | |
8 | @Component({ | |
9 | selector: 'my-instance-about-accordion', | |
10 | templateUrl: './instance-about-accordion.component.html', | |
9df52d66 | 11 | styleUrls: [ './instance-about-accordion.component.scss' ] |
40360c17 K |
12 | }) |
13 | export class InstanceAboutAccordionComponent implements OnInit { | |
431ebbd5 | 14 | @ViewChild('accordion', { static: true }) accordion: NgbAccordionDirective |
071f3e51 | 15 | |
40360c17 K |
16 | @Output() init: EventEmitter<InstanceAboutAccordionComponent> = new EventEmitter<InstanceAboutAccordionComponent>() |
17 | ||
6f03f944 C |
18 | @Input() displayInstanceName = true |
19 | @Input() displayInstanceShortDescription = true | |
20 | ||
071f3e51 C |
21 | @Input() pluginScope: PluginClientScope |
22 | @Input() pluginHook: ClientFilterHookName | |
23 | ||
40360c17 K |
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 = { | |
40360c17 K |
34 | terms: '', |
35 | codeOfConduct: '', | |
36 | moderationInformation: '', | |
37 | administrator: '' | |
38 | } | |
39 | ||
071f3e51 C |
40 | pluginPanels: { id: string, title: string, html: string }[] = [] |
41 | ||
40360c17 K |
42 | constructor ( |
43 | private instanceService: InstanceService, | |
071f3e51 C |
44 | private notifier: Notifier, |
45 | private hookService: HooksService | |
40360c17 K |
46 | ) { } |
47 | ||
071f3e51 | 48 | async ngOnInit () { |
40360c17 | 49 | this.instanceService.getAbout() |
1378c0d3 C |
50 | .subscribe({ |
51 | next: async about => { | |
40360c17 K |
52 | this.about = about |
53 | ||
54 | this.aboutHtml = await this.instanceService.buildHtml(about) | |
55 | ||
56 | this.init.emit(this) | |
57 | }, | |
58 | ||
1378c0d3 C |
59 | error: err => this.notifier.error(err.message) |
60 | }) | |
071f3e51 C |
61 | |
62 | this.pluginPanels = await this.hookService.wrapObject([], this.pluginScope, this.pluginHook) | |
40360c17 K |
63 | } |
64 | ||
ed22eaab C |
65 | expandTerms () { |
66 | this.accordion.expand('terms') | |
67 | } | |
68 | ||
69 | expandCodeOfConduct () { | |
70 | this.accordion.expand('code-of-conduct') | |
71 | } | |
72 | ||
40360c17 K |
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 | ||
6f03f944 C |
80 | getTermsTitle () { |
81 | return $localize`Terms of ${this.about.instance.name}` | |
82 | } | |
83 | ||
40360c17 K |
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 | } |