reading-confirmation-progress.component.ts 1.68 KB
Newer Older
1
import { ChangeDetectorRef, Component, Input, SecurityContext } from '@angular/core';
2
import { DomSanitizer, SafeStyle } from '@angular/platform-browser';
3
import { CustomMarkdownService } from '../../../../service/custom-markdown/custom-markdown.service';
4
import { I18nService } from '../../../../service/i18n/i18n.service';
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
5 6

@Component({
7 8 9
  selector: 'app-reading-confirmation-progress',
  templateUrl: './reading-confirmation-progress.component.html',
  styleUrls: ['./reading-confirmation-progress.component.scss'],
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
10
})
11 12
export class ReadingConfirmationProgressComponent {
  public static TYPE = 'ReadingConfirmationProgressComponent';
13
  public absolute: number;
14

15 16
  private _percent: string;

Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
17 18 19 20 21 22 23 24
  get percent(): string {
    return this._percent;
  }

  set percent(value: string) {
    this._percent = value;
  }

25 26
  private _base: number;

Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
27 28 29 30 31 32 33 34
  get base(): number {
    return this._base;
  }

  set base(value: number) {
    this._base = value;
  }

35 36
  private _data: Object;

37
  @Input() set data(value: any) {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
38
    this._data = value;
39
    this.percent = value.percent;
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
40 41 42
    this.base = value.base;
    this.absolute = value.absolute;
    this._hasData = true;
43
    this.cd.markForCheck();
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
44 45
  }

46 47
  private _name: string;

48
  @Input() set name(value: string) {
49
    this._name = this.customMarkdownService.parseGithubFlavoredMarkdown(value);
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
50 51 52 53
  }

  private _hasData = false;

54 55 56 57 58 59
  constructor(
    private i18nService: I18nService,
    private sanitizer: DomSanitizer,
    private cd: ChangeDetectorRef,
    private customMarkdownService: CustomMarkdownService,
  ) {
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
60 61
  }

62 63
  public sanitizeStyle(value: string): SafeStyle {
    value = value.replace(/\s/g, '');
64
    return this.sanitizer.sanitize(SecurityContext.STYLE, `${value}`);
Christopher Mark Fullarton's avatar
Christopher Mark Fullarton committed
65 66
  }
}