private void onTimeEntryUpdated(EntityUpdate <IThreadSafeTimeEntry> update) { var timeEntry = update.Entity; if (timeEntry == null) { return; } if (timeEntry.IsDeleted || timeEntry.IsRunning()) { onTimeEntryRemoved(timeEntry.Id); } else { var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat); if (timeEntry.Id == timeEntryToDelete?.Id) { // Ignore this update because the entity is hidden and might be deleted unless the user // undoes the action. In that case bring the time entry but with the updated data. timeEntryToDelete = timeEntryViewModel; } else { TimeEntries.UpdateItem(update.Id, timeEntryViewModel); } } }
private void onTimeEntryUpdated(EntityUpdate <IThreadSafeTimeEntry> update) { var timeEntry = update.Entity; var shouldBeAdded = timeEntry != null && !timeEntry.IsRunning() && !timeEntry.IsDeleted; var oldCollectionIndex = TimeEntries.IndexOf(c => c.Any(vm => vm.Id == update.Id)); var collectionIndex = TimeEntries.IndexOf(vm => vm.Date == timeEntry.Start.LocalDateTime.Date); var wasMovedIntoDifferentCollection = oldCollectionIndex >= 0 && oldCollectionIndex != collectionIndex; var shouldBeRemoved = shouldBeAdded == false || wasMovedIntoDifferentCollection; if (shouldBeRemoved) { safeRemoveTimeEntry(update.Id); } if (shouldBeAdded) { var timeEntryIndex = collectionIndex < 0 ? -1 : TimeEntries[collectionIndex].IndexOf(vm => vm.Id == update.Id); var timeEntryExistsInTheCollection = timeEntryIndex >= 0; if (timeEntryExistsInTheCollection) { var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat); TimeEntries.ReplaceInChildCollection(collectionIndex, timeEntryIndex, timeEntryViewModel); return; } safeInsertTimeEntry(timeEntry); } }
private async Task delete(TimeEntryViewModel timeEntryViewModel) { await interactorFactory.DeleteTimeEntry(timeEntryViewModel.Id).Execute(); analyticsService.DeleteTimeEntry.Track(); dataSource.SyncManager.PushSync(); }
private IObservable <Unit> continueTimeEntry(TimeEntryViewModel timeEntry) { return(interactorFactory .ContinueTimeEntry(timeEntry) .Execute() .Do(_ => onboardingStorage.SetTimeEntryContinued()) .SelectUnit()); }
private void insertNewTimeEntryGroup(IThreadSafeTimeEntry timeEntry, DateTime indexDate) { var timeEntryToAdd = new TimeEntryViewModel(timeEntry, durationFormat); var newCollection = new TimeEntryViewModelCollection(indexDate, new[] { timeEntryToAdd }, durationFormat); var foundIndex = TimeEntries.IndexOf(TimeEntries.FirstOrDefault(x => x.Date < indexDate)); var indexToInsert = foundIndex == -1 ? TimeEntries.Count : foundIndex; TimeEntries.Insert(indexToInsert, newCollection); }
private IObservable <Unit> deleteTimeEntry(TimeEntryViewModel timeEntry) { return(interactorFactory .DeleteTimeEntry(timeEntry.Id) .Execute() .Do(_ => { analyticsService.DeleteTimeEntry.Track(); dataSource.SyncManager.PushSync(); })); }
private IObservable <Unit> timeEntrySelected(TimeEntryViewModel timeEntry) { if (isEditViewOpen) { return(Observable.Empty <Unit>()); } onboardingStorage.TimeEntryWasTapped(); return(navigate <EditTimeEntryViewModel, long>(timeEntry.Id).ToObservable()); }
private void cancelDeleteTimeEntry() { if (!TimeEntries.IndexOf(timeEntryToDelete.Id).HasValue) { TimeEntries.InsertItem(timeEntryToDelete); } timeEntryToDelete = null; delayedDeletionDisposable.Dispose(); showUndoSubject.OnNext(false); }
private IObservable <Unit> cancelDeleteTimeEntry() { if (!TimeEntries.IndexOf(timeEntryToDelete.Id).HasValue) { TimeEntries.InsertItem(timeEntryToDelete); } timeEntryToDelete = null; delayedDeletionDisposable.Dispose(); showUndoSubject.OnNext(false); return(Observable.Return(Unit.Default)); }
public async Task FinilizeDelayDeleteTimeEntryIfNeeded() { if (timeEntryToDelete == null) { return; } delayedDeletionDisposable.Dispose(); await deleteTimeEntry(timeEntryToDelete); timeEntryToDelete = null; showUndoSubject.OnNext(false); }
private async Task continueTimeEntry(TimeEntryViewModel timeEntryViewModel) { areContineButtonsEnabled = false; ContinueTimeEntryCommand.RaiseCanExecuteChanged(); await interactorFactory .ContinueTimeEntry(timeEntryViewModel) .Execute() .Do(_ => { areContineButtonsEnabled = true; ContinueTimeEntryCommand.RaiseCanExecuteChanged(); }); }
private async Task continueTimeEntry(TimeEntryViewModel timeEntryViewModel) { await dataSource.User .Current() .Select(user => new StartTimeEntryDTO { UserId = user.Id, TaskId = timeEntryViewModel.TaskId, WorkspaceId = user.DefaultWorkspaceId, Billable = timeEntryViewModel.Billable, StartTime = timeService.CurrentDateTime, ProjectId = timeEntryViewModel.ProjectId, Description = timeEntryViewModel.Description }) .SelectMany(dataSource.TimeEntries.Start) .Do(_ => dataSource.SyncManager.PushSync()); }
private void delayDeleteTimeEntry(TimeEntryViewModel timeEntry) { timeEntryToDelete = timeEntry; onTimeEntryRemoved(timeEntry.Id); showUndoSubject.OnNext(true); delayedDeletionDisposable = Observable.Merge( // If 5 seconds pass or we try to delete another TE Observable.Return(timeEntry).Delay(Constants.UndoTime, schedulerProvider.DefaultScheduler), showUndoSubject.Where(t => t).SelectValue(timeEntry) ) .Take(1) .SelectMany(deleteTimeEntry) .Do(te => { if (te == timeEntryToDelete) // Hide bar if there isn't other TE trying to be deleted { showUndoSubject.OnNext(false); } }) .Subscribe(); }
private void onTimeEntryUpdated(EntityUpdate <IThreadSafeTimeEntry> update) { var timeEntry = update.Entity; if (timeEntry == null) { return; } if (timeEntry.IsDeleted || timeEntry.IsRunning()) { var index = TimeEntries.IndexOf(timeEntry.Id); if (index.HasValue) { TimeEntries.RemoveItemAt(index.Value.Section, index.Value.Row); } } else { var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat); TimeEntries.UpdateItem(update.Id, timeEntryViewModel); } }
private Task edit(TimeEntryViewModel timeEntryViewModel) => navigationService.Navigate <EditTimeEntryViewModel, IdParameter>(IdParameter.WithId(timeEntryViewModel.Id));
private void onTimeEntryAdded(IThreadSafeTimeEntry timeEntry) { var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat); TimeEntries.InsertItem(timeEntryViewModel); }
private Task edit(TimeEntryViewModel timeEntryViewModel) => navigationService.Navigate <EditTimeEntryViewModel, long>(timeEntryViewModel.Id);
private Task edit(TimeEntryViewModel timeEntryViewModel) { onboardingStorage.TimeEntryWasTapped(); return(navigationService.Navigate <EditTimeEntryViewModel, long>(timeEntryViewModel.Id)); }
private void insertTimeEntryInGroup(IThreadSafeTimeEntry timeEntry, int collectionIndex) { var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat); TimeEntries.InsertInChildCollection(collectionIndex, timeEntryViewModel); }