public override void Refresh(BoxEditingPool.Item changes) { if (changes != null && changes.IsAgendaChanged && Width > 100) { RefreshDefinitely(); } }
/// <summary> /// Refresh all expanded non-root nodes that could be affected by the given change (more expensive since it loads the nodes) /// </summary> /// <param name="changes">NOT null</param> void RefreshChildren(BoxEditingPool.Item changes) { foreach (var rowVM in VM.RootRows) { if (RefreshChildrenOf(rowVM, changes)) { break; } } }
public override void Refresh(BoxEditingPool.Item changes) { bool rootChanged = changes != null && changes.IsRootSubjectsChanged; if (VM.RootRows.Count == 0 || rootChanged) { RefreshRoot(); } if (changes != null) { RefreshChildren(changes); } }
/// <summary> /// Recursively refresh rowVM's children if it contains the given box; return true if this or any descendant level /// found the box /// </summary> /// <returns></returns> bool RefreshChildrenOf(SubjectVM.RowVM rowVM, BoxEditingPool.Item changes) { long thisId = rowVM.Persistent.RowId; bool reloadNeeded = false; if (rowVM.Status == SubjectVM.ChildrenStatus.No) { reloadNeeded = changes.NewParentId == thisId; } else if (rowVM.Status == SubjectVM.ChildrenStatus.YesLoaded) { reloadNeeded = (changes.IsParentageChanged || changes.IsTitleChanged || changes.NewDoneDate != changes.OldDoneDate) && (changes.OldParentId == thisId || changes.NewParentId == thisId); } else if (rowVM.Status == SubjectVM.ChildrenStatus.YesPlaceholder) { reloadNeeded = false; //was: changes.IsParentageChanged && (changes.OldParentId == thisId || changes.NewParentId == thisId); } //found it, so reload (which collapses children) if (reloadNeeded) { LoadChildrenOf(rowVM); return(true); } //didn't find it, so recurse children and exit when found if (rowVM.Status == SubjectVM.ChildrenStatus.YesLoaded) { foreach (var c in rowVM.Children) { if (RefreshChildrenOf(c, changes)) { return(true); } } } return(false); }
public override void Refresh(BoxEditingPool.Item changes) { }
public void BoxCacheChanged(BoxEditingPool.Item changes) { UIGlobals.Do.RebuildViews(changes, false); }
public override void Refresh(BoxEditingPool.Item changes) { //no refresh needed if we know the reason for calling is a non-scheduled box change //(but we still might need to refresh if there was no change) if (changes != null && !changes.IsAgendaChanged) { return; } SaveChunks(); string fourHours = DateUtil.ToYMDHM(DateTime.Now.AddHours(4)); bool anyChunkAssignments = false; //collect items from cache var agenda = Globals.BoxCache.GetAgenda(); var agendaItems = agenda.Where(r => r.Time.StartsWith(Date)).ToList(); if (IsToday) { string midnight = Date + "0000"; var oldStuff = agenda.Where(r => DateUtil.IsBefore(r.Time, midnight)); agendaItems.AddRange(oldStuff); } //disregard low-clutter items if its time is more than 4 hrs in the future agendaItems = agendaItems.Where(a => { bool shouldHide = a.Box.Visibility == Constants.VISIBILITY_LOWCLUTTER && DateUtil.IsBefore(fourHours, a.Box.BoxTime); return(!shouldHide); }) .OrderBy(a => a.Box.BoxTime) .ToList(); //get list of chunks established for the day var chunkList = Globals.DayChunks.Days.FirstOrDefault(c => c.Date == Date); //exit now if no changes int hash = HashContent(agendaItems, chunkList); bool wasChanged = hash != priorContentHash || chunkList == null; priorContentHash = hash; if (!wasChanged) { return; } VM.Chunks.Clear(); if (chunkList != null && chunkList.Chunks.Count > 0) { //init VM's chunks foreach (var c in chunkList.Chunks) { VM.Chunks.Add(new TodayVM.ChunkVM(VM, UserRemovedChunk) { Title = c.Title }); } //init VM's boxes within chunks foreach (var a in agendaItems) { //chunk assignment can come from persistence, from DeferredBehavior, from changes argument, or default to first chunk var assignedChunk = chunkList.Chunks.FirstOrDefault(c => c.BoxIds != null && c.BoxIds.Contains(a.Box.RowId)); if (assignedChunk == null) { var ta = UIGlobals.Deferred.GetAndRemoveTaskAssign(a.Box.RowId); if (ta != null) { assignedChunk = chunkList.Chunks.FirstOrDefault(c => c.Title == ta.ChunkTitle); anyChunkAssignments = true; } else if (changes != null && changes.NewBoxId == a.Box.RowId && changes.OldBoxTime == null) { //newly added task should go to the 2nd or 3rd chunk based on time of day int cidx = MultiDayChunkSet.GetDefaultChunkIndex(a.Time); if (cidx == 2 && chunkList.Chunks.Count > 2) { assignedChunk = chunkList.Chunks[2]; } if (cidx == 1 && chunkList.Chunks.Count > 1) { assignedChunk = chunkList.Chunks[1]; } anyChunkAssignments = true; } } if (assignedChunk == null) { assignedChunk = chunkList.Chunks[0]; } int chindex = chunkList.Chunks.IndexOf(assignedChunk); var preview = new BoxPreviewVM(a, Date, ItemGotFocus) { TimeClicked = HandleTimeClicked, DragStartRequested = DragStartRequested, MouseOpenRequested = MouseOpenRequested, DropUnderBoxRequested = DropUnderBox }; VM.Chunks[chindex].Items.Add(preview); } } if (anyChunkAssignments) { SaveChunks(force: true); } }
/// <summary> /// Efficiently refresh/rebuild viewmodels if changes detected; can be called often /// </summary> /// <param name="changes">can be null if this is called because of elapsed time</param> public abstract void Refresh(BoxEditingPool.Item changes);