Skip to content

Commit

Permalink
add new upload dataset page (#715)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Jan 19, 2022
1 parent afc5074 commit 108b84f
Show file tree
Hide file tree
Showing 9 changed files with 888 additions and 6 deletions.
69 changes: 66 additions & 3 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import get from 'lodash/get';
import { getUserInfo } from '@js/api/geonode/user';
import { setFilterById } from '@js/utils/SearchUtils';
import { ResourceTypes, availableResourceTypes, setAvailableResourceTypes } from '@js/utils/ResourceUtils';
import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils';

/**
* Actions for GeoNode save workflow
Expand All @@ -39,7 +40,8 @@ let endpoints = {
'owners': '/api/v2/owners',
'keywords': '/api/v2/keywords',
'regions': '/api/v2/regions',
'groups': '/api/v2/groups'
'groups': '/api/v2/groups',
'uploads': '/api/v2/uploads'
};

const RESOURCES = 'resources';
Expand All @@ -54,7 +56,7 @@ const REGIONS = 'regions';
const CATEGORIES = 'categories';
const KEYWORDS = 'keywords';
const GROUPS = 'groups';

const UPLOADS = 'uploads';

function addCountToLabel(name, count) {
return `${name} (${count || 0})`;
Expand Down Expand Up @@ -707,6 +709,64 @@ export const copyResource = (resource) => {
.then(({ data }) => data);
};

export const getPendingUploads = () => {
return axios.get(parseDevHostname(endpoints[UPLOADS]), {
params: {
'filter{-state}': 'PROCESSED',
'page': 1,
'page_size': 99999
}
})
.then(({ data }) => data?.uploads);
};

export const getProcessedUploadsById = (ids) => {
return axios.get(parseDevHostname(endpoints[UPLOADS]), {
params: {
'filter{state}': 'PROCESSED',
'page': 1,
'page_size': ids.length,
'filter{id.in}': ids
}
})
.then(({ data }) => data?.uploads);
};

export const getProcessedUploadsByImportId = (importIds) => {
return axios.get(parseDevHostname(endpoints[UPLOADS]), {
params: {
'filter{state}': 'PROCESSED',
'page': 1,
'page_size': importIds.length,
'filter{import_id.in}': importIds
}
})
.then(({ data }) => data?.uploads);
};

export const uploadDataset = ({
file,
auxiliaryFiles,
ext,
charset = 'UTF-8',
permissions = { users: { AnonymousUser: [] }, groups: {}}
}) => {
const formData = new FormData();
formData.append('base_file', file);
formData.append('permissions', JSON.stringify(permissions));
formData.append('charset', charset);
const { timeEnabled } = getConfigProp('geoNodeSettings') || {};
if (timeEnabled) {
formData.append('time', ['csv', 'shp'].includes(ext) ? true : false);
}
Object.keys(auxiliaryFiles)
.forEach((auxExt) => {
formData.append(auxExt + '_file', auxiliaryFiles[auxExt]);
});
return axios.post(`${parseDevHostname(endpoints[UPLOADS])}/upload`, formData)
.then(({ data }) => (data));
};

export default {
getEndpoints,
getResources,
Expand Down Expand Up @@ -737,5 +797,8 @@ export default {
updateCompactPermissionsByPk,
deleteResource,
copyResource,
getDatasets
getDatasets,
getPendingUploads,
getProcessedUploadsById,
getProcessedUploadsByImportId
};
6 changes: 6 additions & 0 deletions geonode_mapstore_client/client/js/apps/gn-catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import annotations from '@mapstore/framework/reducers/annotations';
import SearchRoute from '@js/routes/Search';
import DetailRoute from '@js/routes/Detail';
import ViewerRoute from '@js/routes/Viewer';
import UploadDatasetRoute from '@js/routes/UploadDataset';

import gnsearch from '@js/reducers/gnsearch';
import gnresource from '@js/reducers/gnresource';
Expand Down Expand Up @@ -182,6 +183,11 @@ const routes = [
'/detail/:ctype/:pk'
],
component: DetailRoute
},
{
name: 'upload_dataset',
path: ['/upload/dataset'],
component: UploadDatasetRoute
}
];

Expand Down
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/js/epics/gnsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const setResourceApi = {
* Get resource type and data for state update in sync process
* @param {String} appType geostory or dashboard
* @param {Object} resourceData Resource Object
* @param {Optional: Array} successArr Array of success responses only used in case of dashboard
* @param {Array} successArr Array of success responses only used in case of dashboard
* @returns {Object}
*/
const getSyncInfo = (appType, resourceData, successArr = []) => {
Expand Down
Loading

0 comments on commit 108b84f

Please sign in to comment.