10 changed files with 273 additions and 3 deletions
@ -0,0 +1,53 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2024 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<mat-toolbar color="primary"> |
|||
<h2 class="main-label">{{ 'entity.version-conflict.label' | translate }}</h2> |
|||
<span fxFlex></span> |
|||
<button mat-icon-button |
|||
(click)="onCancel()" |
|||
type="button"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
</mat-toolbar> |
|||
<div mat-dialog-content> |
|||
<div class="message-container"> |
|||
<span>{{ data.message }}.</span> |
|||
<span *ngIf="ExportableEntityTypes.includes(data.entityId.entityType)"> |
|||
{{ 'entity.version-conflict.link' | translate: |
|||
{ entityType: (entityTypeTranslations.get(data.entityId.entityType).type | translate) } |
|||
}} |
|||
<a class="cursor-pointer" (click)="onLinkClick($event)">{{ 'entity.link' | translate }}</a>. |
|||
</span> |
|||
<span>{{ 'entity.version-conflict.message' | translate }}</span> |
|||
</div> |
|||
</div> |
|||
<div mat-dialog-actions fxLayout="row" fxLayoutAlign="end center"> |
|||
<button mat-button color="primary" |
|||
type="button" |
|||
(click)="onCancel()" |
|||
cdkFocusInitial |
|||
> |
|||
{{ 'entity.version-conflict.cancel' | translate }} |
|||
</button> |
|||
<button mat-raised-button color="primary" |
|||
type="submit" |
|||
(click)="onConfirm()" |
|||
> |
|||
{{ 'entity.version-conflict.overwrite' | translate }} |
|||
</button> |
|||
</div> |
|||
@ -0,0 +1,26 @@ |
|||
/** |
|||
* Copyright © 2016-2024 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0 |
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
$conflict-dialog-width: 700px; |
|||
|
|||
:host { |
|||
.main-label { |
|||
padding-left: 8px; |
|||
} |
|||
|
|||
.message-container { |
|||
max-width: #{$conflict-dialog-width}; |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { Component, Inject } from '@angular/core'; |
|||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
|||
import { SharedModule } from '@shared/shared.module'; |
|||
import { ImportExportService } from '@shared/import-export/import-export.service'; |
|||
import { ExportableEntityTypes } from '@shared/import-export/import-export.models'; |
|||
import { EntityId } from '@shared/models/id/entity-id'; |
|||
import { CommonModule } from '@angular/common'; |
|||
import { EntityType, entityTypeTranslations } from '@shared/models/entity-type.models'; |
|||
|
|||
interface EntityConflictDialogData { |
|||
message: string; |
|||
entityId: EntityId & {entityType: EntityType}; |
|||
} |
|||
|
|||
@Component({ |
|||
selector: 'tb-entity-conflict-dialog', |
|||
templateUrl: 'entity-conflict-dialog.component.html', |
|||
styleUrls: ['./entity-conflict-dialog.component.scss'], |
|||
standalone: true, |
|||
imports: [ |
|||
CommonModule, |
|||
SharedModule, |
|||
], |
|||
}) |
|||
export class EntityConflictDialogComponent { |
|||
readonly ExportableEntityTypes = ExportableEntityTypes; |
|||
readonly entityTypeTranslations = entityTypeTranslations; |
|||
|
|||
constructor( |
|||
@Inject(MAT_DIALOG_DATA) public data: EntityConflictDialogData, |
|||
private dialogRef: MatDialogRef<EntityConflictDialogComponent>, |
|||
private importExportService: ImportExportService, |
|||
) {} |
|||
|
|||
onCancel(): void { |
|||
this.dialogRef.close(false); |
|||
} |
|||
|
|||
onConfirm(): void { |
|||
this.dialogRef.close(true); |
|||
} |
|||
|
|||
onLinkClick(event: MouseEvent): void { |
|||
event.preventDefault(); |
|||
this.importExportService.exportEntity(this.data.entityId); |
|||
} |
|||
} |
|||
@ -0,0 +1,63 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { Injectable } from '@angular/core'; |
|||
import { |
|||
HttpEvent, |
|||
HttpHandler, |
|||
HttpInterceptor, |
|||
HttpRequest, |
|||
HttpErrorResponse, |
|||
HttpStatusCode |
|||
} from '@angular/common/http'; |
|||
import { Observable, throwError, of } from 'rxjs'; |
|||
import { catchError, switchMap } from 'rxjs/operators'; |
|||
import { MatDialog } from '@angular/material/dialog'; |
|||
import { EntityConflictDialogComponent } from '@shared/components/dialog/entity-conflict-dialog/entity-conflict-dialog.component'; |
|||
import { EntityId } from '@shared/models/id/entity-id'; |
|||
|
|||
interface ConflictedEntity { version: number; id: EntityId } |
|||
|
|||
@Injectable() |
|||
export class EntityConflictInterceptor implements HttpInterceptor { |
|||
constructor(private dialog: MatDialog) {} |
|||
|
|||
intercept(request: HttpRequest<unknown & ConflictedEntity>, next: HttpHandler): Observable<HttpEvent<unknown>> { |
|||
return next.handle(request).pipe( |
|||
catchError((error: HttpErrorResponse) => { |
|||
if (error.status === HttpStatusCode.Conflict) { |
|||
return this.resolveConflictRequest(request, error.error.message) |
|||
.pipe(switchMap(httpRequest => next.handle(httpRequest))); |
|||
} else { |
|||
return throwError(() => error); |
|||
} |
|||
}) |
|||
); |
|||
} |
|||
|
|||
private resolveConflictRequest(request: HttpRequest<unknown & ConflictedEntity>, message: string): Observable<HttpRequest<unknown>> { |
|||
const dialogRef = this.dialog.open(EntityConflictDialogComponent, {data: {message, entityId: request.body.id}}); |
|||
|
|||
return dialogRef.afterClosed().pipe( |
|||
switchMap(result => { |
|||
if (result) { |
|||
request.body.version = null; |
|||
} |
|||
return of(request); |
|||
}) |
|||
); |
|||
} |
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
///
|
|||
/// Copyright © 2016-2024 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
export * from './entity-conflict.interceptor'; |
|||
Loading…
Reference in new issue