src/app/core/admin/admin-entity-details/admin-entity-field/admin-edit-description-only-field/admin-edit-description-only-field.component.ts

Implements

OnChanges

Metadata

Relationships

Used by

No results matching.

Depends on

import {
  Component,
  OnChanges,
  SimpleChanges,
  inject,
  ChangeDetectionStrategy,
} from "@angular/core";
import {
  FormBuilder,
  FormGroup,
  FormsModule,
  ReactiveFormsModule,
  Validators,
} from "@angular/forms";
import { MatButtonModule } from "@angular/material/button";
import {
  MAT_DIALOG_DATA,
  MatDialogModule,
  MatDialogRef,
} from "@angular/material/dialog";
import { MatInputModule } from "@angular/material/input";
import { MatTooltipModule } from "@angular/material/tooltip";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { v4 as uuid } from "uuid";
import { DialogCloseComponent } from "../../../../common-components/dialog-close/dialog-close.component";
import { FormFieldConfig } from "../../../../common-components/entity-form/FormConfig";

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-admin-edit-description-only-field",
  imports: [
    MatDialogModule,
    MatButtonModule,
    DialogCloseComponent,
    MatInputModule,
    FormsModule,
    ReactiveFormsModule,
    FontAwesomeModule,
    MatTooltipModule,
  ],
  templateUrl: "./admin-edit-description-only-field.component.html",
  styleUrl: "./admin-edit-description-only-field.component.scss",
})
export class AdminEditDescriptionOnlyFieldComponent implements OnChanges {
  private dialogRef = inject<MatDialogRef<any>>(MatDialogRef);
  private fb = inject(FormBuilder);

  formField: FormFieldConfig;
  schemaFieldsForm: FormGroup;

  constructor() {
    const data = inject<FormFieldConfig>(MAT_DIALOG_DATA);

    this.formField = data;

    this.initSettings();
  }

  ngOnChanges(changes: SimpleChanges): void {
    if (changes.entitySchemaField) {
      this.initSettings();
    }
  }

  public initSettings() {
    this.schemaFieldsForm = this.fb.group({
      label: [this.formField.label, Validators.required],
    });
  }

  save() {
    this.schemaFieldsForm.markAllAsTouched();
    if (this.schemaFieldsForm.invalid) {
      return;
    }
    if (!this.formField.id) {
      this.formField.id = uuid();
    }

    const newSchemaField = {
      id: this.formField.id,
      viewComponent: "DisplayDescriptionOnly",
      label: this.schemaFieldsForm.get("label").value,
    };

    this.dialogRef.close(newSchemaField);
  }
}
<h2 mat-dialog-title i18n>Configure Text Block</h2>
<app-dialog-close mat-dialog-close></app-dialog-close>

<mat-dialog-content>
  <p i18n>
    This text is displayed as part of the form to provide additional information
    without any input options for the user:
  </p>

  <form [formGroup]="schemaFieldsForm">
    <div class="entity-form-cell">
      <mat-form-field>
        <textarea formControlName="label" matInput rows="3"></textarea>
        <mat-hint i18n>
          You can use Markdown syntax to format this text. For more details,
          check out the
          <a href="https://www.markdownguide.org/basic-syntax" target="_blank"
            >Markdown Guide</a
          >
        </mat-hint>
      </mat-form-field>
    </div>
  </form>
</mat-dialog-content>

<mat-dialog-actions>
  <button mat-button (click)="save()" i18n="Button label">Apply</button>
  <button mat-button mat-dialog-close i18n="Button label">Cancel</button>
</mat-dialog-actions>

./admin-edit-description-only-field.component.scss

.entity-form-cell {
  mat-form-field {
    width: 100%;
  }
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""