all files / src/app/widgets/active-tags/ active-tags.component.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 7/7
100% Lines 18/18
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                       84×   84×                     84× 84× 84×             84×             84× 84×         84× 249× 249×   249×                   901×        
import { Component, Input, OnInit } from '@angular/core';
import { AngularFirestore } from '@angular/fire/firestore';
import { Observable } from 'rxjs';
import { map } from 'rxjs/internal/operators';
import { TaxonomyModel } from '../../models';
import { AlertService, PageService } from '../../services';
 
/**
 * Active Tags Component
 */
@Component({
    selector: 'app-active-tags',
    templateUrl: './active-tags.component.html'
})
export class ActiveTagsComponent implements OnInit {
    /** limit number of tags to show */
    @Input() readonly tagLimit = 10;
    /** css class of header */
    @Input() readonly headerCssClass = '';
 
    /** taxonomy object array */
    taxonomyList$: Observable<Array<TaxonomyModel>>;
 
    /**
     * constructor of ActiveTagsComponent
     * @param alert: AlertService
     * @param pageService: PageService
     * @param afs: AngularFirestore
     */
    constructor(private readonly alert: AlertService,
                public pageService: PageService,
                private readonly afs: AngularFirestore) {
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.getTaxonomyList();
    }
 
    /**
     * get taxonomy list
     */
    getTaxonomyList(): void {
        this.taxonomyList$ = this.afs.collection(`taxonomy_${this.pageService.locale}`,
            ref => ref.orderBy('orderNo')
                .limit(this.tagLimit)
        )
            .snapshotChanges()
            .pipe(map(taxonomyList =>
                taxonomyList.map(taxonomy => {
                    const id = taxonomy.payload.doc.id;
                    const data = taxonomy.payload.doc.data() as TaxonomyModel;
 
                    return { id, ...data };
                })));
    }
 
    /**
     * track content object array by index
     * @param index: index no
     * @param item: object
     */
    trackByIndex(index, item): number {
        return index;
    }
 
}