Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/wip 1139 title progress #1313

Merged
merged 15 commits into from
Sep 26, 2022
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
<div mat-dialog-title style="display: flex">
<h1 i18n="Edit the progress of one or multiple tasks">Edit Progress</h1>
<h1>
<input
[formControl]="title"
matInput
type="text"
i18n-placeholder="Title Progress|Edit the progress of one or multiple tasks"
placeholder="Title"
/>
</h1>
</div>

<mat-dialog-content class="dialog-content">
<div *ngFor="let control of forms.controls; let index=index" class="entry-wrapper mat-elevation-z1" [formGroup]="$any(control)">
<div *ngFor="let control of parts.controls; let index=index" class="entry-wrapper mat-elevation-z1" [formGroup]="$any(control)">
<mat-form-field class="header-field">
<input
formControlName="label"
Expand Down Expand Up @@ -92,8 +100,8 @@ <h1 i18n="Edit the progress of one or multiple tasks">Edit Progress</h1>
<mat-dialog-actions>
<button
mat-stroked-button
[mat-dialog-close]="forms.value"
[disabled]="!forms.valid"
[mat-dialog-close]="outputData.value"
[disabled]="!parts.valid"
>
<span [matTooltip]="tooltipOnSave" i18n>Save</span>
TheSlimvReal marked this conversation as resolved.
Show resolved Hide resolved
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Component, Inject } from "@angular/core";
import { MAT_DIALOG_DATA } from "@angular/material/dialog";
import { ProgressDashboardPart } from "../progress-dashboard/progress-dashboard-config";
import {
ProgressDashboardPart,
ProgressDashboardConfig,
} from "../progress-dashboard/progress-dashboard-config";
import {
FormArray,
FormBuilder,
Expand All @@ -13,24 +16,27 @@ import {
} from "@angular/forms";
import { ErrorStateMatcher } from "@angular/material/core";

export interface EditProgressDashboardComponentData {
parts: ProgressDashboardPart[];
}

@Component({
selector: "app-edit-progress-dashboard",
templateUrl: "./edit-progress-dashboard.component.html",
styleUrls: ["./edit-progress-dashboard.component.scss"],
})
export class EditProgressDashboardComponent {
forms: FormArray;
outputData: FormGroup;
title: FormControl;
parts: FormArray;
currentErrorStateMatcher = new FormCurrentErrorStateMatcher();

constructor(
@Inject(MAT_DIALOG_DATA) public data: EditProgressDashboardComponentData,
@Inject(MAT_DIALOG_DATA) public data: ProgressDashboardConfig,
private fb: FormBuilder
) {
this.forms = fb.array(data.parts.map((part) => this.formGroup(part)));
this.title = new FormControl(data.title);
this.parts = fb.array(data.parts.map((part) => this.formGroup(part)));
this.outputData = new FormGroup({
title: this.title,
parts: this.parts,
});
}

formGroup(part: ProgressDashboardPart): FormGroup {
Expand Down Expand Up @@ -70,17 +76,17 @@ export class EditProgressDashboardComponent {
currentValue: 1,
targetValue: 10,
};
this.forms.push(this.formGroup(newPart));
this.parts.push(this.formGroup(newPart));
}

get tooltipOnSave(): string {
TheSlimvReal marked this conversation as resolved.
Show resolved Hide resolved
return this.forms.valid
return this.parts.valid
? ""
: $localize`:Shown when there are errors that prevent saving:Fix the errors to save the form`;
}

removePart(index: number) {
this.forms.removeAt(index);
this.parts.removeAt(index);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class ProgressDashboardComponent
.afterClosed()
.subscribe(async (next) => {
if (next) {
this.data.parts = next;
Object.assign(this.data, next);
await this.save();
}
});
Expand Down