|
| 1 | +<template> |
| 2 | + <b-modal |
| 3 | + id="jump-to-cue" |
| 4 | + ref="jump-to-cue" |
| 5 | + title="Jump to Cue" |
| 6 | + size="md" |
| 7 | + :hide-header-close="searching || showResults" |
| 8 | + :hide-footer="searching" |
| 9 | + :no-close-on-backdrop="searching" |
| 10 | + :no-close-on-esc="searching" |
| 11 | + @ok="performCueSearch" |
| 12 | + @hidden="resetCueSearch" |
| 13 | + > |
| 14 | + <!-- Search Form --> |
| 15 | + <b-form |
| 16 | + v-if="!showResults" |
| 17 | + v-show="!searching" |
| 18 | + @submit.stop.prevent="performCueSearch" |
| 19 | + > |
| 20 | + <b-form-group |
| 21 | + label="Cue Type" |
| 22 | + label-for="cue-type-input" |
| 23 | + :invalid-feedback="cueTypeError" |
| 24 | + :state="cueTypeErrorState" |
| 25 | + > |
| 26 | + <b-form-select |
| 27 | + id="cue-type-input" |
| 28 | + v-model="$v.cueSearchForm.cueTypeId.$model" |
| 29 | + :options="cueTypeOptions" |
| 30 | + :state="cueTypeErrorState" |
| 31 | + :disabled="searching" |
| 32 | + /> |
| 33 | + </b-form-group> |
| 34 | + |
| 35 | + <b-form-group |
| 36 | + label="Identifier" |
| 37 | + label-for="identifier-input" |
| 38 | + :invalid-feedback="identifierError" |
| 39 | + :state="identifierErrorState" |
| 40 | + > |
| 41 | + <b-form-input |
| 42 | + id="identifier-input" |
| 43 | + v-model="$v.cueSearchForm.identifier.$model" |
| 44 | + placeholder="e.g., 1, 42, 1.5" |
| 45 | + :state="identifierErrorState" |
| 46 | + :disabled="searching" |
| 47 | + /> |
| 48 | + </b-form-group> |
| 49 | + |
| 50 | + <!-- General Error Message --> |
| 51 | + <b-alert |
| 52 | + v-if="generalError" |
| 53 | + variant="danger" |
| 54 | + show |
| 55 | + > |
| 56 | + {{ generalError }} |
| 57 | + </b-alert> |
| 58 | + </b-form> |
| 59 | + |
| 60 | + <!-- Loading Spinner --> |
| 61 | + <div |
| 62 | + v-if="searching" |
| 63 | + class="text-center" |
| 64 | + > |
| 65 | + <b-spinner |
| 66 | + variant="primary" |
| 67 | + label="Searching..." |
| 68 | + /> |
| 69 | + <p class="mt-2"> |
| 70 | + Searching for cue... |
| 71 | + </p> |
| 72 | + </div> |
| 73 | + |
| 74 | + <!-- Multiple Matches - Selection List --> |
| 75 | + <div v-else-if="multipleMatches"> |
| 76 | + <p>Found {{ cueSearchResults.exact_matches.length }} cues matching "{{ cueSearchForm.identifier }}":</p> |
| 77 | + <b-list-group> |
| 78 | + <b-list-group-item |
| 79 | + v-for="(match, idx) in cueSearchResults.exact_matches" |
| 80 | + :key="idx" |
| 81 | + button |
| 82 | + @click="navigateToMatch(match)" |
| 83 | + > |
| 84 | + <strong>{{ match.cue_type.prefix }} {{ match.cue.ident }}</strong> |
| 85 | + - Page {{ match.location.page }} |
| 86 | + </b-list-group-item> |
| 87 | + </b-list-group> |
| 88 | + </div> |
| 89 | + |
| 90 | + <!-- Suggestions (No Exact Match) --> |
| 91 | + <div v-else-if="showSuggestions"> |
| 92 | + <b-alert |
| 93 | + variant="warning" |
| 94 | + show |
| 95 | + > |
| 96 | + No exact match found for "{{ cueSearchForm.identifier }}" |
| 97 | + </b-alert> |
| 98 | + <p>Did you mean one of these?</p> |
| 99 | + <b-list-group> |
| 100 | + <b-list-group-item |
| 101 | + v-for="(suggestion, idx) in cueSearchResults.suggestions" |
| 102 | + :key="idx" |
| 103 | + button |
| 104 | + @click="navigateToMatch(suggestion)" |
| 105 | + > |
| 106 | + <strong>{{ suggestion.cue_type.prefix }} {{ suggestion.cue.ident }}</strong> |
| 107 | + - Page {{ suggestion.location.page }} |
| 108 | + <b-badge |
| 109 | + variant="secondary" |
| 110 | + class="float-right" |
| 111 | + > |
| 112 | + {{ Math.round(suggestion.similarity_score * 100) }}% match |
| 113 | + </b-badge> |
| 114 | + </b-list-group-item> |
| 115 | + </b-list-group> |
| 116 | + </div> |
| 117 | + |
| 118 | + <!-- No Matches At All --> |
| 119 | + <div v-else-if="noMatches"> |
| 120 | + <b-alert |
| 121 | + variant="danger" |
| 122 | + show |
| 123 | + > |
| 124 | + No cues found matching "{{ cueSearchForm.identifier }}" for the selected cue type. |
| 125 | + </b-alert> |
| 126 | + </div> |
| 127 | + |
| 128 | + <!-- Footer for results --> |
| 129 | + <template |
| 130 | + v-if="showResults" |
| 131 | + #modal-footer |
| 132 | + > |
| 133 | + <b-button |
| 134 | + variant="secondary" |
| 135 | + @click="resetCueSearch" |
| 136 | + > |
| 137 | + New Search |
| 138 | + </b-button> |
| 139 | + <b-button |
| 140 | + variant="primary" |
| 141 | + @click="$bvModal.hide('jump-to-cue')" |
| 142 | + > |
| 143 | + Cancel |
| 144 | + </b-button> |
| 145 | + </template> |
| 146 | + </b-modal> |
| 147 | +</template> |
| 148 | + |
| 149 | +<script> |
| 150 | +import { required } from 'vuelidate/lib/validators'; |
| 151 | +import { mapActions, mapGetters } from 'vuex'; |
| 152 | +import log from 'loglevel'; |
| 153 | +import Vue from 'vue'; |
| 154 | +import { notNull } from '@/js/customValidators'; |
| 155 | +
|
| 156 | +export default { |
| 157 | + name: 'JumpToCueModal', |
| 158 | + data() { |
| 159 | + return { |
| 160 | + cueSearchForm: { |
| 161 | + cueTypeId: null, |
| 162 | + identifier: '', |
| 163 | + }, |
| 164 | + cueSearchResults: null, |
| 165 | + generalError: null, |
| 166 | + searching: false, |
| 167 | + showResults: false, |
| 168 | + }; |
| 169 | + }, |
| 170 | + validations: { |
| 171 | + cueSearchForm: { |
| 172 | + cueTypeId: { |
| 173 | + required, |
| 174 | + notNull, |
| 175 | + }, |
| 176 | + identifier: { |
| 177 | + required, |
| 178 | + }, |
| 179 | + }, |
| 180 | + }, |
| 181 | + computed: { |
| 182 | + ...mapGetters(['CUE_TYPES']), |
| 183 | + cueTypeOptions() { |
| 184 | + const options = [{ value: null, text: 'Select a cue type...', disabled: true }]; |
| 185 | + this.CUE_TYPES.forEach((type) => { |
| 186 | + options.push({ |
| 187 | + value: type.id, |
| 188 | + text: `${type.prefix} - ${type.description || 'No description'}`, |
| 189 | + }); |
| 190 | + }); |
| 191 | + return options; |
| 192 | + }, |
| 193 | + multipleMatches() { |
| 194 | + return this.cueSearchResults?.exact_matches?.length > 1; |
| 195 | + }, |
| 196 | + showSuggestions() { |
| 197 | + return ( |
| 198 | + this.cueSearchResults?.exact_matches?.length === 0 |
| 199 | + && this.cueSearchResults?.suggestions?.length > 0 |
| 200 | + ); |
| 201 | + }, |
| 202 | + noMatches() { |
| 203 | + return ( |
| 204 | + this.cueSearchResults?.exact_matches?.length === 0 |
| 205 | + && this.cueSearchResults?.suggestions?.length === 0 |
| 206 | + ); |
| 207 | + }, |
| 208 | + cueTypeErrorState() { |
| 209 | + const { $dirty, $error } = this.$v.cueSearchForm.cueTypeId; |
| 210 | + return $dirty ? !$error : null; |
| 211 | + }, |
| 212 | + cueTypeError() { |
| 213 | + if (this.$v.cueSearchForm.cueTypeId.$dirty) { |
| 214 | + if (!this.$v.cueSearchForm.cueTypeId.required || !this.$v.cueSearchForm.cueTypeId.notNull) { |
| 215 | + return 'Cue type is required'; |
| 216 | + } |
| 217 | + } |
| 218 | + return ''; |
| 219 | + }, |
| 220 | + identifierErrorState() { |
| 221 | + const { $dirty, $error } = this.$v.cueSearchForm.identifier; |
| 222 | + return $dirty ? !$error : null; |
| 223 | + }, |
| 224 | + identifierError() { |
| 225 | + if (this.$v.cueSearchForm.identifier.$dirty && !this.$v.cueSearchForm.identifier.required) { |
| 226 | + return 'Identifier is required'; |
| 227 | + } |
| 228 | + return ''; |
| 229 | + }, |
| 230 | + }, |
| 231 | + methods: { |
| 232 | + ...mapActions(['SEARCH_CUES']), |
| 233 | + async performCueSearch(event) { |
| 234 | + if (event) { |
| 235 | + event.preventDefault(); |
| 236 | + } |
| 237 | + this.$v.$touch(); |
| 238 | + if (this.$v.$anyError) { |
| 239 | + return; |
| 240 | + } |
| 241 | +
|
| 242 | + this.searching = true; |
| 243 | + this.generalError = null; |
| 244 | + try { |
| 245 | + const result = await this.SEARCH_CUES({ |
| 246 | + identifier: this.cueSearchForm.identifier.trim(), |
| 247 | + cueTypeId: this.cueSearchForm.cueTypeId, |
| 248 | + }); |
| 249 | + this.cueSearchResults = result; |
| 250 | +
|
| 251 | + if (result.exact_matches?.length === 1) { |
| 252 | + await this.navigateToMatch(result.exact_matches[0]); |
| 253 | + this.$bvModal.hide('jump-to-cue'); |
| 254 | + } else { |
| 255 | + this.showResults = true; |
| 256 | + } |
| 257 | + } catch (error) { |
| 258 | + this.generalError = 'Search failed. Please try again.'; |
| 259 | + log.error('Cue search error:', error); |
| 260 | + } finally { |
| 261 | + this.searching = false; |
| 262 | + } |
| 263 | + }, |
| 264 | + async navigateToMatch(match) { |
| 265 | + const targetPage = match.location.page; |
| 266 | + this.$emit('navigate', targetPage); |
| 267 | + Vue.$toast.success( |
| 268 | + `Jumped to ${match.cue_type.prefix} ${match.cue.ident} on page ${targetPage}`, |
| 269 | + ); |
| 270 | + }, |
| 271 | + resetCueSearch() { |
| 272 | + this.cueSearchForm.identifier = ''; |
| 273 | + this.cueSearchForm.cueTypeId = null; |
| 274 | + this.cueSearchResults = null; |
| 275 | + this.generalError = null; |
| 276 | + this.showResults = false; |
| 277 | + this.$v.$reset(); |
| 278 | + }, |
| 279 | + }, |
| 280 | +}; |
| 281 | +</script> |
0 commit comments