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