Skip to content

Commit

Permalink
Merge pull request #284 from computas/SP24-data-validation-stats
Browse files Browse the repository at this point in the history
Sp24 data validation stats
  • Loading branch information
Ivan-Computas authored Oct 15, 2024
2 parents 3d170a2 + 9b12705 commit 3b46c2c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
12 changes: 6 additions & 6 deletions src/app/admin/statistics/statistics.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
<app-select-year-component (valueSelected)="onYearSelected($event)"></app-select-year-component>
}


<!-- Confirm Button -->
<button mat-button class="confirm-btn" (click)="confirmSelection()">Hent statistikk</button>

</div>
<div> @if (errorMessage) {
<br>
<p>{{errorMessage}}</p>
}</div>

<!-- Confirm Button -->
</div>

<!-- Display Fetched Data -->
@if (dataFetched()) {
Expand All @@ -39,8 +42,5 @@ <h2>Statistikk for {{ selectedYear }}</h2>

</div>
}

<!-- Close Button -->
<!-- <button mat-button mat-dialog-close class="close-btn" (click)="closeStatistics()">Lukk</button> -->
</div>
</div>
57 changes: 34 additions & 23 deletions src/app/admin/statistics/statistics.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,48 @@ export class StatisticsComponent implements OnDestroy {
year= "";
selected = "month";
selectedYear = "";
errorMessage = "";

constructor(
public dialogRef: MatDialogRef<StatisticsComponent>,
private loginService: LoginService,
@Inject(MAT_DIALOG_DATA) public data: string) { }


confirmSelection() {
if (this.selected === "month") {
this.loginService.getStatisticsPerMonth(this.month, this.year).subscribe({
next: (res) => {
this.dataFetched.set(true);
this.scoreCount = res;
confirmSelection() {
this.errorMessage = ""; // Reset error message

},
error: (err) => {
console.error('Failed to fetch statistics', err);
}
});
} else {
this.loginService.getStatisticsPerYear(this.selectedYear).subscribe({
next: (res) => {
this.dataFetched.set(true);
this.scoreCount = res;

},
error: (err) => {
console.error('Failed to fetch statistics', err);
if (this.selected === "month" && this.month !== "") {
this.loginService.getStatisticsPerMonth(this.month, this.year).subscribe({
next: (res) => {
this.dataFetched.set(true);
this.scoreCount = res;
this.month = "";
this.year = "";
},
error: (err) => {
console.error('Failed to fetch statistics', err);
}
});

} else if (this.selected === "year" && this.selectedYear !== "") {
this.loginService.getStatisticsPerYear(this.selectedYear).subscribe({
next: (res) => {
this.dataFetched.set(true);
this.scoreCount = res;
},
error: (err) => {
console.error('Failed to fetch statistics', err);
}
});
} else {
if (this.selected === "month") {
this.errorMessage = "Vennligst velg en dato";
} else if (this.selected === "year") {
this.errorMessage = "Vennligst velg et år";
}
});
}
}
}

closeDialog(): void {
this.dialogRef.close();
Expand All @@ -73,6 +83,7 @@ export class StatisticsComponent implements OnDestroy {
onToggleChanged(value: string) {
this.selected = value;
this.dataFetched.set(false);
this.errorMessage = "";
}

onYearSelected(year: string) {
Expand All @@ -84,7 +95,7 @@ export class StatisticsComponent implements OnDestroy {
this.month = date[0];
this.display_month = date[1]
this.year = date[2];
}
}

ngOnDestroy(): void {
this.dialogRef.close();
Expand Down

0 comments on commit 3b46c2c

Please sign in to comment.