Skip to content

Commit

Permalink
- ADD: Added trait category check to prevent users from spefifying tr…
Browse files Browse the repository at this point in the history
…ait categories as comma-separated lists.
  • Loading branch information
sebastian-raubach committed Nov 19, 2024
1 parent 92105ac commit 436d795
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
52 changes: 39 additions & 13 deletions src/components/TraitDefinitionComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<div>
<b-row>
<b-col cols=12 lg=6 class="mb-3">
<b-form @submit.prevent="addTrait">
<b-form @submit.prevent="addTrait(false)">
<b-form-group :description="$t('formDescriptionTraitName')" label-for="trait-name" :state="formState.name">
<template #label>
<IBiTextarea /> {{ $t('formLabelTraitName') }}
</template>
<b-form-input v-model.trim.lazy="newTrait.name" trim lazy id="trait-name" autofocus required :state="formState.name" ref="traitName" v-on:keyup.enter="newTrait.id ? updateTrait() : addTrait()" />
<b-form-input v-model.trim.lazy="newTrait.name" trim lazy id="trait-name" autofocus required :state="formState.name" ref="traitName" v-on:keyup.enter="newTrait.id ? updateTrait(false) : addTrait(false)" />
<b-form-invalid-feedback>
{{ $t('formFeedbackTraitNameInvalidOrDuplicate') }}
</b-form-invalid-feedback>
Expand Down Expand Up @@ -116,8 +116,8 @@
</b-collapse>
</b-form>

<b-button v-if="newTrait.id" @click="updateTrait" variant="primary" :disabled="!newTrait.name"><IBiPencilSquare /> {{ $t('buttonUpdate') }}</b-button>
<b-button v-else @click="addTrait" variant="primary" :disabled="!newTrait.name"><IBiPlusSquareFill /> {{ $t('buttonAdd') }}</b-button>
<b-button v-if="newTrait.id" @click="updateTrait(false)" variant="primary" :disabled="!newTrait.name"><IBiPencilSquare /> {{ $t('buttonUpdate') }}</b-button>
<b-button v-else @click="addTrait(false)" variant="primary" :disabled="!newTrait.name"><IBiPlusSquareFill /> {{ $t('buttonAdd') }}</b-button>
</b-col>
<b-col cols=12 lg=6 class="mb-3">
<div class="d-flex align-items-center justify-content-between">
Expand Down Expand Up @@ -519,7 +519,7 @@ export default {
return copy
},
checkTrait: function (checkForDuplicate) {
checkTrait: function (checkForDuplicate, ignoreCategoryWarning = false) {
this.formValidated = true
const hasDuplicate = checkForDuplicate ? this.traits.some(t => t.name === this.newTrait.name) : false
Expand All @@ -530,10 +530,35 @@ export default {
this.formState.name = true
}
if (this.newTrait.dataType === 'categorical' && (!this.newTrait.restrictions.categories || this.newTrait.restrictions.categories === '')) {
this.formState.categories = false
} else {
this.formState.categories = true
this.formState.categories = true
if (this.newTrait.dataType === 'categorical') {
if (!this.newTrait.restrictions.categories || this.newTrait.restrictions.categories === '') {
this.formState.categories = false
} else {
const categories = this.newTrait.restrictions.categories.split(/\r?\n/).filter(c => c !== undefined && c !== null && c !== '').map(c => c.trim())
if (categories.length < 2 && !ignoreCategoryWarning) {
this.formState.categories = false
emitter.emit('show-confirm', {
title: 'modalTitleCategoricalTraitPotentialWrongFormat',
message: 'modalTextCategoricalTraitPotentialWrongFormat',
okTitle: 'buttonYes',
cancelTitle: 'buttonNo',
okVariant: 'warning',
callback: (result) => {
if (result) {
if (checkForDuplicate) {
this.addTrait(true)
} else {
this.updateTrait(true)
}
}
}
})
}
}
}
if (this.newTrait.dataType === 'range') {
Expand All @@ -557,8 +582,8 @@ export default {
return !Object.values(this.formState).some(v => v === false)
},
updateTrait: function () {
const valid = this.checkTrait(false)
updateTrait: function (ignoreCategoryWarning = false) {
const valid = this.checkTrait(false, ignoreCategoryWarning)
if (!valid) {
return
Expand All @@ -570,8 +595,8 @@ export default {
this.reset()
},
addTrait: function () {
const valid = this.checkTrait(true)
addTrait: function (ignoreCategoryWarning = false) {
const valid = this.checkTrait(true, ignoreCategoryWarning)
if (!valid) {
return
Expand Down Expand Up @@ -658,6 +683,7 @@ export default {
callback: (result) => {
if (result) {
this.traits.splice(index, 1)
this.reset()
}
}
})
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/i18n/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,8 @@
"modalTextResetTraitValue": "Sicher, dass der Merkmalswert zurückgesetzt werden. Dies entferne jegliche Werte die eingegeben/ausgewählt wurden.",
"modalTitleUploadTraitImage": "Merkmals-Referenzbild hochladen",
"modalTextUploadTraitImage": "Merkmals-Referenzbilder können für bereits geteilte Versuche zum GridScore Server hochgeladen werden. Diese agieren als visuelle Referenz für Datensammler beim bewerten von Daten.",
"modalTitleCategoricalTraitPotentialWrongFormat": "Verdächtige Kategorien",
"modalTextCategoricalTraitPotentialWrongFormat": "Es sieht so aus als wurde nur eine Kategorie angegeben. Jede Kategorie muss in einer eigenen Zeile angegeben werden. Falls Kategorien Komma-separiert angegeben wurden, bitte in einzelne Zeilen umwandeln.<br/><br/>Soll das Merkmal trotzdem so wie es aktuell definiert ist hinzugefügt werden?",
"pageAboutChangelog": "Changelog-Information anzeigen",
"pageAboutVersion": "Version {version}",
"pageAboutDocumentationLink": "Eine detaillierte Anleitung für GridScore und wie man es benutzt ist auf der <a href='https://cropgeeks.github.io/gridscore-next-client'>Dokumentationsseite<a/> verfügbar.",
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/i18n/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@
"modalTextResetTraitValue": "Are you sure you want to reset the trait value? This will erase any value you entered/selected.",
"modalTitleUploadTraitImage": "Upload trait reference image",
"modalTextUploadTraitImage": "You can upload trait reference images to the GridScore server for a shared trial. These act as visual references to data collectors during the scoring process.",
"modalTitleCategoricalTraitPotentialWrongFormat": "Suspicious categories",
"modalTextCategoricalTraitPotentialWrongFormat": "It looks like you only specified one category option. Individual categories need to be specified one per row/line. If you have specified them as a comma-separated list please convert this to individual rows/lines.<br/><br/>Do you still want to add the trait as it currently is?",
"pageAboutChangelog": "View Changelog Information",
"pageAboutVersion": "Version {version}",
"pageAboutGitHubLink": "The source code of GridScore is available on <a href='https://github.com/cropgeeks/gridscore-next-client/'>GitHub</a>.",
Expand Down

0 comments on commit 436d795

Please sign in to comment.