1 import { AfterContentInit, Component, ContentChildren, Input, OnChanges, OnInit, QueryList, TemplateRef } from '@angular/core'
2 import { I18n } from '@ngx-translate/i18n-polyfill'
3 import { MarkdownService } from '@app/shared/renderer'
4 import { PeerTubeTemplateDirective } from '@app/shared/angular/peertube-template.directive'
8 styleUrls: [ './help.component.scss' ],
9 templateUrl: './help.component.html'
12 export class HelpComponent implements OnInit, OnChanges, AfterContentInit {
13 @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
14 @Input() tooltipPlacement = 'right auto'
16 @ContentChildren(PeerTubeTemplateDirective) templates: QueryList<PeerTubeTemplateDirective<'preHtml' | 'customHtml' | 'postHtml'>>
18 isPopoverOpened = false
21 preHtmlTemplate: TemplateRef<any>
22 customHtmlTemplate: TemplateRef<any>
23 postHtmlTemplate: TemplateRef<any>
25 constructor (private i18n: I18n) { }
31 ngAfterContentInit () {
33 const t = this.templates.find(t => t.name === 'preHtml')
34 if (t) this.preHtmlTemplate = t.template
38 const t = this.templates.find(t => t.name === 'customHtml')
39 if (t) this.customHtmlTemplate = t.template
43 const t = this.templates.find(t => t.name === 'postHtml')
44 if (t) this.postHtmlTemplate = t.template
53 this.isPopoverOpened = false
57 this.isPopoverOpened = true
61 if (this.helpType === 'markdownText') {
62 this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
66 if (this.helpType === 'markdownEnhanced') {
67 this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
72 private formatMarkdownSupport (rules: string[]) {
73 // tslint:disable:max-line-length
74 return this.i18n('<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> compatible that supports:') +
75 this.createMarkdownList(rules)
78 private createMarkdownList (rules: string[]) {
80 'emphasis': this.i18n('Emphasis'),
81 'link': this.i18n('Links'),
82 'newline': this.i18n('New lines'),
83 'list': this.i18n('Lists'),
84 'image': this.i18n('Images')
87 const bullets = rules.map(r => rulesToText[r])
89 .map(text => '<li>' + text + '</li>')
92 return '<ul>' + bullets + '</ul>'