All files / src/app/pages/blog-detail blog-detail.component.ts

100% Statements 21/21
100% Branches 2/2
100% Functions 4/4
100% Lines 19/19

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 641x 1x 1x   1x 1x                 1x       10x                       10x 10x 10x 10x 10x 10x               10x 1210x       540x   670x 670x               670x        
import { Component, OnInit } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { ActivatedRoute, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { BlogModel } from '../../models';
import { AlertService, PageService, SeoService } from '../../services';
 
/**
 * Blog Detail Component
 */
@Component({
    selector: 'app-blog-detail',
    templateUrl: './blog-detail.component.html'
})
export class BlogDetailComponent implements OnInit {
    /** current blog object */
    blog$: Observable<BlogModel>;
    /** current blog ID */
    blogID = '';
 
    /**
     * constructor of BlogDetailComponent
     * @param afs: AngularFirestore
     * @param seo: SeoService
     * @param alert: AlertService
     * @param router: Router
     * @param route: ActivatedRoute
     * @param pageService: PageService
     */
    constructor(
        private readonly afs: AngularFirestore,
        private readonly seo: SeoService,
        private readonly alert: AlertService,
        public router: Router,
        private readonly route: ActivatedRoute,
        public pageService: PageService
    ) {
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.route.paramMap.subscribe(pmap => {
            if (this.pageService.checkToRedirectByIDParam(pmap,
                'blogs',
                this.pageService.routerLinks.blogs,
                this.pageService.routerLinks.blog)) {
                return;
            }
            this.blogID = pmap.get('id');
            this.initBlog();
        });
    }
 
    /**
     * init blog
     */
    initBlog(): void {
        this.blog$ = this.pageService.getPageFromFirestore(BlogModel, 'blogs', this.blogID);
    }
 
}