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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[30865] Show all work packages belonging to the version in status graph
Christophe Bliard717a85a600c7
diff --git a/app/helpers/versions_helper.rb b/app/helpers/versions_helper.rbindex aae660bc8ad..d843edf9c4d 100644--- a/app/helpers/versions_helper.rb+++ b/app/helpers/versions_helper.rb@@ -85,4 +85,17 @@ module VersionsHelperhashendend++ def version_wp_overview_graph_initial_filters(version)+ filters = []+ case version.sharing+ when 'hierarchy', 'tree'+ filters << { project: { operator: '=', values: version.projects.visible.ids } }+ when 'descendants'+ filters << { subprojectId: { operator: '*', values: [] } }+ end+ filters << { version: { operator: '=', values: [version.id] } }++ JSON.dump(filters)+ endenddiff --git a/app/models/version.rb b/app/models/version.rbindex 973c1353af4..cf171aa25d4 100644--- a/app/models/version.rb+++ b/app/models/version.rb@@ -101,6 +101,10 @@ class Version < ApplicationRecordeffective_date && (effective_date <= Date.today) && open_issues_count.zero?end+ def systemwide?+ sharing == 'system'+ end+# Returns the completion percentage of this version based on the amount of open/closed issues# and the time spent on the open issues.def completed_percentdiff --git a/app/views/versions/show.html.erb b/app/views/versions/show.html.erbindex b4c1f28b940..345bad49aa1 100644--- a/app/views/versions/show.html.erb+++ b/app/views/versions/show.html.erb@@ -110,7 +110,8 @@ See COPYRIGHT and LICENSE files for more details.<% if @version.work_packages.count > 0 %><div class="widget-box -thin -wider"><wp-overview-graph- additional-filter='{ "version": { "operator": "=", "values": [<%= @version.id %>] }}'>+ global-scope='<%= @version.systemwide? %>'+ initial-filters='<%= version_wp_overview_graph_initial_filters(@version) %>'></wp-overview-graph></div><% end %>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.tsindex 20f3d2d8d6d..e48a8af232a 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@@ -24,6 +24,8 @@ import {export class WpGraphConfigurationService {private _configuration:WpGraphConfiguration;+ private _globalScope = false;+private _forms:{ [id:string]:QueryFormResource } = {};private _formsPromise:Promise<unknown>|null;@@ -81,8 +83,8 @@ export class WpGraphConfigurationService {.loadWithParams({ pageSize: 0 },undefined,- this.currentProject.identifier,- WpGraphConfiguration.queryCreationParams(this.I18n, !!this.currentProject.identifier),+ this.projectIdentifier(),+ WpGraphConfiguration.queryCreationParams(this.I18n, this.isPublicQuery()),).pipe(switchMap(([form, query]) => this.apiv3Service.queries.post(query, form)),@@ -100,9 +102,10 @@ export class WpGraphConfigurationService {.apiv3Service.queries.find(+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument{ pageSize: 0, ...params.props },params.id,- this.currentProject.identifier,+ this.projectIdentifier(),)).then((query) => {if (params.name) {@@ -123,6 +126,14 @@ export class WpGraphConfigurationService {.toPromise());}+ private projectIdentifier() {+ return this.globalScope ? null : this.currentProject.identifier;+ }++ private isPublicQuery() {+ return !!this.projectIdentifier();+ }+public get configuration() {return this._configuration;}@@ -132,6 +143,15 @@ export class WpGraphConfigurationService {this._formsPromise = null;}+ public get globalScope() {+ return this._globalScope;+ }++ public set globalScope(value:boolean) {+ this._globalScope = value;+ this._formsPromise = null;+ }+public async formFor(query:QueryResource):Promise<QueryFormResource> {return this.loadForms()diff --git a/frontend/src/app/shared/components/work-package-graphs/overview/wp-overview-graph.component.ts b/frontend/src/app/shared/components/work-package-graphs/overview/wp-overview-graph.component.tsindex 01be36c09d7..39f4db7dba6 100644--- a/frontend/src/app/shared/components/work-package-graphs/overview/wp-overview-graph.component.ts+++ b/frontend/src/app/shared/components/work-package-graphs/overview/wp-overview-graph.component.ts@@ -32,7 +32,9 @@ export const wpOverviewGraphSelector = 'wp-overview-graph';})export class WorkPackageOverviewGraphComponent implements OnInit {- @Input() additionalFilter:any;+ @Input() initialFilters:any;++ @Input() globalScope:boolean;@ViewChild('wpEmbeddedGraphMulti') private embeddedGraphMulti:WorkPackageEmbeddedGraphComponent;@@ -50,10 +52,12 @@ export class WorkPackageOverviewGraphComponent implements OnInit {public error:string|null = null;- constructor(readonly elementRef:ElementRef,+ constructor(+ readonly elementRef:ElementRef<Element>,readonly I18n:I18nService,readonly graphConfigurationService:WpGraphConfigurationService,- protected readonly cdr:ChangeDetectorRef) {+ protected readonly cdr:ChangeDetectorRef,+ ) {this.availableGroupBy = [{ label: I18n.t('js.work_packages.properties.category'), key: 'category' },{ label: I18n.t('js.work_packages.properties.type'), key: 'type' },{ label: I18n.t('js.work_packages.properties.status'), key: 'status' },@@ -64,7 +68,9 @@ export class WorkPackageOverviewGraphComponent implements OnInit {ngOnInit() {const element = this.elementRef.nativeElement;- this.additionalFilter = JSON.parse(element.getAttribute('additional-filter'));+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment+ this.initialFilters = JSON.parse(element.getAttribute('initial-filters') || 'null');+ this.globalScope = element.getAttribute('global-scope') === 'true';this.setQueryProps();}@@ -75,6 +81,7 @@ export class WorkPackageOverviewGraphComponent implements OnInit {const params = this.graphParams;this.graphConfigurationService.configuration = new WpGraphConfiguration(params, {}, 'horizontalBar');+ this.graphConfigurationService.globalScope = this.globalScope;// 'finally' was not available yet so the code for the change detection is duplicatedthis@@ -128,14 +135,17 @@ export class WorkPackageOverviewGraphComponent implements OnInit {}private baseProps(filter?:any) {- const filters = [{ subprojectId: { operator: '*', values: [] } }];+ const filters = [];- if (filter) {- filters.push(filter);+ if (Array.isArray(this.initialFilters)) {+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument+ filters.push(...this.initialFilters);+ } else {+ filters.push({ subprojectId: { operator: '*', values: [] } });}- if (this.additionalFilter) {- filters.push(this.additionalFilter);+ if (filter) {+ filters.push(filter);}return {diff --git a/spec/features/versions/graph_spec.rb b/spec/features/versions/graph_spec.rbindex 8dbb3e60388..a4bc8871fd4 100644--- a/spec/features/versions/graph_spec.rb+++ b/spec/features/versions/graph_spec.rb@@ -29,23 +29,148 @@require 'spec_helper'RSpec.describe 'version show graph', :js do- let(:user) { create(:admin) }- let(:project) { create(:project) }- let(:version) { create(:version, project:) }+ shared_let(:user) { create(:admin) }+ # parent+ # +- sibling+ # +- main <- version created here+ # +- child+ # other+ shared_let(:parent_project) { create(:project, name: 'parent') }+ shared_let(:sibling_project) { create(:project, parent: parent_project, name: 'sibling') }+ shared_let(:main_project) { create(:project, parent: parent_project, name: 'main') }+ shared_let(:child_project) { create(:project, parent: main_project, name: 'child') }+ shared_let(:other_project) { create(:project, name: 'other') }+ shared_let(:version) { create(:version, project: main_project) }- let!(:wp) do+ # as assertions against the graph can't be made, we use different statuses and+ # test the graph labels to ensure the work packages are drawn in the graph.+ shared_let(:status_control) { create(:status, name: 'Control') }+ shared_let(:status_sut) { create(:status, name: 'Subject under test') }++ # This one exists to have at least one work package in the graph+ shared_let(:control_wp) docreate(:work_package,- project:,+ project: main_project,+ status: status_control,version:)end- before do- login_as(user)- visit version_path(version)- end+ current_user { user }- it 'shows a status graph' do+ def expect_work_packages_visible_in_graphexpect(page).to have_css('.work-packages-embedded-view--container', wait: 20)expect(page).to have_css('.op-wp-embeded-graph', visible: :all, wait: 20)+ canvas = find('.op-wp-embeded-graph canvas')+ expect(canvas['ng-reflect-labels']).to eq('Control,Subject under test')+ end++ context 'for a version not shared' do+ before do+ version.update(sharing: 'none')+ end++ it 'can show a work package from the same project' do+ create(:work_package,+ project: main_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end+ end++ context 'for a version shared with all projects' do+ before do+ version.update(sharing: 'system')+ end++ it 'can show a work package from a different project' do+ create(:work_package,+ project: other_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end+ end++ context 'for a version shared with subprojects' do+ before do+ version.update(sharing: 'descendants')+ end++ it 'can show a work package from a descendant project' do+ create(:work_package,+ project: child_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end+ end++ context 'for a version shared with hierarchy' do+ before do+ version.update(sharing: 'hierarchy')+ end++ it 'can show a work package from a descendant project' do+ create(:work_package,+ project: child_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end++ it 'can show a work package from an ancestor project' do+ create(:work_package,+ project: parent_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end+ end++ context 'for a version shared with tree' do+ before do+ version.update(sharing: 'tree')+ end++ it 'can show a work package from a descendant project' do+ create(:work_package,+ project: child_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end++ it 'can show a work package from an ancestor project' do+ create(:work_package,+ project: parent_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ end++ it 'can show a work package from a sibling project' do+ create(:work_package,+ project: sibling_project,+ status: status_sut,+ version:)++ visit version_path(version)+ expect_work_packages_visible_in_graph+ endendend