All files / app/form/plugin plugin.component.ts

80% Statements 20/25
62.96% Branches 17/27
77.77% Functions 7/9
75% Lines 15/20

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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 7571x                 71x                 71x         1x   1x   1x   1x 1x 1x 1x             2x       2x       2x       2x                             1x                
import { Component, Input } from '@angular/core';
import {
  ReactiveFormsModule,
  UntypedFormBuilder,
  UntypedFormControl,
  UntypedFormGroup,
  Validators
} from '@angular/forms';
import { v4 as uuid } from 'uuid';
import { JsonComponent } from '../json/json.component';
 
@Component({
  selector: 'app-plugin-form',
  templateUrl: './plugin.component.html',
  styleUrls: ['./plugin.component.scss'],
  host: { 'class': 'nested-form' },
  imports: [ReactiveFormsModule, JsonComponent]
})
export class PluginFormComponentI {
 
  @Input()
  group!: UntypedFormGroup;
  @Input()
  configErrors: string[] = [];
  @Input()
  defaultsErrors: string[] = [];
  @Input()
  schemaErrors: string[] = [];
 
  id = 'plugin-' + uuid();
  editingConfig = false;
  editingDefaults = false;
  editingSchema = false;
 
  get tag() {
    return this.group.get('tag') as UntypedFormControl;
  }
 
  get name() {
    return this.group.get('name') as UntypedFormControl;
  }
 
  get config() {
    return this.editingConfig ||= this.group.get('config')?.value;
  }
 
  get defaults() {
    return this.editingDefaults ||= this.group.get('defaults')?.value;
  }
 
  get schema() {
    return this.editingSchema ||= this.group.get('schema')?.value;
  }
 
  validate(input: HTMLInputElement) {
    if (this.name.touched) {
      if (this.name.errors?.['required']) {
        input.setCustomValidity($localize`Name must not be blank.`);
        input.reportValidity();
      }
    }
  }
 
}
 
export function pluginForm(fb: UntypedFormBuilder) {
  return fb.group({
    tag: [{value: '', disabled: true}, [Validators.required]],
    name: ['', [Validators.required]],
    config: [],
    defaults: [],
    schema: [],
  });
}