data-discovery.model.ts 3.02 KB
Newer Older
1
import { BrapiResults } from './brapi.model';
2
3
4
5
6
7
import { Params } from '@angular/router';
import { asArray } from '../utils';


export const MAX_RESULTS = 10000;
export const DEFAULT_PAGE_SIZE = 10;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

export interface DataDiscoveryCriteria {
    accessions: string[];
    crops: string[];
    facetFields: string[];
    germplasmLists: string[];
    observationVariableIds: string[];
    sources: string[];
    types: string[];

    /**
     * Used to store the top selected node ids from the trait ontology widget
     */
    topSelectedTraitOntologyIds: string[];

    page: number;
    pageSize: number;
}

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
export class DataDiscoveryCriteriaUtils {
    static emptyCriteria(): DataDiscoveryCriteria {
        return {
            accessions: null,
            crops: null,
            facetFields: ['sources', 'types'],
            germplasmLists: null,
            observationVariableIds: null,
            topSelectedTraitOntologyIds: null,
            sources: null,
            types: null,

            page: 0,
            pageSize: DEFAULT_PAGE_SIZE
        };
    }

    static fromQueryParams(queryParams: Params): DataDiscoveryCriteria {
        return {
            ...DataDiscoveryCriteriaUtils.emptyCriteria(),

            crops: asArray(queryParams.crops),
            germplasmLists: asArray(queryParams.germplasmLists),
            accessions: asArray(queryParams.accessions),
            sources: asArray(queryParams.sources),
            types: asArray(queryParams.types),

            // The URL should only contain top selected trait ontology node ids
            topSelectedTraitOntologyIds: asArray(queryParams.observationVariableIds),

            page: queryParams.page - 1 || 0
        };
    }

    static toQueryParams(newCriteria: DataDiscoveryCriteria) {
        return {
            crops: newCriteria.crops,
            accessions: newCriteria.accessions,
            germplasmLists: newCriteria.germplasmLists,
            sources: newCriteria.sources,
            types: newCriteria.types,

            // The URL should only contain top selected trait ontology node ids
            observationVariableIds: newCriteria.topSelectedTraitOntologyIds,

            page: newCriteria.page + 1
        };
    }
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
}

export interface DataDiscoverySource {
    ['@id']: string;
    ['@type']: ['schema:DataCatalog'];
    ['schema:identifier']: string;
    ['schema:name']: string;
    ['schema:url']: string;
    ['schema:image']: string;
}

export interface DataDiscoveryDocument {
    ['@id']: string;
    ['@type']: DataDiscoveryType[];
    ['schema:identifier']: string;
    ['schema:name']: string;
    ['schema:url']: string;
    ['schema:description']: string;
    ['schema:includedInDataCatalog']: DataDiscoverySource;
}

export type DataDiscoveryType = 'Germplasm' | 'Phenotyping Study';

export interface DataDiscoveryResults extends BrapiResults<DataDiscoveryDocument> {
    facets: DataDiscoveryFacet[];
}

export interface DataDiscoveryFacet {
    field: string;
    terms: {
        term: string;
        label: string;
        count: number;
    }[];
}