all files / component/data-grid/data-grid-row/ data-grid-row.component.ts

93.55% Statements 29/31
50% Branches 5/10
100% Functions 8/8
93.1% Lines 27/29
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                                                  140×     140× 140×         140×               140× 140× 174×         1240×     3575×     140×   140× 140×       1300×      
/*
 *  @license
 *  Copyright Hôpitaux Universitaires de Genève. All Rights Reserved.
 *
 *  Use of this source code is governed by an Apache-2.0 license that can be
 *  found in the LICENSE file at https://github.com/DSI-HUG/dejajs-components/blob/master/LICENSE
 */
 
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, Input, OnDestroy } from '@angular/core';
import { from as observableFrom, Subscription } from 'rxjs';
import { ItemListService } from '../../../common/core/item-list/item-list.service';
import { IDejaGridColumnLayout } from '../data-grid-column/data-grid-column-layout';
import { IDejaGridRow } from './data-grid-row';
 
/** Composant représentant une ligne de la grille */
@Component({
    changeDetection: ChangeDetectionStrategy.OnPush,
    selector: 'deja-grid-row',
    styles: [require('./data-grid-row.component.scss')],
    template: require('./data-grid-row.component.html'),
})
export class DejaGridRowComponent implements OnDestroy {
    /** Définit la structure de la ligne associée à ce composant */
    @Input() public row: IDejaGridRow;
 
    /** Template de cellule si définit extérieurement à la grille */
    @Input() public cellTemplateExternal: any;
 
    /** Index de la ligne sur la liste plate de ItemListService */
    @Input() public flatIndex: number;
 
    /** Template de cellule par defaut  définit dans le HTML de la grille */
    @ContentChild('cellTemplate') protected cellTemplateInternal: any;
 
    private _columnLayout = {} as IDejaGridColumnLayout;
    private refresh$sub: Subscription;
 
    @Input()
    public set columnLayout(layout: IDejaGridColumnLayout) {
        Iif (this.refresh$sub) {
            this.refresh$sub.unsubscribe();
            this.refresh$sub = undefined;
        }
 
        this._columnLayout = layout || {
            columns: [],
            scrollLeft: 0,
            vpAfterWidth: 0,
            vpBeforeWidth: 0,
            refresh$: undefined,
        };
 
        Eif (this._columnLayout.refresh$) {
            this.refresh$sub = observableFrom(this._columnLayout.refresh$)
                .subscribe(() => this.changeDetectorRef.markForCheck());
        }
    }
 
    public get columnLayout() {
        return this._columnLayout;
    }
 
    protected get cellTemplate() {
        return this.cellTemplateExternal || this.cellTemplateInternal;
    }
 
    constructor(private changeDetectorRef: ChangeDetectorRef) { }
 
    public ngOnDestroy() {
        Eif (this.refresh$sub) {
            this.refresh$sub.unsubscribe();
        }
    }
 
    public getCellText(row: IDejaGridRow, textField: string) {
        return ItemListService.getItemText(row, textField);
    }
}