예제 #1
0
        public void DeleteLine(LaneViewModel lane)
        {
            var index = Lanes.IndexOf(lane);

            if (index == Lanes.Count - 1)
            {
                if (index > 0)
                {
                    LaneViewModel previousLane = Lanes[index - 1];

                    PropertyChanged -= lane.PoolPropertyChanged;
                    PropertyChanged += previousLane.PoolPropertyChanged;
                }
            }
            else if (index > 0)
            {
                LaneViewModel next         = lane.Next;
                LaneViewModel previousLane = Lanes[index - 1];
                previousLane.Next = next;
            }
            Lanes.Remove(lane);
            _poolElement.Lanes.Remove(lane.Lane);
            NotifyOfPropertyChange(nameof(Height));

            NotifyActionPerformed(new GenericDeletedAction <LaneViewModel>(this, lane));
        }
예제 #2
0
        public void UpdateLane(Lane laneToUpdateWith)
        {
            //Try getting the lane from the Lanes
            Lane regularLaneToReplace = Lanes.FirstOrDefault(lane => lane.Id == laneToUpdateWith.Id);

            if (regularLaneToReplace != null)
            {
                int laneIndex = Lanes.IndexOf(regularLaneToReplace);
                Lanes.RemoveAt(laneIndex);
                Lanes.Insert(laneIndex, laneToUpdateWith);
                return;
            }

            //If none, try getting from Backlog
            Lane backLogLaneToReplace = Backlog.FirstOrDefault(lane => lane.Id == laneToUpdateWith.Id);

            if (backLogLaneToReplace != null)
            {
                int laneIndex = Backlog.IndexOf(backLogLaneToReplace);
                Backlog.RemoveAt(laneIndex);
                Backlog.Insert(laneIndex, laneToUpdateWith);
                return;
            }

            //Lastly, get it from Archive
            Lane archiveLaneToReplace = Archive.FirstOrDefault(lane => lane.Id == laneToUpdateWith.Id);

            if (archiveLaneToReplace != null)
            {
                int laneIndex = Archive.IndexOf(archiveLaneToReplace);
                Archive.RemoveAt(laneIndex);
                Archive.Insert(laneIndex, laneToUpdateWith);
                return;
            }

            throw new ItemNotFoundException("Could not find the Lane to replace with the updated Lane.");
        }
예제 #3
0
        private void RecalculateLanes()
        {
            if (Application.Current.MainWindow.Dispatcher.CheckAccess())
            {
                if (_recalculatingLanes)
                {
                    return;
                }

                _recalculatingLanes = true;
                var currentlyDragging = Application.Current.MainWindow.FindVisualChildren <TimeslotControl>().Where(x => x.HoldingStart || x.HoldingEnd).Select(x => x.Model);

                foreach (var lane in Lanes.ToList())
                {
                    var overlappers = lane.Items.Where(x => x.OverlapsAny(lane.Items)).Except(currentlyDragging).ToList();
                    while (overlappers.Count > 0)
                    {
                        lane.Items.Remove(overlappers.First());
                        var newLane = new TimelineLaneModel()
                        {
                            LaneNumber = Lanes.Count + 1
                        };
                        newLane.Items.Add(overlappers.First());
                        Lanes.Add(newLane);
                        overlappers = lane.Items.Where(x => x.OverlapsAny(lane.Items)).ToList();
                    }
                }

                foreach (var lane in Lanes.OrderByDescending(x => x.LaneNumber).ToList())
                {
                    foreach (var item in lane.Items.ToList())
                    {
                        foreach (var lane2 in Lanes.Where(x => x.LaneNumber < lane.LaneNumber).ToList())
                        {
                            if (!item.OverlapsAny(lane2.Items))
                            {
                                if (currentlyDragging.Contains(item))
                                {
                                    foreach (var item2 in lane2.Items.ToList())
                                    {
                                        lane.Items.Add(item2);
                                        lane2.Items.Remove(item2);
                                    }
                                }
                                else
                                {
                                    lane2.Items.Add(item);
                                    lane.Items.Remove(item);
                                }
                            }
                        }
                    }
                }

                foreach (var lane in Lanes.ToList())
                {
                    if (lane.Items.Count == 0)
                    {
                        Lanes.Remove(lane);
                    }
                }

                foreach (var lane in Lanes)
                {
                    lane.LaneNumber = Lanes.IndexOf(lane);
                }

                RaisePropertyChanged("Lanes");
                _recalculatingLanes = false;
            }
            else
            {
                Application.Current.MainWindow.Dispatcher.Invoke(RecalculateLanes);
            }
        }