2020-02-12 17:24:42 +01:00
|
|
|
import { Component, OnInit, AfterViewChecked } from '@angular/core';
|
|
|
|
import { UserGuideService } from '@app/core/services/user-guide/user-guide.service';
|
|
|
|
import { BaseComponent } from '@common/base/base.component';
|
|
|
|
import { takeUntil } from 'rxjs/internal/operators/takeUntil';
|
2020-12-10 14:45:55 +01:00
|
|
|
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
2020-12-10 10:34:01 +01:00
|
|
|
import { LanguageService } from '@app/core/services/language/language.service';
|
2020-12-11 15:53:22 +01:00
|
|
|
import { SecurityContext } from '@angular/core';
|
2020-02-12 17:24:42 +01:00
|
|
|
|
|
|
|
@Component({
|
2020-12-10 14:45:55 +01:00
|
|
|
selector: 'app-user-guide-content',
|
|
|
|
templateUrl: './user-guide-content.component.html',
|
|
|
|
styleUrls: ['./user-guide-content.component.scss']
|
2020-02-12 17:24:42 +01:00
|
|
|
})
|
|
|
|
export class UserGuideContentComponent extends BaseComponent implements OnInit, AfterViewChecked {
|
|
|
|
|
|
|
|
|
|
|
|
guideHTML: any;
|
2020-12-10 14:45:55 +01:00
|
|
|
guideHTMLUrl: SafeResourceUrl;
|
2020-12-11 15:53:22 +01:00
|
|
|
sanitizedGuideUrl: any;
|
2020-02-13 17:18:54 +01:00
|
|
|
private scrollEvent: EventListener;
|
2020-02-12 17:24:42 +01:00
|
|
|
|
2020-12-10 14:45:55 +01:00
|
|
|
constructor(
|
|
|
|
private userGuideService: UserGuideService,
|
2020-12-10 14:49:34 +01:00
|
|
|
private sanitizer: DomSanitizer,
|
|
|
|
private languageService: LanguageService
|
2020-12-10 14:45:55 +01:00
|
|
|
) { super(); }
|
2020-02-12 17:24:42 +01:00
|
|
|
|
2020-12-10 14:45:55 +01:00
|
|
|
ngOnInit() {
|
|
|
|
this.scrollEvent = ((ev) => this.scroll(ev));
|
2020-12-10 14:49:34 +01:00
|
|
|
this.userGuideService.getUserGuide(this.languageService.getCurrentLanguage())
|
2020-12-10 14:45:55 +01:00
|
|
|
.pipe(takeUntil(this._destroyed))
|
|
|
|
.subscribe(response => {
|
|
|
|
const blob = new Blob([response.body], { type: 'text/html' });
|
|
|
|
this.readBlob(blob);
|
2020-12-11 15:53:22 +01:00
|
|
|
this.guideHTMLUrl = this.sanitizer.bypassSecurityTrustResourceUrl((window.URL ? URL : webkitURL).createObjectURL(blob));
|
|
|
|
// this.sanitizedGuideUrl = this.sanitizer.sanitize(SecurityContext.URL, this.guideHTMLUrl);
|
|
|
|
// console.log(this.guideHTMLUrl);
|
2020-12-10 14:45:55 +01:00
|
|
|
});
|
|
|
|
}
|
2020-02-12 17:24:42 +01:00
|
|
|
|
2020-12-10 14:45:55 +01:00
|
|
|
ngAfterViewChecked(): void {
|
2020-02-12 17:24:42 +01:00
|
|
|
this.parse();
|
2020-12-10 14:45:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
readBlob(blob: Blob) {
|
|
|
|
const fr = new FileReader();
|
|
|
|
fr.onload = ev => {
|
|
|
|
this.guideHTML = this.sanitizer.bypassSecurityTrustHtml(fr.result as string);
|
|
|
|
this.parse();
|
|
|
|
};
|
|
|
|
fr.readAsText(blob);
|
|
|
|
}
|
|
|
|
|
|
|
|
scroll(ev: Event) {
|
|
|
|
document.getElementById((ev.srcElement as any).getAttribute('path')).scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
|
|
}
|
|
|
|
|
|
|
|
private parse() {
|
|
|
|
const specialElements: HTMLCollection = document.getElementsByClassName('href');
|
|
|
|
for (let i = 0; i < specialElements.length; i++) {
|
|
|
|
const element = specialElements.item(i);
|
|
|
|
element.removeEventListener('click', this.scrollEvent);
|
|
|
|
element.addEventListener('click', this.scrollEvent);
|
|
|
|
}
|
|
|
|
}
|
2020-02-12 17:24:42 +01:00
|
|
|
|
|
|
|
}
|