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

show number of all relations in relation tab in wp full view

Behrokh Satarnejad8c6ea18e9a15
diff --git a/app/controllers/work_packages/split_view_controller.rb b/app/controllers/work_packages/split_view_controller.rb
index 4a5a9057d95..08304abc6f0 100644
--- a/app/controllers/work_packages/split_view_controller.rb
+++ b/app/controllers/work_packages/split_view_controller.rb
@@ -30,8 +30,8 @@ require "rack/utils"
class WorkPackages::SplitViewController < ApplicationController
# Authorization is checked in the find_work_package action
- no_authorization_required! :update_counter
- before_action :find_work_package, only: %i[update_counter]
+ no_authorization_required! :update_counter, :get_counter
+ before_action :find_work_package
def update_counter
respond_to do |format|
@@ -45,6 +45,10 @@ class WorkPackages::SplitViewController < ApplicationController
end
end
+ def get_counter
+ render plain: WorkPackageRelationsTab::RelationsMediator.new(work_package: @work_package).all_relations_count
+ end
+
private
def find_work_package
diff --git a/config/routes.rb b/config/routes.rb
index cb8eabdbace..52ee10b14cb 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -658,6 +658,9 @@ Rails.application.routes.draw do
get "/split_view/update_counter" => "work_packages/split_view#update_counter",
on: :member
+ get "/split_view/get_counter" => "work_packages/split_view#get_counter",
+ on: :member
+
# states managed by client-side (angular) routing on work_package#show
get "/" => "work_packages#index", on: :collection, as: "index"
get "/create_new" => "work_packages#index", on: :collection, as: "new_split"
diff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.ts
index d98bd51724e..cfe63b0dbc1 100644
--- a/frontend/src/app/core/path-helper/path-helper.service.ts
+++ b/frontend/src/app/core/path-helper/path-helper.service.ts
@@ -304,6 +304,10 @@ export class PathHelperService {
return `${this.workPackagePath(workPackageId)}/split_view/update_counter?counter=${counter}`;
}
+ public workPackageGetCounterPath(workPackageId:string|number) {
+ return `${this.workPackagePath(workPackageId)}/split_view/get_counter`;
+ }
+
// Work Package Bulk paths
public workPackagesBulkEditPath() {
diff --git a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts
index f8aa7a4267c..7977fbafd24 100644
--- a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts
+++ b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-relations-count.function.ts
@@ -1,35 +1,24 @@
import { Injector } from '@angular/core';
-import { combineLatest, Observable } from 'rxjs';
+import { Observable, from } from 'rxjs';
import { map } from 'rxjs/operators';
import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { WorkPackageRelationsService } from 'core-app/features/work-packages/components/wp-relations/wp-relations.service';
+import { TurboRequestsService } from 'core-app/core/turbo/turbo-requests.service';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
export function workPackageRelationsCount(
workPackage:WorkPackageResource,
injector:Injector,
):Observable<number> {
- const wpRelations = injector.get(WorkPackageRelationsService);
- const apiV3Service = injector.get(ApiV3Service);
+ const PathHelper = injector.get(PathHelperService);
+ const turboRequests= injector.get(TurboRequestsService);
const wpId = workPackage.id!.toString();
- wpRelations.require(wpId);
-
- return combineLatest([
- wpRelations
- .state(wpId.toString())
- .values$(),
- apiV3Service
- .work_packages
- .id(wpId)
- .requireAndStream(),
- ])
- .pipe(
- map(([relations, workPackage]) => {
- const relationCount = _.size(relations);
- const childrenCount = _.size(workPackage.children);
-
- return relationCount + childrenCount;
- }),
- );
+ const url = PathHelper.workPackageGetCounterPath(wpId.toString());
+ const turbo= turboRequests.request(url);
+ const observable = from(turbo);
+ return observable.pipe(
+ map((response) => {
+ return parseInt(response.html, 10);
+ }),
+ );
}