]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/misc/help.component.ts
Merge branch 'feature/video-filters' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / misc / help.component.ts
CommitLineData
421d935d 1import { AfterContentInit, Component, ContentChildren, Input, OnChanges, OnInit, QueryList, TemplateRef } from '@angular/core'
3c176894 2import { GlobalIconName } from '@app/shared/shared-icons'
47dc5db9 3import { ENHANCED_RULES, TEXT_RULES } from '@shared/core-utils/renderer/markdown'
67ed6552 4import { PeerTubeTemplateDirective } from '../angular'
8a8e02a4
C
5
6@Component({
7 selector: 'my-help',
8 styleUrls: [ './help.component.scss' ],
9 templateUrl: './help.component.html'
10})
11
421d935d 12export class HelpComponent implements OnInit, OnChanges, AfterContentInit {
8a8e02a4 13 @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
fc2df421 14 @Input() tooltipPlacement = 'right auto'
3c176894 15 @Input() iconName: GlobalIconName = 'help'
16 @Input() title = $localize`Get help`
c537763a 17 @Input() autoClose = 'outside'
8a8e02a4 18
421d935d
C
19 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'preHtml' | 'customHtml' | 'postHtml'>>
20
0f7fedc3 21 isPopoverOpened = false
8a8e02a4
C
22 mainHtml = ''
23
421d935d
C
24 preHtmlTemplate: TemplateRef<any>
25 customHtmlTemplate: TemplateRef<any>
26 postHtmlTemplate: TemplateRef<any>
27
8a8e02a4 28 ngOnInit () {
5afdd0a5
C
29 this.init()
30 }
31
421d935d
C
32 ngAfterContentInit () {
33 {
34 const t = this.templates.find(t => t.name === 'preHtml')
35 if (t) this.preHtmlTemplate = t.template
36 }
37
38 {
39 const t = this.templates.find(t => t.name === 'customHtml')
40 if (t) this.customHtmlTemplate = t.template
41 }
42
43 {
44 const t = this.templates.find(t => t.name === 'postHtml')
45 if (t) this.postHtmlTemplate = t.template
46 }
47 }
48
5afdd0a5
C
49 ngOnChanges () {
50 this.init()
51 }
52
0f7fedc3
C
53 onPopoverHidden () {
54 this.isPopoverOpened = false
55 }
56
57 onPopoverShown () {
58 this.isPopoverOpened = true
59 }
60
5afdd0a5 61 private init () {
8a8e02a4 62 if (this.helpType === 'markdownText') {
47dc5db9 63 this.mainHtml = this.formatMarkdownSupport(TEXT_RULES)
8a8e02a4
C
64 return
65 }
66
67 if (this.helpType === 'markdownEnhanced') {
47dc5db9 68 this.mainHtml = this.formatMarkdownSupport(ENHANCED_RULES)
8a8e02a4
C
69 return
70 }
71 }
621d99f5 72
621d99f5 73 private formatMarkdownSupport (rules: string[]) {
9df52d66 74 /* eslint-disable max-len */
66357162 75 return $localize`<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> compatible that supports:` +
621d99f5
C
76 this.createMarkdownList(rules)
77 }
78
79 private createMarkdownList (rules: string[]) {
c199c427 80 const rulesToText = {
9df52d66
C
81 emphasis: $localize`Emphasis`,
82 link: $localize`Links`,
83 newline: $localize`New lines`,
84 list: $localize`Lists`,
85 image: $localize`Images`
621d99f5
C
86 }
87
88 const bullets = rules.map(r => rulesToText[r])
89 .filter(text => text)
90 .map(text => '<li>' + text + '</li>')
91 .join('')
92
93 return '<ul>' + bullets + '</ul>'
94 }
8a8e02a4 95}