|
useCases
|
Default value : []
|
|
|
Methods
|
onSelectionChange
|
onSelectionChange()
|
|
|
|
|
|
availableUseCases
|
Type : Signal<BaseConfig[]>
|
Default value : computed(() => {
const current = this.languageService.getCurrentLocale();
return this.useCases().filter((uc) => (uc.locale ?? current) === current);
})
|
|
|
import {
Component,
computed,
effect,
inject,
input,
InputSignal,
output,
Signal,
ChangeDetectionStrategy,
} from "@angular/core";
import { BaseConfig } from "../../base-config";
import { MatSelectModule } from "@angular/material/select";
import { MarkdownComponent } from "ngx-markdown";
import { FormsModule } from "@angular/forms";
import { LanguageService } from "app/core/language/language.service";
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: "app-choose-use-case",
templateUrl: "./choose-use-case.component.html",
imports: [MatSelectModule, MarkdownComponent, FormsModule],
styleUrls: ["./choose-use-case.component.scss"],
})
export class ChooseUseCaseComponent {
private readonly languageService = inject(LanguageService);
useCases: InputSignal<BaseConfig[]> = input([]);
availableUseCases: Signal<BaseConfig[]> = computed(() => {
const current = this.languageService.getCurrentLocale();
return this.useCases().filter((uc) => (uc.locale ?? current) === current);
});
private readonly switchLanguageIfNoUseCaseInCurrentLocale = effect(() => {
if (this.availableUseCases().length === 0 && this.useCases().length > 0) {
const nextLanguage = this.useCases().find((uc) => !!uc.locale)?.locale;
if (nextLanguage) this.languageService.switchLocale(nextLanguage);
}
});
selectionChanged = output<BaseConfig>();
selectedUseCase: BaseConfig;
onSelectionChange() {
this.selectionChanged.emit(this.selectedUseCase);
}
}
<div class="flex-row flex-wrap gap-regular align-center">
<mat-form-field appearance="fill" class="flex-1 min-width">
<mat-label i18n>Select your use case:</mat-label>
<mat-select
[(ngModel)]="selectedUseCase"
(selectionChange)="onSelectionChange()"
>
@for (useCase of availableUseCases(); track useCase.id) {
<mat-option [value]="useCase">
{{ useCase.name }}
</mat-option>
}
</mat-select>
</mat-form-field>
<div class="flex-1 description-container">
@if (selectedUseCase) {
<div markdown [data]="selectedUseCase.description"></div>
} @else {
<p class="description-no-use-case" i18n>
Select a use case as an initial configuration for your system.
</p>
}
</div>
</div>
@use "variables/colors";
.flex-1 {
flex: 1;
}
.description-container {
padding: 16px;
border-radius: 8px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
min-height: 150px;
align-content: center;
}
.description-no-use-case {
color: colors.$hint-text;
}
.hidden {
padding: 0;
box-shadow: none;
visibility: hidden;
height: 0;
}
.greyed-out {
opacity: 0.5;
}
.min-width {
min-width: 240px;
margin-bottom: 0;
}
Legend
Html element with directive