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

100% Statements 22/22
100% Branches 0/0
100% Functions 7/7
100% Lines 18/18

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 701x 1x   1x   1x                 1x   83x   83x                     83x 83x 83x             83x             83x 83x         83x 246x 246x   246x                   898x        
import { Component, Inject, Input, LOCALE_ID, 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 } 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 afs: AngularFirestore
     * @param locale: LOCALE_ID
     */
    constructor(private readonly alert: AlertService,
                private readonly afs: AngularFirestore,
                @Inject(LOCALE_ID) public locale: string) {
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.getTaxonomyList();
    }
 
    /**
     * get taxonomy list
     */
    getTaxonomyList(): void {
        this.taxonomyList$ = this.afs.collection(`taxonomy_${this.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;
    }
 
}