Skip to content
Snippets Groups Projects
datasets-result.component.ts 1.46 KiB
Newer Older
import {Component, Input, Output, ChangeDetectionStrategy, EventEmitter} from '@angular/core';

import { Dataset, Project } from "../../../metamodel/model";
import { DatasetCount } from "../../store/model";
import {sortByDisplay} from "../../../shared/utils";

@Component({
    selector: 'app-datasets-result',
    templateUrl: 'datasets-result.component.html',
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class DatasetsResultComponent {
    @Input() datasetsCountIsLoaded: boolean;
    @Input() projectList: Project[];
    @Input() datasetList: Dataset[];
    @Input() selectedDatasets: string[];
    @Input() datasetsCount: DatasetCount[];
    @Output() retrieveData: EventEmitter<string> = new EventEmitter();
    getOrderedDatasetWithResults(): Dataset[] {
        let datasets: Dataset[] = [];
        const projectOrderedByName: Project[] = [...this.projectList].sort((a, b) => a.name.localeCompare(b.name));
        projectOrderedByName.map(p => {
            this.datasetList.filter(d => d.project_name === p.name)
                .sort(sortByDisplay)
                .map(d => {
                    this.datasetsCount.map(c => {
                        if (c.dname === d.name && c.count > 0) {
                            datasets.push(d);
                        }
                    });
                });
        });
        return datasets;
    }

    getCount(dname: string): number {
        return this.datasetsCount.find(c => c.dname === dname).count;