Skip to content
Snippets Groups Projects
table-deposits.component.ts 1.42 KiB
Newer Older
import {ChangeDetectionStrategy, Component, EventEmitter, Input, OnInit, Output} from '@angular/core';
import {DepositsModel} from '@app/generated-api';
Florent Poittevin's avatar
Florent Poittevin committed
import {PrimeNgColumnsModel} from '@app/shared/model/prime-ng-columns.model';
// TODO Create a shared component table and preserve this component just for data
@Component({
  selector: 'dlcm-table-deposits',
  templateUrl: './table-deposits.component.html',
  styleUrls: ['./table-deposits.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class TableDepositsComponent implements OnInit {
  @Input()
  deposits: DepositsModel[];

  @Output()
  selectEvent: EventEmitter<string>;

Florent Poittevin's avatar
Florent Poittevin committed
  cols: PrimeNgColumnsModel[];
    this.selectEvent = new EventEmitter<string>();
Florent Poittevin's avatar
Florent Poittevin committed
    // TODO Use typeof to get interface propertie name
    // TODO Use ngx translate
    this.cols = [
      {field: 'title', header: 'Titre'},
      {field: 'publicationDate', header: 'Date de publication'},
      {field: 'creation.when', header: 'Créé le'},
      {field: 'lastUpdate.when', header: 'Modifié le'},
      {field: 'status', header: 'Statut'},
    ];
  }


  getCellData(row: any, col: any): any {
    const nestedProperties: string[] = col.field.split('.');
    let value: any = row;
    for (const prop of nestedProperties) {
      value = value[prop];
    }

    return value;
  }

  showDetail(resId: string) {
    this.selectEvent.emit(resId);
  }