File

src/app/shared/components/slices-input/slices-input.component.ts

Description

Component for entering data on block slices

Metadata

Index

Methods
Inputs
Outputs

Inputs

slicesConfig
Default value : DEFAULT_SLICES_CONFIG

Values of block dimensions to be emitted

Outputs

slicesConfig

Values of block dimensions to be emitted

slicesConfigChange
Type : SlicesConfig

Emitter for slice data values

Methods

emptyStringIfNaN
emptyStringIfNaN(value: number)

Get the original value if not NaN otherwise the empty string

Parameters :
Name Type Optional Description
value number No

Value to check

Returns : number | string

The original value if it is not NaN, '' otherwise

refreshSlices
refreshSlices()

Refreshes all slice data values to empty values

Returns : void
updateSlicesData
updateSlicesData(event: KeyboardEvent, key: string)

Limits the length of the input if needed and updates values when an input changes

Parameters :
Name Type Optional Description
event KeyboardEvent No

Event from the input element which contains the new value

key string No

Name of the dimension to be updated

Returns : void
import { ChangeDetectionStrategy, Component, model, output } from '@angular/core';

/**
 * Interface containing slices data of the tissue block
 */
export interface SlicesConfig {
  /** Thickness of each tissue slice */
  thickness: number;
  /** Number of slices in the block */
  numSlices: number;
}

/** Default values for slices config. */
const DEFAULT_SLICES_CONFIG: SlicesConfig = {
  thickness: 0,
  numSlices: 0,
};

/**
 * Component for entering data on block slices
 */
@Component({
  selector: 'ccf-slices-input',
  standalone: false,
  templateUrl: './slices-input.component.html',
  styleUrl: './slices-input.component.scss',
  changeDetection: ChangeDetectionStrategy.OnPush,
})
export class SlicesInputComponent {
  /**
   * Values of block dimensions to be emitted
   */
  readonly slicesConfig = model(DEFAULT_SLICES_CONFIG);

  /**
   * Emitter for slice data values
   */
  readonly slicesConfigChange = output<SlicesConfig>();

  /**
   * Get the original value if not NaN otherwise the empty string
   *
   * @param value Value to check
   * @returns The original value if it is not NaN, '' otherwise
   */
  emptyStringIfNaN(value: number): number | string {
    return Number.isNaN(value) ? '' : value;
  }

  /**
   * Limits the length of the input if needed and updates values when an input changes
   *
   * @param event Event from the input element which contains the new value
   * @param key Name of the dimension to be updated
   */
  updateSlicesData(event: KeyboardEvent, key: string): void {
    const { value: strValue } = event.target as HTMLInputElement;
    this.slicesConfig.set({ ...this.slicesConfig(), [key]: strValue !== '' ? +strValue : NaN });
    this.slicesConfigChange.emit(this.slicesConfig());
  }

  /**
   * Refreshes all slice data values to empty values
   */
  refreshSlices(): void {
    this.slicesConfig.set(DEFAULT_SLICES_CONFIG);
    this.slicesConfigChange.emit(this.slicesConfig());
  }
}
<div class="header">
  <span class="text title">Tissue Section</span>
</div>

<div class="slices-inputs">
  <mat-form-field hraFeature="thickness" hraClickEvent>
    <mat-label class="text form-input-label">Thickness (μm)</mat-label>
    <input
      matInput
      ccfNumbersOnly
      class="input"
      type="number"
      hraPlainTooltip="Tissue thickness is measured in micrometers"
      [value]="emptyStringIfNaN(slicesConfig().thickness)"
      (keyup)="updateSlicesData($event, 'thickness')"
    />
  </mat-form-field>

  <mat-form-field hraFeature="num-slices" hraClickEvent>
    <mat-label class="text form-input-label">#Sections</mat-label>
    <input
      matInput
      ccfNumbersOnly
      class="input"
      type="number"
      hraPlainTooltip="Total number of tissue sections"
      [value]="emptyStringIfNaN(slicesConfig().numSlices)"
      (keyup)="updateSlicesData($event, 'numSlices')"
    />
  </mat-form-field>
</div>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""