2024-03-27 14:00:40 +01:00
|
|
|
import { NgFor, NgIf, ViewportScroller } from '@angular/common'
|
2021-05-31 11:33:49 +02:00
|
|
|
import { AfterViewChecked, Component, ElementRef, OnInit, ViewChild } from '@angular/core'
|
2024-03-04 10:01:52 +01:00
|
|
|
import { ActivatedRoute, RouterLink } from '@angular/router'
|
2021-06-04 13:31:41 +02:00
|
|
|
import { Notifier, ServerService } from '@app/core'
|
2024-03-27 14:00:40 +01:00
|
|
|
import { AboutHTML } from '@app/shared/shared-main/instance/instance.service'
|
|
|
|
import { maxBy } from '@peertube/peertube-core-utils'
|
2023-07-31 14:34:36 +02:00
|
|
|
import { HTMLServerConfig, ServerStats } from '@peertube/peertube-models'
|
2021-06-15 11:57:15 +02:00
|
|
|
import { copyToClipboard } from '@root-helpers/utils'
|
2024-03-27 14:00:40 +01:00
|
|
|
import { CustomMarkupContainerComponent } from '../../shared/shared-custom-markup/custom-markup-container.component'
|
|
|
|
import { InstanceFeaturesTableComponent } from '../../shared/shared-instance/instance-features-table.component'
|
|
|
|
import { PluginSelectorDirective } from '../../shared/shared-main/plugins/plugin-selector.directive'
|
2020-02-03 10:31:34 +01:00
|
|
|
import { ResolverData } from './about-instance.resolver'
|
2021-06-15 11:57:15 +02:00
|
|
|
import { ContactAdminModalComponent } from './contact-admin-modal.component'
|
2024-03-04 10:01:52 +01:00
|
|
|
import { InstanceStatisticsComponent } from './instance-statistics.component'
|
2018-01-31 17:47:36 +01:00
|
|
|
|
|
|
|
@Component({
|
2018-06-27 14:21:03 +02:00
|
|
|
selector: 'my-about-instance',
|
|
|
|
templateUrl: './about-instance.component.html',
|
2024-03-04 10:01:52 +01:00
|
|
|
styleUrls: [ './about-instance.component.scss' ],
|
|
|
|
standalone: true,
|
|
|
|
imports: [
|
|
|
|
NgIf,
|
|
|
|
RouterLink,
|
|
|
|
NgFor,
|
|
|
|
CustomMarkupContainerComponent,
|
|
|
|
PluginSelectorDirective,
|
|
|
|
InstanceFeaturesTableComponent,
|
|
|
|
InstanceStatisticsComponent,
|
|
|
|
ContactAdminModalComponent
|
|
|
|
]
|
2018-01-31 17:47:36 +01:00
|
|
|
})
|
2020-03-11 19:38:17 +01:00
|
|
|
export class AboutInstanceComponent implements OnInit, AfterViewChecked {
|
2021-05-31 11:33:49 +02:00
|
|
|
@ViewChild('descriptionWrapper') descriptionWrapper: ElementRef<HTMLInputElement>
|
2021-06-15 11:57:15 +02:00
|
|
|
@ViewChild('contactAdminModal', { static: true }) contactAdminModal: ContactAdminModalComponent
|
2019-01-10 11:12:41 +01:00
|
|
|
|
2023-01-19 14:52:27 +01:00
|
|
|
aboutHTML: AboutHTML
|
|
|
|
descriptionElement: HTMLDivElement
|
2019-08-23 15:23:27 +02:00
|
|
|
|
2024-02-20 11:33:01 +01:00
|
|
|
instanceBannerUrl: string
|
|
|
|
|
2019-08-23 15:23:27 +02:00
|
|
|
languages: string[] = []
|
2019-08-27 10:18:49 +02:00
|
|
|
categories: string[] = []
|
2023-01-19 14:52:27 +01:00
|
|
|
shortDescription = ''
|
2018-01-31 17:47:36 +01:00
|
|
|
|
2020-11-16 16:46:15 +01:00
|
|
|
initialized = false
|
|
|
|
|
2023-02-15 15:53:40 +01:00
|
|
|
serverStats: ServerStats
|
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
private serverConfig: HTMLServerConfig
|
|
|
|
|
2020-06-16 09:56:24 +02:00
|
|
|
private lastScrollHash: string
|
|
|
|
|
2018-01-31 17:47:36 +01:00
|
|
|
constructor (
|
2020-03-11 19:38:17 +01:00
|
|
|
private viewportScroller: ViewportScroller,
|
2020-02-03 10:31:34 +01:00
|
|
|
private route: ActivatedRoute,
|
2020-11-17 14:04:44 +01:00
|
|
|
private notifier: Notifier,
|
2023-01-19 14:52:27 +01:00
|
|
|
private serverService: ServerService
|
2018-01-31 17:47:36 +01:00
|
|
|
) {}
|
|
|
|
|
|
|
|
get instanceName () {
|
2019-12-18 15:31:54 +01:00
|
|
|
return this.serverConfig.instance.name
|
2018-01-31 17:47:36 +01:00
|
|
|
}
|
|
|
|
|
2019-01-10 11:12:41 +01:00
|
|
|
get isContactFormEnabled () {
|
2019-12-18 15:31:54 +01:00
|
|
|
return this.serverConfig.email.enabled && this.serverConfig.contactForm.enabled
|
2019-01-10 11:12:41 +01:00
|
|
|
}
|
|
|
|
|
2019-02-21 15:44:12 +01:00
|
|
|
get isNSFW () {
|
2019-12-18 15:31:54 +01:00
|
|
|
return this.serverConfig.instance.isNSFW
|
2019-02-21 15:44:12 +01:00
|
|
|
}
|
|
|
|
|
2023-01-19 14:52:27 +01:00
|
|
|
ngOnInit () {
|
2023-02-15 15:53:40 +01:00
|
|
|
const { about, languages, categories, aboutHTML, descriptionElement, serverStats }: ResolverData = this.route.snapshot.data.instanceData
|
|
|
|
|
|
|
|
this.serverStats = serverStats
|
2023-01-19 14:52:27 +01:00
|
|
|
|
|
|
|
this.aboutHTML = aboutHTML
|
|
|
|
this.descriptionElement = descriptionElement
|
|
|
|
|
|
|
|
this.languages = languages
|
|
|
|
this.categories = categories
|
|
|
|
|
|
|
|
this.shortDescription = about.instance.shortDescription
|
2019-12-18 15:31:54 +01:00
|
|
|
|
2024-02-20 11:33:01 +01:00
|
|
|
this.instanceBannerUrl = about.instance.banners.length !== 0
|
2024-03-27 14:00:40 +01:00
|
|
|
? maxBy(about.instance.banners, 'width').path
|
2024-02-20 11:33:01 +01:00
|
|
|
: undefined
|
|
|
|
|
2021-06-04 13:31:41 +02:00
|
|
|
this.serverConfig = this.serverService.getHTMLConfig()
|
2020-02-03 10:31:34 +01:00
|
|
|
|
2021-06-15 11:57:15 +02:00
|
|
|
this.route.data.subscribe(data => {
|
|
|
|
if (!data?.isContact) return
|
|
|
|
|
|
|
|
const prefill = this.route.snapshot.queryParams
|
|
|
|
|
|
|
|
this.contactAdminModal.show(prefill)
|
|
|
|
})
|
|
|
|
|
2020-11-16 16:46:15 +01:00
|
|
|
this.initialized = true
|
2018-01-31 17:47:36 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 19:38:17 +01:00
|
|
|
ngAfterViewChecked () {
|
2020-11-16 16:46:15 +01:00
|
|
|
if (this.initialized && window.location.hash && window.location.hash !== this.lastScrollHash) {
|
2020-06-16 09:56:24 +02:00
|
|
|
this.viewportScroller.scrollToAnchor(window.location.hash.replace('#', ''))
|
|
|
|
|
|
|
|
this.lastScrollHash = window.location.hash
|
|
|
|
}
|
2020-03-11 19:38:17 +01:00
|
|
|
}
|
|
|
|
|
2020-11-17 14:04:44 +01:00
|
|
|
onClickCopyLink (anchor: HTMLAnchorElement) {
|
|
|
|
const link = anchor.href
|
|
|
|
copyToClipboard(link)
|
2021-08-17 14:42:53 +02:00
|
|
|
this.notifier.success(link, $localize`Link copied`)
|
2020-11-17 14:04:44 +01:00
|
|
|
}
|
2018-01-31 17:47:36 +01:00
|
|
|
}
|