Пример #1
0
        public override async Task Initialize()
        {
            await base.Initialize();

            await CalendarViewModel.Initialize();

            WorkspacesObservable
            .Subscribe(data => Workspaces = data)
            .DisposedBy(disposeBag);

            var user = await dataSource.User.Get();

            userId = user.Id;

            IInteractor <IObservable <IThreadSafeWorkspace> > workspaceInteractor;

            workspaceInteractor = interactorFactory.GetDefaultWorkspace();

            var workspace = await workspaceInteractor
                            .TrackException <InvalidOperationException, IThreadSafeWorkspace>("ReportsViewModel.Initialize")
                            .Execute();

            workspaceId = workspace.Id;
            workspaceSubject.OnNext(workspace);

            CalendarViewModel.SelectedDateRangeObservable
            .Subscribe(changeDateRange)
            .DisposedBy(disposeBag);

            reportSubject
            .AsObservable()
            .Do(setLoadingState)
            .SelectMany(_ =>
                        startDate == default(DateTimeOffset) || endDate == default(DateTimeOffset)
                       ? Observable.Empty <ProjectSummaryReport>()
                       : interactorFactory.GetProjectSummary(workspaceId, startDate, endDate).Execute())
            .Catch(Observable.Return <ProjectSummaryReport>(null))
            .Subscribe(onReport)
            .DisposedBy(disposeBag);

            dataSource.Preferences.Current
            .Subscribe(onPreferencesChanged)
            .DisposedBy(disposeBag);

            dataSource.User.Current
            .Select(currentUser => currentUser.BeginningOfWeek)
            .Subscribe(onBeginningOfWeekChanged)
            .DisposedBy(disposeBag);

            interactorFactory.ObserveDefaultWorkspaceId()
            .Execute()
            .Where(newWorkspaceId => newWorkspaceId != workspaceId)
            .SelectMany(id => interactorFactory.GetWorkspaceById(id).Execute())
            .Where(ws => !ws.IsInaccessible)
            .Subscribe(updateWorkspace)
            .DisposedBy(disposeBag);
        }
Пример #2
0
        public async Task LoadReport(long?workspaceId, DateTimeOffset startDate, DateTimeOffset endDate, ReportsSource source)
        {
            var getWorkspaceInteractor = workspaceId.HasValue
                ? interactorFactory.GetWorkspaceById(this.workspaceId)
                : interactorFactory.GetDefaultWorkspace();

            var workspace = await getWorkspaceInteractor.Execute();

            loadReport(workspace, startDate, endDate, source);
        }
Пример #3
0
        private async Task pickWorkspace()
        {
            var parameters          = WorkspaceParameters.Create(workspaceId, Resources.Workspaces, allowQuerying: false);
            var selectedWorkspaceId =
                await navigationService
                .Navigate <SelectWorkspaceViewModel, WorkspaceParameters, long>(parameters);

            if (selectedWorkspaceId == workspaceId)
            {
                return;
            }

            var workspace = await interactorFactory.GetWorkspaceById(selectedWorkspaceId).Execute();

            clientId      = null;
            ClientName    = "";
            workspaceId   = selectedWorkspaceId;
            WorkspaceName = workspace.Name;

            await setupNameAlreadyTakenError();

            areCustomColorsEnabled = await interactorFactory.AreCustomColorsEnabledForWorkspace(workspace.Id).Execute();

            if (areCustomColorsEnabled || Array.IndexOf(Helper.Color.DefaultProjectColors, Color) >= 0)
            {
                return;
            }

            pickRandomColor();
        }
Пример #4
0
 public IObservable <IThreadSafeWorkspace> Execute()
 => dataSource.User
 .Get()
 .SelectMany(user => user.DefaultWorkspaceId.HasValue
             ? interactorFactory.GetWorkspaceById(user.DefaultWorkspaceId.Value).Execute()
             : chooseWorkspace())
 .Catch((InvalidOperationException exception) => chooseWorkspace())
 .Select(Workspace.From);
