All files / site common_methods.ts

9.09% Statements 3/33
0% Branches 0/20
0% Functions 0/5
9.67% Lines 3/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52        2x                                                   2x                           2x              
import type {MeasureInfo} from '../types'
import type {InputCombobox} from './inputs/combobox'
import type {InputSelect} from './inputs/select'
 
export function options_filter(this: InputCombobox | InputSelect) {
  Iif (this.settings.filters) {
    Object.keys(this.settings.filters).forEach(f => {
      this.current_filter[f] = this.site.valueOf(this.settings.filters[f]) as keyof MeasureInfo
    })
    let first = ''
    Object.keys(this.values).forEach((v, i) => {
      let pass = false
      Iif (v in this.site.data.variables && 'meta' in this.site.data.variables[v]) {
        const info = this.site.data.variables[v].meta as MeasureInfo
        for (const k in this.current_filter)
          Iif (k in info) {
            pass = info[k as keyof MeasureInfo] === this.current_filter[k]
            Iif (!pass) break
          }
      }
      Iif (pass && !first) first = v
      this.options[i].classList[pass ? 'remove' : 'add']('hidden')
    })
    this.current_index = this.values[this.value() as string]
    Iif (first && (-1 === this.current_index || this.options[this.current_index].classList.contains('hidden'))) {
      this.set(first)
    }
  }
}
 
export function set_current_options(this: InputCombobox | InputSelect) {
  const to = this.option_sets[this.dataset]
  this.values = to.values
  this.display = to.display
  this.options = to.options as typeof this.options
  this.groups = to.groups
  this.source = ''
  this.id in this.site.url_options
    ? this.set(this.site.url_options[this.id] as string)
    : this.state in this.values
    ? this.set(this.state)
    : this.reset()
}
 
export function loader(this: InputCombobox | InputSelect) {
  Iif (!this.e.classList.contains('locked')) {
    this.deferred = false
    this.e.removeEventListener('click', this.loader)
    this.site.request_queue(false, this.id)
  }
}