Changeset 35602 for main


Ignore:
Timestamp:
2021-10-15T10:45:15+13:00 (3 years ago)
Author:
cstephen
Message:

Broken attempt to update all words

Location:
main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/TranscriptionItemEditor.vue

    r35548 r35602  
    1212        <ul class="list-view" v-else>
    1313            <li v-for="(word, index) in words" :key="word.id" class="word-container">
    14                 <input :size="word.word.length === 0 ? 1 : word.word.length" :ref="word.id"
     14                <!-- :size="word.word.length === 0 ? 1 : word.word.length" -->
     15                <input :ref="word.id"
    1516                    class="editor-word" v-model="word.word" type="text" :class="{ 'word-highlight-applied': word.shouldHighlight }"
    1617                    @beforeinput="onEditorBeforeInput($event, index)" @focusout="onEditorFocusOut(index)" @focus="onEditorFocus(index)" />
     
    2021    </div>
    2122
    22     <word-timing-selector class="word-timing-selector" :surroundingWords="surroundingWords" v-model:word="selectedWord" v-if="enableEditing" />
     23    <word-timing-selector class="word-timing-selector" v-model:surroundingWords="surroundingWords" :wordIndex="surroundingWordPrincipleIndex" v-if="enableEditing" />
    2324</div>
    2425</template>
     
    114115            words: [],
    115116            lastHighlightedWordIndex: 0,
    116             selectedIndex: 0
     117            selectedIndex: 0,
     118            surroundingWordPrincipleIndex: 0
    117119        }
    118120    },
     
    126128            }
    127129        },
    128         surroundingWords() {
    129             return this.getSurroundingWords(this.selectedIndex);
    130         },
    131         selectedWord: {
     130        surroundingWords: {
    132131            get() {
    133                 return this.words[this.selectedIndex];
     132                return this.getSurroundingWords(this.selectedIndex);
    134133            },
    135134            set(value) {
    136                 this.words[this.selectedIndex] = value;
     135                this.setSurroundingWords(this.selectedIndex, value);
    137136            }
    138137        },
     
    194193        },
    195194
     195        /**
     196         * Gets the minimum viable index that surrounding words can start at.
     197         * @param {Number} principleIndex The index of the primary surrounding word.
     198         * @param {Number} buffer The maximum number of words to take on each side of the principle word.
     199         */
     200        getSurroundingWordMinIndex(principleIndex, buffer) {
     201            let min = principleIndex;
     202            for (let i = principleIndex; i > principleIndex - buffer && i > 0; i--) {
     203                min--;
     204            }
     205
     206            return min;
     207        },
     208
    196209        getSurroundingWords(index) {
    197210            const BUFFER = 2; // The number of words to take on each side
    198211
    199             let min = index;
    200             for (let i = index; i > index - BUFFER && i > 0; i--) {
    201                 min--;
    202             }
     212            const min = this.getSurroundingWordMinIndex(index, BUFFER);
    203213
    204214            let max = index + 1;
     
    207217            }
    208218
     219            this.surroundingWordPrincipleIndex = index - min;
    209220            return this.words.slice(min, max);
     221        },
     222
     223        /**
     224         * Sets the backing value of the surrounding words variable.
     225         * @param {Number} index The index in the back array at which to update the words.
     226         * @param {Array<Word>} value The updated words.
     227         */
     228        setSurroundingWords(index, value) {
     229            const BUFFER = 2; // The number of words to take on each side TODO: Global constant
     230
     231            const startIndex = this.getSurroundingWordMinIndex(index, BUFFER);
     232            console.log(this.words);
     233            this.words.splice(startIndex, value.length - 1, value);
     234            console.log(this.words);
    210235        },
    211236
  • main/trunk/model-interfaces-dev/atea/korero-maori-asr/src/components/WordTimingSelector.vue

    r35601 r35602  
    112112        /** @type {Array<TWord>} */
    113113        surroundingWords: Array,
    114         word: TWord
     114        wordIndex: Number
    115115    },
    116116    data() {
    117117        return {
    118118            isMounted: false,
    119             /** @type {Array<Word>} */
    120             // mySurroundingWords: [],
    121119            canAdjustWordStartTime: false,
    122120            canAdjustWordEndTime: false,
     
    125123        }
    126124    },
    127     emits: [ "update:word" ],
     125    emits: [ "update:surroundingWords" ],
    128126    computed: {
     127        word() {
     128            return this.surroundingWords[this.wordIndex];
     129        },
    129130        myWord() {
    130131            return this.mySurroundingWords[this.wordIndex];
     
    156157        rightHandleLeft() {
    157158            return `calc(${this.myWord.left}px + ${this.myWord.length}px)`;
    158         },
    159         wordIndex() {
    160             return this.surroundingWords.indexOf(this.word);
    161159        },
    162160        audioSnippetLength() {
     
    212210            this.wordsContainerWidth = newValue;
    213211        },
    214         convertSurroundingWords() {
    215             const myWords = [];
    216 
    217             if (this.surroundingWords.length === 0) {
    218                 return myWords;
    219             }
    220 
    221             for (const word of this.surroundingWords) {
    222                 myWords.push(this.convertWord(word));
    223             }
    224 
    225             return myWords;
    226         },
    227212        scaleTime(time) {
    228213            return time * this.scalingFactor;
     
    275260            this.adjustWordStartTime(event.movementX);
    276261
    277             this.myWordToWord();
     262            this.updateSurroundingWords();
    278263        },
    279264        onMaxHandleMouseMove(event) {
     
    296281            word.length += event.movementX;
    297282
    298             this.myWordToWord();
     283            this.updateSurroundingWords();
    299284        },
    300285        onDocumentMouseUp() {
     
    302287            this.canAdjustWordEndTime = false;
    303288        },
    304         myWordToWord() {
    305             const pxLeft = this.myWord.left;
    306             const pxRight = this.myWord.left + this.myWord.length;
    307 
    308             const startTime = (pxLeft + this.wordLeftOffsetPx) / this.scalingFactor;
    309             const endTime = (pxRight + this.wordLeftOffsetPx) / this.scalingFactor;
    310 
    311             const word = new TWord(this.word.word, startTime, endTime, this.word.id, this.word.shouldHighlight, this.word.deletionAttempts);
    312             this.$emit("update:word", word);
    313         },
    314289        adjustWordStartTime(amount) {
    315             const word = this.mySurroundingWords[this.wordIndex];
     290            const word = this.myWord;
    316291            word.left += amount;
    317292            word.length -= amount;
     
    361336                }
    362337            }
     338        },
     339        updateSurroundingWords() {
     340            const updatedWords = [];
     341
     342            for (let i = 0; i < this.mySurroundingWords.length; i++) {
     343                updatedWords.push(
     344                    this.convertMyWord(this.mySurroundingWords[i], this.surroundingWords[i])
     345                );
     346            }
     347
     348            console.log(updatedWords);
     349            this.$emit("update:surroundingWords", updatedWords);
     350        },
     351        convertMyWord(myWord, actualWord) {
     352            const startTime = (myWord.left + this.wordLeftOffsetPx) / this.scalingFactor;
     353            const endTime = (myWord.right() + this.wordLeftOffsetPx) / this.scalingFactor;
     354
     355            return new TWord(actualWord.word, startTime, endTime, actualWord.id, actualWord.shouldHighlight, actualWord.deletionAttempts);
    363356        }
    364357    },
Note: See TracChangeset for help on using the changeset viewer.