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
Render background events as highlights for blocking
Oliver Günther204ef6479f04
diff --git a/frontend/src/app/core/state/collection-store.ts b/frontend/src/app/core/state/collection-store.tsindex 2a15e9f8eb8..e609b2c0588 100644--- a/frontend/src/app/core/state/collection-store.ts+++ b/frontend/src/app/core/state/collection-store.ts@@ -11,10 +11,7 @@ import {listParamsString,} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import { Observable } from 'rxjs';-import {- filter,-} from 'rxjs/operators';-import { HasId } from 'core-app/core/apiv3/cache/state-cache.service';+import { filter } from 'rxjs/operators';export interface CollectionResponse {ids:ID[];diff --git a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.tsindex 3570f93aa13..9c08d39724c 100644--- a/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts+++ b/frontend/src/app/features/team-planner/team-planner/planner/team-planner.component.ts@@ -11,6 +11,7 @@ import {import {CalendarOptions,DateSelectArg,+ EventApi,EventContentArg,EventDropArg,EventInput,@@ -27,7 +28,11 @@ import {finalize,map,mergeMap,+ shareReplay,+ startWith,+ switchMap,take,+ withLatestFrom,} from 'rxjs/operators';import { StateService } from '@uirouter/angular';import resourceTimelinePlugin from '@fullcalendar/resource-timeline';@@ -47,13 +52,15 @@ import { CurrentProjectService } from 'core-app/core/current-project/current-proimport { splitViewRoute } from 'core-app/features/work-packages/routing/split-view-routes.helper';import { QueryFilterInstanceResource } from 'core-app/features/hal/resources/query-filter-instance-resource';import { PrincipalsResourceService } from 'core-app/core/state/principals/principals.service';-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import {+ ApiV3ListFilter,+ ApiV3ListParameters,+} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { ResourceLabelContentArg } from '@fullcalendar/resource-common';import { OpCalendarService } from 'core-app/features/calendar/op-calendar.service';-import { WorkPackageCollectionResource } from 'core-app/features/hal/resources/wp-collection-resource';import { HalResourceEditingService } from 'core-app/shared/components/fields/edit/services/hal-resource-editing.service';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { SchemaCacheService } from 'core-app/core/schemas/schema-cache.service';@@ -69,6 +76,8 @@ import {teamPlannerEventRemoved,} from 'core-app/features/team-planner/team-planner/planner/team-planner.actions';import { imagePath } from 'core-app/shared/helpers/images/path-helper';+import { CapabilitiesResourceService } from 'core-app/core/state/capabilities/capabilities.service';+import { ICapability } from 'core-app/core/state/capabilities/capability.model';import { ToastService } from 'core-app/shared/components/toaster/toast.service';@Component({@@ -138,6 +147,51 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,}),);+ private assigneeCaps$ = this.wpTableFilters+ .live$()+ .pipe(+ this.untilDestroyed(),+ switchMap((queryFilters) => {+ const filters:ApiV3ListFilter[] = [+ ['action', '=', ['work_packages/assigned']],+ ];+ const assigneeFilter = queryFilters.find((queryFilter) => queryFilter._type === 'AssigneeQueryFilter');+ if (assigneeFilter) {+ const values = (assigneeFilter.values as HalResource[]).map((el:HalResource) => el.id as string);+ filters.push(['principal', '=', values]);+ }++ const projectFilter = queryFilters.find((queryFilter) => queryFilter._type === 'ProjectQueryFilter');+ if (projectFilter) {+ const values = (projectFilter.values as HalResource[]).map((el:HalResource) => `p${el.id as string}`);+ filters.push(['context', '=', values]);+ } else {+ filters.push(['context', '=', [`p${this.currentProject.id as string}`]]);+ }++ return this+ .capabilitiesResourceService+ .fetchCapabilities({ pageSize: -1, filters });+ }),+ map((result) => result+ ._embedded+ .elements+ .reduce(+ (list:{ [projectId:string]:string[] }, cap:ICapability) => {+ const project = cap._links.context.href;+ const principal = cap._links.principal.href;+ const cur = list[project] || [];+ return {+ ...list,+ [project]: [...cur, principal],+ };+ },+ {},+ )),+ startWith({} as { [projectId:string]:string[] }),+ shareReplay(1),+ );+private params$ = this.principalIds$.pipe(this.untilDestroyed(),@@ -185,12 +239,14 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,mergeMap((ids:string[]) => this.principalsResourceService.query.byIds(ids)),debounceTime(50),distinctUntilChanged((prev, curr) => prev.length === curr.length && prev.length === 0),+ shareReplay(1),);constructor(private $state:StateService,private configuration:ConfigurationService,private principalsResourceService:PrincipalsResourceService,+ private capabilitiesResourceService:CapabilitiesResourceService,private wpTableFilters:WorkPackageViewFiltersService,private querySpace:IsolatedQuerySpace,private currentProject:CurrentProjectService,@@ -352,8 +408,20 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,],},},- events: this.calendarEventsFunction.bind(this) as unknown,- resources: [],+ eventSources: [+ {+ id: 'work_packages',+ events: this.calendarEventsFunction.bind(this) as unknown,+ },+ {+ events: [],+ id: 'background',+ color: 'red',+ textColor: 'white',+ display: 'background',+ editable: false,+ },+ ],resourceAreaWidth: '180px',select: this.handleDateClicked.bind(this) as unknown,resourceLabelContent: (data:ResourceLabelContentArg) => this.renderTemplate(this.resourceContent, data.resource.id, data),@@ -366,11 +434,13 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,const { el } = dragInfo;el.style.pointerEvents = 'none';this.draggingItem$.next(dragInfo);+ this.addBackgroundEvents(dragInfo.event);},eventDragStop: (dragInfo:EventDragStopArg) => {const { el } = dragInfo;el.style.removeProperty('pointer-events');this.draggingItem$.next(undefined);+ this.removeBackGroundEvents();},eventDrop: (dropInfo:EventDropArg) => this.updateEvent(dropInfo),eventReceive: async (dropInfo:EventReceiveArg) => {@@ -379,9 +449,23 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,this.actions$.dispatch(teamPlannerEventAdded({ workPackage: wp.id as string }));},// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- eventContent: (data:EventContentArg) => this.renderTemplate(this.eventContent, this.eventId(data), data),+ eventContent: (data:EventContentArg):{ domNodes:unknown[] }|undefined => {+ // Let FC handle the background events+ if (data.event.source?.id === 'background') {+ return undefined;+ }++ return this.renderTemplate(this.eventContent, this.eventId(data), data);+ },// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access- eventWillUnmount: (data:EventContentArg) => this.unrenderTemplate(this.eventId(data)),+ eventWillUnmount: (data:EventContentArg) => {+ // Nothing to do for background events+ if (data.event.source?.id === 'background') {+ return;+ }++ this.unrenderTemplate(this.eventId(data));+ },} as CalendarOptions),);});@@ -396,12 +480,13 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,.calendar.currentWorkPackages$.pipe(+ withLatestFrom(this.assigneeCaps$),take(1),finalize(() => this.clearLoading()),).subscribe(- (workPackages:WorkPackageCollectionResource) => {- const events = this.mapToCalendarEvents(workPackages.elements);+ ([workPackages, projectAssignables]) => {+ const events = this.mapToCalendarEvents(workPackages.elements, projectAssignables);this.viewLookup.destroyDetached();@@ -544,7 +629,10 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,this.actions$.dispatch(teamPlannerEventRemoved({ workPackage: workPackage.id as string }));}- private mapToCalendarEvents(workPackages:WorkPackageResource[]):EventInput[] {+ private mapToCalendarEvents(+ workPackages:WorkPackageResource[],+ projectAssignables:{ [projectId:string]:string[] },+ ):EventInput[] {return workPackages.map((workPackage:WorkPackageResource):EventInput|undefined => {if (!workPackage.assignee) {@@ -561,7 +649,7 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,editable: durationEditable || resourceEditable,durationEditable,resourceEditable,- constraint: this.eventConstaints(workPackage),+ constraint: this.eventConstaints(workPackage, projectAssignables),title: workPackage.subject,start: this.wpStartDate(workPackage),end: this.wpEndDate(workPackage),@@ -655,7 +743,10 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,// they are forced to drag the wp to the exact same date in the others assignee row. This might be confusing.// Without these constraints however, users can drag the WP everywhere, thinking that they changed the date as well.// The WP then moves back to the original date when the calendar re-draws again. Also not optimal..- private eventConstaints(wp:WorkPackageResource):{ [key:string]:string|string[] } {+ private eventConstaints(+ wp:WorkPackageResource,+ projectAssignables:{ [projectId:string]:string[] },+ ):{ [key:string]:string|string[] } {const constraints:{ [key:string]:string|string[] } = {};if (!this.calendar.eventDurationEditable(wp)) {@@ -665,6 +756,12 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,if (!this.eventResourceEditable(wp)) {constraints.resourceIds = [this.wpAssignee(wp)];+ return constraints;+ }++ const assignables = projectAssignables[(wp.project as HalResource).href as string];+ if (assignables) {+ constraints.resourceIds = [...assignables];}return constraints;@@ -699,4 +796,42 @@ export class TeamPlannerComponent extends UntilDestroyedMixin implements OnInit,}});}++ private addBackgroundEvents(event:EventApi) {+ const wp = event.extendedProps.workPackage as WorkPackageResource;++ this+ .assigneeCaps$+ .pipe(+ filter((el) => Object.keys(el).length > 0),+ take(1),+ map((projectAssignables) => projectAssignables[(wp.project as HalResource).href as string]),+ withLatestFrom(this.principals$),+ )+ .subscribe(([assignable, principals]) => {+ const api = this.ucCalendar.getApi();++ const eventBase = {+ start: moment().subtract('1', 'month').toDate(),+ end: moment().add('1', 'month').toDate(),+ };++ principals.forEach((principal) => {+ const resourceId = principal._links.self.href;++ if (!assignable.includes(resourceId)) {+ api.addEvent({ ...eventBase, resourceId }, 'background');+ }+ });+ });+ }++ private removeBackGroundEvents() {+ this+ .ucCalendar+ .getApi()+ .getEvents()+ .filter((el) => el.source?.id === 'background')+ .forEach((el) => el.remove());+ }}diff --git a/modules/team_planner/spec/features/team_planner_subproject_constraints_spec.rb b/modules/team_planner/spec/features/team_planner_subproject_constraints_spec.rbnew file mode 100644index 00000000000..e5a6184264b--- /dev/null+++ b/modules/team_planner/spec/features/team_planner_subproject_constraints_spec.rb@@ -0,0 +1,97 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2022 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.+#++++require 'spec_helper'+require_relative './shared_context'++describe 'Team planner constraints for a subproject', type: :feature, js: true do+ before do+ with_enterprise_token(:team_planner_view)+ end++ include_context 'with team planner full access'++ let!(:other_user) do+ create :user,+ firstname: 'Bernd',+ member_in_project: project,+ member_with_permissions: %w[+ view_work_packages view_team_planner work_package_assigned+ ]+ end++ let!(:subproject) { create :project, parent: project }+ let!(:role) { create :role, permissions: %i[view_work_packages edit_work_packages work_package_assigned] }+ let!(:member) { create :member, principal: user, project: subproject, roles: [role] }+ let(:project_include) { ::Components::ProjectIncludeComponent.new }++ let!(:work_package) do+ create :work_package,+ project: subproject,+ assigned_to: user,+ start_date: Time.zone.today.beginning_of_week.next_occurring(:tuesday),+ due_date: Time.zone.today.beginning_of_week.next_occurring(:thursday)+ end++ it 'shows a visual aid that the other user cannot be assigned' do+ team_planner.visit!++ team_planner.add_assignee user+ retry_block do+ team_planner.add_assignee other_user+ end++ # Include the subproject+ project_include.toggle!+ project_include.toggle_checkbox(subproject.id)+ project_include.click_button 'Apply'+ project_include.expect_count 2++ team_planner.within_lane(user) do+ team_planner.expect_event work_package+ end++ retry_block do+ # Ensure we're not dragging anything+ drag_release++ # Try to drag work package to other user+ start_dragging team_planner.event(work_package)+ drag_element_to find(".fc-timeline-lane[data-resource-id='/api/v3/users/#{other_user.id}']")++ # Expect background event on other user+ page.find(".fc-timeline-lane[data-resource-id='/api/v3/users/#{other_user.id}'] .fc-bg-event")+ drag_element_to find(".fc-timeline-lane[data-resource-id='/api/v3/users/#{user.id}']")+ drag_release++ unless page.has_no_selector?(".fc-timeline-lane[data-resource-id='/api/v3/users/#{other_user.id}'] .fc-bg-event")+ raise "Expected to have no bg-event after release"+ end+ end+ end+enddiff --git a/modules/team_planner/spec/support/pages/team_planner.rb b/modules/team_planner/spec/support/pages/team_planner.rbindex 103b9dbcae5..1c94f849e39 100644--- a/modules/team_planner/spec/support/pages/team_planner.rb+++ b/modules/team_planner/spec/support/pages/team_planner.rb@@ -122,7 +122,11 @@ module Pagesenddef expect_event(work_package, present: true)- expect(page).to have_conditional_selector(present, '.fc-event', text: work_package.subject)+ if present+ expect(page).to have_selector('.fc-event', text: work_package.subject, wait: 10)+ else+ expect(page).to have_no_selector('.fc-event', text: work_package.subject)+ endenddef add_assignee(name)