Skip to content

Commit

Permalink
Use default addAssay/Study function #203#180#161
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Jun 27, 2024
1 parent 162bc19 commit 205fb0d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 151 deletions.
116 changes: 1 addition & 115 deletions packages/renderer/src/dialogs/NewAssayDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,58 +8,34 @@ import * as internal from 'stream';
export type NewAssayInformation = {
assayIdentifier: string
studyIdentifier: string [] | null
}
const iProps : {
valid: boolean,
temp_studyInput: string,
assay_identifier: string
study_identifier: string [],
studies: string [],
existingAssays: string [],
existingStudies: string [],
} = reactive({
valid: true,
// Study multiple select with useChips requires "ENTER" to accept new values. This lead to confusion. Here we try to store any input given by the user.
// 👀 The logic is: If temp_studyInput !== '' && temp_studyInput passes validation then add temp_studyInput as identifer.
temp_studyInput: '',
assay_identifier: '',
// This value contains the selected study identifiers, for which the new assay will be registered
study_identifier: [],
// This value contains the currently available select options
// (this can differ from existingStudies if new options are added)
studies: [],
// This is used to disallow adding same assay again
existingAssays: [],
// This value always contains only the existing study identifiers from ARC model
existingStudies: [],
});
// This binds to q-select quasar component
const studySelect = ref(null)
let filterOptions = ref(iProps.studies)
defineEmits([
...useDialogPluginComponent.emits
]);
const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginComponent();
const onSubmit = async () => {
const newAssayInformation : NewAssayInformation = {assayIdentifier: iProps.assay_identifier, studyIdentifier: iProps.study_identifier}
const newAssayInformation : NewAssayInformation = {assayIdentifier: iProps.assay_identifier}
onDialogOK(newAssayInformation);
};
const init = async ()=>{
let arcStudies = ArcControlService.props.arc.ISA.StudyIdentifiers.sort()
let arcAssays = ArcControlService.props.arc.ISA.AssayIdentifiers
iProps.studies = [...arcStudies];
iProps.existingStudies = [...arcStudies];
iProps.existingAssays = arcAssays
iProps.assay_identifier = '';
iProps.study_identifier = [];
};
onMounted(init);
Expand All @@ -73,73 +49,9 @@ function hasValidCharacters (identifier: string) {
}
}
function hasValidCharactersStudies (identifiers: string []) {
if (identifiers.length === 0) return true;
try {
for (const identifier of identifiers) {
checkValidCharacters(identifier)
}
return true;
} catch (err) {
return false;
}
}
function assayIsNew(newAssayIdentifer:string) {
return iProps.existingAssays.includes(newAssayIdentifer) ? false : true
}
function filterStudyIdentifiers (val: string, update) {
update(() => {
if (val === '') {
filterOptions.value = iProps.studies
}
else {
const needle = val.toLowerCase()
filterOptions.value = iProps.studies.filter(
v => v.toLowerCase().indexOf(needle) > -1
)
}
})
}
function createNewStudyIdentifier (val, done) {
if (val.length > 0) {
if (!iProps.studies.includes(val)) {
iProps.studies.push(val)
}
done(val, 'toggle')
}
}
function clearStudyIdentifier (val: {index: number, value: string}) {
let contains = !iProps.existingStudies.includes(val.value)
if (contains) {
let index = iProps.studies.indexOf(val.value);
// console.log("cleared non existing study at index: ", index);
iProps.studies.splice(index, 1)
}
return;
}
function onBlurAddTemp_StudyInput() {
let v = iProps.temp_studyInput
if (v === '') return;
if (!hasValidCharacters(v)) return;
iProps.study_identifier.push(iProps.temp_studyInput);
// only add to studies if it did not exist beforehand
if (!iProps.studies.includes(v)) {
iProps.studies.push(iProps.temp_studyInput);
}
}
function onChangeSetTemp_StudyInput(val: string) {
iProps.temp_studyInput = val;
if (!studySelect.value) return;
// quasar q-select method
studySelect.value.validate(val);
}
</script>

