From b671ecc060de823d3f26ec550679beff6bb5dff0 Mon Sep 17 00:00:00 2001 From: Kevin F Date: Thu, 16 Nov 2023 15:59:07 +0100 Subject: [PATCH] Improve Add Study logic :sparkles: --- packages/main/src/mainWindow.ts | 1 - packages/renderer/src/AppProperties.ts | 6 +- .../renderer/src/components/FormInput.vue | 4 +- .../renderer/src/dialogs/NewAssayDialog.vue | 133 +++++++++++++++--- packages/renderer/src/views/ArcTreeView.vue | 34 +++-- 5 files changed, 142 insertions(+), 36 deletions(-) diff --git a/packages/main/src/mainWindow.ts b/packages/main/src/mainWindow.ts index 9d5ade64..fa18224d 100644 --- a/packages/main/src/mainWindow.ts +++ b/packages/main/src/mainWindow.ts @@ -9,7 +9,6 @@ contextMenu({ }); async function createWindow() { - console.log("HIT; ", join(__dirname, './../../../ressources/icon.png')) const mainWindow = new BrowserWindow({ show: false, // Use 'ready-to-show' event to show window webPreferences: { diff --git a/packages/renderer/src/AppProperties.ts b/packages/renderer/src/AppProperties.ts index 21d8c6a2..82e605c0 100644 --- a/packages/renderer/src/AppProperties.ts +++ b/packages/renderer/src/AppProperties.ts @@ -1,6 +1,10 @@ import { reactive } from 'vue' -const AppProperties = reactive({ +const AppProperties: { + STATES: any, + active_study: string | null + active_assay: string | null +} = reactive({ STATES: { HOME: 0, diff --git a/packages/renderer/src/components/FormInput.vue b/packages/renderer/src/components/FormInput.vue index 37c03e8e..f8a647c8 100644 --- a/packages/renderer/src/components/FormInput.vue +++ b/packages/renderer/src/components/FormInput.vue @@ -124,7 +124,7 @@ const isValidTerm = ()=>{ { import { useDialogPluginComponent } from 'quasar'; -import { reactive, onMounted, watch } from 'vue'; +import { reactive, onMounted, watch, ref } from 'vue'; import FormInput from '../components/FormInput.vue'; import Property from '../Property.ts'; import ArcControlService from '../ArcControlService.ts'; - -const iProps = reactive({ +import {ArcStudy} from "@nfdi4plants/arctrl" +import {checkValidCharacters} from '@nfdi4plants/arctrl/ISA/ISA/Identifier.js' + +export type NewAssayInformation = { + assayIdentifier: string + studyIdentifier: string [] | null +} + +const iProps : { + valid: boolean, + errorMsgs: string [], + assay_identifier: string + study_identifier: string [], + studies: string [] + existingStudies: string [], + form: any [] +} = reactive({ valid: true, + errorMsgs: [], 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 value always contains only the existing study identifiers from ARC model + existingStudies: [], form: [] }); +let filterOptions = ref(iProps.studies) + defineEmits([ ...useDialogPluginComponent.emits ]); -const createStudyString = 'Create New Study'; - const { dialogRef, onDialogHide, onDialogOK, onDialogCancel } = useDialogPluginComponent(); const onSubmit = async () => { - iProps.valid = iProps.assay_identifier && iProps.study_identifier.length; - if(!iProps.valid) - return; - - onDialogOK([iProps.assay_identifier,iProps.study_identifier.includes(createStudyString) ? [] : iProps.study_identifier]); + if (iProps.assay_identifier === ``) { + iProps.valid = false; + iProps.errorMsgs.push('Assay Identifier cannot be empty!') + } + if (!iProps.valid) return; + const newAssayInformation : NewAssayInformation = {assayIdentifier: iProps.assay_identifier, studyIdentifier: iProps.study_identifier} + onDialogOK(newAssayInformation); }; const init = async ()=>{ - iProps.studies = ArcControlService.props.arc.ISA.Studies.map(s => s.Identifier).sort(); + let arcStudies = ArcControlService.props.arc.ISA.Studies.map((s: ArcStudy) => s.Identifier).sort(); + iProps.studies = arcStudies + iProps.existingStudies = arcStudies iProps.assay_identifier = ''; - iProps.study_identifier = [createStudyString]; + iProps.study_identifier = []; iProps.form = [ [Property( iProps, 'assay_identifier', {label:'Assay Identifier'})], - [Property( iProps, 'study_identifier', {label:'Study Identifier',type:'select',multi:true, options:iProps.studies})] ]; }; onMounted(init); -watch( ()=>iProps.study_identifier, ()=>{ - if(iProps.study_identifier.length>1 && iProps.study_identifier.includes(createStudyString)){ - iProps.study_identifier.splice(iProps.study_identifier.indexOf(createStudyString),1); - } else if(iProps.study_identifier.length<1){ - iProps.study_identifier = [createStudyString]; +function resetErrors() { + iProps.valid = true; + iProps.errorMsgs = []; +} + +watch( () => [iProps.study_identifier, iProps.assay_identifier], () =>{ + resetErrors(); + for (let study of iProps.study_identifier) + try { + if (study !== '') checkValidCharacters(study) + } catch (error) { + iProps.valid = false; + iProps.errorMsgs.push(`Invalid Identifier for: "${study}": ${error}`) + } + try { + if (iProps.assay_identifier !== '') checkValidCharacters(iProps.assay_identifier) + } catch (error) { + iProps.valid = false; + iProps.errorMsgs.push(`Invalid Identifier for: "${iProps.assay_identifier}": ${error}`) } }); +function filterStudyIdentifiers (val, 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') + } +} + +// this does not work currently: +// https://github.com/quasarframework/quasar/discussions/16602 +function clearStudyIdentifier (val: any) { + console.log("HIT") + let index = iProps.study_identifier.indexOf(val) + iProps.study_identifier.splice(index) + if (!iProps.existingStudies.includes(val)) { + console.log("cleared non existing study") + let index = iProps.studies.indexOf(val) + iProps.studies.splice(index) + } + return; +} +