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

Send start and duration in Gantt when direction == both

Oliver Güntherfab5435e209b
diff --git a/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/timeline-cell-renderer.ts b/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/timeline-cell-renderer.ts
index 0964ba1474e..271dc2c5e0c 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/timeline-cell-renderer.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/timeline-cell-renderer.ts
@@ -110,11 +110,13 @@ export class TimelineCellRenderer {
* For generic work packages, assigns start and finish date.
*
*/
- public assignDateValues(change:WorkPackageChangeset,
+ public assignDateValues(
+ change:WorkPackageChangeset,
labels:WorkPackageCellLabels,
- dates:any):void {
- this.assignDate(change, 'startDate', dates.startDate);
- this.assignDate(change, 'dueDate', dates.dueDate);
+ dates:CellDateMovement,
+ ):void {
+ this.assignDate(change, 'startDate', dates.startDate as moment.Moment);
+ this.assignDate(change, 'dueDate', dates.dueDate as moment.Moment);
this.updateLabels(true, labels, change);
}
diff --git a/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts b/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts
index f9fbde64925..260b1423668 100644
--- a/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts
+++ b/frontend/src/app/features/work-packages/components/wp-table/timeline/cells/wp-timeline-cell-mouse-handler.ts
@@ -40,7 +40,10 @@ import { WorkPackageResource } from 'core-app/features/hal/resources/work-packag
import { take } from 'rxjs/operators';
import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { WorkPackageCellLabels } from './wp-timeline-cell-labels';
-import { MouseDirection, TimelineCellRenderer } from './timeline-cell-renderer';
+import {
+ MouseDirection,
+ TimelineCellRenderer,
+} from './timeline-cell-renderer';
import { RenderInfo } from '../wp-timeline';
import { WorkPackageTimelineTableController } from '../container/wp-timeline-container.directive';
import Moment = moment.Moment;
@@ -58,8 +61,6 @@ export function registerWorkPackageMouseHandler(this:void,
labels:WorkPackageCellLabels,
renderer:TimelineCellRenderer,
renderInfo:RenderInfo) {
- const querySpace:IsolatedQuerySpace = injector.get(IsolatedQuerySpace);
-
let mouseDownStartDay:number|null = null; // also flag to signal active drag'n'drop
renderInfo.change = halEditing.changeFor(renderInfo.workPackage);
@@ -70,7 +71,7 @@ export function registerWorkPackageMouseHandler(this:void,
bar.onmousedown = (ev:MouseEvent) => {
if (ev.which === 1) {
// Left click only
- workPackageMouseDownFn(bar, ev);
+ workPackageMouseDownFn(ev);
}
};
@@ -83,14 +84,13 @@ export function registerWorkPackageMouseHandler(this:void,
renderer.update(bar, labels, renderInfo);
}
- function getCursorOffsetInDaysFromLeft(renderInfo:RenderInfo, ev:MouseEvent) {
+ function getCursorOffsetInDaysFromLeft(ev:MouseEvent):number {
const leftOffset = workPackageTimeline.getAbsoluteLeftCoordinates();
const cursorOffsetLeftInPx = ev.clientX - leftOffset;
- const cursorOffsetLeftInDays = Math.floor(cursorOffsetLeftInPx / renderInfo.viewParams.pixelPerDay);
- return cursorOffsetLeftInDays;
+ return Math.floor(cursorOffsetLeftInPx / renderInfo.viewParams.pixelPerDay);
}
- function workPackageMouseDownFn(bar:HTMLDivElement, ev:MouseEvent) {
+ function workPackageMouseDownFn(ev:MouseEvent) {
ev.preventDefault();
// add/remove css class while drag'n'drop is active
@@ -99,7 +99,7 @@ export function registerWorkPackageMouseHandler(this:void,
jBody.on('mouseup.timelinecell', () => bar.classList.remove(classNameActiveDrag));
workPackageTimeline.disableViewParamsCalculation = true;
- mouseDownStartDay = getCursorOffsetInDaysFromLeft(renderInfo, ev);
+ mouseDownStartDay = getCursorOffsetInDaysFromLeft(ev);
// If this wp is a parent element, changing it is not allowed
// if it is not on 'Manual scheduling' mode
@@ -113,12 +113,12 @@ export function registerWorkPackageMouseHandler(this:void,
jBody.on('mousemove.timelinecell', createMouseMoveFn(direction));
jBody.on('keyup.timelinecell', keyPressFn);
- jBody.on('mouseup.timelinecell', () => deactivate(false));
+ jBody.on('mouseup.timelinecell', () => deactivate(direction, false));
}
function createMouseMoveFn(direction:MouseDirection) {
return (ev:JQuery.MouseMoveEvent) => {
- const days = getCursorOffsetInDaysFromLeft(renderInfo, ev.originalEvent!) - mouseDownStartDay!;
+ const days = getCursorOffsetInDaysFromLeft(ev.originalEvent as MouseEvent) - (mouseDownStartDay as number);
const offsetDayCurrent = Math.floor(ev.offsetX / renderInfo.viewParams.pixelPerDay);
const dayUnderCursor = renderInfo.viewParams.dateDisplayStart.clone().add(offsetDayCurrent, 'days');
@@ -127,9 +127,9 @@ export function registerWorkPackageMouseHandler(this:void,
}
function keyPressFn(ev:JQuery.TriggeredEvent) {
- const kev:KeyboardEvent = ev as any;
+ const kev:KeyboardEvent = ev.originalEvent as KeyboardEvent;
if (kev.keyCode === KeyCodes.ESCAPE) {
- deactivate(true);
+ deactivate(null, true);
}
}
@@ -163,12 +163,12 @@ export function registerWorkPackageMouseHandler(this:void,
};
// create logic
- cell.onmousedown = (ev) => {
+ cell.onmousedown = (evt) => {
placeholderForEmptyCell.remove();
- ev.preventDefault();
+ evt.preventDefault();
- if (renderer.cursorOrDatesAreNonWorking(ev, renderInfo)) {
+ if (renderer.cursorOrDatesAreNonWorking(evt, renderInfo)) {
return;
}
@@ -176,19 +176,19 @@ export function registerWorkPackageMouseHandler(this:void,
const [clickStart, offsetDayStart] = renderer.cursorDateAndDayOffset(ev, renderInfo);
const dateForCreate = clickStart.format('YYYY-MM-DD');
- const mouseDownType = renderer.onMouseDown(ev, dateForCreate, renderInfo, labels);
+ const direction = renderer.onMouseDown(ev, dateForCreate, renderInfo, labels);
renderer.update(bar, labels, renderInfo);
- if (mouseDownType === 'create') {
- deactivate(false);
+ if (direction === 'create') {
+ deactivate(direction, false);
return;
}
- jBody.on('mousemove.emptytimelinecell', mouseMoveOnEmptyCellFn(offsetDayStart, mouseDownType));
- jBody.on('mouseup.emptytimelinecell', () => deactivate(false));
+ jBody.on('mousemove.emptytimelinecell', mouseMoveOnEmptyCellFn(offsetDayStart, direction));
+ jBody.on('mouseup.emptytimelinecell', () => deactivate(direction, false));
cell.onmouseup = () => {
- deactivate(false);
+ deactivate(direction, false);
};
jBody.on('keyup.timelinecell', keyPressFn);
@@ -207,7 +207,8 @@ export function registerWorkPackageMouseHandler(this:void,
};
}
- function deactivate(cancelled:boolean) {
+ function deactivate(direction:MouseDirection|null, cancelled:boolean) {
+ const change = renderInfo.change;
workPackageTimeline.disableViewParamsCalculation = false;
cell.onmousemove = handleMouseMoveOnEmptyCell;
@@ -223,25 +224,32 @@ export function registerWorkPackageMouseHandler(this:void,
mouseDownStartDay = null;
// Cancel changes if the startDate or dueDate are not allowed
- const { startDate, dueDate } = renderInfo.change.projectedResource;
+ const { startDate, dueDate } = change.projectedResource;
const invalidDates = renderer.cursorOrDatesAreNonWorking([moment(startDate), moment(dueDate)], renderInfo);
- if (cancelled || renderInfo.change.isEmpty() || invalidDates) {
+ if (cancelled || change.isEmpty() || invalidDates) {
cancelChange();
- } else {
- const stopAndRefresh = () => {
- renderInfo.change.clear();
- renderer.onMouseDownEnd(labels, renderInfo.change);
- };
+ return;
+ }
- // Persist the changes
- saveWorkPackage(renderInfo.change)
- .then(stopAndRefresh)
- .catch((error) => {
- notificationService.handleRawError(error, renderInfo.workPackage);
- cancelChange();
- });
+ // Remove due date from sending if we moved the work package as is
+ // and duration was set
+ const duration = change.pristineResource.duration as string|null;
+ if (direction === 'both' && duration) {
+ change.clearValue('dueDate');
+ change.setValue('duration', duration);
}
+
+ // Persist the changes
+ saveWorkPackage(renderInfo.change)
+ .then(() => {
+ renderInfo.change.clear();
+ renderer.onMouseDownEnd(labels, renderInfo.change);
+ })
+ .catch((error) => {
+ notificationService.handleRawError(error, renderInfo.workPackage);
+ cancelChange();
+ });
}
function cancelChange() {