Skip to content

Commit

Permalink
Adding support for "operator-less" conditions, for example the "first…
Browse files Browse the repository at this point in the history
…OfDay.recipe".
  • Loading branch information
igoramadas committed Apr 12, 2024
1 parent 8e7afda commit a6ffaf8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions components/recipes/AddCondition.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,13 @@
<div v-else-if="isGear">
<v-select label="Gear" v-model="selectedGear" :items="allGear" :rules="gearInputRules" multiple dense outlined rounded return-object></v-select>
</div>
<div v-else-if="isBoolean">
<div v-else-if="isBoolean && hasOperators">
<v-select label="Yes or No?" v-model="selectedBoolean" :items="booleans" :rules="booleanInputRules" dense outlined rounded return-object></v-select>
</div>
<div v-else-if="isWeekday">
<v-select label="Weekday" v-model="selectedWeekdays" :items="weekdays" :rules="weekdayInputRules" multiple dense outlined rounded return-object></v-select>
</div>
<div v-else-if="!isLocation">
<v-text-field v-model="valueInput" type="text" :rules="valueInputRules" :suffix="selectedSuffix" :placeholder="inputPlaceholder" dense outlined rounded></v-text-field>
</div>
<div v-else>
<div v-else-if="isLocation">
<v-autocomplete
v-model="locationInput"
label="Location or geo coordinates"
Expand All @@ -63,6 +60,9 @@
no-filter
></v-autocomplete>
</div>
<div v-else-if="hasOperators">
<v-text-field v-model="valueInput" type="text" :rules="valueInputRules" :suffix="selectedSuffix" :placeholder="inputPlaceholder" dense outlined rounded></v-text-field>
</div>
</div>
<div class="text-center mb-6" v-if="isDefaultFor">
<v-icon color="grey" small>mdi-information-outline</v-icon>
Expand Down Expand Up @@ -115,6 +115,9 @@ export default {
inputPlaceholder() {
return this.selectedProperty?.type == "time" ? "00:00" : ""
},
hasOperators() {
return this.selectedProperty?.operators?.length > 0
},
isDefaultFor() {
return this.selectedProperty?.value == "defaultFor"
},
Expand Down Expand Up @@ -331,8 +334,9 @@ export default {
}
},
propertyChanged() {
if (this.isDefaultFor) {
this.selectedOperator = {value: true}
if (this.isDefaultFor || !this.hasOperators) {
this.selectedOperator = {value: "=", text: "is"}
this.selectedBoolean = {value: true, text: "Yes"}
} else if (this.selectedProperty?.operators.length == 1) {
this.selectedOperator = this.selectedProperty.operators[0]
} else {
Expand Down
2 changes: 1 addition & 1 deletion mixins/recipeMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default {
return `!!! ERROR !!! Invalid property: ${condition.property}`
}

const operator = _.find(property.operators, {value: condition.operator})
const operator = property.operators ? _.find(property.operators, {value: condition.operator}) : {text: "is"}
if (!operator) {
return `!!! ERROR !!! Invalid condition operator: ${condition.operator}`
}
Expand Down

0 comments on commit a6ffaf8

Please sign in to comment.