Skip to content

Commit

Permalink
close swate view of deleted/renamed assays/studies; new tree view; co…
Browse files Browse the repository at this point in the history
…de cleanup
  • Loading branch information
JonasLukasczyk committed Jul 5, 2024
1 parent 136157d commit 88cd4bf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 81 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"typecheck": "npm run typecheck:main && npm run typecheck:preload && npm run typecheck:renderer"
},
"dependencies": {
"@fslab/fsspreadsheet": "^6.1.3",
"@fslab/fsspreadsheet": "^6.2.0",
"@imengyu/vue3-context-menu": "^1.3.5",
"@nfdi4plants/arctrl": "^2.0.0-beta.1",
"@nfdi4plants/arctrl": "^2.0.0-beta.2",
"@nfdi4plants/exceljs": "0.2.0",
"@quasar/extras": "^1.16.9",
"chokidar": "^3.5.3",
Expand Down
8 changes: 0 additions & 8 deletions packages/renderer/src/AppProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@ const AppProperties: {
STATES: {
HOME: 0,

OPEN_ARC: 100,
OPEN_DATAHUB: 101,
OPEN_NEW: 102,

EDIT_SWATE: 203,

ADD_STUDY: 301,
ADD_ASSAY: 302,

LOGIN: 400,

GIT_COMMIT: 501,
GIT_SYNC: 502,
GIT_HISTORY: 503,
Expand Down
18 changes: 1 addition & 17 deletions packages/renderer/src/ArcControlService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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 @@ -30,13 +29,6 @@ let init: {
arc: null
}

function closeSwate() {
if (AppProperties.state === AppProperties.STATES.EDIT_SWATE) {
AppProperties.state = AppProperties.STATES.OPEN_ARC;
SwateControlService.props.object = null;
}
}

function relative_to_absolute_path(relativePath: string) {
return ArcControlService.props.arc_root + '/' + relativePath
}
Expand Down Expand Up @@ -90,6 +82,7 @@ const ArcControlService = {
ArcControlService.props.busy = true;
arc.UpdateFileSystem();
for(const contract of contracts) {
// console.log(contract);
switch (contract.Operation) {
case 'DELETE':
await window.ipc.invoke(
Expand Down Expand Up @@ -171,17 +164,11 @@ const ArcControlService = {
},

deleteAssay: async (assay_identifier: string) => {
if (SwateControlService.props.object !== null && SwateControlService.props.object.Identifier === assay_identifier) {
closeSwate();
}
let contracts = ArcControlService.props.arc.RemoveAssay(assay_identifier)
await ArcControlService.handleARCContracts(contracts);
},

rename: async (method:string, old_identifier:string, new_identifier:string) => {
if (SwateControlService.props.object !== null && SwateControlService.props.object.Identifier === old_identifier) {
closeSwate();
}
const contracts = ArcControlService.props.arc[method](
old_identifier,
new_identifier
Expand All @@ -190,9 +177,6 @@ const ArcControlService = {
},

deleteStudy: async (study_identifier: string) => {
if (SwateControlService.props.object !== null && SwateControlService.props.object.Identifier === study_identifier) {
closeSwate();
}
let contracts = ArcControlService.props.arc.RemoveStudy(study_identifier)
await ArcControlService.handleARCContracts(contracts);
},
Expand Down
118 changes: 64 additions & 54 deletions packages/renderer/src/views/ArcTreeView.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<script lang="ts" setup>
import { reactive, ref, nextTick, watch, onMounted, onUnmounted, h } from 'vue';
import ContextMenu from '@imengyu/vue3-context-menu'
Expand All @@ -18,7 +19,6 @@ import NewStudyDialog from '../dialogs/NewStudyDialog.vue';
const Image = 'image';
const Markdown = 'markdown';
const NodeAdd_PreFix = "node_add_"
const NodeEdit_PreFix = "node_edit_"
const $q = useQuasar();
Expand Down Expand Up @@ -144,37 +144,18 @@ const readDir_ = async (path: string) => {
const parent = path.split('/').pop().toLowerCase();
const needsAddElement = (l: string) => {
return [Studies,Assays,Protocols, Dataset, Runs, Workflows].includes( l.toLowerCase() );
};
const isMarkdown = l => {
return ['md','txt','py','xml','cwl','fsx','json','yml','html','csv','css','js','log','gitignore'].some( i=>new RegExp(`\\.${i}$`,'g').test(l.toLowerCase()))
}
};
const isImage = l => {
return ['png','jpeg','jpg'].some( i=>new RegExp(`\\.${i}$`,'g').test(l.toLowerCase()))
}
};
const isEditable = (n,p)=>{
return n.isDirectory && [Studies, Assays].includes(p);
};
function createAddNode (label: string, handler: ((n:any) => Promise<void>) ) {
const node = {
type: formatNodeAddString(label),
label: label,
isDirectory: false,
lazy: false,
icon: 'add_box',
id: path+'/'+'add$'+(uniqueLabelCounter++),
selectable: true,
tickable: false,
handler: handler
}
return node;
};
for(const n of nodes){
n.label = n.id.split('/').pop();
n.lazy = n.isDirectory;
Expand All @@ -188,28 +169,20 @@ const readDir_ = async (path: string) => {
} else if(isImage(n.label)){
n.type = formatNodeEditString(Image);
n.icon = 'image';
} else if(n.label==='assays'){
n.type = 'assays';
n.icon = 'storage';
} else if(n.label==='studies'){
n.type = 'studies';
n.icon = 'science';
} else if(n.label==='workflows'){
n.icon = 'settings';
} else if(n.label==='runs'){
n.icon = 'timer';
} else {
n.type = 'node';
}
};
if(needsAddElement(parent)) {
switch (parent) {
case Studies:
let addStudyNode = createAddNode("Add Study", addStudy);
// checkVacantStudies()
nodes.push(addStudyNode);
break;
case Assays:
let addAssayNode = createAddNode("Add Assay", addAssay);
nodes.push(addAssayNode);
break;
case Protocols:
let addProcotolNode = createAddNode("Add Protocol", addProtocol)
nodes.push(addProcotolNode);
break;
}
};
}
if(nodes.length<1){
nodes.push({
Expand All @@ -230,11 +203,6 @@ const readDir_ = async (path: string) => {
return 1;
}
if(a.type.startsWith(NodeAdd_PreFix) && !b.type.startsWith(NodeAdd_PreFix)){
return 1;
} else if (!a.type.startsWith(NodeAdd_PreFix) && b.type.startsWith(NodeAdd_PreFix)){
return -1;
}
return a.label.localeCompare(b.label);
});
Expand Down Expand Up @@ -272,6 +240,14 @@ const updatePath = async ([path,type]) => {
if (!arcTree.value || type==='file_ch')
return;
// check if swate view needs to be closed
if(type==='dir_rm'){
const elements = path.replace(ArcControlService.props.arc_root+'/','').split('/');
// if a study or assay was deleted/renamed that is currently opened in swate then close the view
if(elements.length===2 && ['assays','studies'].includes(elements[0]) && SwateControlService.props.object.Identifier===elements[1])
AppProperties.state=AppProperties.STATES.HOME;
}
const parentPath = path.split('/').slice(0,-1).join('/');
const n = arcTree.value.getNodeByKey(parentPath);
if(!n)
Expand Down Expand Up @@ -337,7 +313,26 @@ const onCellContextMenu = async (e,node) => {
style:{fontSize: '1.5em',color:'#666'}
};
const rel_path = node.id.replaceAll(ArcControlService.props.arc_root+'/','');
const rel_path_elements = rel_path.split('/');
if(node.isDirectory){
if(rel_path_elements.length===1){
if(rel_path_elements[0]==='assays'){
items.push({
label: "Add Assay",
icon: h( 'i', icon_style, ['add'] ),
onClick: ()=>addAssay(node)
});
} else if (rel_path_elements[0]==='studies') {
items.push({
label: "Add Study",
icon: h( 'i', icon_style, ['add'] ),
onClick: ()=>addStudy()
});
}
}
items.push({
label: "New Text File",
icon: h( 'i', icon_style, ['note_add'] ),
Expand All @@ -360,12 +355,11 @@ const onCellContextMenu = async (e,node) => {
});
} else {
const rel_file_path = node.id.replaceAll(ArcControlService.props.arc_root+'/','');
const lfs_files = await window.ipc.invoke('GitService.run', {
args: ['lfs','ls-files','-n'],
cwd: ArcControlService.props.arc_root
});
if(lfs_files[0] && lfs_files[1].includes(rel_file_path)){
if(lfs_files[0] && lfs_files[1].includes(rel_path)){
items.push({
label: "Download LFS File",
icon: h( 'i', icon_style, ['cloud_download'] ),
Expand Down Expand Up @@ -426,7 +420,7 @@ const onCellContextMenu = async (e,node) => {
});
await window.ipc.invoke('GitService.run', {
args: ['lfs','pull','--include',rel_file_path],
args: ['lfs','pull','--include',rel_path],
cwd: ArcControlService.props.arc_root
});
Expand Down Expand Up @@ -509,7 +503,7 @@ const onCellContextMenu = async (e,node) => {
icon: h( 'i', icon_style, ['delete'] ),
onClick: ()=>confirm_delete(node,()=>window.ipc.invoke('LocalFileSystemService.remove', node.id))
});
}
}
}
if(items.length){
Expand Down Expand Up @@ -559,7 +553,7 @@ onUnmounted( ()=>{window.ipc.off('LocalFileSystemService.updatePath', updatePath
<div class='q-pa-md'>
<div v-if="ArcControlService.props.arc" class='text-h6 text-grey-7' style="font-size:0.9em;border-bottom:0.1em solid #ccc;line-height:1em;padding:0 0 0.7em 0;">{{(props.root.replace(' ', '&nbsp;') || '').split('/').join(' /&nbsp;')}}</div>
<q-tree
v-if="ArcControlService.props.arc"
v-if="ArcControlService.props.arc"
ref='arcTree'
:nodes="props.nodes"
node-key="id"
Expand All @@ -573,9 +567,12 @@ onUnmounted( ()=>{window.ipc.off('LocalFileSystemService.updatePath', updatePath
no-selection-unset
>
<template v-slot:default-header="prop">
<q-icon v-if='prop.node.icon' :name='prop.node.icon' style="padding:0 0.2em 0 0;"></q-icon>
<div style="flex:100;white-space: nowrap;" @contextmenu="e=>onCellContextMenu(e,prop.node)">{{ prop.node.label }}</div>
<div v-if='!prop.node.isDirectory && !["add_box","block"].includes(prop.node.icon)' style="flex:1;white-space: nowrap;margin-left:1em;">{{ formatSize(prop.node.size) }}</div>
<div @contextmenu="e=>onCellContextMenu(e,prop.node)" style="flex:1;">
<q-icon v-if='prop.node.icon' :name='prop.node.icon' style="padding:0 0.2em 0 0;"></q-icon>
{{ prop.node.label }}
<q-icon v-if='prop.node.type==="assays"' name='add' class='tree_add_button' @click='addAssay()'></q-icon>
<q-icon v-if='prop.node.type==="studies"' name='add' class='tree_add_button' @click='addStudy()'></q-icon>
</div>
</template>
</q-tree>

Expand All @@ -597,4 +594,17 @@ onUnmounted( ()=>{window.ipc.off('LocalFileSystemService.updatePath', updatePath
.q-tree__node--selected .q-icon {
color:#fff;
}
.tree_add_button{
text-align: center;
padding: 0;
margin: 0;
border-radius: 1em;
float:right;
}
.tree_add_button:hover{
background:#ccc;
}
</style>

0 comments on commit 88cd4bf

Please sign in to comment.