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

Extract href generator for derived value query

Aaron Contreras3abb27eb8bb8
diff --git a/frontend/src/app/shared/components/fields/display/field-types/compound-progress-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/compound-progress-display-field.module.ts
index 978b713e2f1..77d60c9310d 100644
--- a/frontend/src/app/shared/components/fields/display/field-types/compound-progress-display-field.module.ts
+++ b/frontend/src/app/shared/components/fields/display/field-types/compound-progress-display-field.module.ts
@@ -30,15 +30,16 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { DisplayField } from 'core-app/shared/components/fields/display/display-field.module';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
import { uiStateLinkClass } from 'core-app/features/work-packages/components/wp-fast-table/builders/ui-state-link-builder';
-import * as URI from 'urijs';
+import { HierarchyQueryLinkHelperService } from 'core-app/shared/components/fields/display/field-types/hierarchy-query-link-helper.service';
export class CompoundProgressDisplayField extends DisplayField {
@InjectField() PathHelper:PathHelperService;
@InjectField() apiV3Service:ApiV3Service;
+ @InjectField() hierarchyQueryLinkHelper:HierarchyQueryLinkHelperService;
+
private derivedText = this.I18n.t('js.label_value_derived_from_children');
public render(element:HTMLElement, displayText:string):void {
@@ -70,7 +71,8 @@ export class CompoundProgressDisplayField extends DisplayField {
link.title = `${displayText} ${this.derivedText}`;
link.classList.add('-derived-value', uiStateLinkClass);
- this.addURLToViewWorkPackageChildren(link);
+ this.hierarchyQueryLinkHelper.addHref(link, this.resource);
+ // this.addURLToViewWorkPackageChildren(link);
element.appendChild(link);
}
@@ -85,31 +87,6 @@ export class CompoundProgressDisplayField extends DisplayField {
element.appendChild(span);
}
- private addURLToViewWorkPackageChildren(link:HTMLAnchorElement):void {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- if (this.resource && this.resource.id && this.resource.project) {
- const wpID = this.resource.id.toString();
- this
- .apiV3Service
- .projects
- .id(this.resource.project as ProjectResource)
- .get()
- .subscribe((project:ProjectResource) => {
- const props = {
- c: ['id', 'subject', 'type', 'status', 'estimatedTime', 'remainingTime', 'percentageDone'],
- hi: true,
- is: true,
- f: [{ n: 'parent', o: '=', v: [wpID] }],
- };
- const href = URI(this.PathHelper.projectWorkPackagesPath(project.identifier as string))
- .query({ query_props: JSON.stringify(props) })
- .toString();
-
- link.href = href;
- });
- }
- }
-
public get value():number {
return this.resource[this.name] as number || 0;
}
diff --git a/frontend/src/app/shared/components/fields/display/field-types/estimated-time-display-field.module.ts b/frontend/src/app/shared/components/fields/display/field-types/estimated-time-display-field.module.ts
index 73463c63d50..b76877c43e8 100644
--- a/frontend/src/app/shared/components/fields/display/field-types/estimated-time-display-field.module.ts
+++ b/frontend/src/app/shared/components/fields/display/field-types/estimated-time-display-field.module.ts
@@ -28,12 +28,11 @@
import { DisplayField } from 'core-app/shared/components/fields/display/display-field.module';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
-import * as URI from 'urijs';
import { TimezoneService } from 'core-app/core/datetime/timezone.service';
-import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { uiStateLinkClass } from 'core-app/features/work-packages/components/wp-fast-table/builders/ui-state-link-builder';
+import { HierarchyQueryLinkHelperService } from 'core-app/shared/components/fields/display/field-types/hierarchy-query-link-helper.service';
export class EstimatedTimeDisplayField extends DisplayField {
@InjectField() timezoneService:TimezoneService;
@@ -42,6 +41,8 @@ export class EstimatedTimeDisplayField extends DisplayField {
@InjectField() apiV3Service:ApiV3Service;
+ @InjectField() hierarchyQueryLinkHelper:HierarchyQueryLinkHelperService;
+
private derivedText = this.I18n.t('js.label_value_derived_from_children');
public get valueString():string {
@@ -115,7 +116,7 @@ export class EstimatedTimeDisplayField extends DisplayField {
link.title = `${this.derivedValueString} ${this.derivedText}`;
link.classList.add('-derived-value', uiStateLinkClass);
- this.addURLToViewWorkPackageChildren(link);
+ this.hierarchyQueryLinkHelper.addHref(link, this.resource);
element.appendChild(link);
}
@@ -131,29 +132,4 @@ export class EstimatedTimeDisplayField extends DisplayField {
return !value && !derived;
}
-
- private addURLToViewWorkPackageChildren(link:HTMLAnchorElement):void {
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
- if (this.resource && this.resource.id && this.resource.project) {
- const wpID = this.resource.id.toString();
- this
- .apiV3Service
- .projects
- .id(this.resource.project as ProjectResource)
- .get()
- .subscribe((project:ProjectResource) => {
- const props = {
- c: ['id', 'subject', 'type', 'status', 'estimatedTime', 'remainingTime'],
- hi: true,
- is: true,
- f: [{ n: 'parent', o: '=', v: [wpID] }],
- };
- const href = URI(this.PathHelper.projectWorkPackagesPath(project.identifier as string))
- .query({ query_props: JSON.stringify(props) })
- .toString();
-
- link.href = href;
- });
- }
- }
}
diff --git a/frontend/src/app/shared/components/fields/display/field-types/hierarchy-query-link-helper.service.ts b/frontend/src/app/shared/components/fields/display/field-types/hierarchy-query-link-helper.service.ts
new file mode 100644
index 00000000000..bd14ee69096
--- /dev/null
+++ b/frontend/src/app/shared/components/fields/display/field-types/hierarchy-query-link-helper.service.ts
@@ -0,0 +1,65 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2024 the OpenProject GmbH
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License version 3.
+//
+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+// Copyright (C) 2006-2013 Jean-Philippe Lang
+// Copyright (C) 2010-2013 the ChiliProject Team
+//
+// This program is free software; you can redistribute it and/or
+// modify it under the terms of the GNU General Public License
+// as published by the Free Software Foundation; either version 2
+// of the License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+// See COPYRIGHT and LICENSE files for more details.
+//++
+
+import { Injectable } from '@angular/core';
+import * as URI from 'urijs';
+import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
+import { ProjectResource } from 'core-app/features/hal/resources/project-resource';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+import { HalResource } from 'core-app/features/hal/resources/hal-resource';
+
+@Injectable({ providedIn: 'root' })
+
+export class HierarchyQueryLinkHelperService {
+ constructor(
+ private apiV3Service:ApiV3Service,
+ private pathHelper:PathHelperService,
+ ) {}
+
+ public addHref(link:HTMLAnchorElement, resource:HalResource):void {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
+ if (resource && resource.id && resource.project) {
+ const wpID = resource.id.toString();
+ this.apiV3Service.projects.id(resource.project as ProjectResource).get().subscribe(
+ (project:ProjectResource) => {
+ const props = {
+ c: ['id', 'subject', 'type', 'status', 'estimatedTime', 'remainingTime', 'percentageDone'],
+ hi: true,
+ is: true,
+ f: [{ n: 'parent', o: '=', v: [wpID] }],
+ };
+ const href = URI(this.pathHelper.projectWorkPackagesPath(project.identifier as string))
+ .query({ query_props: JSON.stringify(props) })
+ .toString();
+
+ link.href = href;
+ },
+ );
+ }
+ }
+}