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); }
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); }
public async Task ClosesTheViewModel() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); View.Received().Close(); }
private void toggleTaskSuggestions(ProjectSuggestion projectSuggestion) { var grouping = Suggestions.FirstOrDefault(s => s.WorkspaceId == projectSuggestion.WorkspaceId); if (grouping == null) { return; } var suggestionIndex = grouping.IndexOf(projectSuggestion); if (suggestionIndex < 0) { return; } projectSuggestion.TasksVisible = !projectSuggestion.TasksVisible; var groupingIndex = Suggestions.IndexOf(grouping); Suggestions.Remove(grouping); Suggestions.Insert(groupingIndex, new WorkspaceGroupedCollection <AutocompleteSuggestion>( grouping.WorkspaceName, grouping.WorkspaceId, getSuggestionsWithTasks(grouping) ) ); }
private void insertTasksFor(ProjectSuggestion projectSuggestion) { var indexOfTargetSection = suggestionsSubject.Value.IndexOf(section => section.Header == projectSuggestion.WorkspaceName); if (indexOfTargetSection < 0) { return; } var targetSection = suggestionsSubject.Value.ElementAt(indexOfTargetSection); var indexOfSuggestion = targetSection.Items.IndexOf(project => project == projectSuggestion); if (indexOfSuggestion < 0) { return; } var newItemsInSection = targetSection.Items.InsertRange(indexOfSuggestion + 1, projectSuggestion.Tasks.OrderBy(task => task.Name)); var newSection = new SectionModel <string, AutocompleteSuggestion>(targetSection.Header, newItemsInSection); var newSuggestions = suggestionsSubject.Value.ToList(); newSuggestions[indexOfTargetSection] = newSection; suggestionsSubject.OnNext(newSuggestions); }
public async Task ReturnsNoTaskIfNoProjectWasSelected() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); (await ViewModel.Result) .TaskId.Should().Be(null); }
public async Task ClosesTheViewModel() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); await NavigationService.Received() .Close(Arg.Is(ViewModel), Arg.Any <SelectProjectParameter>()); }
private void toggleTaskSuggestions(ProjectSuggestion parameter) { var offset = SuggestionsTableView.ContentOffset; var frameHeight = SuggestionsTableView.Frame.Height; ViewModel.ToggleTasks.Execute(parameter); SuggestionsTableView.CorrectOffset(offset, frameHeight); }
public async Task ReturnsNoTaskIfNoProjectWasSelected() { ViewModel.SelectProject .Execute(ProjectSuggestion.NoProject(0, "")); await NavigationService.Received().Close( Arg.Is(ViewModel), Arg.Is <SelectProjectParameter>( parameter => parameter.TaskId == null)); }
public async Task ReturnsWorksaceIdIfNoProjectWasSelected() { var noProjectSuggestion = ProjectSuggestion.NoProject(13, ""); prepareDialogService(); ViewModel.SelectProject.Execute(noProjectSuggestion); await ensureReturnsWorkspaceIdOfSuggestion(noProjectSuggestion); }
public async Task ReturnsNoTaskIdWhenSelectingAProject() { var project = Substitute.For <IThreadSafeProject>(); project.Id.Returns(13); var selectedProject = new ProjectSuggestion(project); ViewModel.SelectProject.Execute(selectedProject); (await ViewModel.Result) .TaskId.Should().Be(null); }
public TheToggleProjectSuggestionsCommand() { var suggestions = ProjectSuggestion.FromProjectsPrependingEmpty(Enumerable.Empty <IDatabaseProject>()); AutocompleteProvider .Query(Arg.Is <TextFieldInfo>(info => info.Text.Contains("@"))) .Returns(Observable.Return(suggestions)); AutocompleteProvider .Query(Arg.Any <string>(), Arg.Is(AutocompleteSuggestionType.Projects)) .Returns(Observable.Return(suggestions)); }
public async Task ReturnsWorkspaceIdOfTheProjectIfProjectWasSelected() { var project = Substitute.For <IThreadSafeProject>(); project.WorkspaceId.Returns(13); var projectSuggestion = new ProjectSuggestion(project); prepareDialogService(); ViewModel.SelectProject.Execute(projectSuggestion); await ensureReturnsWorkspaceIdOfSuggestion(projectSuggestion); }
private void toggleTaskSuggestions(ProjectSuggestion projectSuggestion) { if (projectSuggestion.TasksVisible) { removeTasksFor(projectSuggestion); } else { insertTasksFor(projectSuggestion); } projectSuggestion.TasksVisible = !projectSuggestion.TasksVisible; }
private void toggleTasks(ProjectSuggestion projectSuggestion) { var currentExpandedProjects = expandedProjects.Value; if (currentExpandedProjects.Contains(projectSuggestion.ProjectId)) { currentExpandedProjects.Remove(projectSuggestion.ProjectId); } else { currentExpandedProjects.Add(projectSuggestion.ProjectId); } expandedProjects.OnNext(currentExpandedProjects); }
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 async Task ReturnsNoTaskIdWhenSelectingAProject() { var project = Substitute.For <IThreadSafeProject>(); project.Id.Returns(13); var selectedProject = new ProjectSuggestion(project); ViewModel.SelectProject.Execute(selectedProject); await NavigationService.Received().Close( Arg.Is(ViewModel), Arg.Is <SelectProjectParameter>( parameter => parameter.TaskId == null)); }
public async Task ReturnsTheSelectedProjectIdWhenSelectingAProject() { var project = Substitute.For <IDatabaseProject>(); project.Id.Returns(13); var selectedProject = new ProjectSuggestion(project); await ViewModel.SelectProjectCommand.ExecuteAsync(selectedProject); await NavigationService.Received().Close( Arg.Is(ViewModel), Arg.Is <(long?projectId, long?taskId)>( parameter => parameter.projectId == selectedProject.ProjectId)); }
public static TextFieldInfo FromProjectSuggestion( this TextFieldInfo textFieldInfo, ProjectSuggestion projectSuggestion) { var result = textFieldInfo.WithProject( projectSuggestion.WorkspaceId, projectSuggestion.ProjectId, projectSuggestion.ProjectName, projectSuggestion.ProjectColor, null, null ); return(result); }
private void setProject(ProjectSuggestion projectSuggestion) { if (TextFieldInfo.WorkspaceId.HasValue) { clearTagsIfNeeded(TextFieldInfo.WorkspaceId.Value, projectSuggestion.WorkspaceId); } TextFieldInfo = TextFieldInfo .RemoveProjectQueryFromDescriptionIfNeeded() .WithProjectInfo( projectSuggestion.WorkspaceId, projectSuggestion.ProjectId, projectSuggestion.ProjectName, projectSuggestion.ProjectColor); }
public TheSuggestCreationProperty() { var project = Substitute.For <IDatabaseProject>(); project.Name.Returns(name); var suggestion = new ProjectSuggestion(project); DataSource.AutocompleteProvider .Query(Arg.Is <QueryInfo>(info => info.SuggestionType == AutocompleteSuggestionType.Projects)) .Returns(Observable.Return(new List <ProjectSuggestion> { suggestion })); ViewModel.Prepare(); }
private async Task createProject() { var projectId = await navigationService.Navigate <EditProjectViewModel, string, long?>(CurrentQuery.Trim()); if (projectId == null) { return; } var project = await dataSource.Projects.GetById(projectId.Value); var projectSuggestion = new ProjectSuggestion(project); await SelectSuggestionCommand.ExecuteAsync(projectSuggestion); }
public TheSuggestCreationProperty() { var project = Substitute.For <IThreadSafeProject>(); project.Name.Returns(name); var suggestion = new ProjectSuggestion(project); InteractorFactory .GetProjectsAutocompleteSuggestions(Arg.Any <IList <string> >()) .Execute() .Returns(Observable.Return(new List <ProjectSuggestion> { suggestion })); ViewModel.Prepare(); }
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 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()); }); }
private async Task createProject() { var projectId = await Navigate <EditProjectViewModel, string, long?>(currentQuery); if (projectId == null) { return; } var project = await interactorFactory.GetProjectById(projectId.Value).Execute(); var projectSuggestion = new ProjectSuggestion(project); textFieldInfo.Accept(textFieldInfo.Value.FromProjectSuggestion(projectSuggestion)); isSuggestingProjects.Accept(false); queryByTypeSubject.OnNext(AutocompleteSuggestionType.None); hasAnyProjects = true; }
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 async Task createProject() { var createProjectStopwatch = stopwatchProvider.CreateAndStore(MeasuredOperation.OpenCreateProjectViewFromStartTimeEntryView); createProjectStopwatch.Start(); var projectId = await navigationService.Navigate <EditProjectViewModel, string, long?>(currentQuery); if (projectId == null) { return; } var project = await interactorFactory.GetProjectById(projectId.Value).Execute(); var projectSuggestion = new ProjectSuggestion(project); textFieldInfo.Accept(textFieldInfo.Value.FromProjectSuggestion(projectSuggestion)); isSuggestingProjects.Accept(false); queryByTypeSubject.OnNext(AutocompleteSuggestionType.None); hasAnyProjects = true; }
private void removeTasksFor(ProjectSuggestion projectSuggestion) { var indexOfTargetSection = suggestionsSubject.Value.IndexOf(section => section.Items.Contains(projectSuggestion)); if (indexOfTargetSection < 0) { return; } var targetSection = suggestionsSubject.Value.ElementAt(indexOfTargetSection); var newItemsInSection = targetSection.Items.ToList(); foreach (var task in projectSuggestion.Tasks) { newItemsInSection.Remove(task); } var newSection = new SectionModel <string, AutocompleteSuggestion>(targetSection.Header, newItemsInSection); var newSuggestions = suggestionsSubject.Value.ToList(); newSuggestions[indexOfTargetSection] = newSection; suggestionsSubject.OnNext(newSuggestions); }
private static WorkspaceGroupedSuggestionsCollection withNoProject(WorkspaceGroupedSuggestionsCollection collection) { collection.Insert(0, ProjectSuggestion.NoProject(collection.WorkspaceId, collection.WorkspaceName)); return(collection); }