validatePurposeOptions()

in frontend/src/app/modules/config-editor/components/config-editor/config-editor.component.ts [609:639]


  validatePurposeOptions(event: MatAutocompleteSelectedEvent, index: any) {
    /* Validate software*/
    let tempArray: any[] = []
    const indices = [];
    this.ldspFaDevices.value.forEach((element: any) => {
      tempArray.push(element.purpose)
    });
    let idx = tempArray.indexOf(event.option.value);
    this.validateSwap();
    while (idx != -1) {
      indices.push(idx);
      idx = tempArray.indexOf(event.option.value, idx + 1);
    }

    if (indices.length > 1) {
      this.ldspFaDevices.controls[index].get('purpose')?.setErrors({'incorrect': true})
      this.openSnackBar(`${event.option.value} already selected`, 'OK');
    }

    if (event.option.value === 'swap' &&
      this.configEditorForm.get('misc_config_values')?.get('is_swap_configured')?.value) {
      this.ldspFaDevices.controls[index].get('purpose')?.setErrors({'swapIsAlreadyConfigured': true});
      this.openSnackBar('Swap is configured on server', 'OK');
    }
    /*Validate swap */

    if (event.option.value === 'swap') {
      this.ldspFaDevices.controls[index].get('mount_point')?.setValue('');
      this.ldspFaDevices.controls[index].get('name')?.setValue('');
    }
  }