Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ export class WorkPackageFilterValues {
if (filter.id === 'project') {
if (operator !== '=') return;

const currentProjectId = this.currentProject.id;
const projectFilter = _.find(filter.values, (resource:HalResource|string) => {
return ((resource instanceof HalResource) ? resource.href : resource) === this.currentProject.apiv3Path;
const href = (resource instanceof HalResource) ? resource.href : resource;
const hrefParts = href?.split('/');
return hrefParts?.[hrefParts.length - 1] === currentProjectId;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is the option of moving this into the CurrentProjectService so that other callers can profit from it. Currently though, this was the only place I could find.

The other use case within this PR is different in that it actually needs the api href rather than just knowing if it is the current workspace.

});
this.setValue(change, 'project', projectFilter || filter.values[0]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
slot="body"
class="spot-body-small"
>
@if (project.href === currentProjectHref) {
@if (project.href === queryWorkspaceHref) {
<span>{{ text.current_project }}</span>
} @else {
@if (includeSubprojects && parentChecked) {
Expand All @@ -61,6 +61,7 @@
[includeSubprojects]="includeSubprojects"
[parentChecked]="parentChecked || isChecked(project.href)"
[searchText]="searchText"
[queryWorkspaceHref]="queryWorkspaceHref"
(update)="updateList($event)"
></ul>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ export class OpProjectIncludeListComponent {

@Input() parentChecked = false;

public get currentProjectHref():string|null {
return this.currentProjectService.apiv3Path;
}
@Input() queryWorkspaceHref:string|null = null;

public text = {
does_not_match_search: this.I18n.t('js.include_projects.tooltip.does_not_match_search'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ <h1 class="op-project-list-modal--title">{{ text.title }}</h1>
[includeSubprojects]="includeSubprojects$ | async"
[searchText]="searchableProjectListService.searchText"
[root]="true"
[queryWorkspaceHref]="queryWorkspaceHref"
(update)="selectedProjects = $event"
data-test-selector="project-include-list"
data-list-root="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import {
import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';
import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';
import { HalResourceService } from 'core-app/features/hal/services/hal-resource.service';
import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
import { IProject } from 'core-app/core/state/projects/project.model';
import {
SearchableProjectListService,
Expand Down Expand Up @@ -131,6 +130,8 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On

private _selectedProjects:string[] = [];

private queryWorkspaceHref:string | null;

public get selectedProjects():string[] {
return this._selectedProjects;
}
Expand All @@ -150,13 +151,12 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
map((queryFilters) => {
const projectFilter = queryFilters.find((queryFilter) => queryFilter._type === 'ProjectQueryFilter');
const selectedProjectHrefs = ((projectFilter?.values || []) as HalResource[]).map((p) => p.href);
const currentProjectHref = this.currentProjectService.apiv3Path;
if (selectedProjectHrefs.includes(currentProjectHref)) {
if (selectedProjectHrefs.includes(this.queryWorkspaceHref)) {
return selectedProjectHrefs;
}
const selectedProjects = [...selectedProjectHrefs];
if (currentProjectHref) {
selectedProjects.push(currentProjectHref);
if (this.queryWorkspaceHref) {
selectedProjects.push(this.queryWorkspaceHref);
}
return selectedProjects;
}),
Expand Down Expand Up @@ -234,7 +234,7 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
return true;
}

if (project.href === this.currentProjectService.apiv3Path) {
if (project.href === this.queryWorkspaceHref) {
return true;
}

Expand Down Expand Up @@ -263,7 +263,6 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
readonly wpTableFilters:WorkPackageViewFiltersService,
readonly wpIncludeSubprojects:WorkPackageViewIncludeSubprojectsService,
readonly halResourceService:HalResourceService,
readonly currentProjectService:CurrentProjectService,
readonly searchableProjectListService:SearchableProjectListService,
) {
super();
Expand Down Expand Up @@ -291,6 +290,15 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
this.includeSubprojects = includeSubprojects;
});

this
.query$
.pipe(
this.untilDestroyed(),
take(1))
.subscribe((query) => {
this.queryWorkspaceHref = query.project?.href;
});

this.onTextInput = this.searchableProjectListService.queriedSearchText$.subscribe(() => this.loading$.next(true));
}

Expand Down Expand Up @@ -321,7 +329,7 @@ export class OpProjectIncludeComponent extends UntilDestroyedMixin implements On
}

public clearSelection():void {
this.selectedProjects = [this.currentProjectService.apiv3Path || ''];
this.selectedProjects = [this.queryWorkspaceHref ?? ''];
}

public onSubmit(e:Event):void {
Expand Down
11 changes: 1 addition & 10 deletions lib/api/v3/queries/filters/query_filter_instance_representer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,8 @@ def initialize(model)
next unless represented.ar_object_filter?

represented.value_objects.map do |value_object|
href = begin
path_name = value_object.class.name.demodulize.underscore

api_v3_paths.send(path_name, value_object.id)
rescue StandardError => e
Rails.logger.error "Failed to get href for value_object #{value_object}: #{e}"
nil
end

link_object = {
href:,
href: api_v3_paths.path_for_object(value_object),
title: value_object.name
}

Expand Down
13 changes: 13 additions & 0 deletions lib/api/v3/utilities/path_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,19 @@ def self.url_for(path, arguments = nil)

root_url.gsub(duplicate_regexp, "") + send(path, arguments)
end

def self.path_for_object(object)
strategy = if self.class.const_defined?("API::V3::Utilities::PathHelper::#{object.class}Strategy")
"API::V3::Utilities::PathHelper::#{object.class}Strategy".constantize
else
API::V3::Utilities::PathHelper::DefaultStrategy
end

send(strategy.path_name_for_object(object), object.id)
rescue StandardError => e
Rails.logger.error "Failed to get path for object #{object}: #{e}"
nil
end
end

def api_v3_paths
Expand Down
43 changes: 43 additions & 0 deletions lib/api/v3/utilities/path_helper/default_strategy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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.
# ++

module API
module V3
module Utilities
module PathHelper
module DefaultStrategy
def self.path_name_for_object(object)
object.class.name.demodulize.underscore
end
end
end
end
end
end
49 changes: 49 additions & 0 deletions lib/api/v3/utilities/path_helper/project_strategy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# frozen_string_literal: true

# -- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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.
# ++

module API
module V3
module Utilities
module PathHelper
module ProjectStrategy
def self.path_name_for_object(object)
if object.portfolio?
:portfolio
elsif object.program?
:program
else
:project
end
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
end

it_behaves_like "has a project include dropdown" do
let(:work_package_view) { Pages::Calendar.new project }
let(:work_package_view) { Pages::Calendar.new portfolio }
let(:dropdown) { Components::ProjectIncludeComponent.new }

it "correctly filters work packages by project" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
end

it_behaves_like "has a project include dropdown" do
let(:work_package_view) { Pages::TeamPlanner.new(project) }
let(:work_package_view) { Pages::TeamPlanner.new(portfolio) }
let(:dropdown) { Components::ProjectIncludeComponent.new }

it "correctly filters work packages by project" do
Expand Down
Loading
Loading