Skip to content

Commit

Permalink
add new upload document page (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Jan 21, 2022
1 parent 031fdc5 commit bffce14
Show file tree
Hide file tree
Showing 9 changed files with 501 additions and 106 deletions.
16 changes: 15 additions & 1 deletion geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,19 @@ export const uploadDataset = ({
.then(({ data }) => (data));
};

export const uploadDocument = ({
title,
file,
permissions = { users: { AnonymousUser: [] }, groups: {}}
}) => {
const formData = new FormData();
formData.append('title', title);
formData.append('doc_file', file);
formData.append('permissions', JSON.stringify(permissions));

This comment has been minimized.

Copy link
@ridoo

ridoo Nov 5, 2024

@kilichenko-pixida here there permissions attribute got set by the client. but got removed later (will have to find the commit).

return axios.post(`/documents/upload?no__redirect=true`, formData)
.then(({ data }) => (data));
};

export default {
getEndpoints,
getResources,
Expand Down Expand Up @@ -800,5 +813,6 @@ export default {
getDatasets,
getPendingUploads,
getProcessedUploadsById,
getProcessedUploadsByImportId
getProcessedUploadsByImportId,
uploadDocument
};
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 @@ -41,6 +41,7 @@ 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 UploadDocumentRoute from '@js/routes/UploadDocument';

import gnsearch from '@js/reducers/gnsearch';
import gnresource from '@js/reducers/gnresource';
Expand Down Expand Up @@ -188,6 +189,11 @@ const routes = [
name: 'upload_dataset',
path: ['/upload/dataset'],
component: UploadDatasetRoute
},
{
name: 'upload_document',
path: ['/upload/document'],
component: UploadDocumentRoute
}
];

Expand Down
107 changes: 4 additions & 103 deletions geonode_mapstore_client/client/js/routes/UploadDataset.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020, GeoSolutions Sas.
* Copyright 2022, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
Expand All @@ -20,15 +20,13 @@ import ViewerLayout from '@js/components/ViewerLayout';
import FaIcon from '@js/components/FaIcon';
import Button from '@js/components/Button';
import Spinner from '@js/components/Spinner';
import Badge from '@js/components/Badge';
import {
getPendingUploads,
getProcessedUploadsById,
getProcessedUploadsByImportId,
uploadDataset
} from '@js/api/geonode/v2';
import axios from '@mapstore/framework/libs/ajax';
import moment from 'moment';
import { FormControl as FormControlRB } from 'react-bootstrap';
import localizedProps from '@mapstore/framework/components/misc/enhancers/localizedProps';
// import withDebounceOnCallback from '@mapstore/framework/components/misc/enhancers/withDebounceOnCallback';
Expand All @@ -38,6 +36,9 @@ function InputControl({ onChange, value, ...props }) {
return <FormControl {...props} value={value} onChange={event => onChange(event.target.value)}/>;
}
const InputControlWithDebounce = InputControl;
import PendingUploadCard from '@js/routes/upload/PendingUploadCard';
import UploadCard from '@js/routes/upload/UploadCard';


const supportedDatasetTypes = [
{
Expand Down Expand Up @@ -95,106 +96,6 @@ function getDatasetFileType(file) {
return datasetFileType?.id;
}

function PendingUploadCard({
missingExt,
baseName,
onRemove,
filesExt
}) {
return (
<div className="gn-upload-card">
<div className="gn-upload-card-header">
{missingExt.length > 0 ? <div className="gn-upload-card-error"><FaIcon name="exclamation"/></div> : null}
<div className="gn-upload-card-title">{baseName}</div>
{onRemove
? <Button size="xs" onClick={onRemove}>
<FaIcon name="trash"/>
</Button>
: null}
</div>
{missingExt.length > 0 && <div className="gn-upload-card-body">
Missing files: {missingExt.join(', ')}
</div>}
{<ul>
{filesExt.map(ext => {
return (
<li key={ext}>
<Badge>.{ext}</Badge>
</li>
);
})}
</ul>}
</div>
);
}

function UploadCard({
name,
state,
detailUrl,
progress,
createDate,
resumeUrl,
onRemove
}) {
return (
<div className="gn-upload-card">
<div className="gn-upload-card-header">
{state === 'INVALID' ? <div className="gn-upload-card-error"><FaIcon name="exclamation"/></div> : null}
<div className="gn-upload-card-title">
{detailUrl
? <a
href={detailUrl}
target="_blank"
rel="noopener noreferrer"
>
{name}
</a>
: name}
</div>
{(state === 'PENDING' || state === 'COMPLETE') && progress < 100 ? <Spinner /> : null}
{onRemove
? <Button size="xs" onClick={onRemove}>
<FaIcon name="trash"/>
</Button>
: null}
</div>
<div className="gn-upload-card-body">
<div>{moment(createDate).format('MMMM Do YYYY')}</div>
</div>
<div className="gn-upload-card-footer">
<div className="gn-upload-card-tools">
{resumeUrl
? <Button
variant="primary"
size="xs"
href={resumeUrl}
>
Complete upload
</Button>
: null}
</div>
</div>
<div
className={`gn-upload-card-progress ${state && state.toLowerCase() || ''}`}
style={{
width: `100%`,
height: 2
}}
>
<div
style={{
width: `${progress}%`,
height: 2,
transition: '0.3s all'
}}
>
</div>
</div>
</div>
);
}

function UploadList({
children,
onSuccess
Expand Down
Loading

0 comments on commit bffce14

Please sign in to comment.