From b87fd9b1c00ca211ff38d4c23ff1b1444da87cf9 Mon Sep 17 00:00:00 2001 From: Roman Roelofsen Date: Fri, 9 Dec 2016 16:34:53 +0100 Subject: [PATCH] Timeline: start/due dates can't be moved after/before each other --- .../timeline/cell-renderer/timeline-cell-renderer.ts | 11 ++++++++++- .../timeline/wp-timeline-cell-mouse-handler.ts | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts b/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts index 4e7bfae241..c25b3e478d 100644 --- a/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts +++ b/frontend/app/components/wp-table/timeline/cell-renderer/timeline-cell-renderer.ts @@ -42,7 +42,7 @@ export class TimelineCellRenderer { * Handle movement by days of the work package to either (or both) edge(s) * depending on which initial date was set. */ - public onDaysMoved(wp:WorkPackageResourceInterface, delta:number) { + public onDaysMoved(wp: WorkPackageResourceInterface, delta: number): CellDateMovement { const initialStartDate = wp.$pristine['startDate']; const initialDueDate = wp.$pristine['dueDate']; let dates:CellDateMovement = {}; @@ -55,6 +55,15 @@ export class TimelineCellRenderer { dates.dueDate = moment(initialDueDate).add(delta, "days"); } + // only start or due are changed + if (_.keys(dates).length === 1) { + if (dates.startDate != undefined && dates.startDate.isAfter(moment(wp.dueDate))) { + dates.startDate = moment(wp.dueDate); + } else if (dates.dueDate != undefined && dates.dueDate.isBefore(moment(wp.startDate))) { + dates.dueDate = moment(wp.startDate); + } + } + return dates; } diff --git a/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts b/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts index 5124dc3df8..5bf16eb3a3 100644 --- a/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts +++ b/frontend/app/components/wp-table/timeline/wp-timeline-cell-mouse-handler.ts @@ -27,12 +27,12 @@ // ++ import {timelineElementCssClass, RenderInfo} from "./wp-timeline"; import {WorkPackageCacheService} from "../../work-packages/work-package-cache.service"; +import {WorkPackageTimelineTableController} from "./wp-timeline-container.directive"; +import {TimelineCellRenderer} from "./cell-renderer/timeline-cell-renderer"; import IScope = angular.IScope; import Observable = Rx.Observable; import IDisposable = Rx.IDisposable; import Moment = moment.Moment; -import {WorkPackageTimelineTableController} from "./wp-timeline-container.directive"; -import {TimelineCellRenderer} from './cell-renderer/timeline-cell-renderer'; const classNameBar = "bar"; const classNameLeftHandle = "leftHandle"; @@ -76,7 +76,7 @@ export function registerWorkPackageMouseHandler(this: void, dateStates = renderer.onDaysMoved(renderInfo.workPackage, days); - applyDateValues(dateStates); + applyDateValues(dateStates); } function keyPressFn(ev: JQueryEventObject) {