From d3cfd2cfaf119803a13a2871859479b7c84bc0bd Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Mon, 9 Oct 2023 16:30:46 +0200 Subject: [PATCH] Editing Meta Data and Tokens --- .../GeneralFunctionsQueryBuilder.js | 41 +++++++++++++++++++ ...alAttributeBuilderFunctionsQueryBuilder.js | 2 +- ...enAttributeBuilderFunctionsQueryBuilder.js | 12 +++--- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js b/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js index 6ab84169..769a7b6a 100644 --- a/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js +++ b/app/static/js/CorpusAnalysis/QueryBuilder/GeneralFunctionsQueryBuilder.js @@ -128,6 +128,47 @@ class GeneralFunctionsQueryBuilder { let selection = isEnglishEntType ? this.elements.englishEntTypeSelection : this.elements.germanEntTypeSelection; this.resetMaterializeSelection([selection], entType); break; + case 'text-annotation': + this.elements.structuralAttrModal.open(); + this.toggleClass(['text-annotation-builder'], 'hide', 'remove'); + this.toggleEditingAreaStructureAttrModal('add'); + let [textAnnotationSelection, textAnnotationContent] = queryChipElement.dataset.query + .replace(/:: ?match\.text_|"|"/g, '') + .split('='); + this.resetMaterializeSelection([this.elements.textAnnotationSelection], textAnnotationSelection); + this.elements.textAnnotationInput.value = textAnnotationContent; + break; + case 'token': + let [tokenAttr, tokenValue] = queryChipElement.dataset.query.replace(/\[|\]|"/g, '').split('='); + if (tokenAttr === 'pos') { + tokenAttr = this.elements.englishPosSelection.querySelector(`option[value=${tokenValue}]`) ? 'english-pos' : 'german-pos'; + } + this.editTokenChipElement(tokenAttr, tokenValue); + break; + default: + break; + } + } + + editTokenChipElement(tokenAttr, tokenValue) { + this.resetMaterializeSelection([this.elements.positionalAttrSelection], tokenAttr); + this.elements.positionalAttrModal.open(); + switch (tokenAttr) { + case 'word': + this.elements.wordInput.value = tokenValue; + break; + case 'lemma': + this.elements.lemmaInput.value = tokenValue; + break; + case 'english-pos': + this.resetMaterializeSelection([this.elements.englishPosSelection], tokenValue); + break; + case 'german-pos': + this.resetMaterializeSelection([this.elements.germanPosSelection], tokenValue); + break; + case 'simple-pos': + this.resetMaterializeSelection([this.elements.simplePosSelection], tokenValue); + break; default: break; } diff --git a/app/static/js/CorpusAnalysis/QueryBuilder/StructuralAttributeBuilderFunctionsQueryBuilder.js b/app/static/js/CorpusAnalysis/QueryBuilder/StructuralAttributeBuilderFunctionsQueryBuilder.js index 15f7bc57..d8f9fbe9 100644 --- a/app/static/js/CorpusAnalysis/QueryBuilder/StructuralAttributeBuilderFunctionsQueryBuilder.js +++ b/app/static/js/CorpusAnalysis/QueryBuilder/StructuralAttributeBuilderFunctionsQueryBuilder.js @@ -82,7 +82,7 @@ class StructuralAttributeBuilderFunctionsQueryBuilder extends GeneralFunctionsQu }, 3000); } else { let queryText = `:: match.text_${textAnnotationOptions.value}="${textAnnotationInput.value}"`; - this.submitQueryChipElement('text-annotation', `${textAnnotationOptions.value}=${textAnnotationInput.value}`, queryText); + this.submitQueryChipElement('text-annotation', `${textAnnotationOptions.value}=${textAnnotationInput.value}`, queryText, null, false, true); this.elements.structuralAttrModal.close(); } } diff --git a/app/static/js/CorpusAnalysis/QueryBuilder/TokenAttributeBuilderFunctionsQueryBuilder.js b/app/static/js/CorpusAnalysis/QueryBuilder/TokenAttributeBuilderFunctionsQueryBuilder.js index 0e4c4bd1..e11d4731 100644 --- a/app/static/js/CorpusAnalysis/QueryBuilder/TokenAttributeBuilderFunctionsQueryBuilder.js +++ b/app/static/js/CorpusAnalysis/QueryBuilder/TokenAttributeBuilderFunctionsQueryBuilder.js @@ -38,7 +38,8 @@ class TokenAttributeBuilderFunctionsQueryBuilder extends GeneralFunctionsQueryBu this.toggleClass(['incidence-modifiers', 'or', 'and'], 'disabled', 'add'); document.querySelector('#corpus-analysis-concordance-positional-attr-selection option[value="word"]').selected = true; - + this.elements.wordInput.value = ''; + this.elements.lemmaInput.value = ''; this.resetMaterializeSelection([this.elements.englishPosSelection, this.elements.germanPosSelection, this.elements.simplePosSelection]); this.resetMaterializeSelection([this.elements.positionalAttrSelection], "word"); this.elements.editingModusOn = false; @@ -47,6 +48,7 @@ class TokenAttributeBuilderFunctionsQueryBuilder extends GeneralFunctionsQueryBu preparePositionalAttrModal() { let selection = this.elements.positionalAttrSelection.value; + this.toggleClass(['word', 'lemma', 'english-pos', 'german-pos', 'simple-pos'], 'hide', 'add'); if (selection !== 'empty-token') { this.toggleClass([selection], 'hide', 'remove'); this.toggleClass(['incidence-modifiers', 'or', 'and'], 'disabled', 'add'); @@ -80,10 +82,8 @@ class TokenAttributeBuilderFunctionsQueryBuilder extends GeneralFunctionsQueryBu } optionToggleHandler() { - let input; - input = this.tokenInputCheck(); - - if (input.value === '' || input.value === 'default') { + let input = this.tokenInputCheck(); + if ((input.value === '' || input.value === 'default') && this.elements.editingModusOn === false) { this.toggleClass(['incidence-modifiers', 'or', 'and'], 'disabled', 'add'); } else { this.toggleClass(['incidence-modifiers', 'or', 'and'], 'disabled', 'remove'); @@ -182,7 +182,7 @@ class TokenAttributeBuilderFunctionsQueryBuilder extends GeneralFunctionsQueryBu // isTokenQueryInvalid looks if a valid value is passed. If the input fields/dropdowns are empty (isTokenQueryInvalid === true), no token is added. if (this.elements.isTokenQueryInvalid === false) { tokenQueryCQLText = '[' + tokenQueryCQLText + ']'; - this.submitQueryChipElement('token', tokenQueryPrettyText, tokenQueryCQLText); + this.submitQueryChipElement('token', tokenQueryPrettyText, tokenQueryCQLText, null, false, true); this.elements.positionalAttrModal.close(); } }