]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/misc/help.component.ts
NoImplicitAny flag true (#1157)
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / misc / help.component.ts
index b8530e1d4739c2db3ffb95022996808033cc638c..ccce1ccfa5e02cfa32decd698ec8a14609d4f972 100644 (file)
@@ -1,4 +1,6 @@
-import { Component, Input, OnInit } from '@angular/core'
+import { Component, Input, OnChanges, OnInit } from '@angular/core'
+import { MarkdownService } from '@app/videos/shared'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 @Component({
   selector: 'my-help',
@@ -6,41 +8,71 @@ import { Component, Input, OnInit } from '@angular/core'
   templateUrl: './help.component.html'
 })
 
-export class HelpComponent implements OnInit {
+export class HelpComponent implements OnInit, OnChanges {
   @Input() preHtml = ''
   @Input() postHtml = ''
   @Input() customHtml = ''
   @Input() helpType: 'custom' | 'markdownText' | 'markdownEnhanced' = 'custom'
+  @Input() tooltipPlacement = 'right'
 
+  isPopoverOpened = false
   mainHtml = ''
 
+  constructor (private i18n: I18n) { }
+
   ngOnInit () {
+    this.init()
+  }
+
+  ngOnChanges () {
+    this.init()
+  }
+
+  onPopoverHidden () {
+    this.isPopoverOpened = false
+  }
+
+  onPopoverShown () {
+    this.isPopoverOpened = true
+  }
+
+  private init () {
     if (this.helpType === 'custom') {
       this.mainHtml = this.customHtml
       return
     }
 
     if (this.helpType === 'markdownText') {
-      this.mainHtml = 'Markdown compatible.<br /><br />' +
-        'Supports:' +
-        '<ul>' +
-        '<li>Links</li>' +
-        '<li>Lists</li>' +
-        '<li>Emphasis</li>' +
-        '</ul>'
+      this.mainHtml = this.formatMarkdownSupport(MarkdownService.TEXT_RULES)
       return
     }
 
     if (this.helpType === 'markdownEnhanced') {
-      this.mainHtml = 'Markdown compatible.<br /><br />' +
-        'Supports:' +
-        '<ul>' +
-        '<li>Links</li>' +
-        '<li>Lists</li>' +
-        '<li>Emphasis</li>' +
-        '<li>Images</li>' +
-        '</ul>'
+      this.mainHtml = this.formatMarkdownSupport(MarkdownService.ENHANCED_RULES)
       return
     }
   }
+
+  private formatMarkdownSupport (rules: string[]) {
+    // tslint:disable:max-line-length
+    return this.i18n('<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> compatible that supports:') +
+      this.createMarkdownList(rules)
+  }
+
+  private createMarkdownList (rules: string[]) {
+    const rulesToText: any = {
+      'emphasis': this.i18n('Emphasis'),
+      'link': this.i18n('Links'),
+      'newline': this.i18n('New lines'),
+      'list': this.i18n('Lists'),
+      'image': this.i18n('Images')
+    }
+
+    const bullets = rules.map(r => rulesToText[r])
+      .filter(text => text)
+      .map(text => '<li>' + text + '</li>')
+      .join('')
+
+    return '<ul>' + bullets + '</ul>'
+  }
 }