genesys.ts 1.65 KB
Newer Older
1
2
// import {push} from 'react-router-redux';
import { GenesysService } from 'service/GenesysService';
3
4
5
6
import { Descriptor, DataType, DescriptorList, DescriptorListExtra } from 'model/descriptor.model';
import { loadDescriptorList } from 'actions/descriptorList';
import { loadDescriptor } from 'actions/descriptors';

7
8
9
10
11
12
13
14
15
16
17
import { log } from 'utilities/debug';

export const listAccessions = (filters: object, page: number = 0, results: number = 50) => (dispatch, getState) => {

    return GenesysService.listAccessions(filters, page, results)
        .then((data) => {
            return data;
        }).catch((error) => {
            log(`Genesys error`, error);
        });
};
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

export const loadGenesysDescriptors = () => (dispatch, getState) => {
  log('Loading Genesys descriptor list', 'dc1d4e81-a6dd-4f03-b682-53a3a1383988');
  return dispatch(loadDescriptorList('dc1d4e81-a6dd-4f03-b682-53a3a1383988',
    // TODO this can go to a state reducer
    async (descriptorList: DescriptorList) => {
      if (descriptorList.extras[DescriptorListExtra.JSON_MAPPING]) {
        descriptorList.extras[DescriptorListExtra.JSON_MAPPING] = JSON.parse(descriptorList.extras[DescriptorListExtra.JSON_MAPPING]);

        for (const descriptor of descriptorList.descriptors.filter((d) => d.dataType === DataType.SCALE || d.dataType === DataType.CODED)) {
          await dispatch(loadDescriptor(descriptor.uuid, (d: Descriptor) => {
            console.log(`Loaded details for ${d.uuid}`, d);
            descriptor.terms = d.terms;
          }));
        }
      }
      return descriptorList;
    },
    (error) => {
      log(`No Genesys PGR descriptor list`, error);
      return error;
    }));
};