-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdataset.js
More file actions
116 lines (105 loc) · 2.95 KB
/
dataset.js
File metadata and controls
116 lines (105 loc) · 2.95 KB
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
import config from "../app.config";
import {getHeader} from "../utils/common";
export const RECEIVE_FILES_IN_DATASET = "RECEIVE_FILES_IN_DATASET";
export function receiveFilesInDataset(type, json) {
return (dispatch) => {
dispatch({
type: type,
files: json,
receivedAt: Date.now(),
});
};
}
export function fetchFilesInDataset(id) {
let url = `${config.hostname}/clowder/api/datasets/${id}/files?superAdmin=true`;
return (dispatch) => {
return fetch(url, {mode: "cors", headers: getHeader()})
.then((response) => {
if (response.status === 200) {
response.json().then(json => {
dispatch(receiveFilesInDataset(RECEIVE_FILES_IN_DATASET, json));
});
} else {
dispatch(receiveFilesInDataset(RECEIVE_FILES_IN_DATASET, []));
}
});
};
}
export const RECEIVE_DATASET_ABOUT = "RECEIVE_DATASET_ABOUT";
export function receiveDatasetAbout(type, json) {
return (dispatch) => {
dispatch({
type: type,
about: json,
receivedAt: Date.now(),
});
};
}
export function fetchDatasetAbout(id) {
let url = `${config.hostname}/clowder/api/datasets/${id}?superAdmin=true`;
return (dispatch) => {
return fetch(url, {mode: "cors", headers: getHeader()})
.then((response) => {
if (response.status === 200) {
response.json().then(json => {
dispatch(receiveDatasetAbout(RECEIVE_DATASET_ABOUT, json));
});
} else {
dispatch(receiveDatasetAbout(RECEIVE_DATASET_ABOUT, []));
}
});
};
}
export const RECEIVE_DATASETS = "RECEIVE_DATASETS";
export function receiveDatasets(type, json) {
return (dispatch) => {
dispatch({
type: type,
datasets: json,
receivedAt: Date.now(),
});
};
}
export function fetchDatasets(when, date, limit = 5) {
let url = `${config.hostname}/clowder/api/datasets?superAdmin=true&limit=${limit}`;
if (date) url = `${url}&date=${date}`;
if (when) url = `${url}&when=${when}`;
return (dispatch) => {
return fetch(url, {mode: "cors", headers: getHeader()})
.then((response) => {
if (response.status === 200) {
response.json().then(json => {
dispatch(receiveDatasets(RECEIVE_DATASETS, json));
});
} else {
dispatch(receiveDatasets(RECEIVE_DATASETS, []));
}
});
};
}
export const DELETE_DATASET = "DELETE_DATASET";
export function deleteDataset(datasetId) {
let url = `${config.hostname}/clowder/api/datasets/${datasetId}?superAdmin=true`;
return (dispatch) => {
return fetch(url, {mode: "cors", method: "DELETE", headers: getHeader()})
.then((response) => {
if (response.status === 200) {
response.json().then(json => {
dispatch({
type: DELETE_DATASET,
dataset: {"id": datasetId, "status": json["status"] === undefined ? json["status"] : "success"},
receivedAt: Date.now(),
});
});
} else {
response.json().then(json => {
dispatch({
type: DELETE_DATASET,
dataset: {"id": null, "status": json["status"] === undefined ? json["status"] : "fail"},
receivedAt: Date.now(),
});
});
}
});
};
}