]>
Commit | Line | Data |
---|---|---|
40360c17 | 1 | import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core' |
071f3e51 | 2 | import { HooksService, Notifier } from '@app/core' |
40360c17 | 3 | import { NgbAccordion } 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 { | |
14 | @ViewChild('accordion', { static: true }) accordion: NgbAccordion | |
071f3e51 | 15 | |
40360c17 K |
16 | @Output() init: EventEmitter<InstanceAboutAccordionComponent> = new EventEmitter<InstanceAboutAccordionComponent>() |
17 | ||
071f3e51 C |
18 | @Input() pluginScope: PluginClientScope |
19 | @Input() pluginHook: ClientFilterHookName | |
20 | ||
40360c17 K |
21 | @Input() panels = { |
22 | features: true, | |
23 | administrators: true, | |
24 | moderation: true, | |
25 | codeOfConduct: true, | |
26 | terms: true | |
27 | } | |
28 | ||
29 | about: About | |
30 | aboutHtml = { | |
40360c17 K |
31 | terms: '', |
32 | codeOfConduct: '', | |
33 | moderationInformation: '', | |
34 | administrator: '' | |
35 | } | |
36 | ||
071f3e51 C |
37 | pluginPanels: { id: string, title: string, html: string }[] = [] |
38 | ||
40360c17 K |
39 | constructor ( |
40 | private instanceService: InstanceService, | |
071f3e51 C |
41 | private notifier: Notifier, |
42 | private hookService: HooksService | |
40360c17 K |
43 | ) { } |
44 | ||
071f3e51 | 45 | async ngOnInit () { |
40360c17 | 46 | this.instanceService.getAbout() |
1378c0d3 C |
47 | .subscribe({ |
48 | next: async about => { | |
40360c17 K |
49 | this.about = about |
50 | ||
51 | this.aboutHtml = await this.instanceService.buildHtml(about) | |
52 | ||
53 | this.init.emit(this) | |
54 | }, | |
55 | ||
1378c0d3 C |
56 | error: err => this.notifier.error(err.message) |
57 | }) | |
071f3e51 C |
58 | |
59 | this.pluginPanels = await this.hookService.wrapObject([], this.pluginScope, this.pluginHook) | |
40360c17 K |
60 | } |
61 | ||
62 | getAdministratorsPanel () { | |
63 | if (!this.about) return false | |
64 | if (!this.panels.administrators) return false | |
65 | ||
66 | return !!(this.aboutHtml?.administrator || this.about?.instance.maintenanceLifetime || this.about?.instance.businessModel) | |
67 | } | |
68 | ||
69 | get moderationPanel () { | |
70 | return this.panels.moderation && !!this.aboutHtml.moderationInformation | |
71 | } | |
72 | ||
73 | get codeOfConductPanel () { | |
74 | return this.panels.codeOfConduct && !!this.aboutHtml.codeOfConduct | |
75 | } | |
76 | ||
77 | get termsPanel () { | |
78 | return this.panels.terms && !!this.aboutHtml.terms | |
79 | } | |
80 | } |