Methods
|
onEntityTypeChange
|
onEntityTypeChange(entityType: string)
|
|
|
Parameters :
| Name |
Type |
Optional |
| entityType |
string
|
No
|
|
|
onFromBeginningOfWeekChange
|
onFromBeginningOfWeekChange(fromBeginningOfWeek: boolean)
|
|
|
Parameters :
| Name |
Type |
Optional |
| fromBeginningOfWeek |
boolean
|
No
|
|
|
onModeChange
|
onModeChange(mode: string)
|
|
|
Parameters :
| Name |
Type |
Optional |
| mode |
string
|
No
|
|
|
onSinceDaysChange
|
onSinceDaysChange(sinceDays: number)
|
|
|
Parameters :
| Name |
Type |
Optional |
| sinceDays |
number
|
No
|
|
|
entityType
|
Type : unknown
|
Default value : linkedSignal(() => this.formControl().value?.entityType)
|
|
|
|
fromBeginningOfWeek
|
Type : unknown
|
Default value : linkedSignal(
() => this.formControl().value?.fromBeginningOfWeek ?? false,
)
|
|
|
|
localConfig
|
Type : unknown
|
Default value : computed<NotesDashboardSettingsConfig>(() => ({
entityType: this.entityType(),
sinceDays: this.sinceDays(),
fromBeginningOfWeek: this.fromBeginningOfWeek(),
mode: this.mode(),
}))
|
|
|
|
mode
|
Type : unknown
|
Default value : linkedSignal(
() => this.formControl().value?.mode ?? "with-recent-notes",
)
|
|
|
|
sinceDays
|
Type : unknown
|
Default value : linkedSignal(() => this.formControl().value?.sinceDays ?? 28)
|
|
|
import {
Component,
ChangeDetectionStrategy,
computed,
effect,
input,
linkedSignal,
} from "@angular/core";
import { FormControl, FormsModule, ValidatorFn } from "@angular/forms";
import { MatFormFieldModule } from "@angular/material/form-field";
import { MatInputModule } from "@angular/material/input";
import { MatSelectModule } from "@angular/material/select";
import { MatOptionModule } from "@angular/material/core";
import { MatCheckboxModule } from "@angular/material/checkbox";
import { EntityTypeSelectComponent } from "../../../../core/entity/entity-type-select/entity-type-select.component";
export interface NotesDashboardSettingsConfig {
entityType?: string;
sinceDays?: number;
fromBeginningOfWeek?: boolean;
mode?: string;
}
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: "app-notes-dashboard-settings",
imports: [
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatOptionModule,
MatCheckboxModule,
FormsModule,
EntityTypeSelectComponent,
],
templateUrl: "./notes-dashboard-settings.component.html",
styleUrls: ["./notes-dashboard-settings.component.scss"],
})
export class NotesDashboardSettingsComponent {
formControl = input.required<FormControl<NotesDashboardSettingsConfig>>();
entityType = linkedSignal(() => this.formControl().value?.entityType);
sinceDays = linkedSignal(() => this.formControl().value?.sinceDays ?? 28);
fromBeginningOfWeek = linkedSignal(
() => this.formControl().value?.fromBeginningOfWeek ?? false,
);
mode = linkedSignal(
() => this.formControl().value?.mode ?? "with-recent-notes",
);
localConfig = computed<NotesDashboardSettingsConfig>(() => ({
entityType: this.entityType(),
sinceDays: this.sinceDays(),
fromBeginningOfWeek: this.fromBeginningOfWeek(),
mode: this.mode(),
}));
/** the widget cannot display anything without an entity type, so saving is blocked until one is selected */
private readonly requireEntityType: ValidatorFn = (control) =>
control.value?.entityType ? null : { entityTypeRequired: true };
constructor() {
effect(() => {
const control = this.formControl();
if (!control.hasValidator(this.requireEntityType)) {
control.addValidators(this.requireEntityType);
}
control.setValue(this.localConfig());
});
}
onEntityTypeChange(entityType: string) {
this.entityType.set(entityType);
this.formControl().markAsDirty();
}
onSinceDaysChange(sinceDays: number) {
this.sinceDays.set(sinceDays);
this.formControl().markAsDirty();
}
onFromBeginningOfWeekChange(fromBeginningOfWeek: boolean) {
this.fromBeginningOfWeek.set(fromBeginningOfWeek);
this.formControl().markAsDirty();
}
onModeChange(mode: string) {
this.mode.set(mode);
this.formControl().markAsDirty();
}
}
<div style="padding: 16px">
<mat-form-field appearance="fill" class="full-width">
<mat-label i18n>Record type with notes</mat-label>
<app-entity-type-select
[required]="true"
[ngModel]="entityType()"
(ngModelChange)="onEntityTypeChange($event)"
></app-entity-type-select>
</mat-form-field>
<mat-form-field appearance="fill" class="full-width">
<mat-label i18n>Days since last note</mat-label>
<input
matInput
type="number"
min="1"
[ngModel]="sinceDays()"
(ngModelChange)="onSinceDaysChange($event)"
/>
</mat-form-field>
<mat-checkbox
[ngModel]="fromBeginningOfWeek()"
(ngModelChange)="onFromBeginningOfWeekChange($event)"
i18n
>
From beginning of week
</mat-checkbox>
<mat-form-field appearance="fill" class="full-width">
<mat-label i18n>Mode</mat-label>
<mat-select [ngModel]="mode()" (ngModelChange)="onModeChange($event)">
<mat-option value="with-recent-notes" i18n>With recent notes</mat-option>
<mat-option value="without-recent-notes" i18n
>Without recent notes</mat-option
>
</mat-select>
</mat-form-field>
</div>
Legend
Html element with directive