UI: Change entity version conflict error handling
This commit is contained in:
parent
858bdfeea5
commit
49da787fc4
@ -75,7 +75,7 @@ export class EntityConflictInterceptor implements HttpInterceptor {
|
|||||||
return next.handle(this.updateRequestVersion(request));
|
return next.handle(this.updateRequestVersion(request));
|
||||||
}
|
}
|
||||||
(request.params as HttpParams & { interceptorConfig: InterceptorConfig }).interceptorConfig.ignoreErrors = true;
|
(request.params as HttpParams & { interceptorConfig: InterceptorConfig }).interceptorConfig.ignoreErrors = true;
|
||||||
return throwError(() => new Error(error.error.message));
|
return throwError(() => error);
|
||||||
}
|
}
|
||||||
return of(null);
|
return of(null);
|
||||||
})
|
})
|
||||||
|
|||||||
@ -86,7 +86,7 @@ import { Authority } from '@shared/models/authority.enum';
|
|||||||
import { DialogService } from '@core/services/dialog.service';
|
import { DialogService } from '@core/services/dialog.service';
|
||||||
import { EntityService } from '@core/http/entity.service';
|
import { EntityService } from '@core/http/entity.service';
|
||||||
import { AliasController } from '@core/api/alias-controller';
|
import { AliasController } from '@core/api/alias-controller';
|
||||||
import { BehaviorSubject, Observable, of, Subject, Subscription } from 'rxjs';
|
import { BehaviorSubject, Observable, of, Subject, Subscription, throwError } from 'rxjs';
|
||||||
import { DashboardUtilsService } from '@core/services/dashboard-utils.service';
|
import { DashboardUtilsService } from '@core/services/dashboard-utils.service';
|
||||||
import { DashboardService } from '@core/http/dashboard.service';
|
import { DashboardService } from '@core/http/dashboard.service';
|
||||||
import {
|
import {
|
||||||
@ -156,6 +156,7 @@ import {
|
|||||||
MoveWidgetsDialogComponent,
|
MoveWidgetsDialogComponent,
|
||||||
MoveWidgetsDialogResult
|
MoveWidgetsDialogResult
|
||||||
} from '@home/components/dashboard-page/layout/move-widgets-dialog.component';
|
} from '@home/components/dashboard-page/layout/move-widgets-dialog.component';
|
||||||
|
import { HttpStatusCode } from '@angular/common/http';
|
||||||
|
|
||||||
// @dynamic
|
// @dynamic
|
||||||
@Component({
|
@Component({
|
||||||
@ -1203,15 +1204,31 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
|
|||||||
data: widget
|
data: widget
|
||||||
};
|
};
|
||||||
this.window.parent.postMessage(JSON.stringify(message), '*');
|
this.window.parent.postMessage(JSON.stringify(message), '*');
|
||||||
} else {
|
|
||||||
this.dashboardService.saveDashboard(this.dashboard).pipe(
|
|
||||||
catchError(() => {
|
|
||||||
this.setEditMode(false, true);
|
|
||||||
return of(null);
|
|
||||||
})
|
|
||||||
).subscribe(() => {
|
|
||||||
this.dashboard.version = this.dashboard.version + 1;
|
|
||||||
this.setEditMode(false, false);
|
this.setEditMode(false, false);
|
||||||
|
} else {
|
||||||
|
let reInitDashboard = false;
|
||||||
|
this.dashboardService.saveDashboard(this.dashboard).pipe(
|
||||||
|
catchError((err) => {
|
||||||
|
if (err.status === HttpStatusCode.Conflict) {
|
||||||
|
reInitDashboard = true;
|
||||||
|
return this.dashboardService.getDashboard(this.dashboard.id.id).pipe(
|
||||||
|
map(dashboard => this.dashboardUtils.validateAndUpdateDashboard(dashboard))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return throwError(() => err);
|
||||||
|
})
|
||||||
|
).subscribe((dashboard) => {
|
||||||
|
this.setEditMode(false, false);
|
||||||
|
this.dashboard = dashboard;
|
||||||
|
if (reInitDashboard) {
|
||||||
|
const dashboardPageInitData: DashboardPageInitData = {
|
||||||
|
dashboard,
|
||||||
|
currentDashboardId: dashboard.id ? dashboard.id.id : null,
|
||||||
|
widgetEditMode: false,
|
||||||
|
singlePageMode: false
|
||||||
|
};
|
||||||
|
this.init(dashboardPageInitData);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,11 +40,12 @@ import { UntypedFormGroup } from '@angular/forms';
|
|||||||
import { EntityComponent } from './entity.component';
|
import { EntityComponent } from './entity.component';
|
||||||
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
|
import { TbAnchorComponent } from '@shared/components/tb-anchor.component';
|
||||||
import { EntityAction } from '@home/models/entity/entity-component.models';
|
import { EntityAction } from '@home/models/entity/entity-component.models';
|
||||||
import { Observable, of, ReplaySubject, Subscription } from 'rxjs';
|
import { Observable, ReplaySubject, Subscription, throwError } from 'rxjs';
|
||||||
import { MatTab, MatTabGroup } from '@angular/material/tabs';
|
import { MatTab, MatTabGroup } from '@angular/material/tabs';
|
||||||
import { EntityTabsComponent } from '@home/components/entity/entity-tabs.component';
|
import { EntityTabsComponent } from '@home/components/entity/entity-tabs.component';
|
||||||
import { deepClone, mergeDeep } from '@core/utils';
|
import { deepClone, mergeDeep } from '@core/utils';
|
||||||
import { catchError } from 'rxjs/operators';
|
import { catchError } from 'rxjs/operators';
|
||||||
|
import { HttpStatusCode } from '@angular/common/http';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-entity-details-panel',
|
selector: 'tb-entity-details-panel',
|
||||||
@ -290,7 +291,12 @@ export class EntityDetailsPanelComponent extends PageComponent implements AfterV
|
|||||||
}
|
}
|
||||||
this.entitiesTableConfig.saveEntity(editingEntity, this.editingEntity)
|
this.entitiesTableConfig.saveEntity(editingEntity, this.editingEntity)
|
||||||
.pipe(
|
.pipe(
|
||||||
catchError(() => of(this.entity))
|
catchError((err) => {
|
||||||
|
if (err.status === HttpStatusCode.Conflict) {
|
||||||
|
return this.entitiesTableConfig.loadEntity(this.currentEntityId);
|
||||||
|
}
|
||||||
|
return throwError(() => err);
|
||||||
|
})
|
||||||
)
|
)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(entity) => {
|
(entity) => {
|
||||||
|
|||||||
@ -113,7 +113,7 @@ export class WidgetComponentService {
|
|||||||
hasBasicMode: this.utils.editWidgetInfo.hasBasicMode,
|
hasBasicMode: this.utils.editWidgetInfo.hasBasicMode,
|
||||||
basicModeDirective: this.utils.editWidgetInfo.basicModeDirective,
|
basicModeDirective: this.utils.editWidgetInfo.basicModeDirective,
|
||||||
defaultConfig: this.utils.editWidgetInfo.defaultConfig
|
defaultConfig: this.utils.editWidgetInfo.defaultConfig
|
||||||
}, new WidgetTypeId('1'), new TenantId( NULL_UUID ), undefined, null
|
}, new WidgetTypeId('1'), new TenantId( NULL_UUID ), undefined, undefined
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const initSubject = new ReplaySubject<void>();
|
const initSubject = new ReplaySubject<void>();
|
||||||
|
|||||||
@ -59,12 +59,13 @@ import {
|
|||||||
SaveWidgetTypeAsDialogComponent,
|
SaveWidgetTypeAsDialogComponent,
|
||||||
SaveWidgetTypeAsDialogResult
|
SaveWidgetTypeAsDialogResult
|
||||||
} from '@home/pages/widget/save-widget-type-as-dialog.component';
|
} from '@home/pages/widget/save-widget-type-as-dialog.component';
|
||||||
import { forkJoin, mergeMap, of, Subscription } from 'rxjs';
|
import { forkJoin, mergeMap, of, Subscription, throwError } from 'rxjs';
|
||||||
import { ResizeObserver } from '@juggle/resize-observer';
|
import { ResizeObserver } from '@juggle/resize-observer';
|
||||||
import { widgetEditorCompleter } from '@home/pages/widget/widget-editor.models';
|
import { widgetEditorCompleter } from '@home/pages/widget/widget-editor.models';
|
||||||
import { Observable } from 'rxjs/internal/Observable';
|
import { Observable } from 'rxjs/internal/Observable';
|
||||||
import { catchError, map, tap } from 'rxjs/operators';
|
import { catchError, map, tap } from 'rxjs/operators';
|
||||||
import { beautifyCss, beautifyHtml, beautifyJs } from '@shared/models/beautify.models';
|
import { beautifyCss, beautifyHtml, beautifyJs } from '@shared/models/beautify.models';
|
||||||
|
import { HttpStatusCode } from '@angular/common/http';
|
||||||
import Timeout = NodeJS.Timeout;
|
import Timeout = NodeJS.Timeout;
|
||||||
|
|
||||||
// @dynamic
|
// @dynamic
|
||||||
@ -583,9 +584,11 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
|
|||||||
}
|
}
|
||||||
return of(widgetTypeDetails);
|
return of(widgetTypeDetails);
|
||||||
}),
|
}),
|
||||||
catchError(() => {
|
catchError((err) => {
|
||||||
this.undoWidget();
|
if (id && err.status === HttpStatusCode.Conflict) {
|
||||||
return of(null);
|
return this.widgetService.getWidgetTypeById(id.id);
|
||||||
|
}
|
||||||
|
return throwError(() => err);
|
||||||
}),
|
}),
|
||||||
).subscribe({
|
).subscribe({
|
||||||
next: (widgetTypeDetails) => {
|
next: (widgetTypeDetails) => {
|
||||||
@ -619,7 +622,7 @@ export class WidgetEditorComponent extends PageComponent implements OnInit, OnDe
|
|||||||
config.title = this.widget.widgetName;
|
config.title = this.widget.widgetName;
|
||||||
this.widget.defaultConfig = JSON.stringify(config);
|
this.widget.defaultConfig = JSON.stringify(config);
|
||||||
this.isDirty = false;
|
this.isDirty = false;
|
||||||
this.widgetService.saveWidgetTypeDetails(this.widget, undefined, undefined, null).pipe(
|
this.widgetService.saveWidgetTypeDetails(this.widget, undefined, undefined, undefined).pipe(
|
||||||
mergeMap((widget) => {
|
mergeMap((widget) => {
|
||||||
if (saveWidgetAsData.widgetBundleId) {
|
if (saveWidgetAsData.widgetBundleId) {
|
||||||
return this.widgetService.addWidgetFqnToWidgetBundle(saveWidgetAsData.widgetBundleId, widget.fqn).pipe(
|
return this.widgetService.addWidgetFqnToWidgetBundle(saveWidgetAsData.widgetBundleId, widget.fqn).pipe(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user