src/app/core/admin/json-editor/json-editor-dialog/json-editor-dialog.component.ts

Metadata

Relationships

Used by

No results matching.

Depends on

Index

Properties
Methods

Constructor

constructor()

Methods

onJsonValueCancel
onJsonValueCancel()

Cancel the changes and reset the JSON value.

Returns : void
onJsonValueSave
onJsonValueSave()

Save the JSON value and emit the updated value.

Returns : void

Properties

data
Type : unknown
Default value : inject(MAT_DIALOG_DATA)
jsonDataControl
Type : FormControl
import {
  Component,
  CUSTOM_ELEMENTS_SCHEMA,
  inject,
  ChangeDetectionStrategy,
} from "@angular/core";
import { FormControl, ReactiveFormsModule } from "@angular/forms";
import { MatButtonModule } from "@angular/material/button";
import {
  MAT_DIALOG_DATA,
  MatDialogModule,
  MatDialogRef,
} from "@angular/material/dialog";
import { DialogCloseComponent } from "app/core/common-components/dialog-close/dialog-close.component";
import { JsonEditorComponent } from "../json-editor.component";

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-json-editor-dialog",
  standalone: true,
  imports: [
    JsonEditorComponent,
    MatDialogModule,
    DialogCloseComponent,
    MatButtonModule,
    ReactiveFormsModule,
  ],
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  templateUrl: "./json-editor-dialog.component.html",
  styleUrl: "./json-editor-dialog.component.scss",
})
export class JsonEditorDialogComponent {
  data = inject(MAT_DIALOG_DATA);
  private dialogRef =
    inject<MatDialogRef<JsonEditorDialogComponent>>(MatDialogRef);

  jsonDataControl: FormControl;

  constructor() {
    const data = this.data;

    this.jsonDataControl = new FormControl(data?.value || {});
  }

  /**
   * Save the JSON value and emit the updated value.
   */
  onJsonValueSave() {
    if (this.jsonDataControl.valid) {
      this.dialogRef.close(this.jsonDataControl.value);
    }
  }

  /**
   * Cancel the changes and reset the JSON value.
   */
  onJsonValueCancel() {
    this.dialogRef.close(null);
  }
}
<mat-dialog-content class="mat-typography">
  @if (data.closeButton) {
    <app-dialog-close mat-dialog-close></app-dialog-close>
  }
  <div class="json-editor">
    <app-json-editor
      [formControl]="jsonDataControl"
      class="json-editor-dialog"
    ></app-json-editor>

    <div class="flex-row json-editor-actions">
      <button
        [disabled]="jsonDataControl.invalid"
        mat-raised-button
        (click)="onJsonValueSave()"
        i18n
      >
        Save
      </button>
      <button mat-raised-button (click)="onJsonValueCancel()" i18n>
        Cancel
      </button>
    </div>
  </div>
</mat-dialog-content>

./json-editor-dialog.component.scss

@use "variables/sizes";

.mat-typography {
  max-height: 90vh;
  margin-top: sizes.$large;
  width: 60vw;
}

.json-editor-actions {
  justify-content: end;
  margin-top: sizes.$regular;
  gap: sizes.$regular;
}

.json-editor-dialog {
  height: 50vh;
}
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""