Skip to content

Commit

Permalink
fix: issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrund14 committed Jan 11, 2021
1 parent 5fc7055 commit b4b70ed
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 51 deletions.
24 changes: 16 additions & 8 deletions src/public/components/EditReserveCategoryModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@
</div>
<div class="modalCriteriaPanels mb-18">
<font-awesome-icon
v-if="reserveCategory.priority.length > 1"
icon="trash"
class="deleteCriteriaButton"
@click="deleteCurrentCriteria"
Expand Down Expand Up @@ -304,13 +303,22 @@ export default {
}
},
deleteCurrentCriteria() {
const deletedLastCriteria =
this.currentCriteria === this.reserveCategory.priority.length - 1
this.reserveCategory.priority.splice(this.currentCriteria, 1)
if (deletedLastCriteria) {
this.$nextTick(() => {
this.currentCriteria = this.currentCriteria - 1
})
// clear form if this is the only criteria
if (this.reserveCategory.priority.length === 1) {
this.reserveCategory.priority = [
{
...deepClone(defaultCriteria),
},
]
} else {
const deletedLastCriteria =
this.currentCriteria === this.reserveCategory.priority.length - 1
this.reserveCategory.priority.splice(this.currentCriteria, 1)
if (deletedLastCriteria) {
this.$nextTick(() => {
this.currentCriteria = this.currentCriteria - 1
})
}
}
this.$nextTick(() => {
this.validatePriorities()
Expand Down
85 changes: 44 additions & 41 deletions src/public/pages/load-data.vue
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export default {
? { min: 0, max: 100000 }
: null,
}
const errorMessage = `Patient ${
const errorMessage = `Patient in row ${
patientIndex + 1
} has an invalid value for ${name}: ${field}.`
let realFieldValue = field
Expand All @@ -223,54 +223,57 @@ export default {
recipientIds.push(realFieldValue)
}
}
let typeCheck = dataType
if (hasCustomRandomNumber) {
typeCheck = 'NUMBER'
}
switch (typeCheck) {
case 'BOOLEAN': {
const fieldUC = field.toUpperCase()
if (!['TRUE', 'FALSE'].includes(fieldUC)) {
throw new Error(
`${errorMessage} Please ensure this is a true/false value.`
)
}
realFieldValue = fieldUC === 'TRUE'
break
if (required) {
let typeCheck = dataType
if (hasCustomRandomNumber) {
typeCheck = 'NUMBER'
}
case 'NUMBER': {
if (field && !isFloat(field)) {
throw new Error(
`${errorMessage} Please ensure this is a real number.`
)
switch (typeCheck) {
case 'BOOLEAN': {
const fieldUC = field.toUpperCase()
if (!['TRUE', 'FALSE'].includes(fieldUC)) {
throw new Error(
`${errorMessage} Please ensure this is a true/false value.`
)
}
realFieldValue = fieldUC === 'TRUE'
break
}
const numberVal = parseFloat(field)
if (possibleValues && !isNaN(numberVal)) {
const { min, max } = possibleValues
if (numberVal < min || numberVal > max) {
case 'NUMBER': {
if (field && !isFloat(field)) {
throw new Error(
`${errorMessage} Out of range. Please ensure number is between ${min} and ${max} (inclusive).`
`${errorMessage} Please ensure this is a real number.`
)
}
const numberVal = parseFloat(field)
if (possibleValues && !isNaN(numberVal)) {
const { min, max } = possibleValues
if (numberVal < min || numberVal > max) {
throw new Error(
`${errorMessage} Out of range. Please ensure number is between ${min} and ${max} (inclusive).`
)
}
}
realFieldValue = !isNaN(numberVal) ? numberVal : null
break
}
realFieldValue = !isNaN(numberVal) ? numberVal : null
break
default:
case 'STRING':
if (
possibleValues &&
Array.isArray(possibleValues) &&
!possibleValues.includes(field)
) {
throw new Error(
`${errorMessage} Please ensure value is one of ${possibleValues.join(
', '
)}.`
)
}
break
}
default:
case 'STRING':
if (
possibleValues &&
Array.isArray(possibleValues) &&
!possibleValues.includes(field)
) {
throw new Error(
`${errorMessage} Please ensure value is one of ${possibleValues.join(
', '
)}.`
)
}
break
}
acc[name] = realFieldValue === '' ? null : realFieldValue
acc.usedGeneratedRandomNumber = !hasCustomRandomNumber
Expand Down
6 changes: 4 additions & 2 deletions src/public/pages/reserve-instances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ export default {
break
case 'bins':
priorityStringElements.push(
`number_of_bins = ${filteredPriority.bins.length}`
`number_of_bins = ${
filteredPriority.coarsened ? filteredPriority.bins.length : 1
}`
)
break
case 'numBins':
Expand Down Expand Up @@ -308,7 +310,7 @@ export default {
])
outputArray.push([])
outputArray.push([`Unit Allocated: ${displayConfig.unitType}`])
outputArray.push([`Number Allocated: ${displayConfig.supply}`])
outputArray.push([`Total Supply Rationed: ${displayConfig.supply}`])
outputArray.push([`Units Left Over: ${leftOver}`])
outputArray.push([
[
Expand Down

0 comments on commit b4b70ed

Please sign in to comment.