1import { Controller } from '@hotwired/stimulus'; 2import { itemInfoException } from 'lib/answer_checker/utils/constants' 3import { answerActionFail } from 'lib/answer_checker/utils/constants' 4 5export default class extends Controller { 6 static classes = ['toggleDisabled', 'exceptionHidden']; 7 static targets = ['toggle', 'exception'] 8 static values = { autoOpenAfterIncorrectCount: Number, urlTemplate: String } 9 10 initialize() { 11 this.enable = this.enable.bind(this) 12 this.disable = this.disable.bind(this) 13 } 14 15 connect() { 16 window.addEventListener('willShowNextQuestion', this.disable) 17 window.addEventListener('didAnswerQuestion', this.enable) 18 } 19 20 disconnect() { 21 window.removeEventListener('willShowNextQuestion', this.disable) 22 window.removeEventListener('didAnswerQuestion', this.enable) 23 } 24 25 enable(event) { 26 const { subjectWithStats, results } = event.detail 27 this.showException(results) 28 this.toggleTarget.classList.remove(this.toggleDisabledClass) 29 this.toggleTarget.setAttribute('href', this.urlTemplateValue.replace(':id', subjectWithStats.subject.id)) 30 31 if (this.autoOpenAfterIncorrectCountValue > 0) { 32 const {meaning, reading} = event.detail.subjectWithStats.stats 33 if (results.action === answerActionFail && (meaning.incorrect >= this.autoOpenAfterIncorrectCountValue || reading.incorrect >= this.autoOpenAfterIncorrectCountValue)) { 34 this.toggleTarget.click() 35 } 36 } 37 } 38 39 disable() { 40 this.hideException() 41 this.toggleTarget.classList.add(this.toggleDisabledClass) 42 } 43 44 showException(results) { 45 if (results.message && results.message.type === itemInfoException) { 46 this.exceptionTarget.textContent = results.message.text 47 this.exceptionTarget.classList.remove(this.exceptionHiddenClass) 48 } 49 } 50 51 hideException() { 52 this.exceptionTarget.textContent = '' 53 this.exceptionTarget.classList.add(this.exceptionHiddenClass) 54 } 55}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.