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

Fix offenses due to rxjs bump

Oliver Güntherbcd944cc46d5
diff --git a/frontend/src/app/core/apiv3/cache/cachable-apiv3-resource.ts b/frontend/src/app/core/apiv3/cache/cachable-apiv3-resource.ts
index eccf6616442..9e3eda1d509 100644
--- a/frontend/src/app/core/apiv3/cache/cachable-apiv3-resource.ts
+++ b/frontend/src/app/core/apiv3/cache/cachable-apiv3-resource.ts
@@ -73,10 +73,10 @@ export abstract class ApiV3Resource<T extends HasId = HalResource>
// Return concat of the loading observable
// for error handling and the like,
// but then continue with the streamed cache
- return concat<T>(
+ return concat(
observable,
this.cache.state(id).values$(),
- );
+ ) as Observable<T>;
}
return this.cache.state(id).values$();
@@ -123,7 +123,7 @@ export abstract class ApiV3Resource<T extends HasId = HalResource>
)
// Use a promise to ensure this fires
// even if caller isn't subscribing.
- .toPromise();
+ .toPromise() as Promise<T>;
}
/**
diff --git a/frontend/src/app/core/apiv3/cache/state-cache.service.ts b/frontend/src/app/core/apiv3/cache/state-cache.service.ts
index e06dc03a7c7..295d3c52617 100644
--- a/frontend/src/app/core/apiv3/cache/state-cache.service.ts
+++ b/frontend/src/app/core/apiv3/cache/state-cache.service.ts
@@ -27,7 +27,10 @@
//++
import { MultiInputState, State } from 'reactivestates';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import {
auditTime, map, share, startWith, take,
} from 'rxjs/operators';
@@ -77,7 +80,7 @@ export class StateCacheService<T> {
this
.multiState.get(id)
- .clearAndPutFromPromise(observable.toPromise());
+ .clearAndPutFromPromise(firstValueFrom(observable));
return observable;
}
diff --git a/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts b/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts
index 061b4497eb0..d2f32f5da55 100644
--- a/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts
+++ b/frontend/src/app/core/apiv3/endpoints/work_packages/api-v3-work-packages-paths.ts
@@ -161,13 +161,13 @@ export class ApiV3WorkPackagesPaths extends ApiV3Collection<WorkPackageResource,
protected loadCollectionsFor(ids:string[]):Promise<WorkPackageCollectionResource[]> {
return this
.halResourceService
- .getAllPaginated<WorkPackageCollectionResource>(
- this.path,
- {
- filters: ApiV3Filter('id', '=', ids).toJson(),
- },
- )
- .toPromise();
+ .getAllPaginated<WorkPackageCollectionResource>(
+ this.path,
+ {
+ filters: ApiV3Filter('id', '=', ids).toJson(),
+ },
+ )
+ .toPromise() as Promise<WorkPackageCollectionResource[]>;
}
protected createCache():WorkPackageCache {
diff --git a/frontend/src/app/core/config/configuration.service.ts b/frontend/src/app/core/config/configuration.service.ts
index d0d9051808d..da98247ab4e 100644
--- a/frontend/src/app/core/config/configuration.service.ts
+++ b/frontend/src/app/core/config/configuration.service.ts
@@ -31,6 +31,7 @@ import * as moment from 'moment';
import { ConfigurationResource } from 'core-app/features/hal/resources/configuration-resource';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@Injectable({ providedIn: 'root' })
export class ConfigurationService {
@@ -124,7 +125,7 @@ export class ConfigurationService {
.configuration
.get()
.toPromise()
- .then((configuration) => {
+ .then((configuration:ConfigurationResource) => {
this.configuration = configuration;
});
}
diff --git a/frontend/src/app/core/current-user/current-user.module.ts b/frontend/src/app/core/current-user/current-user.module.ts
index 66b2ff61af7..7319f93203b 100644
--- a/frontend/src/app/core/current-user/current-user.module.ts
+++ b/frontend/src/app/core/current-user/current-user.module.ts
@@ -7,19 +7,14 @@ import { CurrentUserService } from './current-user.service';
import { CurrentUserStore } from './current-user.store';
import { CurrentUserQuery } from './current-user.query';
import { ErrorReporterBase } from 'core-app/core/errors/error-reporter-base';
-import { take } from 'rxjs/operators';
+import { firstValueFrom } from 'rxjs';
export function bootstrapModule(injector:Injector):void {
const currentUserService = injector.get(CurrentUserService);
(window.ErrorReporter as ErrorReporterBase)
.addHook(
- () => currentUserService
- .user$
- .pipe(
- take(1),
- )
- .toPromise()
+ () => firstValueFrom(currentUserService.user$)
.then(({ id }) => ({ user: id || 'anon' })),
);
diff --git a/frontend/src/app/core/setup/globals/openproject.ts b/frontend/src/app/core/setup/globals/openproject.ts
index 3514e036475..f62bae4595a 100644
--- a/frontend/src/app/core/setup/globals/openproject.ts
+++ b/frontend/src/app/core/setup/globals/openproject.ts
@@ -30,6 +30,7 @@ import { OpenProjectPluginContext } from 'core-app/features/plugins/plugin-conte
import { input, InputState } from 'reactivestates';
import { take } from 'rxjs/operators';
import { GlobalHelpers } from 'core-app/core/setup/globals/global-helpers';
+import { firstValueFrom } from 'rxjs';
/**
* OpenProject instance methods
@@ -54,10 +55,7 @@ export class OpenProject {
public editFormsContainModelChanges:boolean;
public getPluginContext():Promise<OpenProjectPluginContext> {
- return this.pluginContext
- .values$()
- .pipe(take(1))
- .toPromise();
+ return firstValueFrom(this.pluginContext.values$());
}
public get urlRoot():string {
diff --git a/frontend/src/app/core/state/days/day.service.ts b/frontend/src/app/core/state/days/day.service.ts
index 6b6b6bdd141..b56b9aeef59 100644
--- a/frontend/src/app/core/state/days/day.service.ts
+++ b/frontend/src/app/core/state/days/day.service.ts
@@ -3,7 +3,10 @@ import {
map,
take,
} from 'rxjs/operators';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { DayStore } from 'core-app/core/state/days/day.store';
import { IDay } from 'core-app/core/state/days/day.model';
@@ -25,13 +28,13 @@ export class DayResourceService extends ResourceStoreService<IDay> {
isNonWorkingDay$(input:Date):Promise<boolean> {
const date = moment(input).format('YYYY-MM-DD');
- return this
- .requireNonWorkingYear$(input)
- .pipe(
- map((days) => days.findIndex((day:IDay) => day.date === date) !== -1),
- take(1),
- )
- .toPromise();
+ return firstValueFrom(
+ this
+ .requireNonWorkingYear$(input)
+ .pipe(
+ map((days) => days.findIndex((day:IDay) => day.date === date) !== -1),
+ ),
+ );
}
requireNonWorkingYear$(date:Date|string):Observable<IDay[]> {
diff --git a/frontend/src/app/features/bim/bcf/api/bcf-authorization.service.ts b/frontend/src/app/features/bim/bcf/api/bcf-authorization.service.ts
index caf46e2fd5b..c52b2beed3b 100644
--- a/frontend/src/app/features/bim/bcf/api/bcf-authorization.service.ts
+++ b/frontend/src/app/features/bim/bcf/api/bcf-authorization.service.ts
@@ -1,8 +1,14 @@
import { multiInput } from 'reactivestates';
import { BcfExtensionResource } from 'core-app/features/bim/bcf/api/extensions/bcf-extension.resource';
import { BcfApiService } from 'core-app/features/bim/bcf/api/bcf-api.service';
-import { Observable } from 'rxjs';
-import { map, take } from 'rxjs/operators';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
+import {
+ map,
+ take,
+} from 'rxjs/operators';
import { Injectable } from '@angular/core';
export type AllowedExtensionKey = keyof BcfExtensionResource;
@@ -28,11 +34,12 @@ export class BcfAuthorizationService {
public authorized$(projectIdentifier:string, extension:AllowedExtensionKey, action:string):Observable<boolean> {
const state = this.authorizationMap.get(projectIdentifier);
- state.putFromPromiseIfPristine(() => this.bcfApi
- .projects.id(projectIdentifier)
- .extensions
- .get()
- .toPromise());
+ state.putFromPromiseIfPristine(() => firstValueFrom(
+ this.bcfApi
+ .projects.id(projectIdentifier)
+ .extensions
+ .get(),
+ ));
return state
.values$()
@@ -51,12 +58,7 @@ export class BcfAuthorizationService {
* @param action The desired action
*/
public isAllowedTo(projectIdentifier:string, extension:AllowedExtensionKey, action:string):Promise<boolean> {
- return this
- .authorized$(projectIdentifier, extension, action)
- .pipe(
- take(1),
- )
- .toPromise()
+ return firstValueFrom(this.authorized$(projectIdentifier, extension, action))
.catch(() => false);
}
}
diff --git a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts
index 3d94146796b..8661c1c1ea9 100644
--- a/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts
+++ b/frontend/src/app/features/bim/ifc_models/ifc-viewer/ifc-viewer.component.ts
@@ -55,7 +55,7 @@ import { take } from 'rxjs/operators';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class IFCViewerComponent implements OnInit, OnDestroy, AfterViewInit {
- private viewInitialized$ = new Subject();
+ private viewInitialized$ = new Subject<void>();
modelCount:number = this.ifcData.models.length;
diff --git a/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts b/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts
index 4e020b6cb9a..8cbbd34f4e4 100644
--- a/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts
+++ b/frontend/src/app/features/boards/board/add-list-modal/add-list-modal.component.ts
@@ -43,7 +43,10 @@ import { HalResourceNotificationService } from 'core-app/features/hal/services/h
import { tap } from 'rxjs/operators';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { OpAutocompleterComponent } from 'core-app/shared/components/autocompleter/op-autocompleter/op-autocompleter.component';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@@ -136,11 +139,11 @@ export class AddListModalComponent extends OpModalComponent implements OnInit {
this.inFlight = true;
this.actionService
.addColumnWithActionAttribute(this.board, this.selectedAttribute!)
- .then((board) => this.boardService.save(board).toPromise())
+ .then((board) => firstValueFrom(this.boardService.save(board)))
.then((board) => {
this.inFlight = false;
this.closeMe();
- this.state.go('boards.partitioned.show', { board_id: board.id, isNew: true });
+ void this.state.go('boards.partitioned.show', { board_id: board.id, isNew: true });
})
.catch(() => (this.inFlight = false));
}
diff --git a/frontend/src/app/features/boards/board/board-actions/assignee/assignee-action.service.ts b/frontend/src/app/features/boards/board/board-actions/assignee/assignee-action.service.ts
index ae9779213fa..009911c35aa 100644
--- a/frontend/src/app/features/boards/board/board-actions/assignee/assignee-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/assignee/assignee-action.service.ts
@@ -10,6 +10,8 @@ import { UserResource } from 'core-app/features/hal/resources/user-resource';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
@Injectable()
export class BoardAssigneeActionService extends CachedBoardActionService {
@@ -108,16 +110,15 @@ export class BoardAssigneeActionService extends CachedBoardActionService {
});
}
- protected loadUncached():Promise<HalResource[]> {
+ protected loadUncached():Observable<HalResource[]> {
return this
.apiV3Service
.projects
.id(this.currentProject.identifier!)
.available_assignees
.get()
- .toPromise()
- .then(
- (collection:CollectionResource<UserResource>) => [this.unassignedUser].concat(collection.elements),
+ .pipe(
+ map((collection:CollectionResource<UserResource>) => [this.unassignedUser].concat(collection.elements) as HalResource[]),
);
}
}
diff --git a/frontend/src/app/features/boards/board/board-actions/cached-board-action.service.ts b/frontend/src/app/features/boards/board/board-actions/cached-board-action.service.ts
index 5b0b580e4a5..1c4cb5352ab 100644
--- a/frontend/src/app/features/boards/board/board-actions/cached-board-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/cached-board-action.service.ts
@@ -1,7 +1,10 @@
import { Injectable } from '@angular/core';
import { BoardActionService } from 'core-app/features/boards/board/board-actions/board-action.service';
import { input } from 'reactivestates';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { map, take } from 'rxjs/operators';
import { Board } from 'core-app/features/boards/board/board';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@@ -13,7 +16,7 @@ export abstract class CachedBoardActionService extends BoardActionService {
protected loadValues(matching?:string):Observable<HalResource[]> {
this
.cache
- .putFromPromiseIfPristine(() => this.loadUncached());
+ .putFromPromiseIfPristine(() => firstValueFrom(this.loadUncached()));
return this
.cache
@@ -42,17 +45,11 @@ export abstract class CachedBoardActionService extends BoardActionService {
protected require(id:string):Promise<HalResource> {
this
.cache
- .putFromPromiseIfPristine(() => this.loadUncached());
+ .putFromPromiseIfPristine(() => firstValueFrom(this.loadUncached()));
- return this
- .cache
- .values$()
- .pipe(
- take(1),
- )
- .toPromise()
- .then((results) => results.find((resource) => resource.id === id)!);
+ return firstValueFrom(this.cache.values$())
+ .then((results:HalResource[]) => results.find((resource) => resource.id === id)!);
}
- protected abstract loadUncached():Promise<HalResource[]>;
+ protected abstract loadUncached():Observable<HalResource[]>;
}
diff --git a/frontend/src/app/features/boards/board/board-actions/status/status-action.service.ts b/frontend/src/app/features/boards/board/board-actions/status/status-action.service.ts
index 205b8cbd12d..74a23c1f066 100644
--- a/frontend/src/app/features/boards/board/board-actions/status/status-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/status/status-action.service.ts
@@ -4,6 +4,8 @@ import { StatusResource } from 'core-app/features/hal/resources/status-resource'
import { CachedBoardActionService } from 'core-app/features/boards/board/board-actions/cached-board-action.service';
import { StatusBoardHeaderComponent } from 'core-app/features/boards/board/board-actions/status/status-board-header.component';
import { imagePath } from 'core-app/shared/helpers/images/path-helper';
+import { map } from 'rxjs/operators';
+import { Observable } from 'rxjs';
@Injectable()
export class BoardStatusActionService extends CachedBoardActionService {
@@ -31,7 +33,7 @@ export class BoardStatusActionService extends CachedBoardActionService {
return this
.loadValues()
.toPromise()
- .then((results) => Promise.all<unknown>(
+ .then((results:StatusResource[]) => Promise.all<unknown>(
results.map((status:StatusResource) => {
if (status.isDefault) {
return this.addColumnWithActionAttribute(board, status);
@@ -47,12 +49,13 @@ export class BoardStatusActionService extends CachedBoardActionService {
return Promise.resolve(this.I18n.t('js.boards.add_list_modal.warning.status'));
}
- protected loadUncached():Promise<StatusResource[]> {
+ protected loadUncached():Observable<StatusResource[]> {
return this
.apiV3Service
.statuses
.get()
- .toPromise()
- .then((collection) => collection.elements);
+ .pipe(
+ map((collection) => collection.elements),
+ );
}
}
diff --git a/frontend/src/app/features/boards/board/board-actions/subproject/subproject-action.service.ts b/frontend/src/app/features/boards/board/board-actions/subproject/subproject-action.service.ts
index 2ac015f8581..5e47afbe810 100644
--- a/frontend/src/app/features/boards/board/board-actions/subproject/subproject-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/subproject/subproject-action.service.ts
@@ -9,6 +9,8 @@ import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { CollectionResource } from 'core-app/features/hal/resources/collection-resource';
+import { Observable } from 'rxjs';
+import { map } from 'rxjs/operators';
@Injectable()
export class BoardSubprojectActionService extends CachedBoardActionService {
@@ -43,7 +45,7 @@ export class BoardSubprojectActionService extends CachedBoardActionService {
changeset.setValue('project', { href });
}
- protected loadUncached():Promise<HalResource[]> {
+ protected loadUncached():Observable<HalResource[]> {
const currentProjectId = this.currentProject.id!;
return this
.apiV3Service
@@ -54,7 +56,8 @@ export class BoardSubprojectActionService extends CachedBoardActionService {
.add('active', '=', true),
)
.get()
- .toPromise()
- .then((collection:CollectionResource<UserResource>) => collection.elements);
+ .pipe(
+ map((collection:CollectionResource<UserResource>) => collection.elements),
+ );
}
}
diff --git a/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts b/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
index 6fc92752d7e..f0feba406f7 100644
--- a/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/subtasks/board-subtasks-action.service.ts
@@ -1,7 +1,10 @@
import { Injectable } from '@angular/core';
import { BoardActionService } from 'core-app/features/boards/board/board-actions/board-action.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { map } from 'rxjs/operators';
import { SubtasksBoardHeaderComponent } from 'core-app/features/boards/board/board-actions/subtasks/subtasks-board-header.component';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
@@ -67,11 +70,6 @@ export class BoardSubtasksActionService extends BoardActionService {
}
protected require(id:string):Promise<HalResource> {
- return this
- .apiV3Service
- .work_packages
- .id(id)
- .get()
- .toPromise();
+ return firstValueFrom(this.apiV3Service.work_packages.id(id).get());
}
}
diff --git a/frontend/src/app/features/boards/board/board-actions/version/version-action.service.ts b/frontend/src/app/features/boards/board/board-actions/version/version-action.service.ts
index 5d6abf16ea9..49366173519 100644
--- a/frontend/src/app/features/boards/board/board-actions/version/version-action.service.ts
+++ b/frontend/src/app/features/boards/board/board-actions/version/version-action.service.ts
@@ -13,6 +13,12 @@ import { CachedBoardActionService } from 'core-app/features/boards/board/board-a
import { imagePath } from 'core-app/shared/helpers/images/path-helper';
import { VersionAutocompleterComponent } from 'core-app/shared/components/autocompleter/version-autocompleter/version-autocompleter.component';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import {
+ firstValueFrom,
+ Observable,
+ of,
+} from 'rxjs';
+import { map } from 'rxjs/operators';
@Injectable()
export class BoardVersionActionService extends CachedBoardActionService {
@@ -54,9 +60,7 @@ export class BoardVersionActionService extends CachedBoardActionService {
}
public addInitialColumnsForAction(board:Board):Promise<Board> {
- return this
- .loadValues()
- .toPromise()
+ return firstValueFrom(this.loadValues())
.then((results) => Promise.all<unknown>(
results.map((version:VersionResource) => {
const definingName = _.get(version, 'definingProject.name', null);
@@ -97,7 +101,8 @@ export class BoardVersionActionService extends CachedBoardActionService {
public disabledAddButtonPlaceholder(version:VersionResource) {
if (version.isLocked()) {
return { icon: 'locked', text: this.I18n.t('js.boards.version.locked') };
- } if (version.isClosed()) {
+ }
+ if (version.isClosed()) {
return { icon: 'not-supported', text: this.I18n.t('js.boards.version.closed') };
}
return undefined;
@@ -107,9 +112,9 @@ export class BoardVersionActionService extends CachedBoardActionService {
return value instanceof VersionResource && value.isOpen();
}
- protected loadUncached():Promise<HalResource[]> {
+ protected loadUncached():Observable<HalResource[]> {
if (this.currentProject.id === null) {
- return Promise.resolve([]);
+ return of([]);
}
return this
@@ -118,8 +123,9 @@ export class BoardVersionActionService extends CachedBoardActionService {
.id(this.currentProject.id)
.versions
.get()
- .toPromise()
- .then((collection) => collection.elements);
+ .pipe(
+ map((collection) => collection.elements),
+ );
}
private patchVersionStatus(version:VersionResource, newStatus:'open'|'closed'|'locked') {
diff --git a/frontend/src/app/features/boards/board/board-list/board-list.component.ts b/frontend/src/app/features/boards/board/board-list/board-list.component.ts
index cb48b4400aa..d8deab0ac72 100644
--- a/frontend/src/app/features/boards/board/board-list/board-list.component.ts
+++ b/frontend/src/app/features/boards/board/board-list/board-list.component.ts
@@ -63,6 +63,7 @@ import {
HalEventsService,
} from 'core-app/features/hal/services/hal-events.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { firstValueFrom } from 'rxjs';
export interface DisabledButtonPlaceholder {
text:string;
@@ -115,7 +116,7 @@ export class BoardListComponent extends AbstractWidgetComponent implements OnIni
/** Whether the add button should be shown */
public showAddButton = false;
- private canAdd = this.wpInlineCreate.canAdd.pipe(take(1)).toPromise();
+ private canAdd = firstValueFrom(this.wpInlineCreate.canAdd);
public columnsQueryProps:any;
diff --git a/frontend/src/app/features/boards/board/board-list/board-lists.service.ts b/frontend/src/app/features/boards/board/board-list/board-lists.service.ts
index 9827dac903e..6b9dc489a3a 100644
--- a/frontend/src/app/features/boards/board/board-list/board-lists.service.ts
+++ b/frontend/src/app/features/boards/board/board-list/board-lists.service.ts
@@ -9,12 +9,18 @@ import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { ApiV3Filter } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
import { GridWidgetResource } from 'core-app/features/hal/resources/grid-widget-resource';
+import {
+ firstValueFrom,
+ Observable,
+ switchMap,
+} from 'rxjs';
@Injectable({ providedIn: 'root' })
export class BoardListsService {
private v3 = this.pathHelper.api.v3;
- constructor(private readonly CurrentProject:CurrentProjectService,
+ constructor(
+ private readonly CurrentProject:CurrentProjectService,
private readonly pathHelper:PathHelperService,
private readonly apiV3Service:ApiV3Service,
private readonly halResourceService:HalResourceService,
@@ -23,7 +29,7 @@ export class BoardListsService {
}
- private create(params:Object, filters:ApiV3Filter[]):Promise<QueryResource> {
+ private create(params:Object, filters:ApiV3Filter[]):Observable<QueryResource> {
const filterJson = JSON.stringify(filters);
return this
@@ -39,19 +45,19 @@ export class BoardListsService {
this.CurrentProject.identifier,
this.buildQueryRequest(params),
)
- .toPromise()
- .then(([form, query]) => {
- // When the permission to create public queries is missing, throw an error.
- // Otherwise private queries would be created.
- if (form.schema.public.writable) {
- return this
- .apiV3Service
- .queries
- .post(query, form)
- .toPromise();
- }
- throw new Error(this.I18n.t('js.boards.error_permission_missing'));
- });
+ .pipe(
+ switchMap(([form, query]) => {
+ // When the permission to create public queries is missing, throw an error.
+ // Otherwise private queries would be created.
+ if (form.schema.public.writable) {
+ return this
+ .apiV3Service
+ .queries
+ .post(query, form);
+ }
+ throw new Error(this.I18n.t('js.boards.error_permission_missing'));
+ }),
+ );
}
/**
@@ -70,7 +76,7 @@ export class BoardListsService {
public async addQuery(board:Board, queryParams:Object, filters:ApiV3Filter[]):Promise<Board> {
const count = board.queries.length;
try {
- const query = await this.create(queryParams, filters);
+ const query = await firstValueFrom(this.create(queryParams, filters));
const source = {
_type: 'GridWidget',
diff --git a/frontend/src/app/features/boards/board/board.service.ts b/frontend/src/app/features/boards/board/board.service.ts
index d31260e0b91..3f51d27de16 100644
--- a/frontend/src/app/features/boards/board/board.service.ts
+++ b/frontend/src/app/features/boards/board/board.service.ts
@@ -3,11 +3,18 @@ import { BoardListsService } from 'core-app/features/boards/board/board-list/boa
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
-import { Board, BoardType } from 'core-app/features/boards/board/board';
+import {
+ Board,
+ BoardType,
+} from 'core-app/features/boards/board/board';
import { GridWidgetResource } from 'core-app/features/hal/resources/grid-widget-resource';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { BoardActionsRegistryService } from 'core-app/features/boards/board/board-actions/board-actions-registry.service';
-import { BehaviorSubject, Observable } from 'rxjs';
+import {
+ BehaviorSubject,
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
export interface CreateBoardParams {
@@ -48,11 +55,13 @@ export class BoardService {
return this.loadAllPromise;
}
- return this.loadAllPromise = this
- .apiV3Service
- .boards
- .allInScope(projectIdentifier!)
- .toPromise();
+ // eslint-disable-next-line no-return-assign
+ return this.loadAllPromise = firstValueFrom(
+ this
+ .apiV3Service
+ .boards
+ .allInScope(projectIdentifier!),
+ );
}
/**
@@ -79,10 +88,12 @@ export class BoardService {
* @param name
*/
public async create(params:CreateBoardParams):Promise<Board> {
- const board = await this
- .apiV3Service
- .boards
- .create(params.type, this.boardName(params), this.CurrentProject.identifier!, params.attribute).toPromise();
+ const board = await firstValueFrom(
+ this
+ .apiV3Service
+ .boards
+ .create(params.type, this.boardName(params), this.CurrentProject.identifier!, params.attribute),
+ );
if (params.type === 'free') {
await this.boardsList.addFreeQuery(board, { name: this.text.unnamed_list });
@@ -90,18 +101,19 @@ export class BoardService {
await this.boardActions.get(params.attribute!).addInitialColumnsForAction(board);
}
- await this.save(board).toPromise();
+ await firstValueFrom(this.save(board));
return board;
}
public delete(board:Board):Promise<unknown> {
- return this
- .apiV3Service
- .boards
- .id(board)
- .delete()
- .toPromise();
+ return firstValueFrom(
+ this
+ .apiV3Service
+ .boards
+ .id(board)
+ .delete(),
+ );
}
/**
diff --git a/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts b/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
index 7b02422f0a7..ffc68def7cd 100644
--- a/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
+++ b/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
@@ -22,7 +22,10 @@ import { splitViewRoute } from 'core-app/features/work-packages/routing/split-vi
import { StateService } from '@uirouter/angular';
import { WorkPackageCollectionResource } from 'core-app/features/hal/resources/wp-collection-resource';
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { WorkPackageViewFiltersService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service';
import { WorkPackagesListService } from 'core-app/features/work-packages/components/wp-list/wp-list.service';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
@@ -141,11 +144,7 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
}
async requireNonWorkingDays(date:Date|string) {
- this.nonWorkingDays = await this
- .dayService
- .requireNonWorkingYear$(date)
- .pipe(take(1))
- .toPromise();
+ this.nonWorkingDays = await firstValueFrom(this.dayService.requireNonWorkingYear$(date));
}
isNonWorkingDay(date:Date|string):boolean {
@@ -187,11 +186,7 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
// such filter exists yet, we need to add it to the existing filter set.
// In order to do both, we first need to fetch the query as we cannot signal
// to the backend yet to only add this one filter but leave the rest unchanged.
- const initialQuery = await this
- .apiV3Service
- .queries
- .find({ pageSize: 0 }, queryId)
- .toPromise();
+ const initialQuery = await firstValueFrom(this.apiV3Service.queries.find({ pageSize: 0 }, queryId));
queryProps = this.generateQueryProps(
initialQuery,
diff --git a/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts b/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
index cb32379ec9d..68d925a00a1 100644
--- a/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
+++ b/frontend/src/app/features/calendar/te-calendar/te-calendar.component.ts
@@ -46,6 +46,7 @@ import { SchemaResource } from 'core-app/features/hal/resources/schema-resource'
import { IFieldSchema } from 'core-app/shared/components/fields/field.base';
import { VerboseFormattingArg } from '@fullcalendar/common';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { firstValueFrom } from 'rxjs';
interface TimeEntrySchema extends SchemaResource {
activity:IFieldSchema;
@@ -197,11 +198,12 @@ export class TimeEntryCalendarComponent {
if (!this.memoizedTimeEntries
|| this.memoizedTimeEntries.start.getTime() !== start.getTime()
|| this.memoizedTimeEntries.end.getTime() !== end.getTime()) {
- const promise = this
- .apiV3Service
- .time_entries
- .list({ filters: this.dmFilters(start, end), pageSize: 500 })
- .toPromise()
+ const promise = firstValueFrom(
+ this
+ .apiV3Service
+ .time_entries
+ .list({ filters: this.dmFilters(start, end), pageSize: 500 }),
+ )
.then((collection) => {
this.memoizedCreateAllowed = !!collection.createTimeEntry;
diff --git a/frontend/src/app/features/hal/hal-link/hal-link.ts b/frontend/src/app/features/hal/hal-link/hal-link.ts
index 5dec381138b..6a370547ff7 100644
--- a/frontend/src/app/features/hal/hal-link/hal-link.ts
+++ b/frontend/src/app/features/hal/hal-link/hal-link.ts
@@ -29,6 +29,7 @@
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { HTTPSupportedMethods } from 'core-app/features/hal/http/http.interfaces';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
+import { firstValueFrom } from 'rxjs';
export interface HalLinkInterface {
href:string|null;
@@ -66,7 +67,7 @@ export class HalLink implements HalLinkInterface {
*/
public static fromObject(halResourceService:HalResourceService, link:HalLinkInterface):HalLink {
return new HalLink(
- (method:HTTPSupportedMethods, href:string, data:any, headers:any) => halResourceService.request(method, href, data, headers).toPromise(),
+ (method:HTTPSupportedMethods, href:string, data:any, headers:any) => firstValueFrom(halResourceService.request(method, href, data, headers)),
link.href,
link.title,
link.method,
diff --git a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts
index 24dd375d7ed..cd4c60b224a 100644
--- a/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts
+++ b/frontend/src/app/features/invite-user-modal/project-selection/project-selection.component.ts
@@ -27,6 +27,7 @@ import { IProjectAutocompleteItem } from 'core-app/shared/components/autocomplet
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
import { ICapability } from 'core-app/core/state/capabilities/capability.model';
+import { firstValueFrom } from 'rxjs';
@Component({
selector: 'op-ium-project-selection',
@@ -151,7 +152,7 @@ export class ProjectSelectionComponent implements OnInit {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
const projectId = idFromLink(this.projectControl?.value?.href);
- const project = await this.apiV3Service.projects.id(projectId).get().toPromise();
+ const project = await firstValueFrom(this.apiV3Service.projects.id(projectId).get());
this.save.emit({
project,
diff --git a/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts b/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts
index 377444d8157..56ab54cd8df 100644
--- a/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts
+++ b/frontend/src/app/features/work-packages/components/filters/filter-project/filter-project.component.ts
@@ -43,6 +43,7 @@ import { IProjectAutocompleteItem } from 'core-app/shared/components/autocomplet
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+import { firstValueFrom } from 'rxjs';
@Component({
selector: 'op-filter-project',
@@ -86,11 +87,13 @@ export class FilterProjectComponent extends UntilDestroyedMixin implements OnIni
// The project autocompleter does not return HalResources, but most filters want them.
// Here we change from one to the other
- const projects = await this.apiV3Service.projects.list({
- filters: [
- ['id', '=', val.map((p:HalResource|IProjectAutocompleteItem) => String(p.id) || '')],
- ],
- }).toPromise();
+ const projects = await firstValueFrom(
+ this.apiV3Service.projects.list({
+ filters: [
+ ['id', '=', val.map((p:HalResource|IProjectAutocompleteItem) => String(p.id) || '')],
+ ],
+ }),
+ );
this.filter.values = projects.elements;
this.filterChanged.emit(this.filter);
diff --git a/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts b/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts
index 8619fea87ce..b3dcbbe9649 100644
--- a/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-card-view/services/wp-card-drag-and-drop.service.ts
@@ -12,6 +12,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
+import { firstValueFrom } from 'rxjs';
@Injectable()
export class WorkPackageCardDragAndDropService {
@@ -81,12 +82,7 @@ export class WorkPackageCardDragAndDropService {
const wpId:string = card.dataset.workPackageId!;
const toIndex = findIndex(card);
- const workPackage = await this
- .apiV3Service
- .work_packages
- .id(wpId)
- .get()
- .toPromise();
+ const workPackage = await firstValueFrom(this.apiV3Service.work_packages.id(wpId).get());
const result = await this.addWorkPackageToQuery(workPackage, toIndex);
if (card.parentElement) {
diff --git a/frontend/src/app/features/work-packages/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts b/frontend/src/app/features/work-packages/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts
index 049b5875b74..d93adc542cc 100644
--- a/frontend/src/app/features/work-packages/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-custom-actions/wp-custom-actions/wp-custom-action.component.ts
@@ -62,9 +62,9 @@ export class WpCustomActionComponent {
private fetchAction() {
if (this.action.href === null) return;
- void this.halResourceService.get<CustomActionResource>(this.action.href)
- .toPromise()
- .then((action) => {
+ void this.halResourceService
+ .get<CustomActionResource>(this.action.href)
+ .subscribe((action) => {
this.action = action;
});
}
diff --git a/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts b/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts
index 02edf66dece..32a5fb61b89 100644
--- a/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts
+++ b/frontend/src/app/features/work-packages/components/wp-fast-table/handlers/state/drag-and-drop-transformer.ts
@@ -18,6 +18,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { isInsideCollapsedGroup } from 'core-app/features/work-packages/components/wp-fast-table/helpers/wp-table-row-helpers';
import { collapsedGroupClass } from 'core-app/features/work-packages/components/wp-fast-table/helpers/wp-table-hierarchy-helpers';
import { WorkPackageTable } from '../../wp-fast-table';
+import { firstValueFrom } from 'rxjs';
export class DragAndDropTransformer {
@InjectField() private readonly states:States;
@@ -81,7 +82,7 @@ export class DragAndDropTransformer {
let rowIndex;
try {
- const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();
+ const workPackage = await firstValueFrom(this.apiV3Service.work_packages.id(wpId).get());
if (isInsideCollapsedGroup(sibling)) {
const collapsedGroupCSSClass = Array.from(sibling!.classList).find((listClass) => listClass.includes(collapsedGroupClass()))!;
@@ -120,7 +121,7 @@ export class DragAndDropTransformer {
},
onAdded: async (el:HTMLElement) => {
const wpId:string = el.dataset.workPackageId!;
- const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();
+ const workPackage = await firstValueFrom(this.apiV3Service.work_packages.id(wpId).get());
const rowIndex = this.findRowIndex(el);
return this.actionService
@@ -137,7 +138,7 @@ export class DragAndDropTransformer {
onCloned: async (clone:HTMLElement, original:HTMLElement) => {
// Replace clone with one TD of the subject
const wpId:string = original.dataset.workPackageId!;
- const workPackage = await this.apiV3Service.work_packages.id(wpId).get().toPromise();
+ const workPackage = await firstValueFrom(this.apiV3Service.work_packages.id(wpId).get());
const colspan = clone.children.length;
const td = document.createElement('td');
@@ -169,7 +170,7 @@ export class DragAndDropTransformer {
const mappedOrder = await Promise.all(
order.map(
- (wpId) => this.apiV3Service.work_packages.id(wpId).get().toPromise(),
+ (wpId) => firstValueFrom(this.apiV3Service.work_packages.id(wpId).get()),
),
);
diff --git a/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts b/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
index d7315355ccc..e36562c70fb 100644
--- a/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-list/wp-list.service.ts
@@ -37,6 +37,7 @@ import { UrlParamsHelperService } from 'core-app/features/work-packages/componen
import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import {
+ firstValueFrom,
from,
Observable,
of,
@@ -165,7 +166,7 @@ export class WorkPackagesListService {
* Load the default query.
*/
public loadDefaultQuery(projectIdentifier?:string):Promise<QueryResource> {
- return this.fromQueryParams({}, projectIdentifier).toPromise();
+ return firstValueFrom(this.fromQueryParams({}, projectIdentifier));
}
/**
@@ -231,19 +232,18 @@ export class WorkPackagesListService {
/**
* Load the query from the given state params
*/
- public loadCurrentQueryFromParams(projectIdentifier?:string) {
- return this
- .fromQueryParams(this.$state.params as any, projectIdentifier)
- .toPromise();
+ public loadCurrentQueryFromParams(projectIdentifier?:string):Promise<QueryResource> {
+ return firstValueFrom(this.fromQueryParams(this.$state.params as any, projectIdentifier));
}
public loadForm(query:QueryResource):Promise<QueryFormResource> {
- return this
- .apiV3Service
- .queries
- .form
- .load(query)
- .toPromise()
+ return firstValueFrom(
+ this
+ .apiV3Service
+ .queries
+ .form
+ .load(query),
+ )
.then(([form, _]) => {
this.wpStatesInitialization.updateStatesFromForm(query, form);
@@ -260,9 +260,7 @@ export class WorkPackagesListService {
query.name = name;
- const promise = this
- .createQueryAndView(query, form)
- .toPromise()
+ const promise = firstValueFrom(this.createQueryAndView(query, form))
.then((createdQuery) => {
this.toastService.addSuccess(this.I18n.t('js.notice_successful_create'));
@@ -377,12 +375,13 @@ export class WorkPackagesListService {
this.toastService.addError(this.I18n.t('js.work_packages.faulty_query.description'), error.message);
return new Promise((resolve, reject) => {
- this
- .apiV3Service
- .queries
- .form
- .loadWithParams(queryProps, queryId, projectIdentifier)
- .toPromise()
+ firstValueFrom(
+ this
+ .apiV3Service
+ .queries
+ .form
+ .loadWithParams(queryProps, queryId, projectIdentifier),
+ )
.then(([form, _]) => {
this
.apiV3Service
diff --git a/frontend/src/app/features/work-packages/components/wp-new/wp-create.service.ts b/frontend/src/app/features/work-packages/components/wp-new/wp-create.service.ts
index a08b7b98dff..2b77a70d084 100644
--- a/frontend/src/app/features/work-packages/components/wp-new/wp-create.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-new/wp-create.service.ts
@@ -31,6 +31,7 @@ import {
Injector,
} from '@angular/core';
import {
+ firstValueFrom,
Observable,
Subject,
} from 'rxjs';
@@ -167,13 +168,14 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {
public getEmptyForm(projectIdentifier:string|null|undefined):Promise<FormResource> {
if (!this.form) {
- this.form = this
- .apiV3Service
- .withOptionalProject(projectIdentifier)
- .work_packages
- .form
- .post({})
- .toPromise();
+ this.form = firstValueFrom(
+ this
+ .apiV3Service
+ .withOptionalProject(projectIdentifier)
+ .work_packages
+ .form
+ .post({}),
+ );
}
return this.form;
@@ -305,7 +307,7 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {
* a valid payload in the sense that all properties are at their correct place and are in the right format. That means
* HalResources are in the _links section and follow the { href: some_link } format while simple properties stay on the
* top level.
- */
+ */
private withFiltersPayload(projectIdentifier:string|null|undefined, defaults?:HalSource):Promise<HalSource> {
const fromFilter = { _links: {} };
this.defaultsFromFilters(fromFilter, defaults);
@@ -385,7 +387,7 @@ export class WorkPackageCreateService extends UntilDestroyedMixin {
// Set update link to form
wp.update = wp.$links.update = form.$links.self;
// Use POST /work_packages for saving link
- wp.updateImmediately = wp.$links.updateImmediately = (payload) => this.apiV3Service.work_packages.post(payload).toPromise();
+ wp.updateImmediately = wp.$links.updateImmediately = (payload) => firstValueFrom(this.apiV3Service.work_packages.post(payload));
// We need to provide the schema to the cache so that it is available in the html form to e.g. determine
// the editability.
diff --git a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.service.ts b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.service.ts
index 26bcbe239e7..d43be3cde8c 100644
--- a/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-relations/wp-relations.service.ts
@@ -5,7 +5,10 @@ import { Injectable } from '@angular/core';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { StateCacheService } from 'core-app/core/apiv3/cache/state-cache.service';
-import { Observable } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { map, take } from 'rxjs/operators';
import { RelationResource } from 'core-app/features/hal/resources/relation-resource';
@@ -40,12 +43,7 @@ export class WorkPackageRelationsService extends StateCacheService<RelationsStat
* @param force Load the value anyway.
*/
public require(id:string, force = false):Promise<RelationsStateValue> {
- return this
- .requireAndStream(id, force)
- .pipe(
- take(1),
- )
- .toPromise();
+ return firstValueFrom(this.requireAndStream(id, force));
}
/**
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/wp-linked-resource-cache.service.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/wp-linked-resource-cache.service.ts
index 5e1b5ce2e2c..92c352b9c83 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/wp-linked-resource-cache.service.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/wp-linked-resource-cache.service.ts
@@ -33,7 +33,11 @@ import {
map,
take,
} from 'rxjs/operators';
-import { Observable, of } from 'rxjs';
+import {
+ firstValueFrom,
+ Observable,
+ of,
+} from 'rxjs';
interface CacheInput<T> {
id:string;
@@ -90,12 +94,7 @@ export abstract class WorkPackageLinkedResourceCache<T> {
}
public require(workPackage:WorkPackageResource, force = false):Promise<T> {
- return this
- .requireAndStream(workPackage, force)
- .pipe(
- take(1),
- )
- .toPromise();
+ return firstValueFrom(this.requireAndStream(workPackage, force));
}
public clear(workPackageId:string|null) {
diff --git a/frontend/src/app/features/work-packages/components/wp-table/configuration-modal/wp-table-configuration.modal.ts b/frontend/src/app/features/work-packages/components/wp-table/configuration-modal/wp-table-configuration.modal.ts
index 4bdae03ce19..73622309730 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/configuration-modal/wp-table-configuration.modal.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/configuration-modal/wp-table-configuration.modal.ts
@@ -32,6 +32,8 @@ import { OpModalLocalsMap } from 'core-app/shared/components/modal/modal.types';
import { ComponentType } from '@angular/cdk/portal';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';
+import { QueryResource } from 'core-app/features/hal/resources/query-resource';
export const WpTableConfigurationModalPrependToken = new InjectionToken<ComponentType<any>>('WpTableConfigurationModalPrependComponent');
@@ -153,7 +155,7 @@ export class WpTableConfigurationModalComponent extends OpModalComponent impleme
.form
.load(query)
.toPromise()
- .then(([form, _]) => {
+ .then(([form, _]:[QueryFormResource, QueryResource]) => {
this.wpStatesInitialization.updateStatesFromForm(query, form);
return form;
diff --git a/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-base.component.ts b/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-base.component.ts
index 52ba5a507b6..5c08aeca8f4 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-base.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-base.component.ts
@@ -1,5 +1,9 @@
import {
- AfterViewInit, ChangeDetectorRef, Directive, Input, SimpleChanges,
+ AfterViewInit,
+ ChangeDetectorRef,
+ Directive,
+ Input,
+ SimpleChanges,
} from '@angular/core';
import {
WorkPackageTableConfiguration,
@@ -15,6 +19,7 @@ import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decora
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { WorkPackageStatesInitializationService } from '../../wp-list/wp-states-initialization.service';
+import { firstValueFrom } from 'rxjs';
@Directive()
export abstract class WorkPackageEmbeddedBaseComponent extends WorkPackagesViewBase implements AfterViewInit {
@@ -105,10 +110,11 @@ export abstract class WorkPackageEmbeddedBaseComponent extends WorkPackagesViewB
}
const params = this.urlParamsHelper.buildV3GetQueryFromQueryResource(query, pagination);
- const promise = this
- .wpListService
- .loadQueryFromExisting(query, params, this.queryProjectScope)
- .toPromise()
+ const promise = firstValueFrom(
+ this
+ .wpListService
+ .loadQueryFromExisting(query, params, this.queryProjectScope),
+ )
.then((query) => this.wpStatesInitialization.updateQuerySpace(query, query.results));
if (visible) {
diff --git a/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts b/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts
index 91abe2b09dd..c019a7dce6c 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/embedded/wp-embedded-table.component.ts
@@ -1,5 +1,11 @@
import {
- AfterViewInit, Component, EventEmitter, Input, OnDestroy, OnInit, Output,
+ AfterViewInit,
+ Component,
+ EventEmitter,
+ Input,
+ OnDestroy,
+ OnInit,
+ Output,
} from '@angular/core';
import { WorkPackageViewTimelineService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-timeline.service';
import { WorkPackageViewPaginationService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-pagination.service';
@@ -11,11 +17,15 @@ import { OpModalService } from 'core-app/shared/components/modal/modal.service';
import { WorkPackageEmbeddedBaseComponent } from 'core-app/features/work-packages/components/wp-table/embedded/wp-embedded-base.component';
import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';
import {
- distinctUntilChanged, map, take, withLatestFrom,
+ distinctUntilChanged,
+ map,
+ take,
+ withLatestFrom,
} from 'rxjs/operators';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { firstValueFrom } from 'rxjs';
@Component({
selector: 'wp-embedded-table',
@@ -77,15 +87,16 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCo
this.untilDestroyed(),
withLatestFrom(this.querySpace.query.values$()),
).subscribe(([_, query]) => {
- const pagination = this.wpTablePagination.paginationObject;
- const params = this.urlParamsHelper.buildV3GetQueryFromQueryResource(query, pagination);
+ const pagination = this.wpTablePagination.paginationObject;
+ const params = this.urlParamsHelper.buildV3GetQueryFromQueryResource(query, pagination);
- this.loadingIndicator = this
+ this.loadingIndicator = firstValueFrom(
+ this
.wpListService
- .loadQueryFromExisting(query, params, this.queryProjectScope)
- .toPromise()
- .then((query) => this.initializeStates(query));
- });
+ .loadQueryFromExisting(query, params, this.queryProjectScope),
+ )
+ .then((query) => this.initializeStates(query));
+ });
}
public async openConfigurationModal(onUpdated:() => void):Promise<void> {
@@ -121,17 +132,20 @@ export class WorkPackageEmbeddedTableComponent extends WorkPackageEmbeddedBaseCo
return this.formPromise;
}
- return this.formPromise = this
- .apiv3Service
- .withOptionalProject(this.projectIdentifier)
- .queries
- .form
- .load(query)
- .toPromise()
+ // eslint-disable-next-line no-return-assign
+ return this.formPromise = firstValueFrom(
+ this
+ .apiv3Service
+ .withOptionalProject(this.projectIdentifier)
+ .queries
+ .form
+ .load(query),
+ )
.then(([form, _]) => {
this.wpStatesInitialization.updateStatesFromForm(query, form);
return form;
})
+ // eslint-disable-next-line no-return-assign
.catch(() => this.formPromise = undefined);
}
diff --git a/frontend/src/app/features/work-packages/components/wp-table/timeline/container/wp-timeline-container.directive.ts b/frontend/src/app/features/work-packages/components/wp-table/timeline/container/wp-timeline-container.directive.ts
index 6028c2bfe67..d233ecc7f55 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/timeline/container/wp-timeline-container.directive.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/timeline/container/wp-timeline-container.directive.ts
@@ -27,15 +27,28 @@
//++
import {
- AfterViewInit, Component, ElementRef, Injector,
+ AfterViewInit,
+ Component,
+ ElementRef,
+ Injector,
} from '@angular/core';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { IToast, ToastService } from 'core-app/shared/components/toaster/toast.service';
+import {
+ IToast,
+ ToastService,
+} from 'core-app/shared/components/toaster/toast.service';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
import * as moment from 'moment';
import { Moment } from 'moment';
-import { filter, takeUntil, take } from 'rxjs/operators';
-import { input, InputState } from 'reactivestates';
+import {
+ filter,
+ takeUntil,
+ take,
+} from 'rxjs/operators';
+import {
+ input,
+ InputState,
+} from 'reactivestates';
import { WorkPackageTable } from 'core-app/features/work-packages/components/wp-fast-table/wp-fast-table';
import { WorkPackageTimelineCellsRenderer } from 'core-app/features/work-packages/components/wp-table/timeline/cells/wp-timeline-cells-renderer';
import { States } from 'core-app/core/states/states.service';
@@ -44,9 +57,16 @@ import { WorkPackageRelationsService } from 'core-app/features/work-packages/com
import { WorkPackageViewHierarchiesService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-hierarchy.service';
import { WorkPackageTimelineCell } from 'core-app/features/work-packages/components/wp-table/timeline/cells/wp-timeline-cell';
import { selectorTimelineSide } from 'core-app/features/work-packages/components/wp-table/wp-table-scroll-sync';
-import { debugLog, timeOutput } from 'core-app/shared/helpers/debug_output';
+import {
+ debugLog,
+ timeOutput,
+} from 'core-app/shared/helpers/debug_output';
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
-import { combineLatest, Observable } from 'rxjs';
+import {
+ combineLatest,
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { WorkPackagesTableComponent } from 'core-app/features/work-packages/components/wp-table/wp-table.component';
import {
@@ -177,7 +197,7 @@ export class WorkPackageTimelineTableController extends UntilDestroyedMixin impl
this.commonPipes,
)
.subscribe(([orderedRows]) => {
- // Remember all visible rows in their order of appearance.
+ // Remember all visible rows in their order of appearance.
this.workPackageIdOrder = orderedRows.filter((row:RenderedWorkPackage) => !row.hidden);
this.orderedRows = orderedRows;
this.refreshView();
@@ -363,11 +383,12 @@ export class WorkPackageTimelineTableController extends UntilDestroyedMixin impl
}
async requireNonWorkingDays(start:Date|string, end:Date|string) {
- this.nonWorkingDays = await this
- .daysService
- .requireNonWorkingYears$(start, end)
- .pipe(take(1))
- .toPromise();
+ this.nonWorkingDays = await firstValueFrom(
+ this
+ .daysService
+ .requireNonWorkingYears$(start, end)
+ .pipe(take(1)),
+ );
}
isNonWorkingDay(date:Date|string):boolean {
@@ -535,7 +556,7 @@ export class WorkPackageTimelineTableController extends UntilDestroyedMixin impl
const keyGroupType = groupTypeFromIdentifier(groupIdentifier);
return this.workPackageViewCollapsedGroupsService.groupTypesWithHeaderCellsWhenCollapsed.includes(keyGroupType)
- && this.workPackageViewCollapsedGroupsService.groupTypesWithHeaderCellsWhenCollapsed.includes(groupsCollapseConfig.groupedBy!);
+ && this.workPackageViewCollapsedGroupsService.groupTypesWithHeaderCellsWhenCollapsed.includes(groupsCollapseConfig.groupedBy!);
}
createCollapsedGroupHeaderCells(groupIdentifier:string, tableWorkPackages:WorkPackageResource[], collapsedGroupsCellsMap:IGroupCellsMap) {
@@ -545,7 +566,7 @@ export class WorkPackageTimelineTableController extends UntilDestroyedMixin impl
const changedGroupType = groupTypeFromIdentifier(groupIdentifier);
const changedGroupTableWorkPackages = tableWorkPackages.filter((tableWorkPackage) => tableWorkPackage[changedGroupType].id === changedGroupId);
const changedGroupWpsWithHeaderCells = changedGroupTableWorkPackages.filter((tableWorkPackage) => this.shouldBeShownInCollapsedGroupHeaders(tableWorkPackage)
- && (tableWorkPackage.date || tableWorkPackage.startDate));
+ && (tableWorkPackage.date || tableWorkPackage.startDate));
const changedGroupWpsWithHeaderCellsIds = changedGroupWpsWithHeaderCells.map((workPackage) => workPackage.id!);
this.collapsedGroupsCellsMap[groupIdentifier] = this.cellsRenderer.buildCellsAndRenderOnRow(changedGroupWpsWithHeaderCellsIds, `group-${groupIdentifier}-timeline`, true);
diff --git a/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts b/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts
index c7e160b1c74..3f132df2f38 100644
--- a/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts
+++ b/frontend/src/app/features/work-packages/directives/query-space/isolated-query-space.ts
@@ -57,7 +57,7 @@ export class IsolatedQuerySpace extends StatesGroup {
));
// Subject used to unregister all listeners of states above.
- stopAllSubscriptions = new Subject();
+ stopAllSubscriptions = new Subject<void>();
// Required work packages to be rendered by hierarchy mode + relation columns
additionalRequiredWorkPackages = input<null>();
diff --git a/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts b/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts
index 7f324d3985d..56d631d2fe7 100644
--- a/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts
+++ b/frontend/src/app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.ts
@@ -48,6 +48,7 @@ import { InviteUserModalComponent } from 'core-app/features/invite-user-modal/in
import { WorkPackageFilterContainerComponent } from 'core-app/features/work-packages/components/filters/filter-container/filter-container.directive';
import isPersistedResource from 'core-app/features/hal/helpers/is-persisted-resource';
import { UIRouterGlobals } from '@uirouter/core';
+import { firstValueFrom } from 'rxjs';
export interface DynamicComponentDefinition {
component:ComponentType<any>;
@@ -261,9 +262,7 @@ export class PartitionedQuerySpacePageComponent extends WorkPackagesViewBase imp
promise = this.loadFirstPage();
} else {
const pagination = this.wpListService.getPaginationInfo();
- promise = this.wpListService
- .loadQueryFromExisting(query, pagination, this.projectIdentifier)
- .toPromise();
+ promise = firstValueFrom(this.wpListService.loadQueryFromExisting(query, pagination, this.projectIdentifier));
}
return promise;
@@ -271,7 +270,7 @@ export class PartitionedQuerySpacePageComponent extends WorkPackagesViewBase imp
protected loadFirstPage():Promise<QueryResource> {
if (this.currentQuery) {
- return this.wpListService.reloadQuery(this.currentQuery, this.projectIdentifier).toPromise();
+ return firstValueFrom(this.wpListService.reloadQuery(this.currentQuery, this.projectIdentifier));
}
return this.wpListService.loadCurrentQueryFromParams(this.projectIdentifier);
}
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service.ts
index 150082768cf..cdee9a8a231 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-filters.service.ts
@@ -31,7 +31,6 @@ import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/q
import { combine, input, InputState } from 'reactivestates';
import { States } from 'core-app/core/states/states.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { mapTo, take } from 'rxjs/operators';
import { QuerySchemaResource } from 'core-app/features/hal/resources/query-schema-resource';
import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
@@ -39,6 +38,8 @@ import { cloneHalResourceCollection } from 'core-app/features/hal/helpers/hal-re
import { QueryFilterInstanceSchemaResource } from 'core-app/features/hal/resources/query-filter-instance-schema-resource';
import { QueryFilterResource } from 'core-app/features/hal/resources/query-filter-resource';
import { WorkPackageQueryStateService } from './wp-view-base.service';
+import { firstValueFrom } from 'rxjs';
+import { map } from 'rxjs/operators';
@Injectable()
export class WorkPackageViewFiltersService extends WorkPackageQueryStateService<QueryFilterInstanceResource[]> {
@@ -307,13 +308,11 @@ export class WorkPackageViewFiltersService extends WorkPackageQueryStateService<
* Filters service depends on two states
*/
public onReady():Promise<null> {
- return combine(this.pristineState, this.availableState)
- .values$()
- .pipe(
- take(1),
- mapTo(null),
- )
- .toPromise();
+ return firstValueFrom(
+ combine(this.pristineState, this.availableState)
+ .values$()
+ .pipe(map(() => null)),
+ );
}
/**
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts
index 7fcc46f4138..4a77fb03278 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-hierarchy-indentation.service.ts
@@ -6,6 +6,7 @@ import { WorkPackageRelationsHierarchyService } from 'core-app/features/work-pac
import { States } from 'core-app/core/states/states.service';
import { WorkPackageViewDisplayRepresentationService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-display-representation.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { firstValueFrom } from 'rxjs';
@Injectable()
export class WorkPackageViewHierarchyIdentationService {
@@ -88,7 +89,7 @@ export class WorkPackageViewHierarchyIdentationService {
// If the predecessor is in an ancestor chain.
// get the first element of the ancestor chain that workPackage is not in
- const predecessor = await this.apiV3Service.work_packages.id(predecessorId).get().toPromise();
+ const predecessor = await firstValueFrom(this.apiV3Service.work_packages.id(predecessorId).get());
const difference = _.difference(predecessor.ancestorIds, workPackage.ancestorIds);
if (difference && difference.length > 0) {
diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts
index baa7427478f..d85a8836778 100644
--- a/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts
+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/view-services/wp-view-order.service.ts
@@ -43,6 +43,7 @@ import { CausedUpdatesService } from 'core-app/features/boards/board/caused-upda
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { QueryOrder } from 'core-app/core/apiv3/endpoints/queries/apiv3-query-order';
import { WorkPackageQueryStateService } from './wp-view-base.service';
+import { firstValueFrom } from 'rxjs';
@Injectable()
export class WorkPackageViewOrderService extends WorkPackageQueryStateService<QueryOrder> {
@@ -186,10 +187,7 @@ export class WorkPackageViewOrderService extends WorkPackageQueryStateService<Qu
this.positions.putValue({});
}
- return this.positions
- .values$()
- .pipe(take(1))
- .toPromise();
+ return firstValueFrom(this.positions.values$());
}
public valueFromQuery(query:QueryResource) {
diff --git a/frontend/src/app/shared/components/autocompleter/version-autocompleter/version-autocompleter.component.ts b/frontend/src/app/shared/components/autocompleter/version-autocompleter/version-autocompleter.component.ts
index 7e553303886..50e67ed4057 100644
--- a/frontend/src/app/shared/components/autocompleter/version-autocompleter/version-autocompleter.component.ts
+++ b/frontend/src/app/shared/components/autocompleter/version-autocompleter/version-autocompleter.component.ts
@@ -27,7 +27,12 @@
//++
import {
- AfterViewInit, ChangeDetectorRef, Component, EventEmitter, Injector, Output,
+ AfterViewInit,
+ ChangeDetectorRef,
+ Component,
+ EventEmitter,
+ Injector,
+ Output,
} from '@angular/core';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { CreateAutocompleterComponent } from 'core-app/shared/components/autocompleter/create-autocompleter/create-autocompleter.component';
@@ -36,6 +41,7 @@ import { VersionResource } from 'core-app/features/hal/resources/version-resourc
import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { firstValueFrom } from 'rxjs';
@Component({
templateUrl: '../create-autocompleter/create-autocompleter.component.html',
@@ -77,12 +83,13 @@ export class VersionAutocompleterComponent extends CreateAutocompleterComponent
return Promise.resolve(false);
}
- return this
- .apiV3Service
- .versions
- .available_projects
- .exists(this.currentProject.id)
- .toPromise()
+ return firstValueFrom(
+ this
+ .apiV3Service
+ .versions
+ .available_projects
+ .exists(this.currentProject.id),
+ )
.catch(() => false);
}
diff --git a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
index 8aef08a1a46..c8262fc1354 100644
--- a/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
+++ b/frontend/src/app/shared/components/fields/changeset/resource-changeset.ts
@@ -39,6 +39,7 @@ import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { SchemaProxy } from 'core-app/features/hal/schemas/schema-proxy';
import { IHalOptionalTitledLink } from 'core-app/core/state/hal-resource';
import isNewResource from 'core-app/features/hal/helpers/is-new-resource';
+import { firstValueFrom } from 'rxjs';
export const PROXY_IDENTIFIER = '__is_changeset_proxy';
@@ -143,11 +144,7 @@ export class ResourceChangeset<T extends HalResource = HalResource> {
return this.updateForm();
}
- return this
- .form$
- .values$()
- .pipe(take(1))
- .toPromise();
+ return firstValueFrom(this.form$.values$());
}
/**
diff --git a/frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts
index 4c0ee19a66d..bb06c1fe349 100644
--- a/frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts
+++ b/frontend/src/app/shared/components/fields/display/field-types/date-display-field.module.ts
@@ -61,8 +61,7 @@ export class DateDisplayField extends HighlightableDisplayField {
.statuses
.id(this.resource.status.id)
.get()
- .toPromise()
- .then((status) => {
+ .subscribe((status) => {
if (!status.isClosed) {
element.classList.add(Highlighting.overdueDate(diff));
}
diff --git a/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.component.ts b/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.component.ts
index 1c936a72867..8abe7f0e97c 100644
--- a/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/edit-form/edit-form.component.ts
@@ -55,6 +55,7 @@ import { EditingPortalService } from 'core-app/shared/components/fields/edit/edi
import { EditFormRoutingService } from 'core-app/shared/components/fields/edit/edit-form/edit-form-routing.service';
import { ResourceChangesetCommit } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { GlobalEditFormChangesTrackerService } from 'core-app/shared/components/fields/edit/services/global-edit-form-changes-tracker/global-edit-form-changes-tracker.service';
+import { firstValueFrom } from 'rxjs';
@Component({
selector: 'edit-form,[edit-form]',
@@ -186,14 +187,13 @@ export class EditFormComponent extends EditForm<HalResource> implements OnInit,
}
public waitForField(name:string):Promise<EditableAttributeFieldComponent> {
- return this.registeredFields
+ return firstValueFrom(this.registeredFields
.values$()
.pipe(
filter((keys) => keys.indexOf(name) >= 0),
take(1),
map(() => this.fields[name]),
- )
- .toPromise();
+ ));
}
public start() {
diff --git a/frontend/src/app/shared/components/fields/edit/field-types/te-work-package-edit-field.component.ts b/frontend/src/app/shared/components/fields/edit/field-types/te-work-package-edit-field.component.ts
index 85df1ea1b9b..09500c58815 100644
--- a/frontend/src/app/shared/components/fields/edit/field-types/te-work-package-edit-field.component.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-types/te-work-package-edit-field.component.ts
@@ -37,6 +37,7 @@ import {
TimeEntryWorkPackageAutocompleterMode,
} from 'core-app/shared/components/autocompleter/te-work-package-autocompleter/te-work-package-autocompleter.component';
import { ApiV3FilterBuilder } from 'core-app/shared/helpers/api-v3/api-v3-filter-builder';
+import { firstValueFrom } from 'rxjs';
const RECENT_TIME_ENTRIES_MAGIC_NUMBER = 30;
@@ -85,20 +86,24 @@ export class TimeEntryWorkPackageEditFieldComponent extends WorkPackageEditField
// a fixed number returned.
protected loadAllowedValues(query?:string) {
if (!this.recentWorkPackageIds) {
- return this
- .apiV3Service
- .time_entries
- .list({ filters: [['user_id', '=', ['me']]], sortBy: [['updated_at', 'desc']], pageSize: RECENT_TIME_ENTRIES_MAGIC_NUMBER })
- .toPromise()
- .then((collection) => {
- this.recentWorkPackageIds = collection
- .elements
- .filter((timeEntry) => timeEntry.workPackage?.href)
- .map((timeEntry) => idFromLink(timeEntry.workPackage.href))
- .filter((v, i, a) => a.indexOf(v) === i);
-
- return this.fetchAllowedValueQuery(query);
- });
+ return firstValueFrom(
+ this
+ .apiV3Service
+ .time_entries
+ .list({
+ filters: [['user_id', '=', ['me']]],
+ sortBy: [['updated_at', 'desc']],
+ pageSize: RECENT_TIME_ENTRIES_MAGIC_NUMBER,
+ }),
+ ).then((collection) => {
+ this.recentWorkPackageIds = collection
+ .elements
+ .filter((timeEntry) => timeEntry.workPackage?.href)
+ .map((timeEntry) => idFromLink(timeEntry.workPackage.href))
+ .filter((v, i, a) => a.indexOf(v) === i);
+
+ return this.fetchAllowedValueQuery(query);
+ });
}
return this.fetchAllowedValueQuery(query);
}
diff --git a/frontend/src/app/shared/components/fields/macros/attribute-label-macro.component.ts b/frontend/src/app/shared/components/fields/macros/attribute-label-macro.component.ts
index dcfa70905c7..a9f78ca3035 100644
--- a/frontend/src/app/shared/components/fields/macros/attribute-label-macro.component.ts
+++ b/frontend/src/app/shared/components/fields/macros/attribute-label-macro.component.ts
@@ -33,6 +33,7 @@ import {
ElementRef,
HostBinding,
Injector,
+ OnInit,
} from '@angular/core';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
@@ -44,6 +45,7 @@ import {
SupportedAttributeModels,
} from 'core-app/shared/components/fields/macros/attribute-model-loader.service';
import { capitalize } from 'core-app/shared/helpers/string-helpers';
+import { firstValueFrom } from 'rxjs';
export const attributeLabelMacro = 'macro.macro--attribute-label';
@@ -56,7 +58,7 @@ export const attributeLabelMacro = 'macro.macro--attribute-label';
HalResourceEditingService,
],
})
-export class AttributeLabelMacroComponent {
+export class AttributeLabelMacroComponent implements OnInit {
// Whether the value could not be loaded
error:string|null = null;
@@ -78,36 +80,40 @@ export class AttributeLabelMacroComponent {
attribute:string;
// The label to render
- label:string;
+ label:string|undefined;
- constructor(readonly elementRef:ElementRef,
+ constructor(
+ readonly elementRef:ElementRef,
readonly injector:Injector,
readonly resourceLoader:AttributeModelLoaderService,
readonly schemaCache:SchemaCacheService,
readonly displayField:DisplayFieldService,
readonly I18n:I18nService,
- readonly cdRef:ChangeDetectorRef) {
-
+ readonly cdRef:ChangeDetectorRef,
+ ) {
}
- ngOnInit() {
+ ngOnInit():void {
const element = this.elementRef.nativeElement as HTMLElement;
- const model:SupportedAttributeModels = element.dataset.model as any;
- const id:string = element.dataset.id!;
- const attributeName:string = element.dataset.attribute!;
+ const model = element.dataset.model as SupportedAttributeModels;
+ const id = element.dataset.id as string;
+ const attributeName = element.dataset.attribute as string;
this.attributeScope = capitalize(model);
- this.loadResourceAttribute(model, id, attributeName);
+ void this.loadResourceAttribute(model, id, attributeName);
}
- private async loadResourceAttribute(model:SupportedAttributeModels, id:string, attributeName:string) {
+ private async loadResourceAttribute(model:SupportedAttributeModels, id:string, attributeName:string):Promise<void> {
let resource:HalResource|null;
try {
- this.resource = resource = await this.resourceLoader.require(model, id);
+ // eslint-disable-next-line no-multi-assign
+ this.resource = resource = await firstValueFrom(this.resourceLoader.require(model, id));
} catch (e) {
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.error(`Failed to render macro ${e}`);
- return this.markError(this.text.not_found);
+ this.markError(this.text.not_found);
+ return;
}
if (!resource) {
@@ -117,7 +123,8 @@ export class AttributeLabelMacroComponent {
const schema = await this.schemaCache.ensureLoaded(resource);
this.attribute = schema.attributeFromLocalizedName(attributeName) || attributeName;
- this.label = schema[this.attribute]?.name;
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ this.label = schema[this.attribute]?.name as string|undefined;
if (!this.label) {
this.markError(this.text.invalid_attribute(attributeName));
diff --git a/frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts b/frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts
index bf20e130851..0cc334fc750 100644
--- a/frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts
+++ b/frontend/src/app/shared/components/fields/macros/attribute-model-loader.service.ts
@@ -28,9 +28,18 @@
import { Injectable } from '@angular/core';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { NEVER, Observable, throwError } from 'rxjs';
import {
- filter, map, take, tap,
+ firstValueFrom,
+ NEVER,
+ Observable,
+ throwError,
+} from 'rxjs';
+import {
+ filter,
+ map,
+ shareReplay,
+ take,
+ tap,
} from 'rxjs/operators';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { multiInput } from 'reactivestates';
@@ -69,20 +78,21 @@ export class AttributeModelLoaderService {
* @param model
* @param id
*/
- require(model:SupportedAttributeModels, id:string):Promise<HalResource|null> {
+ require(model:SupportedAttributeModels, id:string):Observable<HalResource|null> {
const identifier = `${model}-${id}`;
const state = this.cache$.get(identifier);
if (state.isPristine()) {
- const promise = this
+ const observable = this
.load(model, id)
.pipe(
filter((response) => !!response),
- )
- .toPromise();
- state.clearAndPutFromPromise(promise as PromiseLike<HalResource>);
+ shareReplay(1),
+ );
- return promise;
+ state.clearAndPutFromPromise(firstValueFrom(observable) as PromiseLike<HalResource>);
+
+ return observable;
}
return state
@@ -90,8 +100,7 @@ export class AttributeModelLoaderService {
.pipe(
take(1),
tap((val) => console.log(`VAL ${val}`), (err) => console.error(`ERR ${err}`)),
- )
- .toPromise();
+ );
}
private load(model:SupportedAttributeModels, id?:string|undefined|null):Observable<HalResource|null> {
diff --git a/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts b/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts
index 95cafe02ad4..ee20119a94e 100644
--- a/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts
+++ b/frontend/src/app/shared/components/fields/macros/attribute-value-macro.component.ts
@@ -33,6 +33,7 @@ import {
ElementRef,
HostBinding,
Injector,
+ OnInit,
ViewChild,
} from '@angular/core';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
@@ -45,6 +46,7 @@ import {
AttributeModelLoaderService,
SupportedAttributeModels,
} from 'core-app/shared/components/fields/macros/attribute-model-loader.service';
+import { firstValueFrom } from 'rxjs';
export const attributeValueMacro = 'macro.macro--attribute-value';
@@ -57,7 +59,7 @@ export const attributeValueMacro = 'macro.macro--attribute-value';
HalResourceEditingService,
],
})
-export class AttributeValueMacroComponent {
+export class AttributeValueMacroComponent implements OnInit {
@ViewChild('displayContainer') private displayContainer:ElementRef<HTMLSpanElement>;
// Whether the value could not be loaded
@@ -76,33 +78,36 @@ export class AttributeValueMacroComponent {
fieldName:string;
- constructor(readonly elementRef:ElementRef,
+ constructor(
+ readonly elementRef:ElementRef,
readonly injector:Injector,
readonly resourceLoader:AttributeModelLoaderService,
readonly schemaCache:SchemaCacheService,
readonly displayField:DisplayFieldService,
readonly I18n:I18nService,
- readonly cdRef:ChangeDetectorRef) {
-
+ readonly cdRef:ChangeDetectorRef,
+ ) {
}
- ngOnInit() {
+ ngOnInit():void {
const element = this.elementRef.nativeElement as HTMLElement;
- const model:SupportedAttributeModels = element.dataset.model as any;
- const id:string = element.dataset.id!;
- const attributeName:string = element.dataset.attribute!;
+ const model = element.dataset.model as SupportedAttributeModels;
+ const id = element.dataset.id as string;
+ const attributeName = element.dataset.attribute as string;
- this.loadAndRender(model, id, attributeName);
+ void this.loadAndRender(model, id, attributeName);
}
- private async loadAndRender(model:SupportedAttributeModels, id:string, attributeName:string) {
+ private async loadAndRender(model:SupportedAttributeModels, id:string, attributeName:string):Promise<void> {
let resource:HalResource|null;
try {
- resource = await this.resourceLoader.require(model, id);
+ resource = await firstValueFrom(this.resourceLoader.require(model, id));
} catch (e) {
+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.error(`Failed to render macro ${e}`);
- return this.markError(this.text.not_found);
+ this.markError(this.text.not_found);
+ return;
}
if (!resource) {
diff --git a/frontend/src/app/shared/components/grids/grid/initialization.service.ts b/frontend/src/app/shared/components/grids/grid/initialization.service.ts
index a962ca98009..2216f721124 100644
--- a/frontend/src/app/shared/components/grids/grid/initialization.service.ts
+++ b/frontend/src/app/shared/components/grids/grid/initialization.service.ts
@@ -3,10 +3,15 @@ import { GridResource } from 'core-app/features/hal/resources/grid-resource';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { switchMap } from 'rxjs/operators';
+import {
+ Observable,
+ of,
+} from 'rxjs';
@Injectable()
export class GridInitializationService {
- constructor(readonly apiV3Service:ApiV3Service,
+ constructor(
+ readonly apiV3Service:ApiV3Service,
readonly halResourceService:HalResourceService) {
}
@@ -14,21 +19,22 @@ export class GridInitializationService {
// that page will be used to initialized the grid.
// If it does not exist, fetch the form and then create a new resource.
// The created resource is then used to initialize the grid.
- public initialize(path:string) {
+ public initialize(path:string):Observable<GridResource> {
return this
.apiV3Service
.grids
.list({ filters: [['scope', '=', [path]]] })
- .toPromise()
- .then((collection) => {
- if (collection.total === 0) {
- return this.myPageForm(path);
- }
- return (collection.elements[0]);
- });
+ .pipe(
+ switchMap((collection) => {
+ if (collection.total === 0) {
+ return this.myPageForm(path);
+ }
+ return of(collection.elements[0]);
+ }),
+ );
}
- private myPageForm(path:string):Promise<GridResource> {
+ private myPageForm(path:string):Observable<GridResource> {
const payload = {
_links: {
scope: {
@@ -57,7 +63,6 @@ export class GridInitializationService {
.grids
.post(resource, form.schema);
}),
- )
- .toPromise();
+ );
}
}
diff --git a/frontend/src/app/shared/components/grids/grid/page/grid-page.component.ts b/frontend/src/app/shared/components/grids/grid/page/grid-page.component.ts
index 2a75e85c800..b8a738012aa 100644
--- a/frontend/src/app/shared/components/grids/grid/page/grid-page.component.ts
+++ b/frontend/src/app/shared/components/grids/grid/page/grid-page.component.ts
@@ -35,7 +35,7 @@ export abstract class GridPageComponent implements OnInit, OnDestroy {
this
.gridInitialization
.initialize(this.gridScopePath())
- .then((grid) => {
+ .subscribe((grid) => {
this.grid = grid;
this.cdRef.detectChanges();
});
diff --git a/frontend/src/app/shared/components/grids/widgets/documents/documents.component.ts b/frontend/src/app/shared/components/grids/widgets/documents/documents.component.ts
index 9fd942e22d1..80c29a24c4b 100644
--- a/frontend/src/app/shared/components/grids/widgets/documents/documents.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/documents/documents.component.ts
@@ -45,8 +45,7 @@ export class WidgetDocumentsComponent extends AbstractWidgetComponent implements
ngOnInit() {
this.halResource
.get<CollectionResource>(this.documentsUrl)
- .toPromise()
- .then((collection) => {
+ .subscribe((collection) => {
this.entries = collection.elements as DocumentResource[];
this.entriesLoaded = true;
diff --git a/frontend/src/app/shared/components/grids/widgets/project-details/project-details-menu.component.ts b/frontend/src/app/shared/components/grids/widgets/project-details/project-details-menu.component.ts
index ddb8560ccb3..0aff0d196dc 100644
--- a/frontend/src/app/shared/components/grids/widgets/project-details/project-details-menu.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/project-details/project-details-menu.component.ts
@@ -26,7 +26,10 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { Component, OnInit } from '@angular/core';
+import {
+ Component,
+ OnInit,
+} from '@angular/core';
import { WidgetAbstractMenuComponent } from 'core-app/shared/components/grids/widgets/menu/widget-abstract-menu.component';
import { OpContextMenuItem } from 'core-app/shared/components/op-context-menu/op-context-menu.types';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
@@ -34,6 +37,7 @@ import { PathHelperService } from 'core-app/core/path-helper/path-helper.service
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { CurrentUserService } from 'core-app/core/current-user/current-user.service';
import { take } from 'rxjs/operators';
+import { firstValueFrom } from 'rxjs';
@Component({
selector: 'op-widget-project-details-menu',
@@ -49,10 +53,11 @@ export class WidgetProjectDetailsMenuComponent extends WidgetAbstractMenuCompone
private capabilityPromise:Promise<boolean>;
ngOnInit():void {
- this.capabilityPromise = this.currentUser
- .hasCapabilities$('activities/read', this.currentProject.id)
- .pipe(take(1))
- .toPromise();
+ this.capabilityPromise = firstValueFrom(
+ this.currentUser
+ .hasCapabilities$('activities/read', this.currentProject.id)
+ .pipe(take(1)),
+ );
}
public get menuItems() {
diff --git a/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts b/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts
index 84e51c70f04..969b8997810 100644
--- a/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/time-entries/list/time-entries-list.component.ts
@@ -16,6 +16,10 @@ import { ConfirmDialogService } from 'core-app/shared/components/modals/confirm-
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
import { SchemaResource } from 'core-app/features/hal/resources/schema-resource';
+import {
+ firstValueFrom,
+ Observable,
+} from 'rxjs';
@Directive()
export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetComponent implements OnInit {
@@ -60,7 +64,7 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
this.buildEntries(collection.elements);
if (collection.count > 0) {
- this.schema = await this.loadSchema();
+ this.schema = await firstValueFrom(this.loadSchema());
}
this.entriesLoaded = true;
@@ -202,12 +206,11 @@ export abstract class WidgetTimeEntriesListComponent extends AbstractWidgetCompo
return !this.entries.length && this.entriesLoaded;
}
- private loadSchema():Promise<SchemaResource> {
+ private loadSchema():Observable<SchemaResource> {
return this
.apiV3Service
.time_entries
.schema
- .get()
- .toPromise();
+ .get();
}
}
diff --git a/frontend/src/app/shared/components/grids/widgets/wp-table/wp-table.component.ts b/frontend/src/app/shared/components/grids/widgets/wp-table/wp-table.component.ts
index ee5069526a9..29ee4163c27 100644
--- a/frontend/src/app/shared/components/grids/widgets/wp-table/wp-table.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/wp-table/wp-table.component.ts
@@ -1,14 +1,25 @@
-import { ChangeDetectionStrategy, Component, Injector } from '@angular/core';
+import {
+ ChangeDetectionStrategy,
+ Component,
+ Injector,
+ OnInit,
+} from '@angular/core';
import { AbstractWidgetComponent } from 'core-app/shared/components/grids/widgets/abstract-widget.component';
import { QueryFormResource } from 'core-app/features/hal/resources/query-form-resource';
import { QueryResource } from 'core-app/features/hal/resources/query-resource';
import { WorkPackageTableConfiguration } from 'core-app/features/work-packages/components/wp-table/wp-table-configuration';
-import { Observable } from 'rxjs';
+import {
+ Observable,
+ switchMap,
+} from 'rxjs';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { UrlParamsHelperService } from 'core-app/features/work-packages/components/wp-query/url-params-helper';
import { IsolatedQuerySpace } from 'core-app/features/work-packages/directives/query-space/isolated-query-space';
import { StateService } from '@uirouter/core';
-import { skip } from 'rxjs/operators';
+import {
+ map,
+ skip,
+} from 'rxjs/operators';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
@Component({
@@ -17,7 +28,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
styleUrls: ['./wp-table.component.sass'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class WidgetWpTableComponent extends AbstractWidgetComponent {
+export class WidgetWpTableComponent extends AbstractWidgetComponent implements OnInit {
public queryId:string|null;
private queryForm:QueryFormResource;
@@ -42,10 +53,11 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {
super(i18n, injector);
}
- ngOnInit() {
+ ngOnInit():void {
if (!this.resource.options.queryId) {
- this.createInitial()
- .then((query) => {
+ this
+ .createInitial()
+ .subscribe((query) => {
const changeset = this.setChangesetOptions({ queryId: query.id });
this.resourceChanged.emit(changeset);
@@ -67,8 +79,8 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {
skip(2),
this.untilDestroyed(),
).subscribe((query) => {
- this.ensureFormAndSaveQuery(query);
- });
+ this.ensureFormAndSaveQuery(query);
+ });
}
public get widgetName() {
@@ -109,8 +121,8 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {
);
}
- private createInitial():Promise<QueryResource> {
- const projectIdentifier = this.state.params.projectPath;
+ private createInitial():Observable<QueryResource> {
+ const projectIdentifier = this.state.params.projectPath as string;
const initializationProps = this.resource.options.queryProps as { [key:string]:unknown };
const queryProps = {
pageSize: 0,
@@ -127,17 +139,20 @@ export class WidgetWpTableComponent extends AbstractWidgetComponent {
projectIdentifier,
this.queryCreationParams(),
)
- .toPromise()
- .then(([form, query]) => this
- .apiV3Service
- .queries
- .post(query, form)
- .toPromise()
- .then((query) => {
- delete this.resource.options.queryProps;
-
- return query;
- }));
+ .pipe(
+ switchMap(([form, query]) => this
+ .apiV3Service
+ .queries
+ .post(query, form)
+ .pipe(
+ map((resource:QueryResource) => {
+ delete this.resource.options.queryProps;
+
+ return resource;
+ }),
+ ),
+ ),
+ );
}
protected queryCreationParams() {
diff --git a/frontend/src/app/shared/components/time_entries/create/create.service.ts b/frontend/src/app/shared/components/time_entries/create/create.service.ts
index d4f6544f829..43454497d77 100644
--- a/frontend/src/app/shared/components/time_entries/create/create.service.ts
+++ b/frontend/src/app/shared/components/time_entries/create/create.service.ts
@@ -5,7 +5,10 @@ import {
import { OpModalService } from 'core-app/shared/components/modal/modal.service';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { take } from 'rxjs/operators';
+import {
+ map,
+ take,
+} from 'rxjs/operators';
import { FormResource } from 'core-app/features/hal/resources/form-resource';
import { ResourceChangeset } from 'core-app/shared/components/fields/changeset/resource-changeset';
import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
@@ -17,16 +20,19 @@ import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource';
import { TimeEntryModalOptions } from 'core-app/shared/components/time_entries/edit/edit.service';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+import { Observable } from 'rxjs';
@Injectable()
export class TimeEntryCreateService {
- constructor(readonly opModalService:OpModalService,
+ constructor(
+ readonly opModalService:OpModalService,
readonly injector:Injector,
readonly halResource:HalResourceService,
readonly apiV3Service:ApiV3Service,
readonly schemaCache:SchemaCacheService,
protected halEditing:HalResourceEditingService,
- readonly i18n:I18nService) {
+ readonly i18n:I18nService,
+ ) {
}
public create(
@@ -37,7 +43,7 @@ export class TimeEntryCreateService {
return new Promise<{ entry:TimeEntryResource, action:'create' }>((resolve, reject) => {
void this
.createNewTimeEntry(date, wp)
- .then((changeset) => {
+ .subscribe((changeset) => {
this.opModalService.show(
TimeEntryCreateModalComponent,
this.injector,
@@ -53,12 +59,12 @@ export class TimeEntryCreateService {
reject();
}
});
- });
+ });
});
});
}
- public createNewTimeEntry(date:Moment, wp?:WorkPackageResource):Promise<ResourceChangeset> {
+ public createNewTimeEntry(date:Moment, wp?:WorkPackageResource):Observable<ResourceChangeset> {
const payload:any = {
spentOn: date.format('YYYY-MM-DD'),
};
@@ -77,8 +83,9 @@ export class TimeEntryCreateService {
.time_entries
.form
.post(payload)
- .toPromise()
- .then((form) => this.fromCreateForm(form));
+ .pipe(
+ map((form) => this.fromCreateForm(form)),
+ );
}
public fromCreateForm(form:FormResource):ResourceChangeset {
diff --git a/frontend/src/app/shared/components/time_entries/edit/trigger-actions-entry.component.ts b/frontend/src/app/shared/components/time_entries/edit/trigger-actions-entry.component.ts
index ef20fff1d1d..b7a69bb25ba 100644
--- a/frontend/src/app/shared/components/time_entries/edit/trigger-actions-entry.component.ts
+++ b/frontend/src/app/shared/components/time_entries/edit/trigger-actions-entry.component.ts
@@ -1,5 +1,9 @@
import {
- ChangeDetectionStrategy, ChangeDetectorRef, Component, ElementRef, Injector,
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ ElementRef,
+ Injector,
} from '@angular/core';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { TimeEntryEditService } from 'core-app/shared/components/time_entries/edit/edit.service';
@@ -8,6 +12,10 @@ import { ToastService } from 'core-app/shared/components/toaster/toast.service';
import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { TimeEntryResource } from 'core-app/features/hal/resources/time-entry-resource';
+import {
+ Observable,
+ switchMap,
+} from 'rxjs';
export const triggerActionsEntryComponentSelector = 'time-entry--trigger-actions-entry';
@@ -55,8 +63,9 @@ export class TriggerActionsEntryComponent {
}
editTimeEntry() {
- this.loadEntry()
- .then((entry) => {
+ void this
+ .loadEntry()
+ .subscribe((entry) => {
this.timeEntryEditService
.edit(entry)
.then(() => {
@@ -74,27 +83,26 @@ export class TriggerActionsEntryComponent {
}
this.loadEntry()
- .then((entry) => {
- this
+ .pipe(
+ switchMap((entry) => this
.apiv3Service
.time_entries
.id(entry)
- .delete()
- .subscribe(
- () => window.location.reload(),
- (error) => this.toastService.addError(error || this.text.error),
- );
- });
+ .delete()),
+ )
+ .subscribe(
+ () => window.location.reload(),
+ (error) => this.toastService.addError(error || this.text.error),
+ );
}
- protected loadEntry():Promise<TimeEntryResource> {
- const timeEntryId = this.elementRef.nativeElement.dataset.entry;
+ protected loadEntry():Observable<TimeEntryResource> {
+ const timeEntryId = (this.elementRef.nativeElement as HTMLElement).dataset.entry as string;
return this
.apiv3Service
.time_entries
.id(timeEntryId)
- .get()
- .toPromise();
+ .get();
}
}
diff --git a/frontend/src/app/shared/components/work-package-graphs/configuration/wp-graph-configuration.service.ts b/frontend/src/app/shared/components/work-package-graphs/configuration/wp-graph-configuration.service.ts
index 27d6a6f3021..f9fd428d7d1 100644
--- a/frontend/src/app/shared/components/work-package-graphs/configuration/wp-graph-configuration.service.ts
+++ b/frontend/src/app/shared/components/work-package-graphs/configuration/wp-graph-configuration.service.ts
@@ -14,6 +14,11 @@ import { CurrentProjectService } from 'core-app/core/current-project/current-pro
import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { WorkPackageEmbeddedGraphDataset } from 'core-app/shared/components/work-package-graphs/embedded/wp-embedded-graph.component';
+import {
+ firstValueFrom,
+ Observable,
+ switchMap,
+} from 'rxjs';
@Injectable()
export class WpGraphConfigurationService {
@@ -58,7 +63,7 @@ export class WpGraphConfigurationService {
public ensureQueryAndLoad():Promise<unknown> {
if (this.queryParams.length === 0) {
- return this.createInitial()
+ return firstValueFrom(this.createInitial())
.then((query) => {
this.queryParams.push({ id: query.id! });
@@ -68,7 +73,7 @@ export class WpGraphConfigurationService {
return this.loadQueries();
}
- private createInitial():Promise<QueryResource> {
+ private createInitial():Observable<QueryResource> {
return this
.apiv3Service
.queries
@@ -79,12 +84,9 @@ export class WpGraphConfigurationService {
this.currentProject.identifier,
WpGraphConfiguration.queryCreationParams(this.I18n, !!this.currentProject.identifier),
)
- .toPromise()
- .then(([form, query]) => this
- .apiv3Service
- .queries
- .post(query, form)
- .toPromise());
+ .pipe(
+ switchMap(([form, query]) => this.apiv3Service.queries.post(query, form)),
+ );
}
private loadQueries() {
@@ -93,16 +95,15 @@ export class WpGraphConfigurationService {
return Promise.all(queryPromises);
}
- private loadQuery(params:WpGraphQueryParams) {
- return this
+ private loadQuery(params:WpGraphQueryParams):Promise<unknown> {
+ return firstValueFrom(this
.apiv3Service
.queries
.find(
{ pageSize: 0, ...params.props },
params.id,
this.currentProject.identifier,
- )
- .toPromise()
+ ))
.then((query) => {
if (params.name) {
// eslint-ignore-next-line no-param-reassign
@@ -157,16 +158,16 @@ export class WpGraphConfigurationService {
public loadForms():Promise<unknown> {
if (!this._formsPromise) {
- const formPromises = this.configuration.queries.map((query) => this
- .apiv3Service
+ const formPromises = this
+ .configuration
.queries
- .form
- .load(query)
- .toPromise()
- .then(([form]) => {
- this._forms[query.id as string] = form;
- })
- .catch((error) => this.notificationService.handleRawError(error)));
+ .map(
+ (query) => firstValueFrom(this.apiv3Service.queries.form.load(query))
+ .then(([form]) => {
+ this._forms[query.id as string] = form;
+ })
+ .catch((error) => this.notificationService.handleRawError(error)),
+ );
this._formsPromise = Promise.all(formPromises);
}
diff --git a/frontend/src/app/shared/helpers/rxjs/debounced-event-emitter.ts b/frontend/src/app/shared/helpers/rxjs/debounced-event-emitter.ts
index 6c8ac1904d2..82db7b7da10 100644
--- a/frontend/src/app/shared/helpers/rxjs/debounced-event-emitter.ts
+++ b/frontend/src/app/shared/helpers/rxjs/debounced-event-emitter.ts
@@ -17,7 +17,7 @@ export class DebouncedEventEmitter<T> {
.subscribe((val) => this.emitter.emit(val));
}
- public emit(value?:T):void {
+ public emit(value:T):void {
this.debouncer.next(value);
}