Пример #5
0
        private async Task selectProject()
        {
            analyticsService.EditEntrySelectProject.Track();
            analyticsService.EditViewTapped.Track(EditViewTapSource.Project);

            OnboardingStorage.SelectsProject();

            var chosenProject = await Navigate <SelectProjectViewModel, SelectProjectParameter, SelectProjectParameter>(
                new SelectProjectParameter(projectId, taskId, workspaceId));

            if (chosenProject.WorkspaceId == workspaceId &&
                chosenProject.ProjectId == projectId &&
                chosenProject.TaskId == taskId)
            {
                return;
            }

            projectId = chosenProject.ProjectId;
            taskId    = chosenProject.TaskId;

            if (projectId == null)
            {
                projectClientTaskSubject.OnNext(ProjectClientTaskInfo.Empty);

                clearTagsIfNeeded(workspaceId, chosenProject.WorkspaceId);
                workspaceIdSubject.OnNext(chosenProject.WorkspaceId);

                var workspace = await interactorFactory.GetWorkspaceById(chosenProject.WorkspaceId).Execute();

                isInaccessibleSubject.OnNext(workspace.IsInaccessible);

                return;
            }

            var project = await interactorFactory.GetProjectById(projectId.Value).Execute();

            clearTagsIfNeeded(workspaceId, project.WorkspaceId);

            var task = chosenProject.TaskId.HasValue
                ? await interactorFactory.GetTaskById(taskId.Value).Execute()
                : null;

            var taskName = task?.Name ?? string.Empty;

            projectClientTaskSubject.OnNext(new ProjectClientTaskInfo(
                                                project.DisplayName(),
                                                project.DisplayColor(),
                                                project.Client?.Name,
                                                taskName,
                                                project.IsPlaceholder(),
                                                task?.IsPlaceholder() ?? false));

            workspaceIdSubject.OnNext(chosenProject.WorkspaceId);

            isInaccessibleSubject.OnNext(project.IsInaccessible);
        }
        private async Task selectProject()
        {
            if (!(Workspace.Value?.Id is long workspaceId))
            {
                return;
            }

            var chosenProjectParams = await Navigate <SelectProjectViewModel, SelectProjectParameter, SelectProjectParameter>(
                new SelectProjectParameter(Project.Value?.Id, TaskId.Value, workspaceId, false));

            if (chosenProjectParams.WorkspaceId == workspaceId &&
                chosenProjectParams.ProjectId == Project.Value?.Id &&
                chosenProjectParams.TaskId == TaskId.Value)
            {
                return;
            }

            TaskId.Accept(chosenProjectParams.TaskId);

            var chosenWorkspace = await interactorFactory.GetWorkspaceById(chosenProjectParams.WorkspaceId).Execute();

            if (!(chosenProjectParams.ProjectId is long chosenProjectProjectId))
            {
                projectClientTaskInfo.OnNext(EditTimeEntryViewModel.ProjectClientTaskInfo.Empty);
                clearTagsIfNeeded(workspaceId, chosenProjectParams.WorkspaceId);
                Workspace.Accept(chosenWorkspace);
                Project.Accept(null);
                return;
            }

            var project = await interactorFactory.GetProjectById(chosenProjectProjectId).Execute();

            clearTagsIfNeeded(workspaceId, project.WorkspaceId);

            var task = chosenProjectParams.TaskId.HasValue
                ? await interactorFactory.GetTaskById(chosenProjectParams.TaskId.Value).Execute()
                : null;

            var taskName = task?.Name ?? string.Empty;

            projectClientTaskInfo.OnNext(new EditTimeEntryViewModel.ProjectClientTaskInfo(
                                             project.DisplayName(),
                                             project.DisplayColor(),
                                             project.Client?.Name,
                                             taskName,
                                             project.IsPlaceholder(),
                                             task?.IsPlaceholder() ?? false));

            Workspace.Accept(chosenWorkspace);
            Project.Accept(project);
        }
Пример #7
0
        private async Task pickWorkspace()
        {
            var defaultWorkspace = await interactorFactory.GetDefaultWorkspace()
                                   .TrackException <InvalidOperationException, IThreadSafeWorkspace>(
                "SiriShortcutsSelectReportPeriodViewModel.PickWorkspace")
                                   .Execute();

            var selectWorkspaceParams = new SelectWorkspaceParameters(Resources.SelectWorkspace, SelectedWorkspace.Value?.Id ?? defaultWorkspace.Id);
            var selectedWorkspaceId   =
                await Navigate <SelectWorkspaceViewModel, SelectWorkspaceParameters, long>(selectWorkspaceParams);

            var workspace = await interactorFactory.GetWorkspaceById(selectedWorkspaceId).Execute();

            SelectedWorkspace.Accept(workspace);
        }
Пример #8
0
        private async Task changeDefaultWorkspace(long selectedWorkspaceId)
        {
            if (selectedWorkspaceId == workspaceId)
            {
                return;
            }

            var workspace = await interactorFactory.GetWorkspaceById(selectedWorkspaceId).Execute();

            workspaceId   = selectedWorkspaceId;
            WorkspaceName = workspace.Name;

            await dataSource.User.UpdateWorkspace(workspaceId);

            dataSource.SyncManager.PushSync();
        }
Пример #9
0
        private IObservable <IThreadSafeWorkspace> pickWorkspace()
        {
            return(currentWorkspace.FirstAsync().SelectMany(workspaceFromViewModel));

            IObservable <IThreadSafeWorkspace> workspaceFromViewModel(IThreadSafeWorkspace currentWorkspace)
            => Navigate <SelectWorkspaceViewModel, SelectWorkspaceParameters, long>(new SelectWorkspaceParameters(Resources.SetDefaultWorkspace, currentWorkspace.Id))
            .ToObservable()
            .SelectMany(selectedWorkspaceId => workspaceFromId(selectedWorkspaceId, currentWorkspace));

            IObservable <IThreadSafeWorkspace> workspaceFromId(long selectedWorkspaceId, IThreadSafeWorkspace currentWorkspace)
            => selectedWorkspaceId == currentWorkspace.Id
                    ? Observable.Empty <IThreadSafeWorkspace>()
                    : interactorFactory
            .GetWorkspaceById(selectedWorkspaceId)
            .Execute();
        }
