-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#250 Improve Entity selection (list, filter)
- Loading branch information
Showing
3 changed files
with
63 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<template> | ||
<div> | ||
<label class="form-label" for="entity">Entity</label> | ||
<select size="5" id="entity" @change="emit('update:modelValue', $event.target.value)" :value="modelValue" | ||
class="form-select form-select-sm mb-1" title="The entity you want to display"> | ||
<option v-for="entity in filteredEntities" v-bind:key="entity" :value="entity.entityId">{{ | ||
entity.title | ||
}} | ||
</option> | ||
</select> | ||
<input type="text" class="form-control form-control-sm" v-model="entityFilter" | ||
placeholder="Filter by name or entity_id..."> | ||
</div> | ||
</template> | ||
<script setup> | ||
import {computed, ref} from "vue"; | ||
import {Entity} from "@/modules/pi/entity"; | ||
const props = defineProps({ | ||
modelValue: { | ||
required: true, | ||
type: Object, | ||
default: () => (new Entity()) | ||
}, | ||
availableEntities: { | ||
required: true, | ||
type: [] // Entity[] | ||
} | ||
}) | ||
const emit = defineEmits([ | ||
'update:modelValue' | ||
]) | ||
const entityFilter = ref("") | ||
const filteredEntities = computed(() => { | ||
if (!entityFilter.value) { | ||
return props.availableEntities | ||
} | ||
let filterLc = entityFilter.value.toLowerCase(); | ||
return props.availableEntities.filter(entity => { | ||
let entityIdMatches = entity.entityId.toLowerCase().indexOf(filterLc) !== -1; | ||
let titleMatches = entity.title.toLowerCase().indexOf(filterLc) !== -1; | ||
return entityIdMatches || titleMatches | ||
}) | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters