public UserExploreViewModel(ISessionService applicationService) { Title = "Explore Users"; Items = InternalItems.CreateDerivedCollection(x => new UserItemViewModel(x.Login, x.AvatarUrl, false, () => { var vm = this.CreateViewModel <UserViewModel>(); vm.Init(x.Login, x); NavigateTo(vm); })); var canSearch = this.WhenAnyValue(x => x.SearchKeyword).Select(x => !string.IsNullOrEmpty(x)); SearchCommand = ReactiveCommand.CreateAsyncTask(canSearch, async t => { try { InternalItems.Clear(); var request = new SearchUsersRequest(SearchKeyword); var response = await applicationService.GitHubClient.Search.SearchUsers(request); InternalItems.Reset(response.Items); } catch (Exception e) { var msg = string.Format("Unable to search for {0}. Please try again.", SearchKeyword.Humanize()); throw new Exception(msg, e); } }); }
public ReleasesViewModel(ISessionService applicationService) { Title = "Releases"; Items = InternalItems.CreateDerivedCollection(CreateItemViewModel, x => !x.Draft); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => InternalItems.Reset(await applicationService.GitHubClient.Release.GetAll(RepositoryOwner, RepositoryName))); }
public RepositoryExploreViewModel(ISessionService applicationService) { ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList; Title = "Explore Repositories"; var gotoRepository = new Action <RepositoryItemViewModel>(x => { var vm = this.CreateViewModel <RepositoryViewModel>(); vm.Init(x.Owner, x.Name, x.Repository); NavigateTo(vm); }); Items = InternalItems.CreateDerivedCollection(x => new RepositoryItemViewModel(x, true, gotoRepository)); var canSearch = this.WhenAnyValue(x => x.SearchKeyword).Select(x => !string.IsNullOrEmpty(x)); SearchCommand = ReactiveCommand.CreateAsyncTask(canSearch, async t => { try { InternalItems.Clear(); var request = new SearchRepositoriesRequest(SearchKeyword); var response = await applicationService.GitHubClient.Search.SearchRepo(request); InternalItems.Reset(response.Items); } catch (Exception e) { var msg = string.Format("Unable to search for {0}. Please try again.", SearchKeyword.Humanize()); throw new Exception(msg, e); } }); }
private async Task UpdateIssue(Issue issue) { var localIssue = InternalItems.FirstOrDefault(x => x.Url == issue.Url); if (localIssue == null) { return; } var index = InternalItems.IndexOf(localIssue); if (index < 0) { return; } var matches = System.Text.RegularExpressions.Regex.Matches(issue.Url.AbsolutePath, "/repos/([^/]+)/([^/]+)/.+"); if (matches.Count != 1 || matches[0].Groups.Count != 3) { return; } InternalItems[index] = await _sessionService.GitHubClient.Issue.Get(matches[0].Groups[1].Value, matches[0].Groups[2].Value, issue.Number); InternalItems.Reset(); }
public PullRequestsViewModel(ISessionService sessionService) { _sessionService = sessionService; Title = "Pull Requests"; Items = InternalItems.CreateDerivedCollection(x => { var vm = new PullRequestItemViewModel(x); vm.GoToCommand.Subscribe(_ => { var prViewModel = this.CreateViewModel <PullRequestViewModel>(); prViewModel.Init(RepositoryOwner, RepositoryName, x.Number, x); NavigateTo(prViewModel); prViewModel.WhenAnyValue(y => y.Issue.State) .DistinctUntilChanged() .Skip(1) .Subscribe(y => LoadCommand.ExecuteIfCan()); }); return(vm); }, filter: x => x.Title.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { InternalItems.Reset(await RetrievePullRequests()); }); this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => { InternalItems.Clear(); LoadCommand.ExecuteIfCan(); }); }
public LanguagesViewModel() { Title = "Languages"; DismissCommand = ReactiveCommand.Create(); DismissCommand.Subscribe(_ => this.Dismiss()); Items = InternalItems.CreateDerivedCollection( x => new LanguageItemViewModel(x.Name, x.Slug), filter: x => x.Name.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); Items .Changed.Select(_ => Unit.Default) .Merge(this.WhenAnyValue(x => x.SelectedLanguage).Select(_ => Unit.Default)) .Select(_ => SelectedLanguage) .Where(x => x != null) .Subscribe(x => { foreach (var l in Items) { l.Selected = l.Slug == x.Slug; } }); this.WhenAnyValue(x => x.SelectedLanguage) .IsNotNull() .Subscribe(_ => Dismiss()); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var languageRepository = new LanguageRepository(); var langs = await languageRepository.GetLanguages(); langs.Insert(0, LanguageRepository.DefaultLanguage); InternalItems.Reset(langs); }); }
public PublicGistsViewModel(ISessionService sessionService) { _sessionService = sessionService; Title = "Public Gists"; Items = InternalItems.CreateDerivedCollection(x => CreateGistItemViewModel(x)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { InternalItems.Reset(await RetrieveGists()); }); }
protected BaseUsersViewModel(ISessionService sessionService) { SessionService = sessionService; Items = InternalItems.CreateDerivedCollection(x => CreateItemViewModel(x), x => x.Login.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { InternalItems.Reset(await RetrieveUsers()); }); }
public CommitBranchesViewModel(ISessionService applicationService) { Title = "Branches"; Items = InternalItems.CreateDerivedCollection( x => CreateItemViewModel(x), filter: x => x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => InternalItems.Reset(await applicationService.GitHubClient.Repository.GetAllBranches(RepositoryOwner, RepositoryName))); }
protected BaseGistsViewModel(ISessionService sessionService) { SessionService = sessionService; Items = InternalItems .CreateDerivedCollection(x => CreateGistItemViewModel(x)) .CreateDerivedCollection(x => x, filter: x => x.Description.ContainsKeyword(SearchKeyword) || x.Title.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { InternalItems.Reset(await RetrieveGists()); }); }
protected BaseCommitsViewModel(ISessionService sessionService) { SessionService = sessionService; Title = "Commits"; Items = InternalItems.CreateDerivedCollection( x => x, x => x.Description.ContainsKeyword(SearchKeyword) || x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var ret = await RetrieveCommits(); InternalItems.Reset(ret.Select(x => new CommitItemViewModel(x, GoToCommit))); }); }
protected BaseRepositoriesViewModel(ISessionService sessionService) { SessionService = sessionService; ShowRepositoryOwner = true; Title = "Repositories"; Items = InternalItems.CreateDerivedCollection( x => x, filter: x => x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var ret = await RetrieveRepositories(); InternalItems.Reset(ret.Select(x => new RepositoryItemViewModel(x, ShowRepositoryOwner, GoToRepository))); }); }
public OrganizationsViewModel(ISessionService applicationService) { Title = "Organizations"; Items = InternalItems.CreateDerivedCollection( x => new UserItemViewModel(x.Login, x.AvatarUrl, true, () => { var vm = this.CreateViewModel <OrganizationViewModel>(); vm.Init(x.Login, x); NavigateTo(vm); }), filter: x => x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => InternalItems.Reset(await applicationService.GitHubClient.Organization.GetAll(Username))); }
public TeamsViewModel(ISessionService applicationService) { Title = "Teams"; Items = InternalItems.CreateDerivedCollection( x => new TeamItemViewModel(x.Name, () => { var vm = this.CreateViewModel <TeamMembersViewModel>(); vm.Init(x.Id); NavigateTo(vm); }), filter: x => x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => InternalItems.Reset(await applicationService.GitHubClient.Organization.Team.GetAll(OrganizationName))); }
protected BaseIssuesViewModel(ISessionService sessionService) { _sessionService = sessionService; Items = InternalItems.CreateDerivedCollection( x => CreateItemViewModel(x), filter: IssueFilter, signalReset: this.WhenAnyValue(x => x.SearchKeyword)); Items.Changed.Subscribe(_ => { GroupedIssues = Items.GroupBy(x => x.RepositoryFullName) .Select(x => new IssueGroupViewModel(x.Key, x)).ToList(); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { InternalItems.Reset(await RetrieveIssues()); }); }