Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Wait for grid to be updated before initializing widget

Oliver Günther8ff124157968
diff --git a/frontend/src/app/shared/components/grids/grid/add-widget.service.ts b/frontend/src/app/shared/components/grids/grid/add-widget.service.ts
index 47ef4fb24b8..20b9534f459 100644
--- a/frontend/src/app/shared/components/grids/grid/add-widget.service.ts
+++ b/frontend/src/app/shared/components/grids/grid/add-widget.service.ts
@@ -11,6 +11,7 @@ import { GridResizeService } from 'core-app/shared/components/grids/grid/resize.
import { GridMoveService } from 'core-app/shared/components/grids/grid/move.service';
import { GridGap } from 'core-app/shared/components/grids/areas/grid-gap';
import { I18nService } from 'core-app/core/i18n/i18n.service';
+import { GridResource } from 'core-app/features/hal/resources/grid-resource';
@Injectable()
export class GridAddWidgetService {
@@ -38,7 +39,7 @@ export class GridAddWidgetService {
public widget(area:GridArea):Promise<GridWidgetResource|null> {
return this
.select(area)
- .then((widgetResource) => {
+ .then(async (widgetResource) => {
if (this.layout.isGap(area)) {
this.addLine(area as GridGap);
}
@@ -47,7 +48,7 @@ export class GridAddWidgetService {
this.setMaxWidth(newArea);
- this.persist(newArea);
+ await this.persist(newArea);
return widgetResource;
})
.catch(() => null);
@@ -114,11 +115,12 @@ export class GridAddWidgetService {
});
}
- private persist(area:GridWidgetArea) {
+ private async persist(area:GridWidgetArea):Promise<GridResource> {
area.writeAreaChangeToWidget();
this.layout.widgetAreas.push(area);
this.layout.widgetResources.push(area.widget);
- this.layout.rebuildAndPersist();
+
+ return this.layout.rebuildAndPersist();
}
public get isAllowed() {
diff --git a/frontend/src/app/shared/components/grids/grid/area.service.ts b/frontend/src/app/shared/components/grids/grid/area.service.ts
index 983938489e6..b29d79a95ee 100644
--- a/frontend/src/app/shared/components/grids/grid/area.service.ts
+++ b/frontend/src/app/shared/components/grids/grid/area.service.ts
@@ -8,9 +8,10 @@ import { SchemaResource } from 'core-app/features/hal/resources/schema-resource'
import { WidgetChangeset } from 'core-app/shared/components/grids/widgets/widget-changeset';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { BehaviorSubject } from 'rxjs';
+import { BehaviorSubject, firstValueFrom } from 'rxjs';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { ApiV3GridForm } from 'core-app/core/apiv3/endpoints/grids/apiv3-grid-form';
+import { map } from 'rxjs/operators';
@Injectable()
export class GridAreaService {
@@ -42,7 +43,8 @@ export class GridAreaService {
private apiV3Service:ApiV3Service,
private toastService:ToastService,
private i18n:I18nService,
- ) { }
+ ) {
+ }
public set gridResource(value:GridResource) {
this.resource = value;
@@ -100,9 +102,10 @@ export class GridAreaService {
}
}
- public rebuildAndPersist() {
- this.persist();
+ public async rebuildAndPersist():Promise<GridResource> {
+ const resource = await this.persist();
this.buildAreas(false);
+ return resource;
}
public persist() {
@@ -111,7 +114,7 @@ export class GridAreaService {
this.resource.columnCount = this.numColumns;
this.writeAreaChangesToWidgets();
- this.saveGrid(this.resource, this.schema);
+ return this.saveGrid(this.resource, this.schema);
}
public saveWidgetChangeset(changeset:WidgetChangeset) {
@@ -154,16 +157,22 @@ export class GridAreaService {
}
}
- private saveGrid(resource:GridWidgetResource|any, schema?:SchemaResource) {
- this
+ private async saveGrid(resource:GridResource, schema?:SchemaResource):Promise<GridResource> {
+ const subscription = this
.apiV3Service
.grids
.id(resource)
.patch(resource, schema)
- .subscribe((updatedGrid) => {
- this.assignAreasWidget(updatedGrid);
- this.toastService.addSuccess(this.i18n.t('js.notice_successful_update'));
- });
+ .pipe(
+ map((updatedGrid) => {
+ this.assignAreasWidget(updatedGrid);
+ this.toastService.addSuccess(this.i18n.t('js.notice_successful_update'));
+
+ return updatedGrid;
+ }),
+ );
+
+ return firstValueFrom(subscription);
}
private assignAreasWidget(newGrid:GridResource) {
@@ -276,10 +285,10 @@ export class GridAreaService {
const widget = this
.rowWidgets(row)
.sort((a, b) => a.startColumn - b.startColumn)
- .find((widget) => !(widget.startRow < excludeRow && widget.endRow > excludeRow)
- && (widget.startColumn === column + 1
- || widget.endColumn === column + 1
- || widget.startColumn <= column && widget.endColumn > column));
+ .find((w) => !(w.startRow < excludeRow && w.endRow > excludeRow)
+ && (w.startColumn === column + 1
+ || w.endColumn === column + 1
+ || (w.startColumn <= column && w.endColumn > column)));
if (widget) {
movedWidgets.push(widget);
@@ -304,10 +313,10 @@ export class GridAreaService {
const widget = this
.columnWidgets(column)
.sort((a, b) => a.startRow - b.startRow)
- .find((widget) => !(widget.startColumn < excludeColumn && widget.endColumn > excludeColumn)
- && (widget.startRow === row + 1
- || widget.endRow === row + 1
- || widget.startRow <= row && widget.endRow > row));
+ .find((w) => !(w.startColumn < excludeColumn && w.endColumn > excludeColumn)
+ && (w.startRow === row + 1
+ || w.endRow === row + 1
+ || (w.startRow <= row && w.endRow > row)));
if (widget) {
movedWidgets.push(widget);