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