private List <IThreadSafeTimeEntry> getUnsyncedTimeEntries(IThreadSafeWorkspace workspace)
 => new List <IThreadSafeTimeEntry>
 {
     new MockTimeEntry(workspace.Id + 4, workspace, syncStatus: SyncStatus.RefetchingNeeded),
     new MockTimeEntry(workspace.Id + 5, workspace, syncStatus: SyncStatus.SyncFailed),
     new MockTimeEntry(workspace.Id + 6, workspace, syncStatus: SyncStatus.SyncNeeded),
 };
 private List <IThreadSafeTimeEntry> getSyncedTimeEntries(IThreadSafeWorkspace workspace)
 => new List <IThreadSafeTimeEntry>
 {
     new MockTimeEntry(workspace.Id + 1, workspace),
     new MockTimeEntry(workspace.Id + 2, workspace),
     new MockTimeEntry(workspace.Id + 3, workspace),
 };
Beispiel #3
0
        public SelectableWorkspaceViewModel(IThreadSafeWorkspace workspace, bool selected)
        {
            Ensure.Argument.IsNotNull(workspace, nameof(workspace));

            Selected      = selected;
            WorkspaceId   = workspace.Id;
            WorkspaceName = workspace.Name;
        }
        public override async Task Initialize()
        {
            await base.Initialize();

            startTimeEntryStopwatch = stopwatchProvider.Get(MeasuredOperation.OpenStartView);
            stopwatchProvider.Remove(MeasuredOperation.OpenStartView);

            defaultWorkspace = await interactorFactory.GetDefaultWorkspace()
                               .TrackException <InvalidOperationException, IThreadSafeWorkspace>("StartTimeEntryViewModel.Initialize")
                               .Execute();

            canCreateProjectsInWorkspace =
                await interactorFactory.GetAllWorkspaces().Execute().Select(allWorkspaces =>
                                                                            allWorkspaces.Any(ws => ws.IsEligibleForProjectCreation()));

            if (initialParameters != null)
            {
                var spans = new List <ISpan>();
                spans.Add(new TextSpan(initialParameters.EntryDescription));
                if (initialParameters.ProjectId != null)
                {
                    try
                    {
                        var project = await interactorFactory.GetProjectById((long)initialParameters.ProjectId).Execute();

                        spans.Add(new ProjectSpan(project));
                    }
                    catch
                    {
                        // Intentionally left blank
                    }
                }
                if (initialParameters.TagIds != null)
                {
                    try
                    {
                        var tags = initialParameters.TagIds.ToObservable()
                                   .SelectMany <long, IThreadSafeTag>(tagId => interactorFactory.GetTagById(tagId).Execute())
                                   .ToEnumerable();
                        spans.AddRange(tags.Select(tag => new TagSpan(tag)));
                    }
                    catch
                    {
                        // Intentionally left blank
                    }
                }

                textFieldInfo.Accept(textFieldInfo.Value.ReplaceSpans(spans.ToImmutableList()));
            }
            else
            {
                textFieldInfo.Accept(Autocomplete.TextFieldInfo.Empty(parameter?.WorkspaceId ?? defaultWorkspace.Id));
            }

            hasAnyTags     = (await DataSource.Tags.GetAll()).Any();
            hasAnyProjects = (await DataSource.Projects.GetAll()).Any();
        }
        private void updateWorkspace(IThreadSafeWorkspace newWorkspace)
        {
            if (viewAppearedForTheFirstTime())
            {
                return;
            }

            loadReport(newWorkspace, startDate, endDate, source);
        }
Beispiel #6
0
 public MockTag(
     long id,
     IThreadSafeWorkspace workspace,
     SyncStatus syncStatus = SyncStatus.InSync
     ) : this()
 {
     Id          = id;
     Workspace   = workspace;
     WorkspaceId = workspace.Id;
     SyncStatus  = syncStatus;
 }
Beispiel #7
0
        public async Task LoadReport(long?workspaceId, ReportPeriod period)
        {
            var getWorkspaceInteractor = workspaceId.HasValue
                ? interactorFactory.GetWorkspaceById(this.workspaceId)
                : interactorFactory.GetDefaultWorkspace();

            workspace = await getWorkspaceInteractor.Execute();

            workspaceId = workspace.Id;

            CalendarViewModel.SelectPeriod(period);
        }
Beispiel #8
0
 public Client(long id, long workspaceId, string name, DateTimeOffset at, SyncStatus syncStatus, string lastSyncErrorMessage = "", bool isDeleted = false, DateTimeOffset?serverDeletedAt = null, IThreadSafeWorkspace workspace = null)
 {
     Id                   = id;
     WorkspaceId          = workspaceId;
     Name                 = name;
     At                   = at;
     SyncStatus           = syncStatus;
     LastSyncErrorMessage = lastSyncErrorMessage;
     IsDeleted            = isDeleted;
     ServerDeletedAt      = serverDeletedAt;
     Workspace            = workspace;
 }
