Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
klingebiel committed Feb 9, 2022
1 parent 4f4aa36 commit 23135f1
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 16 deletions.
5 changes: 3 additions & 2 deletions apps/client/src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"Unknown": "Unbekannter Fehler",
"ValueMissing": "Fehlender Wert.",
"NoAdmissionCriteria": "Für diesen Kurs sind keine Zulassungskriterien festgelegt.",
"Conflict": "Konflikt"
"Conflict": "Konflikt",
"ParticipantAlreadyHasAssessment": "Einer der ausgewählten Teilnehmer hat bereits eine Bewertung für diese Aufgabe erhalten."
},
"Event": {
"UserJoinedCourseEvent": "ist dem Kurs beigreten.",
Expand Down Expand Up @@ -295,7 +296,7 @@
"Assignment": {
"BonusPoints": "Bonuspunkte",
"Collaboration": "Zusammenarbeit",
"Comment": "Beschreibung",
"Comment": "Kommentar",
"EndDate": "Enddatum",
"Name": "Name",
"Points": "Punktzahl",
Expand Down
3 changes: 2 additions & 1 deletion apps/client/src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@
"Unknown": "Unknown error",
"ValueMissing": "Value is missing.",
"NoAdmissionCriteria": "This course did not define any admission criteria.",
"Conflict": "Conflict"
"Conflict": "Conflict",
"ParticipantAlreadyHasAssessment": "One of the selected participants has already received an assessment."
},
"Event": {
"UserJoinedCourseEvent": "joined the course.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,19 @@
</div>
</div>

<button mat-flat-button color="accent" class="w-fit" [disabled]="form.invalid">
{{ "Action.Create" | translate }} (not implemented)
<button
mat-flat-button
color="accent"
class="w-fit"
[disabled]="form.invalid"
(click)="onCreate(tabGroup.selectedIndex === 0 ? 'groups' : 'students')"
>
{{ "Action.Create" | translate }}
</button>

<mat-tab-group
color="accent"
#tabGroup
animationDuration="0"
(selectedIndexChange)="selectedTabChanged($event)"
>
Expand Down Expand Up @@ -60,13 +67,13 @@
</div>
</div>
<input
class="col-span-1 my-auto h-fit w-24 rounded bg-color-bg p-1"
class="col-span-1 my-auto h-fit w-24 rounded border border-neutral-300 bg-color-bg p-1"
type="number"
formControlName="achievedPoints"
/>
<div class="col-span-4 py-2 pr-2">
<textarea
class="h-full w-full rounded bg-color-bg p-1"
class="h-full w-full rounded border border-neutral-300 bg-color-bg p-1"
formControlName="comment"
></textarea>
</div>
Expand All @@ -79,7 +86,7 @@
<div class="font-bold">
{{ control.get("entity")?.value.name }}
</div>
<div class="grid py-1">
<div class="grid">
<span
class="text-light text-xs"
*ngFor="let member of control.get('entity')?.value.members"
Expand All @@ -103,3 +110,19 @@
></mat-progress-spinner>
</div>
</ng-template>

<ng-template #confirmDialogContent let-data>
<mat-card-title mat-dialog-title>{{ "Action.Confirm" | translate }}</mat-card-title>
<div mat-dialog-content>
<div class="pb-4">
Es werden <span class="font-bold">{{ data.length }}</span> Bewertungen erstellt.
Fortfahren ?
</div>
</div>
<div class="flex gap-2" mat-dialog-actions>
<button mat-flat-button color="accent" [mat-dialog-close]="true">
{{ "Action.Confirm" | translate }}
</button>
<button mat-button [mat-dialog-close]="false">{{ "Action.Cancel" | translate }}</button>
</div>
</ng-template>
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ChangeDetectionStrategy, Component, OnInit } from "@angular/core";
import { FormBuilder, Validators } from "@angular/forms";
import { ActivatedRoute } from "@angular/router";
import { HttpClient, HttpErrorResponse } from "@angular/common/http";
import { ChangeDetectionStrategy, Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
import { FormBuilder } from "@angular/forms";
import { MatDialog } from "@angular/material/dialog";
import { ActivatedRoute, Router } from "@angular/router";
import { Store } from "@ngrx/store";
import { AuthService } from "@student-mgmt-client/auth";
import { ToastService } from "@student-mgmt-client/services";
import { AssignmentSelectors } from "@student-mgmt-client/state";
import {
AssessmentCreateDto,
AssignmentRegistrationApi,
CourseParticipantsApi,
GroupDto,
Expand All @@ -25,12 +30,18 @@ export class CreateMultipleAssessmentsComponent implements OnInit {

form = this.fb.array([]);

@ViewChild("confirmDialogContent") confirmTemplate!: TemplateRef<unknown>;

constructor(
private registrations: AssignmentRegistrationApi,
private participants: CourseParticipantsApi,
private fb: FormBuilder,
private readonly route: ActivatedRoute,
private readonly store: Store
private readonly router: Router,
private readonly toast: ToastService,
private readonly store: Store,
private readonly http: HttpClient,
private readonly dialog: MatDialog
) {}

async ngOnInit(): Promise<void> {
Expand All @@ -56,8 +67,6 @@ export class CreateMultipleAssessmentsComponent implements OnInit {

this.fillFormArray(entities);

console.log(this.form);

this.isLoading$.next(false);
}

Expand Down Expand Up @@ -85,7 +94,60 @@ export class CreateMultipleAssessmentsComponent implements OnInit {
}
}

async onCreate(): Promise<void> {
// TODO
async onCreate(tab: "groups" | "students"): Promise<void> {
const formValue = this.form.value as {
entity: { id: string } & { userId: string };
achievedPoints?: number;
comment?: string;
}[];

const assessmentWithPoints = formValue.filter(
value => typeof value.achievedPoints === "number"
);

const assessments: AssessmentCreateDto[] = assessmentWithPoints.map(value => ({
assignmentId: this.assignmentId,
isDraft: false,
achievedPoints: value.achievedPoints,
comment: value.comment?.length && value.comment.length > 0 ? value.comment : undefined,
groupId: tab === "groups" ? value.entity.id : undefined,
userId: tab === "students" ? value.entity.userId : undefined
}));

const confirmed = await firstValueFrom(
this.dialog.open(this.confirmTemplate, { data: assessments }).afterClosed()
);

if (confirmed) {
try {
await firstValueFrom(
this.http.post(
`http://localhost:3000/courses/${this.courseId}/assignments/${this.assignmentId}/assessments/bulk`,
assessments,
{
headers: {
Authorization: `Bearer ${AuthService.getAccessToken()}`
}
}
)
);
this.toast.success();
this.router.navigate([
"/courses",
this.courseId,
"assignments",
this.assignmentId,
"assessments"
]);
} catch (error) {
if (error instanceof HttpErrorResponse) {
if (error.status === 409) {
this.toast.error("Error.ParticipantAlreadyHasAssessment");
} else {
this.toast.apiError(error);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CommonModule } from "@angular/common";
import { NgModule } from "@angular/core";
import { ReactiveFormsModule } from "@angular/forms";
import { MatButtonModule } from "@angular/material/button";
import { MatCardModule } from "@angular/material/card";
import { MatDialogModule } from "@angular/material/dialog";
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
import { MatTabsModule } from "@angular/material/tabs";
import { TranslateModule } from "@ngx-translate/core";
Expand All @@ -14,6 +16,8 @@ import { CreateMultipleAssessmentsComponent } from "./create-multiple-assessment
CommonModule,
CreateMultipleAssessmentRoutingModule,
ReactiveFormsModule,
MatDialogModule,
MatCardModule,
MatButtonModule,
MatTabsModule,
TranslateModule,
Expand Down

0 comments on commit 23135f1

Please sign in to comment.