<commit_before>import { Component, forwardRef, Input, OnInit } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
import { ServerService } from '@app/core'
import { SelectOptionsItem } from '../../../../types/select-options-item.model'
import { ItemSelectCheckboxValue } from './select-checkbox.component'

@Component({
  selector: 'my-select-languages',
  styleUrls: [ './select-shared.component.scss' ],
  templateUrl: './select-languages.component.html',
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() => SelectLanguagesComponent),
      multi: true
    }
  ]
})
export class SelectLanguagesComponent implements ControlValueAccessor, OnInit {
  @Input() maxLanguages: number

  selectedLanguages: ItemSelectCheckboxValue[]
  availableLanguages: SelectOptionsItem[] = []

  allLanguagesGroup = $localize`All languages`

  // Fix a bug on ng-select when we update items after we selected items
  private toWrite: any
  private loaded = false

  constructor (
    private server: ServerService
  ) {

  }

  ngOnInit () {
    this.server.getVideoLanguages()
      .subscribe(
        languages => {
          this.availableLanguages = [ { label: $localize`Unknown language`, id: '_unknown', group: this.allLanguagesGroup } ]

          this.availableLanguages = this.availableLanguages
            .concat(languages.map(l => ({ label: l.label, id: l.id, group: this.allLanguagesGroup })))

          this.loaded = true
          this.writeValue(this.toWrite)
        }
      )
  }

  propagateChange = (_: any) => { /* empty */ }

  writeValue (languages: ItemSelectCheckboxValue[]) {
    if (!this.loaded) {
      this.toWrite = languages
      return
    }

    this.selectedLanguages = languages
  }

  registerOnChange (fn: (_: any) => void) {
    this.propagateChange = fn
  }

  registerOnTouched () {
    // Unused
  }

  onModelChange () {
    this.propagateChange(this.selectedLanguages)
  }
}
<commit_msg>Move zxx to its own group in select-languages component (#4664)<commit_after>import { Component, forwardRef, Input, OnInit } from '@angular/core'
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'
import { ServerService } from '@app/core'
import { SelectOptionsItem } from '../../../../types/select-options-item.model'
import { ItemSelectCheckboxValue } from './select-checkbox.component'

@Component({
  selector: 'my-select-languages',
  styleUrls: [ './select-shared.component.scss' ],
  templateUrl: './select-languages.component.html',
  providers: [
    {
      provide: NG_VALUE_ACCESSOR,
      useExisting: forwardRef(() => SelectLanguagesComponent),
      multi: true
    }
  ]
})
export class SelectLanguagesComponent implements ControlValueAccessor, OnInit {
  @Input() maxLanguages: number

  selectedLanguages: ItemSelectCheckboxValue[]
  availableLanguages: (SelectOptionsItem & { groupOrder: number })[] = []

  allLanguagesGroup = $localize`All languages`

  // Fix a bug on ng-select when we update items after we selected items
  private toWrite: any
  private loaded = false

  constructor (
    private server: ServerService
  ) {

  }

  ngOnInit () {
    this.server.getVideoLanguages()
      .subscribe(
        languages => {
          this.availableLanguages = [ {
            label: $localize`Unknown language`,
            id: '_unknown',
            group: this.allLanguagesGroup,
            groupOrder: 1
          } ]

          this.availableLanguages = this.availableLanguages
            .concat(languages.map(l => {
              if (l.id === 'zxx') return { label: l.label, id: l.id, group: $localize`Other`, groupOrder: 0 }
              return { label: l.label, id: l.id, group: this.allLanguagesGroup, groupOrder: 1 }
            }))

          this.availableLanguages.sort((a, b) => a.groupOrder - b.groupOrder)

          this.loaded = true
          this.writeValue(this.toWrite)
        }
      )
  }

  propagateChange = (_: any) => { /* empty */ }

  writeValue (languages: ItemSelectCheckboxValue[]) {
    if (!this.loaded) {
      this.toWrite = languages
      return
    }

    this.selectedLanguages = languages
  }

  registerOnChange (fn: (_: any) => void) {
    this.propagateChange = fn
  }

  registerOnTouched () {
    // Unused
  }

  onModelChange () {
    this.propagateChange(this.selectedLanguages)
  }
}

{'fraction_non_alphanumeric': 0.12309095053567358, 'fraction_numerical': 0.0015956234328698426, 'mean_word_length': 2.9424977538185084, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3873928', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1277, 'n_words': 282}