diff --git a/src/app/admin/organisation/organisation-detail/organisation-detail.component.ts b/src/app/admin/organisation/organisation-detail/organisation-detail.component.ts index a2a2f0ee..38cce3fb 100644 --- a/src/app/admin/organisation/organisation-detail/organisation-detail.component.ts +++ b/src/app/admin/organisation/organisation-detail/organisation-detail.component.ts @@ -65,7 +65,8 @@ export class OrganisationDetailComponent implements OnInit, OnChanges, OnDestroy label: '', editRouterLink: 'edit-organisation', isErasable: true, - } + }; + this.translate.get(['NAV.ORGANISATIONS', 'ORGANISATION.DROPDOWN', 'TITLE.ORGANIZATION']) .subscribe(translations => { this.backButton.label = translations['NAV.ORGANISATIONS']; diff --git a/src/app/admin/organisation/organisation.service.ts b/src/app/admin/organisation/organisation.service.ts index 39902ef4..c480205e 100644 --- a/src/app/admin/organisation/organisation.service.ts +++ b/src/app/admin/organisation/organisation.service.ts @@ -15,7 +15,7 @@ import { UserMinimalService } from '../users/user-minimal.service'; }) export class OrganisationService { URL = 'organization'; - URLMINIMAL ='organization/minimal' + URLMINIMAL = 'organization/minimal'; constructor( private restService: RestService, @@ -38,7 +38,7 @@ export class OrganisationService { (response: OrganisationResponse) => { response.createdByName = this.userMinimalService.getUserNameFrom(response.createdBy); response.updatedByName = this.userMinimalService.getUserNameFrom(response.updatedBy); - return response + return response; } ) ); @@ -48,15 +48,15 @@ export class OrganisationService { return this.restService.get(this.URLMINIMAL, {}).pipe(shareReplay(1)); } - getMultiple( + getMultiple( limit: number = 1000, offset: number = 0, orderByColumn?: string, orderByDirection?: string, ): Observable { return this.restService.get(this.URL, { - limit: limit, - offset: offset, + limit, + offset, orderOn: orderByColumn, sort: orderByDirection, }); diff --git a/src/app/applications/application-detail/application-detail.component.ts b/src/app/applications/application-detail/application-detail.component.ts index f006843b..009f3a63 100644 --- a/src/app/applications/application-detail/application-detail.component.ts +++ b/src/app/applications/application-detail/application-detail.component.ts @@ -44,7 +44,8 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy { label: '', editRouterLink: '../../edit-application/' + this.id, isErasable: true, - } + }; + console.log(this.id); } @@ -58,7 +59,12 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy { } onDeleteApplication() { - this.deleteDialogSubscription = this.deleteDialogService.showSimpleDialog().subscribe( + let message: string; + if (this.applicationHasDevices()) { + message = this.translate.instant('APPLICATION.DELETE-HAS-DEVICES-PROMPT'); + } + + this.deleteDialogSubscription = this.deleteDialogService.showSimpleDialog(message).subscribe( (response) => { if (response) { this.applicationService.deleteApplication(this.application.id).subscribe((response) => { @@ -76,6 +82,10 @@ export class ApplicationDetailComponent implements OnInit, OnDestroy { ); } + applicationHasDevices(): boolean { + return this.application.iotDevices?.length > 0; + } + bindApplication(id: number): void { this.applicationsSubscription = this.applicationService.getApplication(id).subscribe((application) => { this.application = application; diff --git a/src/app/applications/application.service.ts b/src/app/applications/application.service.ts index c150e04f..4cfe2bdd 100644 --- a/src/app/applications/application.service.ts +++ b/src/app/applications/application.service.ts @@ -55,16 +55,16 @@ export class ApplicationService { permissionId?: number ): Observable { const body: GetApplicationParameters = { - limit: limit, - offset: offset, - sort: sort, - orderOn: orderOn, + limit, + offset, + sort, + orderOn, }; if (permissionId) { - body.permissionId = permissionId - return this.restService.get(`permission/${permissionId}/applications`, body) + body.permissionId = permissionId; + return this.restService.get(`permission/${permissionId}/applications`, body); } else if (organizationId) { - body.organizationId = organizationId + body.organizationId = organizationId; return this.restService.get('application', body); } return this.restService.get('application', body); @@ -72,7 +72,7 @@ export class ApplicationService { getApplicationsByOrganizationId(organizationId: number): Observable { const body = { - organizationId: organizationId + organizationId }; return this.restService.get('application', body); diff --git a/src/app/applications/applications-list/applications-table/applications-table.component.ts b/src/app/applications/applications-list/applications-table/applications-table.component.ts index 1dadcca6..4da38304 100644 --- a/src/app/applications/applications-list/applications-table/applications-table.component.ts +++ b/src/app/applications/applications-list/applications-table/applications-table.component.ts @@ -5,6 +5,7 @@ import { Router } from '@angular/router'; import { Application, ApplicationData } from '@applications/application.model'; import { ApplicationService } from '@applications/application.service'; import { environment } from '@environments/environment'; +import { TranslateService } from '@ngx-translate/core'; import { DeleteDialogService } from '@shared/components/delete-dialog/delete-dialog.service'; import { MeService } from '@shared/services/me.service'; import { merge, Observable, of as observableOf } from 'rxjs'; @@ -34,6 +35,7 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit { @ViewChild(MatSort) sort: MatSort; constructor( + public translate: TranslateService, private applicationService: ApplicationService, private router: Router, private meService: MeService, @@ -41,7 +43,7 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit { ) { } ngOnInit() { - this.canEdit = this.meService.canWriteInTargetOrganization() + this.canEdit = this.meService.canWriteInTargetOrganization(); } ngAfterViewInit() { @@ -85,7 +87,12 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit { } deleteApplication(id: number) { - this.deleteDialogService.showSimpleDialog().subscribe((response) => { + let message: string; + if (this.applicationHasDevices(id)) { + message = this.translate.instant('APPLICATION.DELETE-HAS-DEVICES-PROMPT'); + } + + this.deleteDialogService.showSimpleDialog(message).subscribe((response) => { if (response) { this.applicationService.deleteApplication(id).subscribe((response) => { if (response.ok && response.body.affected > 0) { @@ -102,6 +109,11 @@ export class ApplicationsTableComponent implements AfterViewInit, OnInit { }); } + applicationHasDevices(id: number): boolean { + const applicationToDelete = this.data?.find(app => app.id === id); + return applicationToDelete && applicationToDelete.iotDevices.length > 0; + } + navigateToEditPage(applicationId: string) { this.router.navigate(['applications', 'edit-application', applicationId]); } diff --git a/src/app/gateway/gateway-table/gateway-table.component.html b/src/app/gateway/gateway-table/gateway-table.component.html index 4f6086d0..9b50a0f9 100644 --- a/src/app/gateway/gateway-table/gateway-table.component.html +++ b/src/app/gateway/gateway-table/gateway-table.component.html @@ -24,7 +24,7 @@ - + {{ 'LORA-GATEWAY-TABLE.ORGANIZATION' | translate }} diff --git a/src/app/gateway/gateway-table/gateway-table.component.ts b/src/app/gateway/gateway-table/gateway-table.component.ts index fbe3b882..20211329 100644 --- a/src/app/gateway/gateway-table/gateway-table.component.ts +++ b/src/app/gateway/gateway-table/gateway-table.component.ts @@ -57,7 +57,7 @@ export class GatewayTableComponent implements AfterViewInit { ) { this.translate.use('da'); moment.locale('da'); - } +} ngAfterViewInit() { this.organisationChangeSubject.subscribe((x) => { diff --git a/src/app/shared/services/chirpstack-gateway.service.ts b/src/app/shared/services/chirpstack-gateway.service.ts index e06c46d7..fd7a13ae 100644 --- a/src/app/shared/services/chirpstack-gateway.service.ts +++ b/src/app/shared/services/chirpstack-gateway.service.ts @@ -28,7 +28,7 @@ export class ChirpstackGatewayService { (response: GatewayResponse) => { response.gateway.internalOrganizationName = this.sharedVariableService.getOrganizationInfo() .find(org => org.id === response.gateway.internalOrganizationId)?.name; - //move createdat and updatedat to next level ease the use. + // Move createdat and updatedat to next level ease the use. response.gateway.updatedAt = response.updatedAt; response.gateway.createdAt = response.createdAt; response.gateway.lastSeenAt = response.lastSeenAt; diff --git a/src/assets/i18n/da.json b/src/assets/i18n/da.json index 5c26a491..96c8b754 100644 --- a/src/assets/i18n/da.json +++ b/src/assets/i18n/da.json @@ -80,6 +80,7 @@ "CREATE": "Opret applikation", "SAVE": "Gem applikation", "DELETE": "Slet applikation", + "DELETE-HAS-DEVICES-PROMPT": "Der er knyttet IoT-enheder til denne applikation. Disse vil også blive slettet. Slet alligevel?", "NAME": "Applikationens navn", "DESCRIPTION": "Applikationens beskrivelse", "ATTACHED-IOT": "Tilknyttede IoT enheder",