manage-attribute.component.ts 2.74 KB
Newer Older
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
import { Component, OnInit } from '@angular/core';

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

import { Attribute, Column} from '../../store/model';
import * as projectActions from '../../store/action/project.action';
import * as datasetActions from '../../store/action/dataset.action';
import * as attributeActions from '../../store/action/attribute.action';
import * as databaseActions from '../../store/action/database.action';
import * as attributeSelector from '../../store/selector/attribute.selector';
import * as datasetSelector from '../../store/selector/dataset.selector';
import * as instanceSelector from '../../store/selector/instance.selector';
import * as databaseSelector from '../../store/selector/database.selector';
import * as metamodelReducer from '../../store/reducer';

@Component({
    selector: 'app-manage-attribute',
    templateUrl: 'manage-attribute.component.html',
    styleUrls: [ 'manage-attribute.component.css' ]
})
export class ManageAttributeComponent implements OnInit {
    public instanceSelected: Observable<string>;
    public datasetSelected: Observable<string>;
    public attributeList: Observable<Attribute[]>;
    public attributeListIsLoading: Observable<boolean>;
    public attributeListIsLoaded: Observable<boolean>;
    public columnList: Observable<Column[]>;
    public columnListIsLoading: Observable<boolean>;
    public columnListIsLoaded: Observable<boolean>;

    constructor(private store: Store<metamodelReducer.State>) {
        this.instanceSelected = store.select(instanceSelector.getInstanceSelected);
        this.datasetSelected = store.select(datasetSelector.getDatasetSelected);
        this.attributeList = store.select(attributeSelector.getAttributeList);
        this.attributeListIsLoading = store.select(attributeSelector.getAttributeListIsLoading);
        this.attributeListIsLoaded = store.select(attributeSelector.getAttributeListIsLoaded);
        this.columnList = store.select(databaseSelector.getColumnList);
        this.columnListIsLoading = store.select(databaseSelector.getColumnListIsLoading);
        this.columnListIsLoaded = store.select(databaseSelector.getColumnListIsLoaded);
    }

    ngOnInit() {
        this.store.dispatch(new projectActions.LoadProjectListAction());
        this.store.dispatch(new datasetActions.LoadDatasetListAction());
        this.store.dispatch(new attributeActions.LoadAttributeListAction());
        this.store.dispatch(new databaseActions.LoadColumnListAction());
    }

    addAttribute(attribute: Attribute): void {
        this.store.dispatch(new attributeActions.AddNewAttributeAction(attribute));
    }

    deleteAttribute(attribute: Attribute): void {
        this.store.dispatch(new attributeActions.DeleteAttributeAction(attribute));
    }
}