March 27, 2025, 11:55:32 PM

See more Support incidents in our old archived forum.

Author Topic: Moving a task collapses it when RoundToOptions is set to Day  (Read 8242 times)

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Moving a task collapses it when RoundToOptions is set to Day
« on: February 20, 2020, 01:06:33 PM »
Hello,

we have a TaskItem with properties that bind to start and end time.
In the setter of end time we try to retain the original duration after moving a task.
A task is allowed get longer as a result of RoundToOptions, but is not allowed to shrink.
UpdateEndTimeOnMove is default true, because it is needed for resizing (not included in this example).

Code: [Select]
public class TaskItem : BindableBase
    {

        /// <summary>
        /// Used to temporarly store duration of task while moving it.
        /// </summary>
        public TimeSpan? _TaskTimeSpanOld;

        public DateTime? _StartTime;
        public DateTime? _EndTime;

        public DateTime? StartTime
        {
            get { return _StartTime; }
            set
            {
                _TaskTimeSpanOld = EndTime - StartTime;
                SetProperty<DateTime?>(ref _StartTime, value);
            }
        }

        public DateTime? EndTime
        {
            get { return _EndTime; }
            set
            {
                //umcomment this: Task item will have correct duration of 9 hours after moving, but item will be displayed with duration 0.
                //Moving item again to another day will display correct duration again.
                //if (value == this.StartTime && _TaskTimeSpanOld == null)
                //    _TaskTimeSpanOld = EndTime - StartTime;

                if (_TaskTimeSpanOld != null)
                {
                    TimeSpan? taskTimeSpanNew = value - StartTime;
                    //keep original length if item would shrink
                    if (taskTimeSpanNew != null && taskTimeSpanNew < _TaskTimeSpanOld)
                    {
                        long differenceInTicks = (((TimeSpan)_TaskTimeSpanOld) - ((TimeSpan)taskTimeSpanNew)).Ticks;

                        // Reset before StartTime is changed
                        _TaskTimeSpanOld = null;
                        value = ((DateTime)value).AddTicks(differenceInTicks);
                    }
                }
                SetProperty<DateTime?>(ref _EndTime, value);
            }
        }

        public string Name { get; set; }
    }

These conditions must be met:
Task with duration <= 12 hours
Start Time of task == 00:00
RoundToOptions is set to "Day" (no issues with the other options)
Move task to 1 day prior but not far enough, that it actually snaps to 00:00 of the previous day.


Result:
Task stays on the same day, but end time is also set to 00:00 of the same day.
It collapsed to 0 hours duration.


Apparently this is the result of the RoundTime() method. It is only rounded up, if the duration is > 12.
It returns just the date part of the proposed end DateTime, so the time is lost.

Code: [Select]
case RoundToOptions.Day:
    if (dateTime.Date < dateTime && dateTime.Hour > 12)
        return dateTime.Date + TimeSpan.FromDays(1);
    else
        return dateTime.Date;

Moving the task again, the duration stays like this.

I tried to check for this condition and set end time with the original time (see commented code in EndTime.Setter).
Internally the end time is 09:00 (as seen in the StartTime.Setter in debug mode) but the task is still displayed as 00:00.
Only after moving the task to another day, the time of 09:00 is displayed correctly.



How can I keep the duration of the task after moving?
Version 8.0.45.9

Jan
« Last Edit: January 04, 2021, 12:46:48 PM by jan.reker »

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #1 on: February 21, 2020, 03:33:33 PM »
Jan,

We will take a look into it and get back to you soon.

Thanks,
Raja.

ForumAdmin

  • Administrator
  • Jr. Member
  • *****
  • Posts: 96
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #2 on: February 25, 2020, 01:10:59 PM »
Jan,

So, you have used the RoundToOptions.Day option. This also makes the Gantt assume that you usually have or prefer a time span for the task spanning 0 hours or full day(s). Since the Gantt encountered a 9 hour time span, it has to reset that to 0 or a full day and it has reset it to 0.

So, the main questions are:
- How did the timespan of this task get set to 9 hours? Is that outside the Gantt? And is that acceptable? Wouldn't you rather want it to be 0 or a full day?
- Would you also want to pre-process the timespans to ensure that they are either 0 or full days before binding to the Gantt?

Or, you might want to retain the partial-day time span like here, in which case we will have to reconsider or tweak the Rounding behavior for you.

Thanks
Praveen

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #3 on: February 26, 2020, 11:19:24 AM »
Praveen,

thanks for the reply.

