Skip to content
Snippets Groups Projects
dataset.component.ts 2.95 KiB
Newer Older
François Agneray's avatar
François Agneray committed
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { Observable } from 'rxjs';
import { Store } from '@ngrx/store';

import { Criterion } from '../store/model';
import { Project, DatasetFamily, Dataset, Attribute } from '../../metamodel/model';
import * as datasetActions from '../../metamodel/action/dataset.action';
import * as criteriaActions from '../../metamodel/action/criteria.action';
import * as outputActions from '../../metamodel/action/output.action';
import * as searchActions from '../store/search.action';
import * as fromSearch from '../store/search.reducer';
import * as fromMetamodel from '../../metamodel/reducers';
import * as searchSelector from '../store/search.selector';
import * as metamodelSelector from '../../metamodel/selectors';

interface StoreState {
    search: fromSearch.State;
    metamodel: fromMetamodel.State;
}

@Component({
    selector: 'app-dataset',
    templateUrl: 'dataset.component.html',
    styleUrls: [ 'dataset.component.css' ]
})
export class DatasetComponent implements OnInit {
    public projectList: Observable<Project[]>;
    public datasetList: Observable<Dataset[]>;
    public datasetFamilyList: Observable<DatasetFamily[]>;
    public datasetAttributeList: Observable<Attribute[]>;
    public currentStep: Observable<string>;
    public datasetName: Observable<String>;
    public criteriaList: Observable<Criterion[]>;
    public outputList: Observable<number[]>;

    constructor(private store: Store<StoreState>) {
        this.projectList = store.select(metamodelSelector.getProjectList);
        this.datasetList = store.select(metamodelSelector.getDatasetList);
        this.datasetFamilyList = store.select(metamodelSelector.getDatasetFamilyList);
        this.datasetAttributeList = store.select(metamodelSelector.getDatasetAttributeList);
        this.currentStep = store.select(searchSelector.getCurrentStep);
        this.datasetName = store.select(searchSelector.getDatasetName);
        this.criteriaList = this.store.select(searchSelector.getCriteriaList);
        this.outputList = this.store.select(searchSelector.getOutputList);
    }

    ngOnInit() {
        // Create a micro task that is processed after the current synchronous code
        // This micro task prevent the expression has changed after view init error
        Promise.resolve(null).then(() => this.store.dispatch(new searchActions.ChangeStepAction('dataset')));
        this.store.dispatch(new datasetActions.LoadProjectListAction());
        this.store.dispatch(new datasetActions.LoadDatasetListAction());
        this.store.dispatch(new datasetActions.LoadDatasetFamilyListAction());
    }

    selectDataset(datasetName: string): void {
        this.store.dispatch(new searchActions.SelectDatasetAction(datasetName));
        this.store.dispatch(new criteriaActions.LoadDatasetAttributeListAction(datasetName));
        // this.store.dispatch(new outputActions.LoadDatasetOutputFamilyAction(datasetName));
    }
}