File

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

Description

Add Workspace Resource Dialog Component

Modal dialog component which is used to add new resources to the current workspace

Implements

OnInit

Metadata

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

Index

Properties
Methods

Constructor

constructor(dialogRef: MatDialogRef, apiService: WorkspaceDetailService, data: any)
Parameters :
Name Type Optional
dialogRef MatDialogRef<AddDialogComponent> No
apiService WorkspaceDetailService No
data any No

Methods

confirmAdd
confirmAdd()

Function is triggered when user clicks the Add button

Returns : void
ngOnInit
ngOnInit()
Returns : void
onNoClick
onNoClick()

Function is triggered when user clicks the Cancel button

Returns : void
submit
submit()
Returns : void

Properties

Public data
Type : any
Decorators :
@Inject(MAT_DIALOG_DATA)
Public dialogRef
Type : MatDialogRef<AddDialogComponent>
dropdownSettings
Type : object
Default value : {}
files
Type : []
Default value : []
formControl
Default value : new FormControl('', [Validators.required])
selectedFiles
Type : []
Default value : []
workspaceId
Type : string
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import {
  Component,
  OnInit,
  ChangeDetectionStrategy,
  Inject
} from '@angular/core';
import { Validators, FormControl } from '@angular/forms';
import { WorkspaceDetailService } from '@app/features/workspace-detail/services/workspace-detail.service';

/**
 * Add Workspace Resource Dialog Component
 *
 * Modal dialog component which is used to add new resources to the current workspace
 */
@Component({
  selector: 'mev-add-dialog',
  templateUrl: './add-dialog.component.html',
  styleUrls: ['./add-dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AddDialogComponent implements OnInit {
  files = [];
  selectedFiles = [];

  dropdownSettings = {};
  workspaceId: string;

  constructor(
    public dialogRef: MatDialogRef<AddDialogComponent>,
    private apiService: WorkspaceDetailService,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) {}

  formControl = new FormControl('', [Validators.required]);

  ngOnInit(): void {
    this.workspaceId = this.data.workspaceId;
    this.apiService.getAvailableResources().subscribe(data => {
      this.files = data;
    });

    this.dropdownSettings = {
      text: 'Select resources',
      selectAllText: 'Select All',
      unSelectAllText: 'Unselect All',
      enableSearchFilter: true,
      searchBy: ['name', 'readable_resource_type'],
      lazyLoading: true,
      classes: 'resource-dropdown'
    };
  }

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

  submit() {
    // empty stuff
  }

  /**
   * Function is triggered when user clicks the Add button
   *
   */
  confirmAdd() {
    this.selectedFiles.forEach(file => {
      this.apiService
        .addResourceToWorkspace(file.id, this.data.workspaceId)
        .subscribe();
    });
  }
}
<div class="container">
  <h3 mat-dialog-title>Select one or more resources from the list to add to the Workspace.
    <br> Then click the Add button.</h3>

  <form class="mat-dialog-content" (ngSubmit)="submit" #formControl="ngForm">

    <div class="form">

      <angular2-multiselect [data]="files | validFilesPipe" [(ngModel)]="selectedFiles"
        [settings]="dropdownSettings" name="resource">
        <c-item>
          <ng-template let-item="item">
            <span class="resource-label">{{ item.name }} </span>
            <br>
            <span class="resource-type-label">Type: {{ item.readable_resource_type || 'N/A' }}</span>
          </ng-template>
        </c-item>
        <c-badge>
          <ng-template let-item="item">
            <label>{{ item.name }}</label>
          </ng-template>
        </c-badge>
      </angular2-multiselect>

    </div>

    <div mat-dialog-actions>
      <button mat-button [mat-dialog-close]="1" mat-raised-button color="accent" (click)="confirmAdd()">Add</button>
      <button mat-button (click)="onNoClick()" tabindex="-1">Cancel</button>
    </div>

  </form>
</div>

./add-dialog.component.scss

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

.container > * {
  width: 100%;
}

.mat-dialog-content {
  min-height: 350px;
  max-height: none;
  position: relative;
  overflow: visible;
}

.mat-dialog-title {
  font-size: 16px;
}

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

.mat-dialog-actions {
  position: absolute;
  bottom: 0;
}

.resource-label {
  font-size: 16px;
  word-break: break-all;
}

.resource-type-label {
  color: #666;
  font-size: 12px;
}

::ng-deep {
  .selected-list .c-list .c-token {
    word-break: break-all;
  }
}
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""