aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/shared-instance/instance-about-accordion.component.ts
blob: e13703c032159b9ac7e65fff88c8cc17bad8bcfe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { Component, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core'
import { HooksService, Notifier } from '@app/core'
import { NgbAccordion } from '@ng-bootstrap/ng-bootstrap'
import { ClientFilterHookName, PluginClientScope } from '@shared/models/plugins'
import { About } from '@shared/models/server'
import { InstanceService } from './instance.service'

@Component({
  selector: 'my-instance-about-accordion',
  templateUrl: './instance-about-accordion.component.html',
  styleUrls: [ './instance-about-accordion.component.scss' ]
})
export class InstanceAboutAccordionComponent implements OnInit {
  @ViewChild('accordion', { static: true }) accordion: NgbAccordion

  @Output() init: EventEmitter<InstanceAboutAccordionComponent> = new EventEmitter<InstanceAboutAccordionComponent>()

  @Input() displayInstanceName = true
  @Input() displayInstanceShortDescription = true

  @Input() pluginScope: PluginClientScope
  @Input() pluginHook: ClientFilterHookName

  @Input() panels = {
    features: true,
    administrators: true,
    moderation: true,
    codeOfConduct: true,
    terms: true
  }

  about: About
  aboutHtml = {
    terms: '',
    codeOfConduct: '',
    moderationInformation: '',
    administrator: ''
  }

  pluginPanels: { id: string, title: string, html: string }[] = []

  constructor (
    private instanceService: InstanceService,
    private notifier: Notifier,
    private hookService: HooksService
  ) { }

  async ngOnInit () {
    this.instanceService.getAbout()
      .subscribe({
        next: async about => {
          this.about = about

          this.aboutHtml = await this.instanceService.buildHtml(about)

          this.init.emit(this)
        },

        error: err => this.notifier.error(err.message)
      })

    this.pluginPanels = await this.hookService.wrapObject([], this.pluginScope, this.pluginHook)
  }

  getAdministratorsPanel () {
    if (!this.about) return false
    if (!this.panels.administrators) return false

    return !!(this.aboutHtml?.administrator || this.about?.instance.maintenanceLifetime || this.about?.instance.businessModel)
  }

  getTermsTitle () {
    return $localize`Terms of ${this.about.instance.name}`
  }

  get moderationPanel () {
    return this.panels.moderation && !!this.aboutHtml.moderationInformation
  }

  get codeOfConductPanel () {
    return this.panels.codeOfConduct && !!this.aboutHtml.codeOfConduct
  }

  get termsPanel () {
    return this.panels.terms && !!this.aboutHtml.terms
  }
}