Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        private async Task delete(TimeEntryViewModel timeEntryViewModel)
        {
            await interactorFactory.DeleteTimeEntry(timeEntryViewModel.Id).Execute();

            analyticsService.DeleteTimeEntry.Track();
            dataSource.SyncManager.PushSync();
        }
Exemplo n.º 4
0
 private IObservable <Unit> continueTimeEntry(TimeEntryViewModel timeEntry)
 {
     return(interactorFactory
            .ContinueTimeEntry(timeEntry)
            .Execute()
            .Do(_ => onboardingStorage.SetTimeEntryContinued())
            .SelectUnit());
 }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 private IObservable <Unit> deleteTimeEntry(TimeEntryViewModel timeEntry)
 {
     return(interactorFactory
            .DeleteTimeEntry(timeEntry.Id)
            .Execute()
            .Do(_ => {
         analyticsService.DeleteTimeEntry.Track();
         dataSource.SyncManager.PushSync();
     }));
 }
Exemplo n.º 7
0
        private IObservable <Unit> timeEntrySelected(TimeEntryViewModel timeEntry)
        {
            if (isEditViewOpen)
            {
                return(Observable.Empty <Unit>());
            }

            onboardingStorage.TimeEntryWasTapped();
            return(navigate <EditTimeEntryViewModel, long>(timeEntry.Id).ToObservable());
        }
Exemplo n.º 8
0
        private void cancelDeleteTimeEntry()
        {
            if (!TimeEntries.IndexOf(timeEntryToDelete.Id).HasValue)
            {
                TimeEntries.InsertItem(timeEntryToDelete);
            }

            timeEntryToDelete = null;
            delayedDeletionDisposable.Dispose();
            showUndoSubject.OnNext(false);
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        public async Task FinilizeDelayDeleteTimeEntryIfNeeded()
        {
            if (timeEntryToDelete == null)
            {
                return;
            }

            delayedDeletionDisposable.Dispose();
            await deleteTimeEntry(timeEntryToDelete);

            timeEntryToDelete = null;
            showUndoSubject.OnNext(false);
        }
Exemplo n.º 11
0
        private async Task continueTimeEntry(TimeEntryViewModel timeEntryViewModel)
        {
            areContineButtonsEnabled = false;
            ContinueTimeEntryCommand.RaiseCanExecuteChanged();

            await interactorFactory
            .ContinueTimeEntry(timeEntryViewModel)
            .Execute()
            .Do(_ =>
            {
                areContineButtonsEnabled = true;
                ContinueTimeEntryCommand.RaiseCanExecuteChanged();
            });
        }
Exemplo n.º 12
0
 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());
 }
Exemplo n.º 13
0
        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();
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
 private Task edit(TimeEntryViewModel timeEntryViewModel)
 => navigationService.Navigate <EditTimeEntryViewModel, IdParameter>(IdParameter.WithId(timeEntryViewModel.Id));
Exemplo n.º 16
0
        private void onTimeEntryAdded(IThreadSafeTimeEntry timeEntry)
        {
            var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat);

            TimeEntries.InsertItem(timeEntryViewModel);
        }
Exemplo n.º 17
0
 private Task edit(TimeEntryViewModel timeEntryViewModel)
 => navigationService.Navigate <EditTimeEntryViewModel, long>(timeEntryViewModel.Id);
Exemplo n.º 18
0
        private Task edit(TimeEntryViewModel timeEntryViewModel)
        {
            onboardingStorage.TimeEntryWasTapped();

            return(navigationService.Navigate <EditTimeEntryViewModel, long>(timeEntryViewModel.Id));
        }
Exemplo n.º 19
0
        private void insertTimeEntryInGroup(IThreadSafeTimeEntry timeEntry, int collectionIndex)
        {
            var timeEntryViewModel = new TimeEntryViewModel(timeEntry, durationFormat);

            TimeEntries.InsertInChildCollection(collectionIndex, timeEntryViewModel);
        }