src/app/features/location/map/map-properties-popup/map-properties-popup.component.ts

Metadata

Relationships

Used by

No results matching.

Depends on

import { Component, inject, ChangeDetectionStrategy } from "@angular/core";
import {
  MAT_DIALOG_DATA,
  MatDialogModule,
  MatDialogRef,
} from "@angular/material/dialog";
import { DialogCloseComponent } from "../../../../core/common-components/dialog-close/dialog-close.component";
import { MatFormFieldModule } from "@angular/material/form-field";
import { MatSelectModule } from "@angular/material/select";
import { EntityConstructor } from "../../../../core/entity/model/entity";
import { EntityRegistry } from "../../../../core/entity/database-entity.decorator";
import { getLocationProperties } from "../../map-utils";
import { MatButtonModule } from "@angular/material/button";

/**
 * A map of entity types and the (selected) location properties of this type
 */
export type LocationProperties = { [key: string]: string[] };

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-map-properties-popup",
  templateUrl: "./map-properties-popup.component.html",
  styles: [],
  imports: [
    MatDialogModule,
    DialogCloseComponent,
    MatFormFieldModule,
    MatSelectModule,
    MatButtonModule,
  ],
})
export class MapPropertiesPopupComponent {
  private dialogRef =
    inject<MatDialogRef<MapPropertiesPopupComponent>>(MatDialogRef);

  entityProperties: {
    entity: EntityConstructor;
    properties: { name: string; label: string }[];
    selected: string[];
  }[];

  constructor() {
    const mapProperties = inject<LocationProperties>(MAT_DIALOG_DATA);
    const entities = inject(EntityRegistry);

    this.entityProperties = Object.entries(mapProperties).map(
      ([entityType, selected]) => {
        const entity = entities.get(entityType);
        const mapProperties = getLocationProperties(entity);
        const properties = mapProperties.map((name) => ({
          name,
          label: entity.schema.get(name).label,
        }));
        return { entity, properties, selected };
      },
    );
  }

  closeDialog() {
    const result: LocationProperties = {};
    this.entityProperties.forEach(
      ({ entity, selected }) => (result[entity.ENTITY_TYPE] = selected),
    );
    this.dialogRef.close(result);
  }
}
<h1
  matDialogTitle
  i18n="Title of popup to select locations that are displayed in the map"
>
  Select displayed locations
</h1>
<app-dialog-close matDialogClose></app-dialog-close>
<mat-dialog-content>
  @for (row of entityProperties; track row.entity.ENTITY_TYPE) {
    <mat-form-field style="width: 100%">
      <mat-label>{{ row.entity.label }}</mat-label>
      <mat-select
        [(value)]="row.selected"
        [disabled]="row.properties.length < 2"
        multiple
      >
        @for (prop of row.properties; track prop.name) {
          <mat-option [value]="prop.name">{{ prop.label }}</mat-option>
        }
      </mat-select>
    </mat-form-field>
  }
</mat-dialog-content>
<mat-dialog-actions>
  <button
    mat-stroked-button
    (click)="closeDialog()"
    i18n="Button for closing popup and applying changes"
  >
    Apply
  </button>
</mat-dialog-actions>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""