Skip to content

Commit

Permalink
Bugfix/iot 1581 gateway deleted mismatch (#177)
Browse files Browse the repository at this point in the history
* Made error message service look at error message before just error.

* Added error messages if trying to delete organizations with gateways.

* added some margin to for error box.
  • Loading branch information
MadsApollo authored Sep 26, 2024
1 parent b651829 commit 5fb82e0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
>
</app-top-bar>
<div class="container-fluid">
<div *ngIf="errorMessages" class="error-messages p-3">
<ul class="mb-0">
<li *ngFor="let error of errorMessages">
{{ error | translate }}
</li>
</ul>
</div>
<div class="row">
<div class="col-12">
<div class="jumbotron">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { environment } from "@environments/environment";
import { Title } from "@angular/platform-browser";
import { MeService } from "@shared/services/me.service";
import { OrganizationAccessScope } from "@shared/enums/access-scopes";
import { ErrorMessageService } from "@shared/error-message.service";
import { HttpErrorResponse } from "@angular/common/http";

@Component({
selector: "app-organisation-detail",
Expand All @@ -34,6 +36,7 @@ export class OrganisationDetailComponent implements OnInit, OnChanges, OnDestroy
private applicationsSubscription: Subscription;
private deleteDialogSubscription: Subscription;
public dropdownButton: DropdownButton;
public errorMessages: string[];

organisation: OrganisationResponse;
public backButton: BackButton = {
Expand All @@ -53,7 +56,8 @@ export class OrganisationDetailComponent implements OnInit, OnChanges, OnDestroy
private deleteDialogService: DeleteDialogService,
private location: Location,
private titleService: Title,
private meService: MeService
private meService: MeService,
private errorMessageService: ErrorMessageService
) {}

ngOnChanges(changes: SimpleChanges): void {}
Expand Down Expand Up @@ -100,6 +104,10 @@ export class OrganisationDetailComponent implements OnInit, OnChanges, OnDestroy
this.deleteDialogSubscription = this.deleteDialogService.showSimpleDialog().subscribe(response => {
if (response) {
this.organisationService.delete(this.organisation.id).subscribe(response => {
if (response instanceof HttpErrorResponse) {
this.errorMessages = this.errorMessageService.handleErrorMessageWithFields(response).errorMessages;
return;
}
this.location.back();
});
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
<div class="mat-elevation-z8">
<div *ngIf="errorMessages" class="error-messages p-3">
<ul class="mb-0">
<li *ngFor="let error of errorMessages">
{{ error | translate }}
</li>
</ul>
</div>
<div class="mat-elevation-z8 mt-3">
<div class="loading-shade" *ngIf="isLoadingResults">
<mat-spinner *ngIf="isLoadingResults"></mat-spinner>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { MatPaginator, PageEvent } from "@angular/material/paginator";
import { environment } from "@environments/environment";
import { startWith, switchMap, map, catchError } from "rxjs/operators";
import { DefaultPageSizeOptions } from "@shared/constants/page.constants";
import { ErrorMessageService } from "@shared/error-message.service";
import { HttpErrorResponse } from "@angular/common/http";

@Component({
selector: "app-organisation-tabel",
Expand All @@ -30,8 +32,13 @@ export class OrganisationTabelComponent implements AfterViewInit {
pageSizeOptions = DefaultPageSizeOptions;

isLoadingResults = true;
public errorMessages: string[];

constructor(private organisationService: OrganisationService, private deleteDialogService: DeleteDialogService) {}
constructor(
private organisationService: OrganisationService,
private deleteDialogService: DeleteDialogService,
private errorMessageService: ErrorMessageService
) {}

ngAfterViewInit() {
// If the user changes the sort order, reset back to the first page.
Expand Down Expand Up @@ -72,6 +79,10 @@ export class OrganisationTabelComponent implements AfterViewInit {
this.deleteDialogService.showSimpleDialog().subscribe(response => {
if (response) {
this.organisationService.delete(element.id).subscribe(response => {
if (response instanceof HttpErrorResponse) {
this.errorMessages = this.errorMessageService.handleErrorMessageWithFields(response).errorMessages;
return;
}
if (response.ok) {
this.refresh();
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/shared/error-message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ export class ErrorMessageService {

public handleErrorMessageWithFields(error: HttpErrorResponse | Pick<HttpErrorResponse, "error">): ErrorMessage {
const errors: ErrorMessage = { errorFields: [], errorMessages: [] };
if (typeof error.error === "string") {
if (typeof error.error?.message === "string") {
errors.errorMessages.push(error.error.message);
} else if (typeof error.error === "string") {
errors.errorMessages.push(error.error);
} else if (typeof error.error?.error === "string" && !Array.isArray(error.error?.message)) {
errors.errorMessages.push(error.error.error);
} else if (typeof error.error?.message === "string") {
errors.errorMessages.push(error.error.message);
} else {
error.error.message.forEach(err => {
if (err.children?.length > 0) {
Expand Down
3 changes: 2 additions & 1 deletion src/assets/i18n/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,8 @@
"INVALID-VALUE-IN-KEY-VALUE-PAIR": "En eller flere værdier er ugyldige. Det skal være en gyldig tekstværdi",
"INVALID-DATE": "Datoen er ugyldig",
"USER-ALREADY-HAVE-MAIL": "Brugeren har allerede sat en email",
"EMAIL-ALREADY-IN-USE": "Den valgte email er allerede i brug. Kontakt din lokale administrator for hjælp."
"EMAIL-ALREADY-IN-USE": "Den valgte email er allerede i brug. Kontakt din lokale administrator for hjælp.",
"ORGANIZATION-GATEWAYS-EXISTS": "Denne organisation kan ikke slettes, fordi der er tilknyttet en eller flere gateways. Slet først disse eller flyt dem til en ny organisation."
},
"PROFILES": {
"NAME": "LoRaWAN profiler",
Expand Down

0 comments on commit 5fb82e0

Please sign in to comment.