Пример #10
0
        private IObservable <IThreadSafeWorkspace> pickWorkspace()
        {
            return(currentWorkspace.FirstAsync().SelectMany(workspaceFromViewModel));

            IObservable <IThreadSafeWorkspace> workspaceFromViewModel(IThreadSafeWorkspace currentWorkspace)
            => navigationService
            .Navigate <SelectWorkspaceViewModel, long, long>(currentWorkspace.Id)
            .ToObservable()
            .SelectMany(selectedWorkspaceId => workspaceFromId(selectedWorkspaceId, currentWorkspace));

            IObservable <IThreadSafeWorkspace> workspaceFromId(long selectedWorkspaceId, IThreadSafeWorkspace currentWorkspace)
            => selectedWorkspaceId == currentWorkspace.Id
                    ? Observable.Empty <IThreadSafeWorkspace>()
                    : interactorFactory
            .GetWorkspaceById(selectedWorkspaceId)
            .Execute();
        }
Пример #11
0
        public override async Task Initialize(SelectProjectParameter parameter)
        {
            await base.Initialize(parameter);

            creationEnabled = parameter.CreationEnabled;
            taskId          = parameter.TaskId;
            projectId       = parameter.ProjectId;
            workspaceId     = parameter.WorkspaceId;

            var workspaces = await interactorFactory.GetAllWorkspaces().Execute();

            projectCreationSuggestionsAreEnabled = workspaces.Any(ws => ws.IsEligibleForProjectCreation());
            UseGrouping = workspaces.Count() > 1;

            FilterText.Subscribe(async text =>
            {
                var suggestions = interactorFactory.GetProjectsAutocompleteSuggestions(text.SplitToQueryWords()).Execute().SelectMany(x => x).ToEnumerable()
                                  .Cast <ProjectSuggestion>()
                                  .Select(setSelectedProject);

                var collectionSections = suggestions
                                         .GroupBy(project => project.WorkspaceId)
                                         .Select(grouping => grouping.OrderBy(projectSuggestion => projectSuggestion.ProjectName))
                                         .OrderBy(grouping => grouping.First().WorkspaceName)
                                         .Select(grouping => collectionSection(grouping, prependNoProject: string.IsNullOrEmpty(text)))
                                         .ToList();

                if (creationEnabled && shouldSuggestCreation(text))
                {
                    var createEntitySuggestion = new CreateEntitySuggestion(Resources.CreateProject, text);
                    var section = new SectionModel <string, AutocompleteSuggestion>(null, new[] { createEntitySuggestion });
                    collectionSections.Insert(0, section);
                }

                if (collectionSections.None())
                {
                    var workspace           = await interactorFactory.GetWorkspaceById(workspaceId).Execute();
                    var noProjectSuggestion = ProjectSuggestion.NoProject(workspace.Id, workspace.Name);
                    collectionSections.Add(
                        new SectionModel <string, AutocompleteSuggestion>(null, new[] { noProjectSuggestion })
                        );
                }

                suggestionsSubject.OnNext(collectionSections.ToImmutableList());
            });
        }
Пример #12
0
        private IObservable <IThreadSafeWorkspace> pickWorkspace()
        {
            return(currentWorkspace.FirstAsync().SelectMany(workspaceFromViewModel));

            IObservable <IThreadSafeWorkspace> workspaceFromViewModel(IThreadSafeWorkspace currentWorkspace)
            => interactorFactory.GetAllWorkspaces().Execute()
            .SelectMany(allWorkspaces =>
            {
                var eligibleWorkspaces     = allWorkspaces.Where(ws => ws.IsEligibleForProjectCreation()).ToList();
                var selectWorkspaces       = eligibleWorkspaces.Select(ws => new SelectOption <IThreadSafeWorkspace>(ws, ws.Name));
                var selectedWorkspaceIndex = eligibleWorkspaces.IndexOf(ws => ws.Id == currentWorkspace.Id);

                return(View.Select(Resources.Workspace, selectWorkspaces, selectedWorkspaceIndex));
            })
            .SelectMany(selectedWorkspace => workspaceFromId(selectedWorkspace.Id, currentWorkspace));

            IObservable <IThreadSafeWorkspace> workspaceFromId(long selectedWorkspaceId, IThreadSafeWorkspace currentWorkspace)
            => selectedWorkspaceId == currentWorkspace.Id
                    ? Observable.Empty <IThreadSafeWorkspace>()
                    : interactorFactory
            .GetWorkspaceById(selectedWorkspaceId)
            .Execute();
        }