<template>
Expand Down Expand Up @@ -168,32 +80,6 @@ function onChangeSetTemp_StudyInput(val: string) {
/>
</div>
</div>
<div class='row'>
<div class='col' >
<q-select
ref="studySelect"
filled
label="Study Identifiers"
v-model="iProps.study_identifier"
bg-color="grey-3"
use-input
use-chips
multiple
input-debounce="0"
new-value-mode="add-unique"
:options="filterOptions"
hint="Add or create studies. Verify with <Enter>."
:rules="[
val => hasValidCharactersStudies(val) || `New identifier contains forbidden characters! Allowed characters are: letters, digits, underscore (_), dash (-) and whitespace ( ).`,
]"
@new-value="createNewStudyIdentifier"
@filter="filterStudyIdentifiers"
@remove="clearStudyIdentifier"
@input-value="onChangeSetTemp_StudyInput"
@blur="onBlurAddTemp_StudyInput"
/>
</div>
</div>
<div style="min-height:3.5em;margin:1em 1em -1em 1em;">
<q-banner rounded inline-actions class="bg-red-10 text-white" v-if='!iProps.valid' dense>
<template v-slot:avatar>
Expand Down
37 changes: 1 addition & 36 deletions packages/renderer/src/views/ArcTreeView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,6 @@ watch(()=>ArcControlService.props.arc_root, async (newValue, oldValue) => {
arcTree._value.setExpanded(props.root);
});
watch(()=>AppProperties.active_study, async (newValue, oldValue) => {
await nextTick();
selected._value = `${ArcControlService.props.arc_root}/${Studies}/${newValue}`;
onSelectionChanged(selected.value);
});
watch(()=>AppProperties.active_assay, async (newValue, oldValue) => {
await nextTick();
selected._value = `${ArcControlService.props.arc_root}/${Assays}/${newValue}`;
onSelectionChanged(selected.value);
});
watch(()=>AppProperties.state, async (newValue, oldValue) => {
if([
AppProperties.STATES.HOME,
Expand All @@ -104,11 +92,10 @@ let uniqueLabelCounter = 0;
const addStudy_ = async (identifier: string, skip_io: boolean | void)=>{
const study = new ArcStudy(identifier,identifier);
ArcControlService.props.arc.ISA.AddRegisteredStudy(study)
ArcControlService.props.arc.ISA.AddStudy(study)
if(!skip_io){
await ArcControlService.saveARC({});
await ArcControlService.readARC();
AppProperties.active_study = identifier;
}
};
Expand All @@ -125,22 +112,8 @@ const addAssay = async ()=>{
console.log("Add assay")
const assay = new ArcAssay(data.assayIdentifier);
ArcControlService.props.arc.ISA.AddAssay(assay);
if (data.studyIdentifier !== null) {
for(let studyIdentifier of data.studyIdentifier)
try {
ArcControlService.props.arc.ISA.RegisterAssay(studyIdentifier,data.assayIdentifier);
} catch {
console.log("Unfound study identifier: '", studyIdentifier, "'. Created new Study for identifier.")
const study = new ArcStudy(studyIdentifier);
ArcControlService.props.arc.ISA.AddRegisteredStudy(study);
ArcControlService.props.arc.ISA.RegisterAssay(studyIdentifier,data.assayIdentifier);
}
};
await ArcControlService.saveARC({arc_root: ArcControlService.props.arc_root});
await ArcControlService.readARC();
AppProperties.active_assay = data.assayIdentifier;
});
};
Expand Down Expand Up @@ -221,14 +194,6 @@ const readDir_ = async (path: string) => {
}
};
// Here check loose assays/studies ~ WIP, Kevin
// function checkVacantStudies() {
// const arc : ARC = ArcControlService.props.arc
// console.log("HIT")
// if (!arc) return;
// console.log(arc.ISA.RegisteredStudyIdentifiers)
// }
if(needsAddElement(parent)) {
switch (parent) {
case Studies:
Expand Down

0 comments on commit 205fb0d

Please sign in to comment.