-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathreduce.component.ts
152 lines (136 loc) · 4.05 KB
/
reduce.component.ts
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import {
Component,
OnInit,
OnChanges,
SimpleChange,
OnDestroy,
} from "@angular/core";
import { Router } from "@angular/router";
import { Store } from "@ngrx/store";
import { Dataset, DerivedDataset } from "shared/sdk/models";
import {
selectOpenwhiskResult,
selectDatasets,
selectCurrentDataset,
} from "state-management/selectors/datasets.selectors";
import { reduceDatasetAction } from "state-management/actions/datasets.actions";
import { FormControl, Validators, FormBuilder } from "@angular/forms";
import { map } from "rxjs/operators";
import { Subscription } from "rxjs";
import {
selectIsLoading,
selectIsLoggedIn,
} from "state-management/selectors/user.selectors";
import { OwnershipService } from "shared/services/ownership.service";
@Component({
selector: "reduce",
templateUrl: "./reduce.component.html",
styleUrls: ["./reduce.component.scss"],
})
export class ReduceComponent implements OnInit, OnChanges, OnDestroy {
dataset: Dataset | undefined;
subscriptions: Subscription[] = [];
derivedDatasets$ = this.store.select(selectDatasets).pipe(
map((datasets) =>
datasets
.filter((dataset) => dataset.type === "derived")
.map((dataset: unknown) => dataset as DerivedDataset)
.filter((dataset) =>
dataset["inputDatasets"].includes(this.dataset?.pid),
),
),
);
derivedDatasets: DerivedDataset[] = [];
loading$ = this.store.select(selectIsLoading);
loggedIn$ = this.store.select(selectIsLoggedIn);
result$ = this.store.select(selectOpenwhiskResult);
actionsForm = this.formBuilder.group({
formArray: this.formBuilder.array([
this.formBuilder.group({
actionForm: new FormControl("", Validators.required),
}),
this.formBuilder.group({
scriptForm: new FormControl("", Validators.required),
}),
]),
});
actions: string[] = ["Analyze", "Reduce"];
analyzeScripts: Record<string, unknown>[] = [
{
value: "Plot",
description: "Create plot.",
},
];
reduceScripts: Record<string, unknown>[] = [
{
value: "Noise Reduction",
description: "Remove background noise.",
},
];
columnsToDisplay: string[] = ["timestamp", "name", "pid", "software"];
constructor(
private formBuilder: FormBuilder,
private router: Router,
private store: Store,
private ownershipService: OwnershipService,
) {}
reduceDataset(dataset: Dataset): void {
this.store.dispatch(reduceDatasetAction({ dataset }));
}
onRowClick(dataset: Dataset): void {
const pid = encodeURIComponent(dataset.pid);
this.router.navigateByUrl("/datasets/" + pid);
}
get formArray() {
return this.actionsForm.get("formArray");
}
get selectedAction() {
return this.formArray?.get([0])?.get("actionForm");
}
get selectedScript() {
return this.formArray?.get([1])?.get("scriptForm");
}
ngOnInit() {
this.subscriptions.push(
this.store.select(selectCurrentDataset).subscribe((dataset) => {
this.dataset = dataset;
if (dataset) {
this.ownershipService.checkDatasetAccess(
dataset,
this.store,
this.router,
);
}
}),
);
this.subscriptions.push(
this.derivedDatasets$.subscribe((datasets) => {
if (datasets) {
this.derivedDatasets = datasets;
}
}),
);
}
ngOnChanges(changes: { [propKey: string]: SimpleChange }) {
for (const propName in changes) {
if (propName === "dataset") {
this.dataset = changes[propName].currentValue;
this.derivedDatasets$ = this.store.select(selectDatasets).pipe(
map((datasets) =>
datasets
.filter((dataset) => dataset.type === "derived")
.map((dataset: unknown) => dataset as DerivedDataset)
.filter((dataset) =>
dataset["inputDatasets"].includes(this.dataset?.pid),
),
),
);
}
}
}
ngOnDestroy() {
this.subscriptions.forEach((subscription) => {
subscription.unsubscribe();
});
}
}