Beispiel #9
0
 public MockProject(
     long id,
     IThreadSafeWorkspace workspace,
     IThreadSafeClient client = null,
     SyncStatus syncStatus    = SyncStatus.InSync
     ) : this()
 {
     Id          = id;
     Workspace   = workspace;
     WorkspaceId = workspace.Id;
     Client      = client;
     ClientId    = client?.Id;
     SyncStatus  = syncStatus;
 }
Beispiel #10
0
 public MockTask(
     long id,
     IThreadSafeWorkspace workspace,
     IThreadSafeProject project,
     SyncStatus syncStatus = SyncStatus.InSync
     ) : this()
 {
     Id          = id;
     Workspace   = workspace;
     WorkspaceId = workspace.Id;
     Project     = project;
     ProjectId   = project.Id;
     SyncStatus  = syncStatus;
 }
Beispiel #11
0
            private IEnumerable <TagSuggestion> getTagSuggestions(int count, IThreadSafeWorkspace workspace)
            {
                for (int i = 0; i < count; i++)
                {
                    /* Do not inline 'workspace.Id' into another .Return() call
                     * because it's a proxy that won't work later on!
                     * This must be cached before usage.
                     */
                    var workspaceId = workspace.Id;

                    var tag = Substitute.For <IThreadSafeTag>();
                    tag.Id.Returns(i);
                    tag.WorkspaceId.Returns(workspaceId);
                    tag.Workspace.Returns(workspace);
                    tag.Name.Returns($"Tag{i}");

                    yield return(new TagSuggestion(tag));
                }
            }
            public ThePickDefaultWorkspaceMethod()
            {
                defaultWorkspace = new MockWorkspace {
                    Id = defaultWorkspaceId
                };
                workspace = new MockWorkspace {
                    Id = workspaceId, Name = workspaceName
                };

                UserSubject.OnNext(new MockUser());

                InteractorFactory.GetDefaultWorkspace().Execute()
                .Returns(Observable.Return(defaultWorkspace));

                InteractorFactory.GetWorkspaceById(workspaceId).Execute()
                .Returns(Observable.Return(workspace));

                ViewModel.Prepare();
            }
Beispiel #13
0
        private void loadReport(IThreadSafeWorkspace workspace, DateTimeOffset startDate, DateTimeOffset endDate, ReportsSource source)
        {
            if (this.startDate == startDate && this.endDate == endDate && workspaceId == workspace.Id)
            {
                return;
            }

            workspaceId    = workspace.Id;
            this.workspace = workspace;
            this.startDate = startDate;
            this.endDate   = endDate;
            this.source    = source;

            workspaceSubject.OnNext(workspace);
            startDateSubject.OnNext(startDate);
            endDateSubject.OnNext(endDate);

            updateCurrentDateRangeString();

            reportSubject.OnNext(Unit.Default);
        }
 private static IThreadSafeTimeEntry createTimeEntry(
     DateTimeOffset start,
     IThreadSafeWorkspace workspace,
     string description,
     long duration,
     IThreadSafeProject project = null,
     IThreadSafeTask task       = null,
     IThreadSafeTag[] tags      = null,
     bool billable = false)
 => new MockTimeEntry
 {
     Start       = start,
     Workspace   = workspace,
     WorkspaceId = workspace.Id,
     Description = description,
     Duration    = duration,
     Project     = project,
     ProjectId   = project?.Id,
     Task        = task,
     TaskId      = task?.Id,
     Billable    = billable,
     Tags        = tags ?? Array.Empty <IThreadSafeTag>(),
     TagIds      = tags?.Select(tag => tag.Id) ?? new long[0]
 };
Beispiel #15
0
 public MockTimeEntry(
     long id,
     IThreadSafeWorkspace workspace,
     DateTimeOffset?start              = null,
     long?duration                     = null,
     IThreadSafeProject project        = null,
     IThreadSafeTask task              = null,
     IEnumerable <IThreadSafeTag> tags = null,
     SyncStatus syncStatus             = SyncStatus.InSync
     ) : this()
 {
     Id          = id;
     Workspace   = workspace;
     WorkspaceId = workspace.Id;
     Start       = start ?? default(DateTimeOffset);
     Duration    = duration;
     Project     = project;
     ProjectId   = project?.Id;
     Task        = task;
     TaskId      = task?.Id;
     Tags        = tags;
     TagIds      = tags?.Select(tag => tag.Id);
     SyncStatus  = syncStatus;
 }
Beispiel #16
0
 private IObservable <IThreadSafeWorkspace> createOrUpdate(IThreadSafeWorkspace workspace)
 => dataSource
 .GetAll(ws => ws.Id == workspace.Id, includeInaccessibleEntities: true)
 .SelectMany(stored => stored.None()
             ? dataSource.Create(workspace)
             : dataSource.Update(workspace));
 private WorkspaceGroupedSuggestionsCollection workspaceGroupedSuggestionCollection(IThreadSafeWorkspace workspace)
 => new WorkspaceGroupedSuggestionsCollection(
     workspace.Name,
     workspace.Id,
     new[] { ProjectSuggestion.NoProject(workspace.Id, workspace.Name) });
