File

projects/web-mev/src/app/features/workspace-detail/components/dialogs/edit-dialog/edit-dialog/edit-dialog.component.ts

Description

Edit Workspace Resource Dialog Component

Modal dialog component which is used to edit a resource name

Metadata

changeDetection ChangeDetectionStrategy.OnPush
selector mev-edit-dialog
styleUrls ./edit-dialog.component.scss
templateUrl ./edit-dialog.component.html

Index

Properties
Methods

Constructor

constructor(dialogRef: MatDialogRef, data: any, fileService: FileService)
Parameters :
Name Type Optional
dialogRef MatDialogRef<EditDialogComponent> No
data any No
fileService FileService No

Methods

getErrorMessage
getErrorMessage()
Returns : "" | "Required field"
onNoClick
onNoClick()

Function is triggered when user clicks the Cancel button

Returns : void
stopEdit
stopEdit()

Function is triggered when user clicks the Save button

Returns : void
submit
submit()
Returns : void

Properties

Public data
Type : any
Decorators :
@Inject(MAT_DIALOG_DATA)
Public dialogRef
Type : MatDialogRef<EditDialogComponent>
Public fileService
Type : FileService
formControl
Default value : new FormControl('', [Validators.required])
import { Component, ChangeDetectionStrategy, Inject } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
import { FileService } from '@app/features/file-manager/services/file-manager.service';

/**
 * Edit Workspace Resource Dialog Component
 *
 * Modal dialog component which is used to edit a resource name
 */
@Component({
  selector: 'mev-edit-dialog',
  templateUrl: './edit-dialog.component.html',
  styleUrls: ['./edit-dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class EditDialogComponent {
  formControl = new FormControl('', [Validators.required]);

  constructor(
    public dialogRef: MatDialogRef<EditDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
    public fileService: FileService
  ) {}

  getErrorMessage() {
    return this.formControl.hasError('required') ? 'Required field' : '';
  }

  submit() {
    // empty stuff
  }

  /**
   * Function is triggered when user clicks the Cancel button
   *
   */
  onNoClick(): void {
    this.dialogRef.close();
  }

  /**
   * Function is triggered when user clicks the Save button
   *
   */
  stopEdit(): void {
    this.fileService.updateFile(this.data);
  }
}
<div class="container">
    <h3 mat-dialog-title>Edit Resource</h3>
  
    <form class="mat-dialog-content" (ngSubmit)="submit" #formControl="ngForm">
  
      <div class="form">
        <mat-form-field color="accent">
          <input matInput #input class="form-control" placeholder="File name" [(ngModel)]="data.name" name="name"
            required>
          <mat-error *ngIf="formControl.invalid">{{getErrorMessage()}}</mat-error>
        </mat-form-field>
      </div>
  
      <div mat-dialog-actions>
        <button mat-button [type]="submit" [disabled]="!formControl.valid" [mat-dialog-close]="1"
          (click)="stopEdit()" mat-raised-button color="accent">Save</button>
        <button mat-button (click)="onNoClick()" tabindex="-1">Cancel</button>
      </div>
    </form>
  </div>

./edit-dialog.component.scss

.mat-dialog-content {
  min-height: 150px;
  position: relative;
}

.container {
  display: flex;
  flex-direction: column;
  min-width: 450px;
}

.container > * {
  width: 100%;
}

.mat-dialog-content {
  max-height: none;
  overflow: visible;
}

.form {
  display: flex;
  padding-top: 6px;
}

.mat-form-field {
  font-size: 16px;
  flex-grow: 1;
}

.mat-dialog-actions {
  position: absolute;
  bottom: 0;
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""