All files / src/app/components/app app.component.ts

96.55% Statements 28/29
50% Branches 1/2
100% Functions 4/4
96.3% Lines 26/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 831x 1x   1x 1x   1x 1x                 1x                                                   30x   30x 30x 30x 30x 30x 30x 30x 30x   30x 30x 30x             31x   36x     36x 36x   31x 31x   31x                  
import { DOCUMENT } from '@angular/common';
import { Component, Inject, OnInit, PLATFORM_ID, Renderer2, ViewChild } from '@angular/core';
import { SafeHtml } from '@angular/platform-browser';
import { Router } from '@angular/router';
import { Angulartics2GoogleGlobalSiteTag } from 'angulartics2/gst';
import { Observable } from 'rxjs';
import { ConfigModel, HttpStatusModel } from '../../models';
import { AlertService, ConfigService, JsonLDService, PageService, PaginationService, SeoService } from '../../services';
 
/**
 * App Component
 */
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
    /** http status */
    httpStatus$: Observable<HttpStatusModel>;
    /** json-LD */
    jsonLD$: Observable<SafeHtml>;
 
    /** cookieLaw element */
    @ViewChild('cookieLaw', { static: false }) cookieLawEl: any;
 
    /** scroll handler */
    private scrollHandler: any;
 
    /**
     * constructor of AppComponent
     * @param platformId: PLATFORM_ID
     * @param doc: DOCUMENT
     * @param renderer: Renderer2
     * @param router: Router
     * @param seo: SeoService
     * @param jsonLDService: JsonLDService
     * @param alert: AlertService
     * @param pagination: PaginationService
     * @param configService: ConfigService
     * @param pageService: PageService
     * @param angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag
     */
    constructor(@Inject(PLATFORM_ID) private readonly platformId: string,
                @Inject(DOCUMENT) doc: Document,
                private readonly renderer: Renderer2,
                public router: Router,
                public seo: SeoService,
                public jsonLDService: JsonLDService,
                public alert: AlertService,
                public pagination: PaginationService,
                public configService: ConfigService,
                public pageService: PageService,
                angulartics2GoogleGlobalSiteTag: Angulartics2GoogleGlobalSiteTag) {
        angulartics2GoogleGlobalSiteTag.startTracking();
        seo.renderer = renderer;
        renderer.setAttribute(doc.documentElement, 'lang', pageService.locale.substr(0, 2));
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.pageService.getDocumentFromFirestore(ConfigModel, `configs/public_${this.pageService.locale}`)
            .subscribe(config => {
                Iif (!config.configSEO) {
                    config.configSEO = {};
                }
                this.configService.init(config);
                this.seo.configSEO = config.configSEO;
            });
        this.httpStatus$ = this.seo.getHttpStatus();
        this.jsonLD$ = this.jsonLDService.getJsonLD();
 
        this.scrollHandler = this.renderer.listen('window', 'scroll', event => {
            // istanbul ignore next
            if (this.cookieLawEl && !this.cookieLawEl.seen) {
                this.cookieLawEl.dismiss();
                this.scrollHandler();
            }
        });
    }
}