Skip to content

Commit

Permalink
tree view ctx menu upgrade; rename assay/study; write to update contr…
Browse files Browse the repository at this point in the history
…acts
  • Loading branch information
JonasLukasczyk committed Jun 26, 2024
1 parent 23afe1d commit cdeec89
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 133 deletions.
20 changes: 18 additions & 2 deletions packages/main/src/LocalFileSystemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const LocalFileSystemService = {
return result ? result.filePaths.map(path_to_arcitect) : null;
},

selectAnyFolders: async (options: Electron.OpenDialogOptions = {})=> {
selectAnyDirectories: async (options: Electron.OpenDialogOptions = {})=> {
options.properties = options.properties || ['openDirectory','multiSelections'] // if given from outside don't set, otherwise set default.
const window = BrowserWindow.getAllWindows().find(w => !w.isDestroyed())
const result = await dialog.showOpenDialog(window, options);
Expand Down Expand Up @@ -163,6 +163,13 @@ export const LocalFileSystemService = {
return fpath;
},

enforcePath: async (e,path)=>{
try {
FS.mkdirSync(path_to_system(path),{recursive:true});
} catch (err) {
}
},

writeFile: async (e,[path,data,options])=>{
options = options || {encoding:'UTF-8'};
path = path_to_system(path);
Expand Down Expand Up @@ -193,6 +200,13 @@ export const LocalFileSystemService = {
return sizes;
},

rename: async (e,[oldPath,newPath])=>{
try {
FS.renameSync( oldPath, newPath );
return true;
} catch {return false;}
},

exists: async (e,path)=>{
try {
FS.statSync(path_to_system(path))
Expand Down Expand Up @@ -226,10 +240,11 @@ export const LocalFileSystemService = {
ipcMain.handle('LocalFileSystemService.readDir', LocalFileSystemService.readDir);
ipcMain.handle('LocalFileSystemService.readFile', LocalFileSystemService.readFile);
ipcMain.handle('LocalFileSystemService.readImage', LocalFileSystemService.readImage);
ipcMain.handle('LocalFileSystemService.enforcePath', LocalFileSystemService.enforcePath);
ipcMain.handle('LocalFileSystemService.writeFile', LocalFileSystemService.writeFile);
ipcMain.handle('LocalFileSystemService.selectDir', LocalFileSystemService.selectDir);
ipcMain.handle('LocalFileSystemService.selectAnyFiles', LocalFileSystemService.selectAnyFiles);
ipcMain.handle('LocalFileSystemService.selectAnyFolders', LocalFileSystemService.selectAnyFolders);
ipcMain.handle('LocalFileSystemService.selectAnyDirectories', LocalFileSystemService.selectAnyDirectories);
ipcMain.handle('LocalFileSystemService.saveFile', LocalFileSystemService.saveFile);
ipcMain.handle('LocalFileSystemService.copy', LocalFileSystemService.copy);
ipcMain.handle('LocalFileSystemService.createEmptyFile', LocalFileSystemService.createEmptyFile);
Expand All @@ -240,5 +255,6 @@ export const LocalFileSystemService = {
ipcMain.handle('LocalFileSystemService.getFileSizes', LocalFileSystemService.getFileSizes);
ipcMain.handle('LocalFileSystemService.exists', LocalFileSystemService.exists);
ipcMain.handle('LocalFileSystemService.openPath', LocalFileSystemService.openPath);
ipcMain.handle('LocalFileSystemService.rename', LocalFileSystemService.rename);
}
}
6 changes: 4 additions & 2 deletions packages/renderer/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ const openLocalArc = async (path: string | null | void) =>{
AppProperties.state=AppProperties.STATES.HOME;
};
const saveLocalArc = async () =>{
await ArcControlService.writeARC();
const saveLocalArc = async (force) =>{
await ArcControlService.saveARC({
force: force
});
};
const refreshLocalArc = async () =>{
Expand Down
98 changes: 65 additions & 33 deletions packages/renderer/src/ArcControlService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { reactive } from 'vue'

import AppProperties from './AppProperties.ts';
Expand All @@ -7,6 +8,7 @@ import { gitignoreContract } from "@nfdi4plants/arctrl/Contract/Git";
import { Xlsx } from '@fslab/fsspreadsheet/Xlsx.js';
import {Contract} from '@nfdi4plants/arctrl/Contract/Contract.js'


import pDebounce from 'p-debounce';

export const Investigation = "investigation";
Expand All @@ -27,7 +29,7 @@ let init: {
arc: null
}

function relativePath_to_absolute(relativePath: string) {
function relative_to_absolute_path(relativePath: string) {
return ArcControlService.props.arc_root + '/' + relativePath
}

Expand Down Expand Up @@ -82,54 +84,74 @@ const ArcControlService = {

ArcControlService.props.busy = true;
arc.UpdateFileSystem();
for (const contract of contracts) {
for(const contract of contracts) {
switch (contract.Operation) {
case 'DELETE':
await window.ipc.invoke('LocalFileSystemService.remove', relativePath_to_absolute(contract.Path));
break;
return await window.ipc.invoke(
'LocalFileSystemService.remove',
relative_to_absolute_path(contract.Path)
);
case 'UPDATE': case 'WRITE':
const buffer = await Xlsx.toBytes(contract.DTO);
await window.ipc.invoke('LocalFileSystemService.writeFile', [relativePath_to_absolute(contract.Path),buffer,{}]);
break;
if(['ISA_Investigation','ISA_Study','ISA_Assay'].includes(contract.DTOType)){
const buffer = await Xlsx.toBytes(contract.DTO);
return await window.ipc.invoke(
'LocalFileSystemService.writeFile',
[
relative_to_absolute_path(contract.Path),
buffer,
{}
]
);
} else if(contract.DTOType==='PlainText'){
return await window.ipc.invoke('LocalFileSystemService.writeFile', [
arc_root+'/'+contract.Path,
contract.DTO || '',
{encoding:'UTF-8', flag: 'wx'}
]);
} else {
return console.log('unable to resolve write contract', contract);
}
case 'RENAME':
return await window.ipc.invoke(
'LocalFileSystemService.rename',
[
relative_to_absolute_path(contract.Path),
relative_to_absolute_path(contract.DTO)
]
);
default:
console.log(`Warning. 'handleARCContracts' hit unknown expression for contract type: ${contract.Operation} in ${contract}.`)
break;
}
}
},

writeARC: async (arc_root: string | null, filter, arc: ARC | void)=>{
arc = arc || ArcControlService.props.arc;
saveARC: async (options:{
arc_root: string | null,
arc: ARC | void,
force:boolean
})=>{
const arc = options.arc || ArcControlService.props.arc;
if(!arc)
return;
if(!arc_root)
arc_root = ArcControlService.props.arc_root;
const arc_root = options.arc_root || ArcControlService.props.arc_root;
if(!arc_root)
return;

ArcControlService.props.busy = true;

arc.UpdateFileSystem();
let contracts = arc.GetWriteContracts();
/// Add default .gitignore
contracts.push(gitignoreContract)
if(filter)
contracts = contracts.filter( x=>filter.includes(x.DTOType) );
let contracts = options.force ? arc.GetWriteContracts() : arc.GetUpdateContracts();

for(const contract of contracts){
if(['ISA_Investigation','ISA_Study','ISA_Assay'].includes(contract.DTOType)){
const buffer = await Xlsx.toBytes(contract.DTO);
await window.ipc.invoke('LocalFileSystemService.writeFile', [arc_root+'/'+contract.Path,buffer,{}]);
} else if(contract.DTOType==='PlainText'){
await window.ipc.invoke('LocalFileSystemService.writeFile', [
arc_root+'/'+contract.Path,
contract.DTO || '',
{encoding:'UTF-8', flag: 'wx'}
]);
} else {
console.log('unable to resolve write contract', contract);
}
}
/// Add default .gitignore if it does not exist
const ignore_exists = await window.ipc.invoke(
'LocalFileSystemService.exists',
relative_to_absolute_path('/.gitignore')
);
if(!ignore_exists)
contracts.push(gitignoreContract);

await ArcControlService.handleARCContracts(contracts);

ArcControlService.props.busy = false;
},
Expand All @@ -142,7 +164,14 @@ const ArcControlService = {
};
let contracts = ArcControlService.props.arc.RemoveAssay(assay_identifier)
await ArcControlService.handleARCContracts(contracts);
await ArcControlService.readARC();
},

rename: async (method:string, old_identifier:string, new_identifier:string) => {
const contracts = ArcControlService.props.arc[method](
old_identifier,
new_identifier
);
ArcControlService.handleARCContracts(contracts);
},

deleteStudy: async (study_identifier: string) => {
Expand All @@ -152,14 +181,17 @@ const ArcControlService = {
};
let contracts = ArcControlService.props.arc.RemoveStudy(study_identifier)
await ArcControlService.handleARCContracts(contracts);
await ArcControlService.readARC();
},

new_arc: async (path: string) =>{
const arc = new ARC(
ArcInvestigation.init(path.split('/').pop())
);
await ArcControlService.writeARC(path,null,arc);
await ArcControlService.saveARC({
path:path,
arc:arc,
force: true
});
await ArcControlService.readARC(path);

await window.ipc.invoke('GitService.run', {
Expand Down
Loading

0 comments on commit cdeec89

Please sign in to comment.