- How did the timespan of this task get set to 9 hours? Is that outside the Gantt? And is that acceptable?
Yes, it is acceptable if a task is 9 hours long. The users can enter start and end time via dialog or resize the task in gantt. They can switch between the RoundToOptions any time.

Wouldn't you rather want it to be 0 or a full day?
- Would you also want to pre-process the timespans to ensure that they are either 0 or full days before binding to the Gantt?
No, I want to keep the duration after moving a task.

RoundToOptions are used to round the task when the user resizes it. This works fine.
But when the user moves a task I want to keep the previously set duration. I only want to use RoundToOptions to snap the start time or end time to the nearest valid value.

For example: task is 08:00 to 14:00. After moving it near the beginning of a different day with RoundToOptions.Day it should be 00:00 to 06:00. Or moving it near the end of a different day it should be 18:00 to 00:00.
Same for the other respective RoundToOptions.

Is it possible to implement this behavior?


Jan

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #4 on: February 27, 2020, 02:37:04 PM »
Jan,

Can you try RoundToOptions.HalfDay feature which is almost similar to the requirement. Let us know if you need further customization.

Thanks
Raja

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #5 on: February 27, 2020, 05:10:33 PM »
Raja,

the user must be able to choose the RoundToOptions. Because of that RoundToOptions.Day must sill be available. I understand if the snapping behavior I described is difficult to implement.

Adding an optional property flag to disable rounding while moving, but not while resizing, would be a great help. This way I can keep the original duration of a task, which is the main concern in this case.


Jan

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #6 on: February 28, 2020, 02:24:38 PM »
Hi Jan, We assumed it as FlexyGantt and started looking on the feature requested. Please confirm it.

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #7 on: March 02, 2020, 10:37:17 AM »
Yes, it is FlexyGantt.

Thanks
Jan

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #8 on: March 04, 2020, 01:55:15 PM »
Jan,

We are making slow but steady progress, will keep you updated on this. Thank you for your patience.

Thanks,
Raja

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #9 on: March 10, 2020, 12:46:40 PM »
Jan,

We have introduced a new event 'RoundTimeAdjustedTo' to let the user override/modify the end result of Rounding.

We have sent you the updated assembly and reference sample. Kindly check your e-mail.

Thanks,
Raja

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #10 on: March 11, 2020, 01:30:02 PM »
Raja,

thank you for your support.
Your new event RoundTimeAdjustedTo works great in the sample project you provided.

Unfortunately when I use the dll in my actual project I get a NullReferenceException on app start:

Code: [Select]
   at RadiantQ.Windows.Controls.FlexyGantt.FGMultipleTaskSelector.<BindGlobalEvents>b__22_0(Object sender1, RoutedEventArgs e1)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   [...]

Could you please also send us a new full delivery of the most current version, including the sources, documentation, samples, etc.?


Thanks,
Jan

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #11 on: March 13, 2020, 08:32:45 AM »
Hi Jan,

We have tried to reproduce the issue, but unfortunately we can't. Anyway, we have sent you the latest source to your email id. Please get it.

Thanks,
Raja

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #12 on: March 16, 2020, 02:12:48 PM »
Raja,

I found the issue with the NullReferenceException:

Set Visibility to Collapsed on FlexyGantt in xaml.
Start application.

In RadiantQ.Windows.Controls.FlexyGantt.FGMultipleTaskSelector.BindGlobalEvents() the GanttChart is null:

Code: [Select]
this.flexyGantt.GanttChart.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(delegate(object sender2, MouseButtonEventArgs e2)
//GanttChart is null, because it was not constructed yet

Same with FlexyTable a few lines further down:

Code: [Select]
flexyGantt.FlexyTable.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(delegate(object sender2, MouseButtonEventArgs e2)
//FlexyTable is null, because it was not constructed yet


Jan

Rajagopal

  • RQ Members
  • Full Member
  • *
  • Posts: 182
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #13 on: March 17, 2020, 02:29:36 PM »
Jan,

We have reproduced and fixed the issue, testing is in progress. Will share the fix soon.

Thanks,
Raja.

tim

  • Customers
  • Jr. Member
  • *
  • Posts: 60
Re: Moving a task collapses it when RoundToOptions is set to Day
« Reply #14 on: March 18, 2020, 09:00:31 AM »
Raja,

the new event works great, it is very useful.  :)

Could you add a property to the event args that shows which end of a task is resized? Similar to TaskTimeChangingType.ResizeAtEnd and TaskTimeChangingType.ResizeAtStart.


Thanks
Jan