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

[63475] Set dates when dropping work packages in team planner

Christophe Bliardfeaf2a8e6d00
diff --git a/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts b/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
index 326daf91999..529b64ce3d1 100644
--- a/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
+++ b/frontend/src/app/features/calendar/op-work-packages-calendar.service.ts
@@ -435,10 +435,33 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
const startDate = resizeInfo.event.startStr;
const endDate = moment(resizeInfo.event.endStr).subtract(1, 'day').format('YYYY-MM-DD');
- if (dragged && !this.isMilestone(workPackage)) {
+ // When resizing an event, or if it's a milestone, set work package dates to
+ // event dates
+ if (!dragged || this.isMilestone(workPackage)) {
+ return this.changeToDates(workPackage, startDate, endDate);
+ }
+
+ // When drag&drop, adjust existing dates and duration of work package,
+ //
+ // In TeamPlanner, work packages can be moved from a work package list to
+ // the calendar. In this case, there is no `delta` property (EventReceiveArg
+ // event type) and dates need to set, even if not set initially.
+ //
+ // When moving inside the calendar, event is an EventDropArg and `delta`
+ // property is present. Dates must be changed only if they are already set.
+ const isMovingInSameCalendar = !!(resizeInfo as EventDropArg).delta;
+ if (isMovingInSameCalendar) {
return this.moveToDates(workPackage, startDate, endDate);
}
- return this.changeToDates(workPackage, startDate, endDate);
+ return this.moveToStartDate(workPackage, startDate);
+ }
+
+ private changeToDates(workPackage:WorkPackageResource, startDate:string, endDate:string):ResourceChangeset<WorkPackageResource> {
+ const changeset = this.halEditing.edit(workPackage);
+ changeset.setValue('startDate', startDate);
+ changeset.setValue('dueDate', endDate);
+
+ return changeset;
}
private moveToDates(workPackage:WorkPackageResource, startDate:string, endDate:string):ResourceChangeset<WorkPackageResource> {
@@ -461,10 +484,12 @@ export class OpWorkPackagesCalendarService extends UntilDestroyedMixin {
return changeset;
}
- private changeToDates(workPackage:WorkPackageResource, startDate:string, endDate:string):ResourceChangeset<WorkPackageResource> {
+ private moveToStartDate(workPackage:WorkPackageResource, startDate:string):ResourceChangeset<WorkPackageResource> {
const changeset = this.halEditing.edit(workPackage);
+
changeset.setValue('startDate', startDate);
- changeset.setValue('dueDate', endDate);
+ // keep duration if present to deal with non-working days, or defaults to 1 day
+ changeset.setValue('duration', workPackage.duration || 'P1D');
return changeset;
}
diff --git a/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb b/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb
index 6102d8fb701..34429384b44 100644
--- a/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb
+++ b/modules/team_planner/spec/features/team_planner_add_existing_work_packages_spec.rb
@@ -137,41 +137,65 @@ RSpec.describe "Team planner add existing work packages",
add_existing_pane.search "Task"
add_existing_pane.expect_result second_wp
- sleep 2
-
# Drag it to the team planner...
add_existing_pane.drag_wp_by_pixel second_wp, 800, 0
team_planner.expect_and_dismiss_toaster(message: "Successful update.")
# ... and thus update its attributes. Thereby the duration is maintained
- second_wp.reload
- expect(second_wp.start_date).to eq(start_of_week.next_occurring(:tuesday))
- expect(second_wp.due_date).to eq(start_of_week.next_occurring(:thursday))
- expect(second_wp.assigned_to_id).to eq(user.id)
+ expect(second_wp.reload).to have_attributes(
+ start_date: start_of_week.next_occurring(:tuesday),
+ due_date: start_of_week.next_occurring(:thursday),
+ assigned_to_id: user.id
+ )
# Search for another work package
add_existing_pane.search "Ta"
add_existing_pane.expect_result third_wp
- sleep 2
-
# Drag it to the team planner...
add_existing_pane.drag_wp_by_pixel third_wp, 800, 100
team_planner.expect_and_dismiss_toaster(message: "Successful update.")
# ... and thus update its attributes. Since no dates were set before, start and end date are set to the same day
- third_wp.reload
- expect(third_wp.start_date).to eq(start_of_week.next_occurring(:tuesday))
- expect(third_wp.due_date).to eq(start_of_week.next_occurring(:tuesday))
- expect(third_wp.assigned_to_id).to eq(user.id)
+ expect(third_wp.reload).to have_attributes(
+ start_date: start_of_week.next_occurring(:tuesday),
+ due_date: start_of_week.next_occurring(:tuesday),
+ assigned_to_id: user.id
+ )
# New events are directly clickable
split_view = team_planner.open_split_view_by_info_icon(third_wp)
split_view.expect_open
end
+ context "with non-working days" do
+ shared_let(:working_days) { week_with_saturday_and_sunday_as_weekend }
+
+ it "keeps duration when adding work packages via drag&drop from the left hand shortlist" do
+ # add initial duration to task 3
+ third_wp.update!(duration: 11)
+
+ # Search for a work package
+ add_existing_pane.search third_wp.subject
+ add_existing_pane.expect_result third_wp
+
+ # Drag it to the team planner...
+ add_existing_pane.drag_wp_by_pixel third_wp, 800, 0
+ team_planner.expect_and_dismiss_toaster(message: "Successful update.")
+
+ # ... and thus update its attributes. Thereby the duration is maintained
+ # and the due date is set to 15 days from the start date (11 days of
+ # duration + 2x2 non-working days for the weekends)
+ expect(third_wp.reload).to have_attributes(
+ start_date: start_of_week.next_occurring(:tuesday),
+ due_date: start_of_week.next_occurring(:tuesday) + 14.days,
+ assigned_to_id: user.id
+ )
+ end
+ end
+
it "the search applies the filter from the team planner" do
# Search for a work package
add_existing_pane.search "Task"