Beispiel #18
0
 private IObservable <IThreadSafeWorkspace> markAsGhost(IThreadSafeWorkspace workspaceToMark)
 => dataSource.Update(workspaceToMark.AsGhost());
Beispiel #19
0
 private Client(IClient entity, SyncStatus syncStatus, string lastSyncErrorMessage, bool isDeleted = false, IThreadSafeWorkspace workspace = null)
     : this(entity.Id, entity.WorkspaceId, entity.Name, entity.At, syncStatus, lastSyncErrorMessage, isDeleted, entity.ServerDeletedAt, workspace)
 {
 }
Beispiel #20
0
 public static IThreadSafeWorkspace AsInaccessible(this IThreadSafeWorkspace workspace)
 => new Workspace(workspace, isInaccessible: true);
Beispiel #21
0
 internal Workspace(IThreadSafeWorkspace workspace, bool isInaccessible)
     : this(workspace)
 {
     IsInaccessible = isInaccessible;
 }
        public override async Task Initialize(StartTimeEntryParameters parameter)
        {
            await base.Initialize(parameter);

            this.parameter = parameter;
            startTime      = parameter.StartTime;
            duration       = parameter.Duration;

            PlaceholderText = parameter.PlaceholderText;
            if (!string.IsNullOrEmpty(parameter.EntryDescription))
            {
                initialParameters = parameter;
            }

            displayedTime.Accept(duration ?? TimeSpan.Zero);

            timeService.CurrentDateTimeObservable
            .Where(_ => isRunning)
            .Subscribe(currentTime => displayedTime.Accept(currentTime - startTime))
            .DisposedBy(disposeBag);

            defaultWorkspace = await interactorFactory.GetDefaultWorkspace()
                               .TrackException <InvalidOperationException, IThreadSafeWorkspace>("StartTimeEntryViewModel.Initialize")
                               .Execute();

            canCreateProjectsInWorkspace =
                await interactorFactory.GetAllWorkspaces().Execute().Select(allWorkspaces =>
                                                                            allWorkspaces.Any(ws => ws.IsEligibleForProjectCreation()));

            if (initialParameters != null)
            {
                var spans = new List <ISpan>();
                spans.Add(new TextSpan(initialParameters.EntryDescription));
                if (initialParameters.ProjectId != null)
                {
                    try
                    {
                        var project = await interactorFactory.GetProjectById((long)initialParameters.ProjectId).Execute();

                        spans.Add(new ProjectSpan(project));
                    }
                    catch
                    {
                        // Intentionally left blank
                    }
                }
                if (initialParameters.TagIds != null)
                {
                    try
                    {
                        var tags = initialParameters.TagIds.ToObservable()
                                   .SelectMany <long, IThreadSafeTag>(tagId => interactorFactory.GetTagById(tagId).Execute())
                                   .ToEnumerable();
                        spans.AddRange(tags.Select(tag => new TagSpan(tag)));
                    }
                    catch
                    {
                        // Intentionally left blank
                    }
                }

                textFieldInfo.Accept(textFieldInfo.Value.ReplaceSpans(spans.ToImmutableList()));
            }
            else
            {
                textFieldInfo.Accept(Autocomplete.TextFieldInfo.Empty(parameter?.WorkspaceId ?? defaultWorkspace.Id));
            }

            hasAnyTags     = (await DataSource.Tags.GetAll()).Any();
            hasAnyProjects = (await DataSource.Projects.GetAll()).Any();
        }
 private IObservable <IThreadSafeUser> updateDefaultWorkspace(IThreadSafeWorkspace workspace)
 => userDataSource.Get()
 .Select(user => user.With(workspace.Id))
 .SelectMany(userDataSource.Update);
Beispiel #24
0
 public static IThreadSafeWorkspace AsGhost(this IThreadSafeWorkspace workspace)
 => new Workspace(workspace, isGhost: true);
 private IObservable <IThreadSafeWorkspace> markAsInaccessible(IThreadSafeWorkspace workspaceToMark)
 => dataSource.Update(workspaceToMark.AsInaccessible());
Beispiel #26
0
 private IObservable <Unit> setDefaultWorkspace(IThreadSafeWorkspace workspace)
 => new SetDefaultWorkspaceInteractor(timeService, dataSource.User, workspace.Id).Execute();
 private SelectableWorkspaceViewModel toSelectable(IThreadSafeWorkspace workspace)
 => new SelectableWorkspaceViewModel(workspace, false);
Beispiel #28
0
 internal Workspace(IThreadSafeWorkspace workspace, bool isGhost)
     : this(workspace)
 {
     IsGhost = isGhost;
 }