Skip to content

Commit

Permalink
Enable deleting assays/studies via context menu ✨ #68
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Nov 17, 2023
1 parent bd016a5 commit c556583
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 69 deletions.
52 changes: 52 additions & 0 deletions packages/renderer/src/ArcControlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import { ARC } from "@nfdi4plants/arctrl/ARC.js";
import { ArcInvestigation } from "@nfdi4plants/arctrl/ISA/ISA/ArcTypes/ArcTypes.js";
import { gitignoreContract } from "@nfdi4plants/arctrl/Contracts/Contracts.Git.js";
import { Xlsx } from '@fslab/fsspreadsheet/Xlsx.js';
import {Assays} from './views/ArcTreeView.vue';
import {FileSystemTree} from '@nfdi4plants/arctrl/FileSystem/FileSystemTree.js'

export const Investigation = "investigation";
export const Studies = "studies";
export const Assays = "assays";
export const Protocols = 'protocols';
export const Dataset = 'dataset';
export const Runs = 'runs';
export const Workflows = 'workflows';

let init: {
arc_root: null | string ,
Expand Down Expand Up @@ -100,6 +110,48 @@ const ArcControlService = {
ArcControlService.props.busy = false;
},

deleteAssay: async (assay_identifier: string) => {
const relativePath = `${Assays}/${assay_identifier}`;
const path = `${ArcControlService.props.arc_root}/${relativePath}`;
const filePaths : string [] = ArcControlService.props.arc.FileSystem.Tree.ToFilePaths();
const filteredPaths : string [] = filePaths.filter(path => !path.startsWith(relativePath));
const newFsTree = FileSystemTree.fromFilePaths(filteredPaths);
// possibly remove assay from edit view
if (AppProperties.active_assay === assay_identifier) {
AppProperties.active_assay = null;
AppProperties.state = AppProperties.STATES.HOME;
};
await ArcControlService.props.arc.ISA.RemoveAssay(assay_identifier);
ArcControlService.props.arc._fs.Tree = newFsTree;
await window.ipc.invoke('LocalFileSystemService.remove', path);
await ArcControlService.writeARC();
await ArcControlService.readARC();
},

deleteStudy: async (study_identifier: string) => {

const relativePath = `${Studies}/${study_identifier}`;
const path = `${ArcControlService.props.arc_root}/${relativePath}`;
const filePaths : string [] = ArcControlService.props.arc.FileSystem.Tree.ToFilePaths();
const filteredPaths : string [] = filePaths.filter(path => !path.startsWith(relativePath));
const newFsTree = FileSystemTree.fromFilePaths(filteredPaths);
// possibly remove study from edit view
if (AppProperties.active_study === study_identifier) {
AppProperties.active_study = null;
AppProperties.state = AppProperties.STATES.HOME;
};
// remove study
await ArcControlService.props.arc.ISA.RemoveStudy(study_identifier);
// remove study from registered study identifiers
ArcControlService.props.arc.ISA.RegisteredStudyIdentifiers = ArcControlService.props.arc.ISA.RegisteredStudyIdentifiers.filter((i: string) => i !== study_identifier)
// remove study folder from file system
ArcControlService.props.arc._fs.Tree = newFsTree;
// remove study folder from disc
await window.ipc.invoke('LocalFileSystemService.remove', path);
await ArcControlService.writeARC();
await ArcControlService.readARC();
},

new_arc: async (path: string) =>{
const arc = new ARC(
ArcInvestigation.init(path.split('/').pop())
Expand Down
119 changes: 52 additions & 67 deletions packages/renderer/src/views/ArcTreeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { reactive, ref, nextTick, watch, onMounted, onUnmounted, h } from 'vue';
import ContextMenu from '@imengyu/vue3-context-menu'
import AppProperties from '../AppProperties';
import ArcControlService from '../ArcControlService';
import {Investigation, Assays, Studies, Workflows, Runs, Dataset, Protocols} from '../ArcControlService';
import StringDialog from '../dialogs/StringDialog.vue';
import AddProtocolDialog from '../dialogs/AddProtocolDialog.vue';
import NewAssayDialog from '../dialogs/NewAssayDialog.vue';
Expand All @@ -11,6 +12,10 @@ import { useQuasar } from 'quasar'
import {ArcStudy, ArcAssay} from '@nfdi4plants/arctrl/ISA/ISA/ArcTypes/ArcTypes.js';
import NewStudyDialog from '../dialogs/NewStudyDialog.vue';
const Markdown = 'markdown';
const NodeAdd_PreFix = "node_add_"
const NodeEdit_PreFix = "node_edit_"
const $q = useQuasar();
interface ArcTreeViewNode {
Expand Down Expand Up @@ -38,17 +43,6 @@ const props = reactive(init);
const arcTree = ref(null);
const selected = ref(null);
const Investigation = "investigation";
const Studies = "studies";
const Assays = "assays";
const Protocols = 'protocols';
const Dataset = 'dataset';
const Runs = 'runs';
const Workflows = 'workflows';
const Markdown = 'markdown';
const NodeAdd_PreFix = "node_add_"
const NodeEdit_PreFix = "node_edit_"
watch(()=>ArcControlService.props.arc_root, async (newValue, oldValue) => {
if(oldValue)
Expand Down Expand Up @@ -295,7 +289,8 @@ const readDir = async ({ node, key, done, fail }) => {
done( await readDir_(key) );
};
const onSelectionChanged = id=>{
const onSelectionChanged = id =>{
if (!arcTree.value) return;
const n = arcTree._value.getNodeByKey(id);
const type = n ? n.type : null;
Expand Down Expand Up @@ -335,63 +330,53 @@ const formatSize = size => {
return (size / Math.pow(1024,log)).toFixed(2) + ' ' + suffix;
};
const deleteAssay = async (assay_identifier: string) => {
await ArcControlService.props.arc.ISA.RemoveAssay(assay_identifier);
await ArcControlService.props.arc.UpdateFileSystem();
// console.log(ArcControlService.props.arc);
await ArcControlService.writeARC(ArcControlService.props.arc_root);
await ArcControlService.readARC();
const path = `${ArcControlService.props.arc_root}/assays/${assay_identifier}`;
await window.ipc.invoke('LocalFileSystemService.remove', path);
};
const onCellContextMenu = (e,node) => {
// console.log(node);
// if(node.type==='node_edit_Assay'){
// e.preventDefault();
// ContextMenu.showContextMenu({
// x: e.x,
// y: e.y,
// theme: 'flat',
// items: [
// {
// label: "Delete Assay",
// icon: h(
// 'i',
// {
// class: 'q-icon on-left notranslate material-icons',
// role:'img',
// style:{fontSize: '1.5em',color:'#333'}
// },
// ['delete']
// ),
// onClick: () =>{deleteAssay(node.label)}
// },
// ]
// });
// } else if (node.type==='node_edit_Study'){
// e.preventDefault();
// ContextMenu.showContextMenu({
// x: e.x,
// y: e.y,
// theme: 'flat',
// items: [
// {
// label: "Delete Study",
// icon: h(
// 'i',
// {
// class: 'q-icon on-left notranslate material-icons',
// role:'img',
// style:{fontSize: '1.5em',color:'#333'}
// },
// ['delete']
// ),
// onClick: () =>{props.table.RemoveRow(cell.rowIndex);refresh_hack();}
// },
// ]
// });
// }
if(node.type===formatNodeEditString(Assays)){
e.preventDefault();
ContextMenu.showContextMenu({
x: e.x,
y: e.y,
theme: 'flat',
items: [
{
label: "Delete Assay",
icon: h(
'i',
{
class: 'q-icon on-left notranslate material-icons',
role:'img',
style:{fontSize: '1.5em',color:'#333'}
},
['delete']
),
onClick: () =>{ArcControlService.deleteAssay(node.label)}
},
]
});
} else if (node.type===formatNodeEditString(Studies)){
e.preventDefault();
ContextMenu.showContextMenu({
x: e.x,
y: e.y,
theme: 'flat',
items: [
{
label: "Delete Study",
icon: h(
'i',
{
class: 'q-icon on-left notranslate material-icons',
role:'img',
style:{fontSize: '1.5em',color:'#333'}
},
['delete']
),
onClick: () =>{ArcControlService.deleteStudy(node.label)}
},
]
});
}
};
onMounted( ()=>{window.ipc.on('LocalFileSystemService.updatePath', updatePath);} );
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/views/AssayView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const iProps = reactive({
});
const init = async ()=>{
if(!ArcControlService.props.arc) return;
if(!ArcControlService.props.arc || !AppProperties.active_assay) return;
iProps.assay = ArcControlService.props.arc.ISA.GetAssay(AppProperties.active_assay);
};
Expand Down
2 changes: 1 addition & 1 deletion packages/renderer/src/views/StudyView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const iProps = reactive({
});
const init = async ()=>{
if(!ArcControlService.props.arc) return;
if(!ArcControlService.props.arc || !AppProperties.active_study) return;
iProps.study = ArcControlService.props.arc.ISA.GetStudy(AppProperties.active_study);
iProps.people = iProps.study.Contacts;
Expand Down

0 comments on commit c556583

Please sign in to comment.