Skip to content

Commit

Permalink
archived and non archived flows when uploading an existing file
Browse files Browse the repository at this point in the history
  • Loading branch information
isuru-aot committed Jul 26, 2023
1 parent 9385d7d commit a73724b
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 223 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,17 @@ def find_by_document_name_and_project_guid(cls, document_name, project_guid=None
psdx_alias = aliased(ProjectSummaryDocumentXref)
ps_alias = aliased(ProjectSummary)
p_alias = aliased(Project)

# Define the ON clause explicitly
on_clause = md_alias.mine_document_guid == psdx_alias.mine_document_guid


query = query\
.select_from(md_alias)\
.join(psdx_alias, on_clause)\
.with_entities(md_alias.document_name, md_alias.mine_document_guid, p_alias.project_guid, md_alias.is_archived, \
md_alias.mine_guid, md_alias.document_class, md_alias.update_timestamp, md_alias.update_user)\
.filter(md_alias.document_name == document_name, md_alias.deleted_ind == False)\
.join(ps_alias, ps_alias.project_summary_id == psdx_alias.project_summary_id)\
.join(psdx_alias, psdx_alias.mine_document_guid == md_alias.mine_document_guid)\
.join(ps_alias, psdx_alias.project_summary_id == ps_alias.project_summary_id)\
.join(p_alias, p_alias.project_guid == ps_alias.project_guid)\
.filter(p_alias.project_guid == project_guid)

resp = query.first()

return resp

return query.first()

raise ValueError("Missing 'project_guid', This is required to continue the file upload process.")
10 changes: 8 additions & 2 deletions services/core-api/app/api/services/document_manager_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ def validateFileNameAndInitializeFileUploadWithDocumentManager(cls, request, min
if not mine_document: # No existing file found in this application hence continuing the file uploading
return DocumentManagerService.initializeFileUploadWithDocumentManager(request, mine, document_category)
elif mine_document.is_archived: # An archived file with the same name in this application found, hence responing with 409
content = f'{{"description" : "File already exist with the given name: {file_name}. Replace with the new version", "status_code": 409, "status": "ARCHIVED_FILE_EXIST"}}'
content = f'{{"description" : "Archived file already exist with the given name: {file_name}", "status_code": 409, \
"status": "ARCHIVED_FILE_EXIST", "file_name": "{file_name}", "mine_guid": "{mine_document.mine_guid}", \
"file_type": "{mine_document.document_class}", "update_timestamp": "{mine_document.update_timestamp}", "update_user": "{mine_document.update_user}", \
"mine_document_guid": "{mine_document.mine_document_guid}"}}'
return Response(content, 409)
else: # The found file with the same name in this application is not archived.
content = f'{{"description" : "Archived file already exist with the given name: {file_name}", "status_code": 409, "status": "REPLACEABLE_FILE_EXIST"}}'
content = f'{{"description" : "File already exist with the given name: {file_name}. Replace with the new version", \
"status_code": 409, "status": "REPLACEABLE_FILE_EXIST", "file_name": "{file_name}", "mine_guid": "{mine_document.mine_guid}", \
"file_type": "{mine_document.document_class}", "update_timestamp": "{mine_document.update_timestamp}", "update_user": "{mine_document.update_user}", \
"mine_document_guid": "{mine_document.mine_document_guid}"}}'
return Response(content, 409, content_type='application/json')

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion services/minespace-web/common/constants/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const PROJECT_SUMMARY_DOCUMENTS = ({ projectGuid, projectSummaryGuid, min
)}`;
//New version upload
export const NEW_VERSION_PROJECT_SUMMARY_DOCUMENTS = ({ mineGuid, mineDocumentGuid }) =>
`mines/${mineGuid}/documents/${mineDocumentGuid}/versions/upload`;
`/mines/${mineGuid}/documents/${mineDocumentGuid}/versions/upload`;
export const PROJECT_SUMMARY_DOCUMENT = (
projectGuid,
projectSummaryGuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import {
} from "@common/constants/API";
import FileUpload from "@/components/common/FileUpload";
import { Alert, Form, Typography, Modal, Table, Divider, Popconfirm } from "antd";
import { fetchUserMineInfo } from "@/actionCreators/userDashboardActionCreator";

const propTypes = {
onFileLoad: PropTypes.func.isRequired,
onRemoveFile: PropTypes.func.isRequired,
acceptedFileTypesMap: PropTypes.objectOf(PropTypes.string).isRequired,
params: PropTypes.objectOf(PropTypes.string).isRequired,
fetchUserMineInfo: PropTypes.func.isRequired,
};

const notificationDisabledStatusCodes = [409]; // Define the notification disabled status codes
Expand All @@ -22,67 +24,36 @@ export const ProjectSummaryFileUpload = (props) => {
const [isArchivedFileModalVisible, setIsArchivedFileModalVisible] = useState(false);
const [relaplaceableFileModalMessage, setRelaplaceableFileModalMessage] = useState("");
const [isRelaplaceableFileModalVisible, setRelaplaceableFileModalVisible] = useState(false);
const [isFileUploading, setIsFileUploading] = useState(false);
const [uploading, setUploading] = useState(false);
const [fileName, setFileName] = useState("");
const [uploadUrl, setUploadUrl] = useState("");
const [uploadKey, setUploadKey] = useState(0);
const [shouldReplaceFile, setShouldReplaceFile] = useState(false);
const [replaceFileUploadUrl, setReplaceFileUploadUrl] = useState(false);
const [mineDocumentGuid, setMineDocumentGuid] = useState(null);
const [mineGuid, setMineGuid] = useState(null);
const [fileDetails, setFileDetails] = useState(null);

const handleCloseModal = () => {
console.log("Closing....");
setIsArchivedFileModalVisible(false);
setRelaplaceableFileModalVisible(false);
};

const childRef = useRef(null);

const handleManualUpload = () => {
// Call the upload.start() function using the ref
const uploadInstance = childRef.current?.props?.onFileLoad();
// Do whatever you need with the 'uploadInstance', you can start the upload by calling 'uploadInstance.start()'
};

const handleNewVersionSubmit = () => {
console.log("TODO: handleNewVersionSubmit()");
setRelaplaceableFileModalVisible(false);
console.log("TODO: callFileUpload()");
// setIsFileUploading(true)
setUploadUrl(NEW_VERSION_PROJECT_SUMMARY_DOCUMENTS('mine_guid', 'mine_document_guid'));
// setUploadRetryCount(uploadRetryCount + 1);
handleManualUpload();

// childRef.current.startFileUpload();

//
// props.onFileLoad(fileName, document_manager_guid)
// props.onFileLoad(fileName, "document_manager_guid")

console.log("-->>>>props.onFileReplace");
setReplaceFileUploadUrl(
NEW_VERSION_PROJECT_SUMMARY_DOCUMENTS({
mineGuid: props.params.mineGuid,
mineDocumentGuid: mineDocumentGuid,
})
);
setShouldReplaceFile(true);
};

const dataOriginal = [
{
fileName: "file1.pdf",
fileType: "spatial",
date: "Nov 23 2022",
uploader: "idr/ignw",
},
];

const dataNew = [
{
fileName: "file1.pdf",
fileType: "spatial",
date: "Nov 23 2022",
uploader: "idr/ignw",
},
];

const columns = [
{ dataIndex: "fileName", width: "40%" },
{ dataIndex: "fileType", width: "20%" },
{ dataIndex: "date", width: "20%" },
{ dataIndex: "uploader", width: "20%" },
{ dataIndex: "fileName" },
{ dataIndex: "fileType" },
{ dataIndex: "date" },
{ dataIndex: "uploader" },
];

return (
Expand All @@ -92,34 +63,43 @@ export const ProjectSummaryFileUpload = (props) => {
id="fileUpload"
name="fileUpload"
component={FileUpload}
addFileStart={() => setUploading(isFileUploading)}
shouldReplaceFile={shouldReplaceFile}
uploadUrl={PROJECT_SUMMARY_DOCUMENTS(props.params)}
replaceFileUploadUrl={replaceFileUploadUrl}
acceptedFileTypesMap={props.acceptedFileTypesMap}
onFileLoad={props.onFileLoad}
onRemoveFile={props.onRemoveFile}
notificationDisabledStatusCodes={notificationDisabledStatusCodes}
allowRevert
allowMultiple
key={uploadKey}
onError={(filename, e) => {
setFileName(fileName);
if (
e.response.status_code &&
notificationDisabledStatusCodes.includes(e.response.status_code)
) {
console.log("Error STATUS: ", e.response.status);
if (e.response.status === "ARCHIVED_FILE_EXIST") {
let message = `An archived file named ${filename} already exists. If you would like to restore it, download the archived file and upload it again with a different file name.`;
setArchivedFileModalMessage(message);
setIsArchivedFileModalVisible(true);
}
if (e.response.status === "REPLACEABLE_FILE_EXIST") {
//replace belows
let message = `A file with the same name already exists in this project. Replacing it will create a new version of the original file and replace it as part of this submission.`;
setRelaplaceableFileModalMessage(message);
setRelaplaceableFileModalVisible(true);
console.log("_______________RESP", e.response);
console.log("_______________ORGREQ", e.originalRequest);
setMineGuid(e.response.mine_guid);
setMineDocumentGuid(e.response.mine_document_guid);

const date = new Date(e.response.update_timestamp);
const options = { year: "numeric", month: "short", day: "2-digit" };
const formattedDate = date.toLocaleDateString("en-US", options);

setFileDetails({
file_name: filename,
file_type: e.response.file_type,
update_timestamp: `${formattedDate}`,
update_user: e.response.update_user,
});
}
}
}}
Expand Down Expand Up @@ -149,31 +129,13 @@ export const ProjectSummaryFileUpload = (props) => {
okText="Yes, replace"
cancelText="Cancel"
width={1000}
// orientationMargin="0"
// bodyStyle={{ padding: '24px 0px 24px 0px'}}
className="custom-modal"
className="new-file-replace-modal"
>
<style>
{`
.custom-modal .ant-modal-body {
padding-bottom: 24px;
padding-left: 0px;
padding-right: 0px;
padding-top: 24px;
color: red;
}
.ant-modal-footer {
padding: 24px;
}
`}
</style>
<Typography.Paragraph strong style={{ padding: "0px 0px 0px 24px" }}>
Replace File?
</Typography.Paragraph>
<Divider style={{ height: "3px", background: "#F0F0F0" }} />
<div style={{ padding: "0px 24px 0px 24px" }}>
{/* // onFinish={() => props.handleSubmit(props.documents).then(props.closeModal)} */}

<Typography.Paragraph>
<Alert
message="File Already exists"
Expand All @@ -182,36 +144,44 @@ export const ProjectSummaryFileUpload = (props) => {
description={relaplaceableFileModalMessage}
/>
</Typography.Paragraph>

<>
<style>
{`
.custom-table .ant-table-tbody > tr.ant-table-row > td {
border-bottom: none;
}
`}
</style>
<Typography.Text title="Original Doc">
<b>Original Document</b>
</Typography.Text>
<Table
dataSource={dataOriginal}
columns={columns}
showHeader={false} // Hide table header
pagination={false} // Disable pagination
className="custom-table" // Apply custom CSS class
/>
<Typography.Text title="Upload new">
<b>Upload new file</b>
</Typography.Text>
<Table
dataSource={dataNew}
columns={columns}
showHeader={false} // Hide table header
pagination={false} // Disable pagination
className="custom-table" // Apply custom CSS class
/>
</>
<Typography.Text title="Original Doc">
<b>Original Document</b>
</Typography.Text>
<Table
dataSource={[
{
fileName: fileDetails?.file_name ?? "-",
fileType: fileDetails?.file_type ?? "-",
date: fileDetails?.update_timestamp ?? "-",
uploader: fileDetails?.update_user ?? "-",
},
]}
columns={columns}
showHeader={false} // Hide table header
pagination={false} // Disable pagination
className="new-file-replace-table"
/>
<Typography.Text title="Upload new">
<b>Upload new file</b>
</Typography.Text>
<Table
dataSource={[
{
fileName: fileDetails?.file_name ?? "-",
fileType: "File Type",
date: new Date().toLocaleDateString("en-US", {
year: "numeric",
month: "short",
day: "2-digit",
}),
uploader: "user@bceid",
},
]}
columns={columns}
showHeader={false} // Hide table header
pagination={false} // Disable pagination
className="new-file-replace-table"
/>
</div>
</Modal>
</>
Expand All @@ -221,64 +191,3 @@ export const ProjectSummaryFileUpload = (props) => {
ProjectSummaryFileUpload.propTypes = propTypes;

export default ProjectSummaryFileUpload;

// import React, { useRef } from 'react';
// import ChildComponent from './ChildComponent';

// const ParentComponent = () => {
// const childRef = useRef();

// const handleClick = () => {
// childRef.current.myFunction();
// };

// return (
// <div>
// <h1>Parent Component</h1>
// <ChildComponent ref={childRef} />
// <button onClick={handleClick}>Call Child Function</button>
// </div>
// );
// };

// export default ParentComponent;

// const handleNewVersionSubmit = () => {
// console.log('TODO: handleNewVersionSubmit()')
// setRelaplaceableFileModalVisible(false);
// console.log('TODO: callFileUpload()')

// if (childRef.current) {
// console.log('CALLLLING child function________________________')
// childRef.current.childFunction(); // Step 2: Call the child function using the ref
// }

// childRef.current.childFunction();

// const fileUpload = new FileUpload(props);
// // fileUpload.setFileUploading(true);
// fileUpload.addFileStart = true

// // fileUpload.uploadUrl = 'http://localhost:3000/upload';
// // fileUpload.onFileLoad = onFileLoad
// // // fileUpload.server.process.up

// // return (
// // <Field
// // id="fileUpload"
// // name="fileUpload"
// // component={FileUpload}
// // uploadUrl={PROJECT_SUMMARY_DOCUMENTS(props.params)}
// // acceptedFileTypesMap={props.acceptedFileTypesMap}
// // onFileLoad={props.onFileLoad}
// // onRemoveFile={props.onRemoveFile}
// // // notificationDisabledStatusCodes={notificationDisabledStatusCodes}
// // allowRevert
// // allowMultiple
// // onError={(filename, e) => {
// // console.log('Error in uploading ', filename, ' as new version ', e)
// // }
// // }
// // />
// // )
// }
Loading

0 comments on commit a73724b

Please sign in to comment.