private IEnumerable <SectionModel <string, AutocompleteSuggestion> > toCollections(IEnumerable <IGrouping <long, AutocompleteSuggestion> > suggestions) { var sections = suggestions.Select(group => { var header = ""; var items = group .Distinct(AutocompleteSuggestionComparer.Instance) .SelectMany(includeTasksIfExpanded); if (group.First() is ProjectSuggestion projectSuggestion) { header = projectSuggestion.WorkspaceName; items = items.Prepend(ProjectSuggestion.NoProject(projectSuggestion.WorkspaceId, projectSuggestion.WorkspaceName)); } else if (group.First() is TimeEntrySuggestion timeEntrySuggestion) { header = timeEntrySuggestion.WorkspaceName; } return(new SectionModel <string, AutocompleteSuggestion>(header, items)); } ); return(sections); }
private IEnumerable <SectionModel <string, AutocompleteSuggestion> > toCollections(IEnumerable <IGrouping <long, AutocompleteSuggestion> > suggestions) { var sections = suggestions.Select(group => { var header = ""; var items = group .Distinct(AutocompleteSuggestionComparer.Instance) .SelectMany(includeTasksIfExpanded); if (group.First() is ProjectSuggestion projectSuggestion) { header = projectSuggestion.WorkspaceName; items = items.Prepend(ProjectSuggestion.NoProject(projectSuggestion.WorkspaceId, projectSuggestion.WorkspaceName)); } return(new SectionModel <string, AutocompleteSuggestion>(header, items)); } ); if (suggestionsLoadingStopwatches.ContainsKey(currentQuery)) { suggestionsLoadingStopwatches[currentQuery]?.Stop(); suggestionsLoadingStopwatches = new Dictionary <string, IStopwatch>(); } return(sections); }
public async Task ClosesTheViewModel() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); View.Received().Close(); }
public async Task ClosesTheViewModel() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); await NavigationService.Received() .Close(Arg.Is(ViewModel), Arg.Any <SelectProjectParameter>()); }
public async Task ReturnsNoTaskIfNoProjectWasSelected() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); (await ViewModel.Result) .TaskId.Should().Be(null); }
public async Task ReturnsWorksaceIdIfNoProjectWasSelected() { var noProjectSuggestion = ProjectSuggestion.NoProject(13, ""); prepareDialogService(); ViewModel.SelectProject.Execute(noProjectSuggestion); await ensureReturnsWorkspaceIdOfSuggestion(noProjectSuggestion); }
public async Task ReturnsNoTaskIfNoProjectWasSelected() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); await NavigationService.Received().Close( Arg.Is(ViewModel), Arg.Is <SelectProjectParameter>( parameter => parameter.TaskId == null)); }
private SectionModel <string, AutocompleteSuggestion> collectionSection(IEnumerable <ProjectSuggestion> suggestions, bool prependNoProject) { var workspaceName = suggestions.First().WorkspaceName; var sectionItems = suggestions.ToList(); if (prependNoProject) { var workspaceIdForNoProject = suggestions.First().WorkspaceId; var noProjectSuggestion = ProjectSuggestion.NoProject(workspaceIdForNoProject, workspaceName); sectionItems.Insert(0, noProjectSuggestion); } return(new SectionModel <string, AutocompleteSuggestion>(workspaceName, sectionItems)); }
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()); }); }
public async Task ReturnsWorkspaceIfNoProjectWasSelected() { View.Confirm( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>() ).Returns(Observable.Return(true)); long workspaceId = 420; ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(workspaceId, "")); (await ViewModel.Result) .WorkspaceId.Should().Be(workspaceId); }
public async Task ReturnsWorkspaceIfNoProjectWasSelected() { DialogService.Confirm( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>() ).Returns(Observable.Return(true)); long workspaceId = 420; ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(workspaceId, "")); await NavigationService.Received().Close( Arg.Is(ViewModel), Arg.Is <SelectProjectParameter>( parameter => parameter.WorkspaceId == workspaceId)); }
private static WorkspaceGroupedSuggestionsCollection withNoProject(WorkspaceGroupedSuggestionsCollection collection) { collection.Insert(0, ProjectSuggestion.NoProject(collection.WorkspaceId, collection.WorkspaceName)); return(collection); }
private WorkspaceGroupedSuggestionsCollection workspaceGroupedSuggestionCollection(IThreadSafeWorkspace workspace) => new WorkspaceGroupedSuggestionsCollection( workspace.Name, workspace.Id, new[] { ProjectSuggestion.NoProject(workspace.Id, workspace.Name) });