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
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType, concatLatestFrom } from '@ngrx/effects';
import { Store, Action } from '@ngrx/store';
import { of } from 'rxjs';
import { map, tap, mergeMap, catchError } from 'rxjs/operators';
import { ToastrService } from 'ngx-toastr';
import { criterionToString, stringToCriterion } from '../models';
import { SearchService } from '../services/search.service';
import * as documentationActions from '../actions/documentation.actions';
import * as searchActions from '../actions/search.actions';
import * as attributeActions from 'src/app/metamodel/actions/attribute.actions';
import * as attributeSelector from 'src/app/metamodel/selectors/attribute.selector';
import * as criteriaFamilyActions from 'src/app/metamodel/actions/criteria-family.actions';
import * as outputFamilyActions from 'src/app/metamodel/actions/output-family.actions';
import * as outputCategoryActions from 'src/app/metamodel/actions/output-category.actions';
import * as datasetSelector from 'src/app/metamodel/selectors/dataset.selector';
import * as searchSelector from '../selectors/search.selector';
@Injectable()
export class DocumentationEffects {
loadAttributeList$ = createEffect(() =>
this.actions$.pipe(
ofType(documentationActions.loadAttributeList),
concatLatestFrom(() => this.store.select(datasetSelector.selectDatasetNameByRoute)),
mergeMap(([action, datasetName]) => {
console.log('ok');
return of(attributeActions.loadAttributeList());
})
)
);
// initSearch$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.initSearch),
// concatLatestFrom(() => [
// this.store.select(datasetSelector.selectDatasetNameByRoute),
// this.store.select(searchSelector.selectCurrentDataset),
// this.store.select(searchSelector.selectPristine),
// this.store.select(searchSelector.selectStepsByRoute)
// ]),
// mergeMap(([action, datasetName, currentDataset, pristine, steps]) => {
// // User has changed dataset: reload initial state + init search
// if (datasetName && currentDataset && datasetName !== currentDataset) {
// return of(searchActions.restartSearch());
// }
//
// // User has selected a dataset or page is reloaded: load dataset metamodel
// if (datasetName && pristine) {
// let actions: Action[] = [
// searchActions.changeCurrentDataset({ currentDataset: datasetName }),
// attributeActions.loadAttributeList(),
// criteriaFamilyActions.loadCriteriaFamilyList(),
// outputFamilyActions.loadOutputFamilyList(),
// outputCategoryActions.loadOutputCategoryList()
// ];
// if (steps) {
// if(steps[0] === '1') {
// actions.push(searchActions.checkCriteria());
// }
// if(steps[1] === '1') {
// actions.push(searchActions.checkOutput());
// }
// if(steps[2] === '1') {
// actions.push(searchActions.checkResult());
// }
// }
// return actions;
// }
//
// // User come back to the search module: reload initial state
// if(!datasetName && !pristine) {
// return of(searchActions.resetSearch());
// }
//
// // User change step and it's the same search: No action
// return of({ type: '[No Action] Init Search' });
// })
// )
// );
//
// restartSearch$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.restartSearch),
// map(() => searchActions.initSearch())
// )
// );
//
// loadDefaultFormParameters$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.loadDefaultFormParameters),
// concatLatestFrom(() => [
// this.store.select(attributeSelector.selectAllAttributes),
// this.store.select(searchSelector.selectCriteriaListByRoute),
// this.store.select(searchSelector.selectOutputListByRoute)
// ]),
// mergeMap(([action, attributeList, criteriaList, outputList]) => {
// // Update criteria list
// let defaultCriteriaList = [];
// if (criteriaList) {
// // Build criteria list with the URL query parameters (c)
// defaultCriteriaList = criteriaList.split(';').map((c: string) => {
// const params = c.split('::');
// const attribute = attributeList.find(a => a.id === parseInt(params[0], 10));
// return stringToCriterion(attribute, params);
// });
// } else {
// // Build default criteria list with the attribute list metamodel configuration
// defaultCriteriaList = attributeList
// .filter(attribute => attribute.id_criteria_family && attribute.search_type && attribute.min)
// .map(attribute => stringToCriterion(attribute));
// }
//
// // Update output list
// let defaultOutputList = [];
// if (outputList) {
// // Build output list with the URL query parameters (a)
// defaultOutputList = outputList.split(';').map((o: string) => parseInt(o, 10));
// } else {
// // Build default output list with the attribute list metamodel configuration
// defaultOutputList = attributeList
// .filter(attribute => attribute.selected && attribute.id_output_category)
// .map(attribute => attribute.id);
// }
//
// // Returns actions and mark the form as dirty
// return [
// searchActions.updateCriteriaList({ criteriaList: defaultCriteriaList }),
// searchActions.updateOutputList({ outputList: defaultOutputList }),
// searchActions.markAsDirty()
// ];
// })
// )
// );
//
// retrieveDataLength$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.retrieveDataLength),
// concatLatestFrom(() => [
// this.store.select(datasetSelector.selectDatasetNameByRoute),
// this.store.select(searchSelector.selectCriteriaList)
// ]),
// mergeMap(([action, datasetName, criteriaList]) => {
// let query = datasetName + '?a=count';
// if (criteriaList.length > 0) {
// query += '&c=' + criteriaList.map(criterion => criterionToString(criterion)).join(';');
// }
//
// return this.searchService.retrieveDataLength(query)
// .pipe(
// map((response: { nb: number }[]) => searchActions.retrieveDataLengthSuccess({ length: response[0].nb })),
// catchError(() => of(searchActions.retrieveDataLengthFail()))
// )
// })
// )
// );
//
// retrieveDataLengthFail$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.retrieveDataLengthFail),
// tap(() => this.toastr.error('Loading Failed', 'The search data length loading failed'))
// ), { dispatch: false}
// );
//
// retrieveData$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.retrieveData),
// concatLatestFrom(() => [
// this.store.select(datasetSelector.selectDatasetNameByRoute),
// this.store.select(searchSelector.selectCriteriaList),
// this.store.select(searchSelector.selectOutputList)
// ]),
// mergeMap(([action, datasetName, criteriaList, outputList]) => {
// let query = datasetName + '?a=' + outputList.join(';');
// if (criteriaList.length > 0) {
// query += '&c=' + criteriaList.map(criterion => criterionToString(criterion)).join(';');
// }
// query += '&p=' + action.pagination.nbItems + ':' + action.pagination.page;
// query += '&o=' + action.pagination.sortedCol + ':' + action.pagination.order;
//
// return this.searchService.retrieveData(query)
// .pipe(
// map((data: any[]) => searchActions.retrieveDataSuccess({ data })),
// catchError(() => of(searchActions.retrieveDataFail()))
// )
// })
// )
// );
//
// retrieveDataFail$ = createEffect(() =>
// this.actions$.pipe(
// ofType(searchActions.retrieveDataFail),
// tap(() => this.toastr.error('Loading Failed', 'The search data loading failed'))
// ), { dispatch: false}
// );
constructor(
private actions$: Actions,
private store: Store<{ }>
) {}
}