File

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

Description

Add Annotation Dialog Component

Modal dialog component which is used to incorporate an annotation file as custom observation set.

Implements

OnInit

Metadata

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

Index

Properties
Methods

Constructor

constructor(formBuilder: FormBuilder, dialogRef: MatDialogRef, data: any, apiService: AnalysesService)
Parameters :
Name Type Optional
formBuilder FormBuilder No
dialogRef MatDialogRef<AddAnnotationDialogComponent> No
data any No
apiService AnalysesService 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
onSelectAnnonation
onSelectAnnonation()

Method is triggered when the user selects an annotation file from the dropdown list

Get the annotation file content to get the list of attributes

Returns : void
onSelectAttribute
onSelectAttribute()

Method is triggered when the user select an attribure from the annotation file

Get the list of unique attribute values

Returns : void
submit
submit()
Returns : void

Properties

annotationFileContent
Type : []
Default value : []
attributes
Type : []
Default value : []
attributeValues
Type : []
Default value : []
Public data
Type : any
Decorators :
@Inject(MAT_DIALOG_DATA)
Public dialogRef
Type : MatDialogRef<AddAnnotationDialogComponent>
dropdownSettings
Type : object
Default value : {}
files
Type : []
Default value : []
form
Type : FormGroup
selectedAnnotationFileId
Type : string
selectedAttribute
Type : string
selectedAttributeValues
Type : []
Default value : []
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import {
  Component,
  OnInit,
  ChangeDetectionStrategy,
  Inject
} from '@angular/core';
import { FormBuilder, Validators, FormGroup } from '@angular/forms';
import { AnalysesService } from '@app/features/analysis/services/analysis.service';
import { CustomSetType } from '@app/_models/metadata';
import { Utils } from '@app/shared/utils/utils';

/**
 * Add Annotation Dialog Component
 *
 * Modal dialog component which is used to incorporate an annotation file as custom observation set.
 */
@Component({
  selector: 'mev-add-annotation-dialog',
  templateUrl: './add-annotation-dialog.component.html',
  styleUrls: ['./add-annotation-dialog.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AddAnnotationDialogComponent implements OnInit {
  files = [];
  attributes = [];
  selectedAnnotationFileId: string;
  annotationFileContent = [];
  selectedAttribute: string;
  attributeValues = [];
  selectedAttributeValues = [];
  form: FormGroup;

  dropdownSettings = {};
  constructor(
    private formBuilder: FormBuilder,
    public dialogRef: MatDialogRef<AddAnnotationDialogComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
    private apiService: AnalysesService
  ) {}

  ngOnInit(): void {
    this.form = this.formBuilder.group({
      annotation: ['', Validators.required],
      attribute: ['', Validators.required],
      attributeValue: ['', Validators.required]
    });

    this.dropdownSettings = {
      primaryKey: 'name',
      text: 'Select custom observation sets to create',
      selectAllText: 'Select All',
      unSelectAllText: 'Unselect All',
      classes: 'resource-dropdown'
    };

    this.files = this.data.workspaceResources;
  }

  /**
   * Method is triggered when the user selects an annotation file from the dropdown list
   *
   * Get the annotation file content to get the list of attributes
   */
  onSelectAnnonation() {
    this.apiService
      .getResourceContent(this.selectedAnnotationFileId)
      .subscribe(response => {
        if (response.length) {
          this.annotationFileContent = response;
          this.attributes = Object.keys(response[0].values);
          this.selectedAttributeValues = []; // reset selected attributes in multi-select dropdown
        }
      });
  }

  /**
   * Method is triggered when the user select an attribure from the annotation file
   *
   * Get the list of unique attribute values
   */
  onSelectAttribute() {
    this.attributeValues = [
      ...new Set(
        this.annotationFileContent.map(
          item => item.values[this.selectedAttribute]
        )
      )
    ].map(el => ({ name: el }));
  }

  /**
   * 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() {
    const customSets = [];
    this.form.value.attributeValue.forEach(attrValue => {
      const attrSamples = this.annotationFileContent
        .filter(
          sample => sample.values[this.selectedAttribute] === attrValue.name
        )
        .map(sample => ({ id: sample.rowname, attributes: sample.values }));

      const customSet = {
        name: attrValue.name,
        type: CustomSetType.ObservationSet,
        elements: attrSamples,
        color: Utils.getRandomColor(),
        multiple: true
      };
      customSets.push(customSet);
    });
    this.dialogRef.close(customSets);
  }
}
<div class="container">
  <p> Fill in the parameters and click the Add button. <br> 
    After you have created custom observations sets from your annotation file,
     you can rename them and assign new colors instead default ones.</p>
  <form class="mat-dialog-content" (ngSubmit)="submit" [formGroup]="form">

    <div class="form">
      <mat-form-field class="form-control" color="accent">
        <mat-label>Annotation file</mat-label>
        <mat-select formControlName=annotation [(value)]="selectedAnnotationFileId"
          (selectionChange)="onSelectAnnonation()">
          <mat-option *ngFor="let file of files | annotationFilesPipe" [value]="file.id">
            {{ file.name }}
          </mat-option>
        </mat-select>
      </mat-form-field>

    
      <mat-form-field *ngIf="attributes.length" class="form-control" color="accent">
        <mat-label>Annotation attribute</mat-label>
        <mat-select formControlName=attribute [(value)]="selectedAttribute" (selectionChange)="onSelectAttribute()">
          <mat-option *ngFor="let attribute of attributes" [value]="attribute">
            {{ attribute }}
          </mat-option>
        </mat-select>
      </mat-form-field>

     
      <angular2-multiselect *ngIf="attributeValues.length" formControlName=attributeValue [data]="attributeValues"
        class="form-control" [settings]="dropdownSettings" [(ngModel)]="selectedAttributeValues" >
        <c-item>
          <ng-template let-item="item">
            <label>{{ item.name }}</label>
          </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" [type]="submit" (click)="confirmAdd()" [disabled]="!form.valid">Add</button>
      <button mat-button (click)="onNoClick()" tabindex="-1">Cancel</button>
    </div>

  </form>
</div>

./add-annotation-dialog.component.scss

.container {
  display: flex;
  flex-direction: column;
  min-width: 450px;
  max-width: 700px;
  font-size: 14px !important;
}

.container > * {
  width: 100%;
}

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

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

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

result-matching ""

    No results matching ""