diff --git a/renderer/src/layouts/projects/Export/ExportProjectPopUp.js b/renderer/src/layouts/projects/Export/ExportProjectPopUp.js
index 71c2dc47..d6f4e7fe 100644
--- a/renderer/src/layouts/projects/Export/ExportProjectPopUp.js
+++ b/renderer/src/layouts/projects/Export/ExportProjectPopUp.js
@@ -38,6 +38,7 @@ export default function ExportProjectPopUp(props) {
const [metadata, setMetadata] = React.useState({});
const [audioExport, setAudioExport] = React.useState('default');
const [checkText, setCheckText] = React.useState(false);
+ const [checkZip, setCheckZip] = React.useState(true);
const [totalExported, setTotalExported] = React.useState(0);
const [totalExports, setTotalExports] = React.useState(0);
@@ -87,38 +88,51 @@ export default function ExportProjectPopUp(props) {
const updateCommon = (fs, path, folder, project) => {
const fse = window.require('fs-extra');
logger.debug('ExportProjectPopUp.js', 'Updated Scripture burrito');
- let data = fs.readFileSync(path.join(folder, 'metadata.json'), 'utf-8');
- const sb = JSON.parse(data);
- // Adding the below line in 0.5.8 version, since the id in the previous versions is autographa.org
- sb.idAuthorities.scribe.id = 'http://www.scribe.bible';
- if (!sb.copyright?.shortStatements && sb.copyright?.licenses) {
- delete sb.copyright.publicDomain;
- data = JSON.stringify(sb);
- }
- const success = validate('metadata', path.join(folder, 'metadata.json'), data, sb.meta.version);
- if (success) {
- logger.debug('ExportProjectPopUp.js', 'Burrito validated successfully');
- fse.copy(folder, path.join(folderPath, project.name))
- .then(() => {
- deleteGitAfterCopy(fs, path.join(folderPath, project.name), path)
- .then(() => {
- resetExportProgress(); // reset export states
- logger.debug('ExportProjectPopUp.js', 'Exported Successfully');
- setNotify('success');
- setSnackText(t('dynamic-msg-export-success'));
- setOpenSnackBar(true);
- closePopUp(false);
+ let data = fs.readFileSync(path.join(folder, 'metadata.json'), 'utf-8');
+ const sb = JSON.parse(data);
+ // Adding the below line in 0.5.8 version, since the id in the previous versions is autographa.org
+ sb.idAuthorities.scribe.id = 'http://www.scribe.bible';
+ if (!sb.copyright?.shortStatements && sb.copyright?.licenses) {
+ delete sb.copyright.publicDomain;
+ data = JSON.stringify(sb);
+ }
+ const success = validate('metadata', path.join(folder, 'metadata.json'), data, sb.meta.version);
+ if (success) {
+ logger.debug('ExportProjectPopUp.js', 'Burrito validated successfully');
+ fse.copy(folder, path.join(folderPath, project.name))
+ .then(() => {
+ deleteGitAfterCopy(fs, path.join(folderPath, project.name), path)
+ .then(async () => {
+ // convert to zip if text translation and zip checked
+ if (project?.type === 'Text Translation' && checkZip) {
+ const AdmZip = window.require('adm-zip');
+ const zip = new AdmZip();
+ zip.addLocalFolder(path.join(folderPath, project.name));
+ zip.writeZip(path.join(folderPath, `${project.name}.zip`));
+ // delete folder
+ await fs.rmdirSync(path.join(folderPath, project.name), { recursive: true }, async (err) => {
+ if (err) {
+ throw new Error(`Remove Org Exported Dir failed : ${err}`);
+ }
});
- })
- .catch((err) => {
- resetExportProgress(); // reset export states
- logger.error('ExportProjectPopUp.js', `Failed to export ${err}`);
- setNotify('failure');
- setSnackText(t('dynamic-msg-export-fail'));
- setOpenSnackBar(true);
- closePopUp(false);
- });
- }
+ }
+ resetExportProgress(); // reset export states
+ logger.debug('ExportProjectPopUp.js', 'Exported Successfully');
+ setNotify('success');
+ setSnackText(t('dynamic-msg-export-success'));
+ setOpenSnackBar(true);
+ closePopUp(false);
+ });
+ })
+ .catch((err) => {
+ resetExportProgress(); // reset export states
+ logger.error('ExportProjectPopUp.js', `Failed to export ${err}`);
+ setNotify('failure');
+ setSnackText(t('dynamic-msg-export-fail'));
+ setOpenSnackBar(true);
+ closePopUp(false);
+ });
+ }
};
const updateBurritoVersion = (username, fs, path, folder) => {
@@ -295,6 +309,16 @@ export default function ExportProjectPopUp(props) {
Full project
+ )}
+ {project?.type === 'Text Translation' && (
+
+
+
+ setCheckZip(!checkZip)} />
+ Project as zip
+
+
+
)}
diff --git a/renderer/src/layouts/projects/ImportProjectPopUp.js b/renderer/src/layouts/projects/ImportProjectPopUp.js
index a9796a2c..4a4b747f 100644
--- a/renderer/src/layouts/projects/ImportProjectPopUp.js
+++ b/renderer/src/layouts/projects/ImportProjectPopUp.js
@@ -39,6 +39,7 @@ export default function ImportProjectPopUp(props) {
const [processMerge, setProcessMerge] = React.useState(false);
const [currentUser, setCurrentUser] = React.useState();
const [sbData, setSbData] = React.useState({});
+ const [importingIsZip, setImportingIsZip] = React.useState(false);
const [model, setModel] = React.useState({
openModel: false,
title: '',
@@ -58,8 +59,9 @@ export default function ImportProjectPopUp(props) {
completedSteps: 0,
});
- function close() {
- logger.debug('ImportProjectPopUp.js', 'Closing the Dialog box');
+ async function close(triggeredFrom) {
+ logger.debug('ImportProjectPopUp.js', `Closing the Dialog box : Triggered from : ${triggeredFrom}`);
+ removeExtractedZipDir()
setValid(false);
closePopUp(false);
setShow(false);
@@ -68,27 +70,58 @@ export default function ImportProjectPopUp(props) {
const openFileDialogSettingData = async () => {
logger.debug('ImportProjectPopUp.js', 'Inside openFileDialogSettingData');
- const options = { properties: ['openDirectory'] };
+ // const options = { properties: ['openDirectory', 'openFile'] };
+ const options = { properties: [] };
const { dialog } = window.require('@electron/remote');
const chosenFolder = await dialog.showOpenDialog(options);
+ let selectedFolderPath;
if ((chosenFolder.filePaths).length > 0) {
logger.debug('ImportProjectPopUp.js', 'Selected a directory');
await localforage.getItem('userProfile').then(async (value) => {
setShow(true);
setCurrentUser(value.username)
// Adding 'projects' to check the duplication in the user project resources list
- const result = await viewBurrito(chosenFolder.filePaths[0], value.username, 'projects');
+ selectedFolderPath = chosenFolder.filePaths[0]
+ // check if zip
+ if(chosenFolder.filePaths[0].endsWith('.zip')) {
+ const AdmZip = window.require('adm-zip');
+ setImportingIsZip(true)
+ const path = require('path');
+ const zip = new AdmZip(chosenFolder.filePaths[0]);
+ const extractFileName = chosenFolder.filePaths[0].replace('.zip',"__extracted")
+ zip.extractAllTo(path.join(extractFileName),true);
+ // change the choosefolder Filepath to new path
+ selectedFolderPath = extractFileName
+ }
+
+ const result = await viewBurrito(selectedFolderPath, value.username, 'projects');
setSbData(result);
});
} else {
logger.debug('ImportProjectPopUp.js', 'Didn\'t select any project');
setSbData({});
- close();
+ close("else");
}
- setFolderPath(chosenFolder.filePaths[0]);
+ setFolderPath(selectedFolderPath);
};
- const modelClose = () => {
+ const removeExtractedZipDir = async() => {
+ const path = require('path');
+ const fs = window.require('fs');
+ // delete the extracted zip file after successfull / failed import
+ if(importingIsZip) {
+ setImportingIsZip(false)
+ if (fs.existsSync(path.join(folderPath))) {
+ await fs.rmdirSync(path.join(folderPath), { recursive: true }, async (err) => {
+ if (err) {
+ throw new Error(`Remove extracted zip folder : ${err}`);
+ }
+ });
+ }
+ }
+ }
+
+ const modelClose = async () => {
setModel({
openModel: false,
title: '',
@@ -99,11 +132,15 @@ export default function ImportProjectPopUp(props) {
};
const callImport = async (updateBurriot) => {
- modelClose();
+ await modelClose();
setImportProgress((prev)=>({...prev, importStarted:true, completedSteps: prev.completedSteps + 1 }))
logger.debug('ImportProjectPopUp.js', 'Inside callImport');
+ const path = require('path');
+ const fs = window.require('fs');
await localforage.getItem('userProfile').then(async (value) => {
const status = await importBurrito(folderPath, value.username, updateBurriot, languages);
+ // delete the extracted zip file after successfull / failed import
+ await removeExtractedZipDir()
setImportProgress((prev)=>({...prev, importStarted:true, completedSteps: prev.completedSteps + 1 }))
setOpenSnackBar(true);
closePopUp(false);
@@ -112,7 +149,7 @@ export default function ImportProjectPopUp(props) {
setImportProgress((prev)=>({...prev, importStarted:true, completedSteps: 0, totalSteps: 0}))
if (status[0].type === 'success') {
setSbData({});
- close();
+ close("Success");
FetchProjects();
router.push('/projects');
}
@@ -210,7 +247,8 @@ export default function ImportProjectPopUp(props) {
initialFocus={cancelButtonRef}
static
open={show}
- onClose={close}
+ // onClose={() => close('X')}
+ onClose={() => {}}
>
@@ -221,7 +259,7 @@ export default function ImportProjectPopUp(props) {
{t('label-import-project')}