public ChangesetViewModel(IApplicationService applicationService) { _applicationService = applicationService; Comments = new ReactiveList <CommentModel>(); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)); GoToHtmlUrlCommand.Select(x => Commit).Subscribe(GoToUrlCommand.ExecuteIfCan); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToFileCommand = ReactiveCommand.Create(); GoToFileCommand.OfType <CommitModel.CommitFileModel>().Subscribe(x => { if (x.Patch == null) { var vm = CreateViewModel <SourceViewModel>(); vm.Branch = Commit.Sha; vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.Items = new [] { new SourceViewModel.SourceItemModel { ForceBinary = true, GitUrl = x.BlobUrl, Name = x.Filename, Path = x.Filename, HtmlUrl = x.BlobUrl } }; vm.CurrentItemIndex = 0; ShowViewModel(vm); } else { var vm = CreateViewModel <ChangesetDiffViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.Branch = Commit.Sha; vm.Filename = x.Filename; ShowViewModel(vm); } }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Get(), forceCacheInvalidation, response => Commit = response.Data); Comments.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.GetAll(), forceCacheInvalidation).FireAndForget(); return(t1); }); }
public RepositoryViewModel(ISessionService applicationService, IAccountsRepository accountsService, IActionMenuFactory actionMenuService) { ApplicationService = applicationService; _accountsService = accountsService; var validRepositoryObservable = this.WhenAnyValue(x => x.Repository).Select(x => x != null); this.WhenAnyValue(x => x.RepositoryName).Subscribe(x => Title = x); this.WhenAnyValue(x => x.Repository.Owner.AvatarUrl) .Select(x => new GitHubAvatar(x)) .ToProperty(this, x => x.Avatar, out _avatar); this.WhenAnyValue(x => x.Repository).Subscribe(x => { Stargazers = (int?)x?.StargazersCount; Watchers = (int?)x?.SubscribersCount; }); this.WhenAnyValue(x => x.Repository.Description) .Select(x => Emojis.FindAndReplace(x)) .ToProperty(this, x => x.Description, out _description); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), t => ToggleStar()); ToggleWatchCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsWatched, x => x.HasValue), t => ToggleWatch()); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); GoToOwnerCommand.Select(_ => Repository.Owner).Subscribe(x => { if (AccountType.Organization.Equals(x.Type)) { var vm = this.CreateViewModel <OrganizationViewModel>(); vm.Init(RepositoryOwner); NavigateTo(vm); } else { var vm = this.CreateViewModel <UserViewModel>(); vm.Init(RepositoryOwner); NavigateTo(vm); } }); PinCommand = ReactiveCommand.Create(validRepositoryObservable); PinCommand.Subscribe(x => PinRepository()); GoToForkParentCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && x.Fork && x.Parent != null)); GoToForkParentCommand.Subscribe(x => { var vm = this.CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = Repository.Parent.Owner.Login; vm.RepositoryName = Repository.Parent.Name; vm.Repository = Repository.Parent; NavigateTo(vm); }); GoToStargazersCommand = ReactiveCommand.Create(); GoToStargazersCommand.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryStargazersViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToWatchersCommand = ReactiveCommand.Create(); GoToWatchersCommand.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryWatchersViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryEventsViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToIssuesCommand = ReactiveCommand.Create(); GoToIssuesCommand .Select(_ => this.CreateViewModel <IssuesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName)) .Subscribe(NavigateTo); GoToReadmeCommand = ReactiveCommand.Create(); GoToReadmeCommand .Select(_ => this.CreateViewModel <ReadmeViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName)) .Subscribe(NavigateTo); GoToBranchesCommand = ReactiveCommand.Create(); GoToBranchesCommand .Select(_ => this.CreateViewModel <CommitBranchesViewModel>()) .Select(x => x.Init(RepositoryOwner, RepositoryName)) .Subscribe(NavigateTo); GoToCommitsCommand = ReactiveCommand.Create(); GoToCommitsCommand.Subscribe(_ => { if (Branches != null && Branches.Count == 1) { var vm = this.CreateViewModel <CommitsViewModel>(); var branch = Repository == null ? null : Repository.DefaultBranch; NavigateTo(vm.Init(RepositoryOwner, RepositoryName, branch)); } else { GoToBranchesCommand.ExecuteIfCan(); } }); GoToPullRequestsCommand = ReactiveCommand.Create(); GoToPullRequestsCommand.Subscribe(_ => { var vm = this.CreateViewModel <PullRequestsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToSourceCommand = ReactiveCommand.Create(); GoToSourceCommand.Subscribe(_ => { var vm = this.CreateViewModel <BranchesAndTagsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToContributors = ReactiveCommand.Create(); GoToContributors.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryContributorsViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); GoToForksCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <RepositoryForksViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToReleasesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <ReleasesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); ShareCommand = ReactiveCommand.Create(validRepositoryObservable); ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, Repository.HtmlUrl)); var canShowMenu = this.WhenAnyValue(x => x.Repository, x => x.IsStarred, x => x.IsWatched) .Select(x => x.Item1 != null && x.Item2 != null && x.Item3 != null); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(canShowMenu, sender => { var menu = actionMenuService.Create(); menu.AddButton(IsPinned ? "Unpin from Slideout Menu" : "Pin to Slideout Menu", PinCommand); menu.AddButton(IsStarred.Value ? "Unstar This Repo" : "Star This Repo", ToggleStarCommand); menu.AddButton(IsWatched.Value ? "Unwatch This Repo" : "Watch This Repo", ToggleWatchCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); menu.AddButton("Share", ShareCommand); return(menu.Show(sender)); }); var gotoWebUrl = new Action <string>(x => { var vm = this.CreateViewModel <WebBrowserViewModel>(); vm.Init(x); NavigateTo(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Select(_ => Repository.HtmlUrl).Subscribe(gotoWebUrl); GoToHomepageCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.Homepage))); GoToHomepageCommand.Select(_ => Repository.Homepage).Subscribe(gotoWebUrl); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var t1 = applicationService.GitHubClient.Repository.Get(RepositoryOwner, RepositoryName); applicationService.GitHubClient.Repository.Content.GetReadme(RepositoryOwner, RepositoryName) .ToBackground(x => Readme = x); applicationService.GitHubClient.Repository.GetAllBranches(RepositoryOwner, RepositoryName) .ToBackground(x => Branches = x); applicationService.GitHubClient.Activity.Watching.CheckWatched(RepositoryOwner, RepositoryName) .ToBackground(x => IsWatched = x); applicationService.GitHubClient.Activity.Starring.CheckStarred(RepositoryOwner, RepositoryName) .ToBackground(x => IsStarred = x); applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContributors()) .ToBackground(x => Contributors = x.Data.Count); // applicationService.GitHubClient.Repository.GetAllLanguages(RepositoryOwner, RepositoryName) // .ToBackground(x => Languages = x.Count); applicationService.Client.ExecuteAsync(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReleases()) .ToBackground(x => Releases = x.Data.Count); Repository = await t1; }); }
public PullRequestViewModel(IApplicationService applicationService, IMarkdownService markdownService, IActionMenuService actionMenuService) { _applicationService = applicationService; _markdownService = markdownService; GoToUrlCommand = this.CreateUrlCommand(); Comments = new ReactiveList <Octokit.IssueComment>(); Events = new ReactiveList <Octokit.IssueEvent>(); this.WhenAnyValue(x => x.Id).Subscribe(x => Title = "Pull Request #" + x); _canMerge = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged) .ToProperty(this, x => x.CanMerge); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { var req = new Octokit.MergePullRequest(null); var response = await _applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) { throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); } LoadCommand.ExecuteIfCan(); }); ToggleStateCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), async t => { var newState = PullRequest.State == Octokit.ItemState.Open ? Octokit.ItemState.Closed : Octokit.ItemState.Open; try { var req = new Octokit.PullRequestUpdate { State = newState }; PullRequest = await _applicationService.GitHubClient.PullRequest.Update(RepositoryOwner, RepositoryName, Id, req); } catch (Exception e) { throw new Exception("Unable to " + (newState == Octokit.ItemState.Closed ? "close" : "open") + " the item. " + e.Message, e); } }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null)); GoToHtmlUrlCommand.Select(_ => PullRequest.HtmlUrl).Subscribe(this.ShowWebBrowser); GoToCommitsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <PullRequestCommitsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.PullRequestId = Id; ShowViewModel(vm); }); GoToFilesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <PullRequestFilesViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.PullRequestId = Id; ShowViewModel(vm); }); // // ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))) // .WithSubscription(_ => shareService.ShareUrl(PullRequest.HtmlUrl)); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; //vm.Issue = Issue; // vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x); ShowViewModel(vm); }); GoToLabelsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => { var vm = CreateViewModel <IssueLabelsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.IssueId = Id; vm.SaveOnSelect = true; // vm.SelectedLabels.Reset(Issue.Labels); // vm.WhenAnyValue(x => x.Labels).Skip(1).Subscribe(x => // { // Issue.Labels = x.ToList(); // this.RaisePropertyChanged("Issue"); // }); ShowViewModel(vm); }); GoToMilestoneCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => { var vm = CreateViewModel <IssueMilestonesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.IssueId = Id; vm.SaveOnSelect = true; // vm.SelectedMilestone = Issue.Milestone; // vm.WhenAnyValue(x => x.SelectedMilestone).Skip(1).Subscribe(x => // { // Issue.Milestone = x; // this.RaisePropertyChanged("Issue"); // }); ShowViewModel(vm); }); GoToAssigneeCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => { var vm = CreateViewModel <IssueAssignedToViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.IssueId = Id; vm.SaveOnSelect = true; // vm.SelectedUser = Issue.Assignee; // vm.WhenAnyValue(x => x.SelectedUser).Skip(1).Subscribe(x => // { // Issue.Assignee = x; // this.RaisePropertyChanged("Issue"); // }); ShowViewModel(vm); }); GoToAddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <IssueCommentViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.CommentAdded.Subscribe(Comments.Add); ShowViewModel(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(PullRequest.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", GoToAddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); _markdownDescription = this.WhenAnyValue(x => x.PullRequest).IsNotNull() .Select(x => _markdownService.Convert(x.Body)) .ToProperty(this, x => x.MarkdownDescription); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var pullRequest = _applicationService.GitHubClient.PullRequest.Get(RepositoryOwner, RepositoryName, Id); var comments = _applicationService.GitHubClient.PullRequest.Comment.GetAll(RepositoryOwner, RepositoryName, Id); var events = _applicationService.GitHubClient.Issue.Events.GetForIssue(RepositoryOwner, RepositoryName, Id); var issue = _applicationService.GitHubClient.Issue.Get(RepositoryOwner, RepositoryName, Id); await Task.WhenAll(pullRequest, issue, comments, events); PullRequest = pullRequest.Result; Issue = issue.Result; }); }
public RepositoryViewModel(IApplicationService applicationService, IAccountsService accountsService, IActionMenuService actionMenuService) { ApplicationService = applicationService; _accountsService = accountsService; this.WhenAnyValue(x => x.RepositoryName).Subscribe(x => Title = x); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), t => ToggleStar()); ToggleWatchCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsWatched, x => x.HasValue), t => ToggleWatch()); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); GoToOwnerCommand.Select(_ => Repository.Owner).Subscribe(x => { if (string.Equals(x.Type, "organization", StringComparison.OrdinalIgnoreCase)) { var vm = CreateViewModel <OrganizationViewModel>(); vm.Username = RepositoryOwner; ShowViewModel(vm); } else { var vm = CreateViewModel <UserViewModel>(); vm.Username = RepositoryOwner; ShowViewModel(vm); } }); PinCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); PinCommand.Subscribe(x => PinRepository()); GoToForkParentCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && x.Fork && x.Parent != null)); GoToForkParentCommand.Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = Repository.Parent.Owner.Login; vm.RepositoryName = Repository.Parent.Name; vm.Repository = Repository.Parent; ShowViewModel(vm); }); GoToStargazersCommand = ReactiveCommand.Create(); GoToStargazersCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryStargazersViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToWatchersCommand = ReactiveCommand.Create(); GoToWatchersCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryWatchersViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryEventsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToIssuesCommand = ReactiveCommand.Create(); GoToIssuesCommand.Subscribe(_ => { var vm = CreateViewModel <IssuesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToReadmeCommand = ReactiveCommand.Create(); GoToReadmeCommand.Subscribe(_ => { var vm = CreateViewModel <ReadmeViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToBranchesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <CommitBranchesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToCommitsCommand = ReactiveCommand.Create(); GoToCommitsCommand.Subscribe(_ => { if (Branches != null && Branches.Count == 1) { var vm = CreateViewModel <ChangesetsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Branch = Repository == null ? null : Repository.DefaultBranch; ShowViewModel(vm); } else { GoToBranchesCommand.ExecuteIfCan(); } }); GoToPullRequestsCommand = ReactiveCommand.Create(); GoToPullRequestsCommand.Subscribe(_ => { var vm = CreateViewModel <PullRequestsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToSourceCommand = ReactiveCommand.Create(); GoToSourceCommand.Subscribe(_ => { var vm = CreateViewModel <BranchesAndTagsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToContributors = ReactiveCommand.Create(); GoToContributors.Subscribe(_ => { var vm = CreateViewModel <RepositoryContributorsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToForksCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <RepositoryForksViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToReleasesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <ReleasesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Repository, x => x.IsStarred, x => x.IsWatched) .Select(x => x.Item1 != null && x.Item2 != null && x.Item3 != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton(IsPinned ? "Unpin from Slideout Menu" : "Pin to Slideout Menu", PinCommand); menu.AddButton(IsStarred.Value ? "Unstar This Repo" : "Star This Repo", ToggleStarCommand); menu.AddButton(IsWatched.Value ? "Unwatch This Repo" : "Watch This Repo", ToggleWatchCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Select(_ => Repository.HtmlUrl).Subscribe(this.ShowWebBrowser); GoToHomepageCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.Homepage))); GoToHomepageCommand.Select(_ => Repository.Homepage).Subscribe(this.ShowWebBrowser); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Get(), forceCacheInvalidation, response => Repository = response.Data); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme(), forceCacheInvalidation, response => Readme = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches(), forceCacheInvalidation, response => Branches = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].IsWatching(), forceCacheInvalidation, response => IsWatched = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].IsStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContributors(), forceCacheInvalidation, response => Contributors = response.Data.Count).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetLanguages(), forceCacheInvalidation, response => Languages = response.Data.Count).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReleases(), forceCacheInvalidation, response => Releases = response.Data.Count).FireAndForget(); return(t1); }); }
public CommitViewModel(ISessionService applicationService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory) { Title = "Commit"; var comments = new ReactiveList <CommentModel>(); Comments = comments.CreateDerivedCollection(x => new CommitCommentItemViewModel(x)); this.WhenAnyValue(x => x.Commit) .Select(x => new GitHubAvatar(x.GenerateGravatarUrl())) .ToProperty(this, x => x.Avatar, out _avatar); var files = this.WhenAnyValue(x => x.Commit.Files).IsNotNull(); files.Select(x => x.Count(y => string.Equals(y.Status, "added"))) .ToProperty(this, x => x.DiffAdditions, out _diffAdditions); files.Select(x => x.Count(y => string.Equals(y.Status, "removed"))) .ToProperty(this, x => x.DiffDeletions, out _diffDeletions); files.Select(x => x.Count(y => string.Equals(y.Status, "modified"))) .ToProperty(this, x => x.DiffModifications, out _diffModifications); GoToAddedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffAdditions).Select(x => x > 0)); GoToAddedFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Added", Commit.Files.Where(x => string.Equals(x.Status, "added")))) .Subscribe(NavigateTo); GoToRemovedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffDeletions).Select(x => x > 0)); GoToRemovedFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Removed", Commit.Files.Where(x => string.Equals(x.Status, "removed")))) .Subscribe(NavigateTo); GoToModifiedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffModifications).Select(x => x > 0)); GoToModifiedFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Modified", Commit.Files.Where(x => string.Equals(x.Status, "modified")))) .Subscribe(NavigateTo); GoToAllFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit.Files).Select(x => x != null)); GoToAllFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "All Changes", Commit.Files)) .Subscribe(NavigateTo); this.WhenAnyValue(x => x.Commit) .IsNotNull() .Select(x => x.GenerateCommiterName()) .ToProperty(this, x => x.CommiterName, out _commiterName); this.WhenAnyValue(x => x.Commit) .IsNotNull() .Select(x => x.Commit.Message ?? string.Empty) .Select(x => Emojis.FindAndReplace(x)) .ToProperty(this, x => x.CommitMessage, out _commitMessage); this.WhenAnyValue(x => x.CommitMessage) .IsNotNull() .Select(x => { var firstNewLine = x.IndexOf("\n", StringComparison.Ordinal); return(firstNewLine > 0 ? x.Substring(0, firstNewLine) : x); }) .ToProperty(this, x => x.CommitMessageSummary, out _commitMessageSummary); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)); GoToHtmlUrlCommand .Select(_ => this.CreateViewModel <WebBrowserViewModel>()) .Select(x => x.Init(Commit.HtmlUrl)) .Subscribe(NavigateTo); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.Create(s); comments.Add((await applicationService.Client.ExecuteAsync(request)).Data); }, alertDialogFactory); NavigateTo(vm); }); var validCommitObservable = this.WhenAnyValue(x => x.Commit).Select(x => x != null); var copyShaCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => actionMenuService.SendToPasteBoard(this.Commit.Sha)); var shareCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(sender => actionMenuService.ShareUrl(sender, this.Commit.HtmlUrl)); var browseCodeCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => { var vm = this.CreateViewModel <SourceTreeViewModel>(); vm.RepositoryName = RepositoryName; vm.RepositoryOwner = RepositoryOwner; vm.Branch = this.Commit.Sha; NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(sender => { var menu = actionMenuService.Create(); menu.AddButton("Add Comment", AddCommentCommand); menu.AddButton("Copy SHA", copyShaCommand); menu.AddButton("Browse Code", browseCodeCommand); menu.AddButton("Share", shareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show(sender)); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var commentRequest = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.GetAll(); applicationService.Client.ExecuteAsync(commentRequest).ToBackground(x => comments.Reset(x.Data.Where(y => y.Position.HasValue))); Commit = await applicationService.GitHubClient.Repository.Commits.Get(RepositoryOwner, RepositoryName, Node); }); }
public CommitViewModel(IApplicationService applicationService, IActionMenuFactory actionMenuService) { Title = "Commit"; var comments = new ReactiveList <Octokit.CommitComment>(); Comments = comments.CreateDerivedCollection(x => x); this.WhenAnyValue(x => x.Commit) .IsNotNull() .Select(x => x.Commit.Message ?? string.Empty) .Select(x => { var firstNewLine = x.IndexOf("\n", StringComparison.Ordinal); return(firstNewLine > 0 ? x.Substring(0, firstNewLine) : x); }) .ToProperty(this, x => x.CommitMessageSummary, out _commitMessageSummary); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)); GoToHtmlUrlCommand.Select(x => Commit.HtmlUrl).Subscribe(x => { var vm = this.CreateViewModel <WebBrowserViewModel>(); vm.Url = x; NavigateTo(vm); }); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; NavigateTo(vm); }); GoToCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <CommitCommentViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Node = Node; vm.SaveCommand.Subscribe(comments.Add); NavigateTo(vm); }); GoToFileCommand = ReactiveCommand.Create(); GoToFileCommand.OfType <Octokit.GitHubCommitFile>().Subscribe(x => { if (x.Patch == null) { var vm = this.CreateViewModel <SourceViewModel>(); vm.Branch = Commit.Sha; vm.Path = x.Filename; vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Name = System.IO.Path.GetFileName(x.Filename); vm.ForceBinary = true; NavigateTo(vm); } else { var vm = this.CreateViewModel <ChangesetDiffViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.Branch = Commit.Sha; vm.Filename = x.Filename; NavigateTo(vm); } }); var validCommitObservable = this.WhenAnyValue(x => x.Commit).Select(x => x != null); var copyShaCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => actionMenuService.SendToPasteBoard(this.Commit.Sha)); var shareCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => actionMenuService.ShareUrl(this.Commit.HtmlUrl)); var browseCodeCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => { var vm = this.CreateViewModel <SourceTreeViewModel>(); vm.RepositoryName = RepositoryName; vm.RepositoryOwner = RepositoryOwner; vm.Branch = this.Commit.Sha; NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(_ => { var menu = actionMenuService.Create(Title); menu.AddButton("Add Comment", GoToCommentCommand); menu.AddButton("Copy SHA", copyShaCommand); menu.AddButton("Browse Code", browseCodeCommand); menu.AddButton("Share", shareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { applicationService.GitHubClient.Repository.RepositoryComments.GetForCommit(RepositoryOwner, RepositoryName, Node) .ToBackground(x => comments.Reset(x)); Commit = await applicationService.GitHubClient.Repository.Commits.Get(RepositoryOwner, RepositoryName, Node); }); }
public GistViewModel( ISessionService sessionService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory) { Comments = new ReactiveList <GistCommentModel>(); Title = "Gist"; this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0) .Select(x => x.Files.First().Key).Subscribe(x => Title = x); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null)); ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, new Uri(Gist.HtmlUrl))); this.WhenAnyValue(x => x.Gist.Owner.AvatarUrl) .Select(x => new GitHubAvatar(x)) .ToProperty(this, x => x.Avatar, out _avatar); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), async t => { try { if (!IsStarred.HasValue) { return; } var request = IsStarred.Value ? sessionService.Client.Gists[Id].Unstar() : sessionService.Client.Gists[Id].Star(); await sessionService.Client.ExecuteAsync(request); IsStarred = !IsStarred.Value; } catch (Exception e) { throw new Exception("Unable to start gist. Please try again.", e); } }); ForkCommand = ReactiveCommand.CreateAsyncTask(async t => { var gist = await sessionService.GitHubClient.Gist.Fork(Id); var vm = this.CreateViewModel <GistViewModel>(); vm.Id = gist.Id; vm.Gist = gist; NavigateTo(vm); }); ForkCommand.IsExecuting.Subscribe(x => { if (x) { alertDialogFactory.Show("Forking..."); } else { alertDialogFactory.Hide(); } }); GoToEditCommand = ReactiveCommand.Create(); GoToEditCommand.Subscribe(_ => { var vm = this.CreateViewModel <GistEditViewModel>(); vm.Gist = Gist; vm.SaveCommand.Subscribe(x => Gist = x); NavigateTo(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand .Select(_ => this.CreateViewModel <WebBrowserViewModel>()) .Select(x => x.Init(Gist.HtmlUrl)) .Subscribe(NavigateTo); GoToFileSourceCommand = ReactiveCommand.Create(); GoToFileSourceCommand.OfType <GistFile>().Subscribe(x => { var vm = this.CreateViewModel <GistFileViewModel>(); vm.Id = Id; vm.GistFile = x; vm.Filename = x.Filename; NavigateTo(vm); }); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist.Owner).Select(x => x != null)); GoToOwnerCommand .Select(_ => this.CreateViewModel <UserViewModel>()) .Select(x => x.Init(Gist.Owner.Login)) .Subscribe(NavigateTo); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(new ComposerViewModel("Add Comment", async x => { var request = sessionService.Client.Gists[Id].CreateGistComment(x); Comments.Add((await sessionService.Client.ExecuteAsync(request)).Data); }, alertDialogFactory))); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Gist).Select(x => x != null), sender => { var menu = actionMenuService.Create(); if (Gist.Owner != null && string.Equals(sessionService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase)) { menu.AddButton("Edit", GoToEditCommand); } else { menu.AddButton("Fork", ForkCommand); } menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show(sender)); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { sessionService.GitHubClient.Gist.IsStarred(Id).ToBackground(x => IsStarred = x); Comments.SimpleCollectionLoad(sessionService.Client.Gists[Id].GetComments()); Gist = await sessionService.GitHubClient.Gist.Get(Id); }); }
public GistViewModel(IApplicationService applicationService, IShareService shareService, IActionMenuService actionMenuService, IStatusIndicatorService statusIndicatorService) { Comments = new ReactiveList <GistCommentModel>(); Title = "Gist"; GoToUrlCommand = this.CreateUrlCommand(); this.WhenAnyValue(x => x.Gist).Where(x => x != null && x.Files != null && x.Files.Count > 0) .Select(x => x.Files.First().Key).Subscribe(x => Title = x); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(Gist.HtmlUrl)); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), async t => { try { if (!IsStarred.HasValue) { return; } var request = IsStarred.Value ? applicationService.Client.Gists[Id].Unstar() : applicationService.Client.Gists[Id].Star(); await applicationService.Client.ExecuteAsync(request); IsStarred = !IsStarred.Value; } catch (Exception e) { throw new Exception("Unable to start gist. Please try again.", e); } }); ForkCommand = ReactiveCommand.CreateAsyncTask(async t => { var data = await applicationService.Client.ExecuteAsync(applicationService.Client.Gists[Id].ForkGist()); var forkedGist = data.Data; var vm = CreateViewModel <GistViewModel>(); vm.Id = forkedGist.Id; vm.Gist = forkedGist; ShowViewModel(vm); }); ForkCommand.IsExecuting.Subscribe(x => { if (x) { statusIndicatorService.Show("Forking..."); } else { statusIndicatorService.Hide(); } }); GoToEditCommand = ReactiveCommand.Create(); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Select(_ => Gist.HtmlUrl).Subscribe(this.ShowWebBrowser); GoToFileSourceCommand = ReactiveCommand.Create(); GoToFileSourceCommand.OfType <GistFileModel>().Subscribe(x => { var vm = CreateViewModel <GistFileViewModel>(); vm.Id = Id; vm.GistFile = x; vm.Filename = x.Filename; ShowViewModel(vm); }); GoToUserCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && x.Owner != null)); GoToUserCommand.Subscribe(x => { var vm = CreateViewModel <UserViewModel>(); vm.Username = Gist.Owner.Login; ShowViewModel(vm); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <GistCommentViewModel>(); vm.Id = Id; vm.CommentAdded.Subscribe(Comments.Add); ShowViewModel(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Gist).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); if (Gist.Owner != null && string.Equals(applicationService.Account.Username, Gist.Owner.Login, StringComparison.OrdinalIgnoreCase)) { menu.AddButton("Edit", GoToEditCommand); } else { menu.AddButton("Fork", ForkCommand); } menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(applicationService.Client.Gists[Id].Get(), forceCacheInvalidation, response => Gist = response.Data); this.RequestModel(applicationService.Client.Gists[Id].IsGistStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget(); Comments.SimpleCollectionLoad(applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation).FireAndForget(); return(t1); }); }
public ChangesetViewModel(IApplicationService applicationService, IActionMenuService actionMenuService) { _applicationService = applicationService; Title = "Commit"; GoToUrlCommand = this.CreateUrlCommand(); Comments = new ReactiveList <CommentModel>(); var goToUrlCommand = this.CreateUrlCommand(); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)); GoToHtmlUrlCommand.Select(x => Commit.HtmlUrl).Subscribe(goToUrlCommand.ExecuteIfCan); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <CommitCommentViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Node = Node; vm.CommentAdded.Subscribe(Comments.Add); ShowViewModel(vm); }); GoToFileCommand = ReactiveCommand.Create(); GoToFileCommand.OfType <CommitModel.CommitFileModel>().Subscribe(x => { if (x.Patch == null) { var vm = CreateViewModel <SourceViewModel>(); vm.Branch = Commit.Sha; vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; // vm.Items = new [] // { // new SourceViewModel.SourceItemModel // { // ForceBinary = true, // GitUrl = x.BlobUrl, // Name = x.Filename, // Path = x.Filename, // HtmlUrl = x.BlobUrl // } // }; // vm.CurrentItemIndex = 0; ShowViewModel(vm); } else { var vm = CreateViewModel <ChangesetDiffViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.Branch = Commit.Sha; vm.Filename = x.Filename; ShowViewModel(vm); } }); var copyShaCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)) .WithSubscription(x => actionMenuService.SendToPasteBoard(this.Commit.Sha)); var shareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)) .WithSubscription(x => actionMenuService.ShareUrl(this.Commit.HtmlUrl)); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(_ => { var menu = actionMenuService.Create(Title); menu.AddButton("Add Comment", GoToCommentCommand); menu.AddButton("Copy SHA", copyShaCommand); menu.AddButton("Share", shareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Get(), forceCacheInvalidation, response => Commit = response.Data); Comments.SimpleCollectionLoad(_applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.GetAll(), forceCacheInvalidation).FireAndForget(); return(t1); }); }
public PullRequestViewModel( IApplicationService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuService) : base(applicationService, markdownService) { this.WhenAnyValue(x => x.Id) .Subscribe(x => Title = "Pull Request #" + x); _canMerge = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged) .ToProperty(this, x => x.CanMerge); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { var req = new Octokit.MergePullRequest(null); var response = await applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) { throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); } LoadCommand.ExecuteIfCan(); }); // ToggleStateCommand = ReactiveCommand.CreateAsyncTask( // this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), // async t => // { // var newState = PullRequest.State == Octokit.ItemState.Open ? Octokit.ItemState.Closed : Octokit.ItemState.Open; // // try // { // var req = new Octokit.PullRequestUpdate { State = newState }; // PullRequest = await applicationService.GitHubClient.PullRequest.Update(RepositoryOwner, RepositoryName, Id, req); // } // catch (Exception e) // { // throw new Exception("Unable to " + (newState == Octokit.ItemState.Closed ? "close" : "open") + " the item. " + e.Message, e); // } // }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null)); GoToHtmlUrlCommand.Select(_ => PullRequest.HtmlUrl).Subscribe(GoToUrlCommand.ExecuteIfCan); GoToCommitsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <PullRequestCommitsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.PullRequestId = Id; NavigateTo(vm); }); GoToFilesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <PullRequestFilesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.PullRequestId = Id; NavigateTo(vm); }); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null)); ShareCommand.Subscribe(_ => actionMenuService.ShareUrl(PullRequest.HtmlUrl)); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; //vm.Issue = Issue; // vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(PullRequest.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", GoToAddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); }