all files / src/app/pages/home/ home.component.ts

100% Statements 19/19
100% Branches 0/0
100% Functions 4/4
100% Lines 17/17
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                                                                                  
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { ConfigModel, CustomHtmlModel, PageBaseModel, PageModel } from '../../models';
import { AlertService, CarouselService, ConfigService, PageService, SeoService } from '../../services';
 
/**
 * Home Component
 */
@Component({
    selector: 'app-home',
    templateUrl: './home.component.html'
})
export class HomeComponent implements OnInit {
    /** current page object */
    page$: Observable<PageModel>;
    /** contents of current page */
    contents$: Observable<Array<PageBaseModel>>;
    /** primary custom html widget */
    customHtml: CustomHtmlModel;
 
    /**
     * constructor of HomeComponent
     * @param platformId: PLATFORM_ID
     * @param seo: SeoService
     * @param alert: AlertService
     * @param carouselService: CarouselService
     * @param afs: AngularFirestore
     * @param pageService: PageService
     * @param configService: ConfigService
     */
    constructor(@Inject(PLATFORM_ID) private readonly platformId: string,
                public seo: SeoService,
                public alert: AlertService,
                public carouselService: CarouselService,
                private readonly afs: AngularFirestore,
                public pageService: PageService,
                public configService: ConfigService) {
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.page$ = this.pageService.getPageFromFirestore(PageModel, 'pages', 'home');
 
        this.contents$ = this.pageService.getCollectionFromFirestore(`pages_${this.pageService.locale}/home/contents`,
            ref => ref.orderBy('created', 'desc')
                .limit(3));
 
        this.configService.getConfig()
            .subscribe((config: ConfigModel) => {
                this.customHtml = config.primaryCustomHtmlWidget;
            });
    }
 
}