public async Task <IActionResult> AddComposer(ComposerViewModel composerViewModel) { if (ModelState.IsValid) { using (var httpClient = new HttpClient()) { var composer = new Composer() { FirstName = composerViewModel.FirstName, LastName = composerViewModel.LastName }; var stringData = JsonConvert.SerializeObject(composer); var contentData = new StringContent(stringData, Encoding.UTF8, "application/json"); var response = await httpClient.PostAsync($"{BaseURL}Composer/CreateComposer", contentData); if (response.IsSuccessStatusCode) { return(RedirectToAction("Index", "Composer")); } ViewBag.ErrorMessage = response.ReasonPhrase; return(View(composerViewModel)); } } return(View(composerViewModel)); }
public async Task <IActionResult> AddComposer(ComposerViewModel composerViewModel) { if (ModelState.IsValid) { using (var client = new HttpClient()) { //Get token var JWToken = HttpContext.Session.GetString("token"); if (string.IsNullOrEmpty(JWToken)) { ViewBag.MessageError = "You must be authenticate"; return(View(composerViewModel)); } string stringData = JsonConvert.SerializeObject(composerViewModel); var contentData = new StringContent(stringData, System.Text.Encoding.UTF8, "application/json"); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", JWToken); var response = await client.PostAsync(URLBase + "Composer", contentData); var result = response.IsSuccessStatusCode; if (result) { return(RedirectToAction("Index")); } ViewBag.MessageError = response.ReasonPhrase; return(View(composerViewModel)); } } return(View(composerViewModel)); }
public static void OpenComposerWindow( Window owner, ViewModel parent, string method, string url, bool?isHrefTemplate = null, string body = null, string actionType = null, string description = null, string title = null, Action <ComposerViewModel> modifier = null, StartFocus focus = StartFocus.Method) { ComposerViewModel vm = new ComposerViewModel(parent); if (method != null) { vm.Method = method; } if (url != null) { vm.Url = url; } if (isHrefTemplate != null) { vm.IsHRefTemplate = isHrefTemplate.Value; } if (body != null) { vm.Body = body; } if (actionType != null) { vm.SelectedType = actionType; } if (description != null) { vm.Description = description; } if (title != null) { vm.Title = title; } vm.WindowTitle = title ?? "Request composer"; if (modifier != null) { modifier(vm); } ComposerWindow w = new ComposerWindow(vm, focus); w.Owner = owner; w.ShowDialog(); }
public ChangesetDiffViewModel(ISessionService sessionService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { var comments = new ReactiveList <CommitComment>(); Comments = comments.CreateDerivedCollection( x => new FileDiffCommentViewModel(x.User.Login, x.User.AvatarUrl, x.Body, x.Position ?? 0)); var gotoCreateCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var cmd = new NewCommitComment(s) { Path = Filename, Position = SelectedPatchLine.Item1 }; var comment = await sessionService.GitHubClient.Repository.RepositoryComments.Create(Username, Repository, Branch, cmd); _commentCreatedObservable.OnNext(comment); comments.Add(comment); }, alertDialogFactory); NavigateTo(vm); }); GoToCommentCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.SelectedPatchLine).Select(x => x != null), sender => { var sheet = actionMenuFactory.Create(); sheet.AddButton(string.Format("Add Comment on Line {0}", SelectedPatchLine.Item2), gotoCreateCommentCommand); return(sheet.Show(sender)); }); _patch = this.WhenAnyValue(x => x.CommitFile) .IsNotNull().Select(x => x.Patch).ToProperty(this, x => x.Patch); this.WhenAnyValue(x => x.Filename).Subscribe(x => { if (string.IsNullOrEmpty(x)) { Title = "Diff"; } else { _actualFilename = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); Title = _actualFilename; } }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { sessionService.GitHubClient.Repository.RepositoryComments.GetAllForCommit(Username, Repository, Branch) .ToBackground(x => comments.Reset(x.Where(y => string.Equals(y.Path, Filename)))); var commits = await sessionService.GitHubClient.Repository.Commits.Get(Username, Repository, Branch); CommitFile = commits.Files.FirstOrDefault(x => string.Equals(x.Filename, Filename, StringComparison.Ordinal)); }); }
public PullRequestDiffViewModel(ISessionService sessionService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { var gotoCreateCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var req = new PullRequestReviewCommentCreate(s, ParentViewModel.HeadSha, Filename, SelectedPatchLine.Item1); var comment = await sessionService.GitHubClient.PullRequest.Comment.Create(ParentViewModel.RepositoryOwner, ParentViewModel.RepositoryName, ParentViewModel.PullRequestId, req); _commentCreatedObservable.OnNext(comment); }, alertDialogFactory); NavigateTo(vm); }); GoToCommentCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.SelectedPatchLine).Select(x => x != null), sender => { var sheet = actionMenuFactory.Create(); sheet.AddButton(string.Format("Add Comment on Line {0}", SelectedPatchLine.Item2), gotoCreateCommentCommand); return(sheet.Show(sender)); }); this.WhenAnyValue(x => x.PullRequestFile.Patch) .IsNotNull() .ToProperty(this, x => x.Patch, out _patch); var comments = new ReactiveList <PullRequestReviewComment>(); Comments = comments.CreateDerivedCollection( x => new FileDiffCommentViewModel(x.User.Login, x.User.AvatarUrl, x.Body, x.Position ?? 0)); this.WhenAnyValue(x => x.ParentViewModel.Comments) .Merge(this.WhenAnyObservable(x => x.ParentViewModel.Comments.Changed).Select(_ => ParentViewModel.Comments)) .Select(x => x.Where(y => string.Equals(y.Path, Filename, StringComparison.OrdinalIgnoreCase)).ToList()) .Subscribe(x => comments.Reset(x)); this.WhenAnyValue(x => x.PullRequestFile.FileName) .ToProperty(this, x => x.Filename, out _filename); this.WhenAnyValue(x => x.Filename) .Subscribe(x => { if (string.IsNullOrEmpty(x)) { Title = "Diff"; } else { Title = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); } }); }
public ChangesetDiffViewModel(ISessionService sessionService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { var comments = new ReactiveList<CommitComment>(); Comments = comments.CreateDerivedCollection( x => new FileDiffCommentViewModel(x.User.Login, x.User.AvatarUrl, x.Body, x.Position ?? 0)); var gotoCreateCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var cmd = new NewCommitComment(s) { Path = Filename, Position = SelectedPatchLine.Item1 }; var comment = await sessionService.GitHubClient.Repository.RepositoryComments.Create(Username, Repository, Branch, cmd); _commentCreatedObservable.OnNext(comment); comments.Add(comment); }, alertDialogFactory); NavigateTo(vm); }); GoToCommentCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.SelectedPatchLine).Select(x => x != null), sender => { var sheet = actionMenuFactory.Create(); sheet.AddButton(string.Format("Add Comment on Line {0}", SelectedPatchLine.Item2), gotoCreateCommentCommand); return sheet.Show(sender); }); _patch = this.WhenAnyValue(x => x.CommitFile) .IsNotNull().Select(x => x.Patch).ToProperty(this, x => x.Patch); this.WhenAnyValue(x => x.Filename).Subscribe(x => { if (string.IsNullOrEmpty(x)) Title = "Diff"; else { _actualFilename = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); Title = _actualFilename; } }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { sessionService.GitHubClient.Repository.RepositoryComments.GetAllForCommit(Username, Repository, Branch) .ToBackground(x => comments.Reset(x.Where(y => string.Equals(y.Path, Filename)))); var commits = await sessionService.GitHubClient.Repository.Commits.Get(Username, Repository, Branch); CommitFile = commits.Files.FirstOrDefault(x => string.Equals(x.Filename, Filename, StringComparison.Ordinal)); }); }
public PullRequestDiffViewModel(ISessionService sessionService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { var gotoCreateCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var req = new PullRequestReviewCommentCreate(s, ParentViewModel.HeadSha, Filename, SelectedPatchLine.Item1); var comment = await sessionService.GitHubClient.PullRequest.Comment.Create(ParentViewModel.RepositoryOwner, ParentViewModel.RepositoryName, ParentViewModel.PullRequestId, req); _commentCreatedObservable.OnNext(comment); }, alertDialogFactory); NavigateTo(vm); }); GoToCommentCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.SelectedPatchLine).Select(x => x != null), sender => { var sheet = actionMenuFactory.Create(); sheet.AddButton(string.Format("Add Comment on Line {0}", SelectedPatchLine.Item2), gotoCreateCommentCommand); return sheet.Show(sender); }); this.WhenAnyValue(x => x.PullRequestFile.Patch) .IsNotNull() .ToProperty(this, x => x.Patch, out _patch); var comments = new ReactiveList<PullRequestReviewComment>(); Comments = comments.CreateDerivedCollection( x => new FileDiffCommentViewModel(x.User.Login, x.User.AvatarUrl, x.Body, x.Position ?? 0)); this.WhenAnyValue(x => x.ParentViewModel.Comments) .Merge(this.WhenAnyObservable(x => x.ParentViewModel.Comments.Changed).Select(_ => ParentViewModel.Comments)) .Select(x => x.Where(y => string.Equals(y.Path, Filename, StringComparison.OrdinalIgnoreCase)).ToList()) .Subscribe(x => comments.Reset(x)); this.WhenAnyValue(x => x.PullRequestFile.FileName) .ToProperty(this, x => x.Filename, out _filename); this.WhenAnyValue(x => x.Filename) .Subscribe(x => { if (string.IsNullOrEmpty(x)) Title = "Diff"; else Title = Path.GetFileName(Filename) ?? Filename.Substring(Filename.LastIndexOf('/') + 1); }); }
protected override void ModifyComposerWindow(ComposerViewModel vm) { JToken jsonFile = OriginalJsonValue[MasonProperties.ControlProperties.JsonFile]; if (jsonFile != null) { vm.JsonPartName = jsonFile.Value <string>(); } JArray files = OriginalJsonValue[MasonProperties.ControlProperties.Files] as JArray; if (files != null) { foreach (JObject file in files.OfType <JObject>()) { ComposerFileViewModel fileVm = new ComposerFileViewModel(vm); fileVm.Name = GetValue <string>(file, MasonProperties.ControlPartProperties.Name); fileVm.Title = GetValue <string>(file, MasonProperties.ControlPartProperties.Title); fileVm.Description = GetValue <string>(file, MasonProperties.ControlPartProperties.Description); vm.Files.Add(fileVm); } } }
protected BaseIssueViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; _markdownService = markdownService; _alertDialogFactory = alertDialogFactory; _assigneesCache = new Lazy<Task<IReadOnlyList<Octokit.User>>>(() => _applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName)); _milestonesCache = new Lazy<Task<IReadOnlyList<Octokit.Milestone>>>(() => _applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName)); _labelsCache = new Lazy<Task<IReadOnlyList<Octokit.Label>>>(() => _applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName)); IssueUpdated.Subscribe(x => Issue = x); var issuePresenceObservable = this.WhenAnyValue(x => x.Issue, x => x.CanModify) .Select(x => x.Item1 != null && x.Item2); Events = InternalEvents.CreateDerivedCollection(x => x); this.WhenAnyValue(x => x.Issue.Comments) .ToProperty(this, x => x.CommentCount, out _commentsCount); _participants = Events.Changed .Select(_ => Events.Select(y => y.Actor).Distinct().Count()) .Select(x => x == 0 ? 1 : x) .ToProperty(this, x => x.Participants); GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable); GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable); GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable); _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee) .ToProperty(this, x => x.AssignedUser); _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone) .ToProperty(this, x => x.AssignedMilestone); _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels) .ToProperty(this, x => x.AssignedLabels); _isClosed = this.WhenAnyValue(x => x.Issue.State) .Select(x => x == Octokit.ItemState.Closed) .ToProperty(this, x => x.IsClosed); _markdownDescription = this.WhenAnyValue(x => x.Issue) .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : x.Body)) .Where(x => x != null) .Select(x => GetMarkdownDescription().ToObservable()) .Switch() .ToProperty(this, x => x.MarkdownDescription, null, RxApp.MainThreadScheduler); LoadCommand = ReactiveCommand.CreateAsyncTask(t => Load(applicationService)); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToOwnerCommand .Select(_ => this.CreateViewModel<UserViewModel>()) .Select(x => x.Init(Issue.User.Login)) .Subscribe(NavigateTo); ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => { try { var updatedIssue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate { State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open }); _issueUpdatedObservable.OnNext(updatedIssue); } catch (Exception e) { var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open"; throw new Exception("Unable to " + close + " the item. " + e.Message, e); } RetrieveEvents().ToBackground(x => InternalEvents.Reset(x)); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(s); var comment = (await applicationService.Client.ExecuteAsync(request)).Data; InternalEvents.Add(new IssueCommentItemViewModel(comment)); }, alertDialogFactory); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Issue).Select(x => x != null), sender => { var menu = actionMenuFactory.Create(); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(Issue.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", AddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return menu.Show(sender); }); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel<IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.Issue = Issue; vm.SaveCommand.Subscribe(_issueUpdatedObservable.OnNext); NavigateTo(vm); }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType<string>().Subscribe(GoToUrl); GoToUrlCommand.OfType<Uri>().Subscribe(x => GoToUrl(x.AbsoluteUri)); var hasHtmlObservable = this.WhenAnyValue(x => x.HtmlUrl).Select(x => x != null); ShareCommand = ReactiveCommand.Create(hasHtmlObservable); ShareCommand.Subscribe(sender => actionMenuFactory.ShareUrl(sender, HtmlUrl)); GoToHtmlUrlCommand = ReactiveCommand.Create(hasHtmlObservable); GoToHtmlUrlCommand.Subscribe(_ => GoToUrl(HtmlUrl.AbsoluteUri)); }
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 ComposerWindow(ComposerViewModel vm, StartFocus focus) { InitializeComponent(); DataContext = vm; Loaded += (s, e) => ComposerWindow_Loaded(focus); }
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 IActionResult AddComposer() { ComposerViewModel composerViewModel = new ComposerViewModel(); return(View(composerViewModel)); }
protected virtual void ModifyComposerWindow(ComposerViewModel vm) { }
protected BaseIssueViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; _markdownService = markdownService; _alertDialogFactory = alertDialogFactory; _assigneesCache = new Lazy <Task <IReadOnlyList <Octokit.User> > >(() => _applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName)); _milestonesCache = new Lazy <Task <IReadOnlyList <Octokit.Milestone> > >(() => _applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName)); _labelsCache = new Lazy <Task <IReadOnlyList <Octokit.Label> > >(() => _applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName)); IssueUpdated.Subscribe(x => Issue = x); _avatar = this.WhenAnyValue(x => x.Issue.User.AvatarUrl) .Select(x => new GitHubAvatar(x)) .ToProperty(this, x => x.Avatar); var issuePresenceObservable = this.WhenAnyValue(x => x.Issue, x => x.CanModify) .Select(x => x.Item1 != null && x.Item2); Events = InternalEvents.CreateDerivedCollection(x => x); this.WhenAnyValue(x => x.Issue.Comments) .ToProperty(this, x => x.CommentCount, out _commentsCount); _participants = Events.Changed .Select(_ => Events.Select(y => y.Actor).Distinct().Count()) .Select(x => x == 0 ? 1 : x) .ToProperty(this, x => x.Participants); GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable); GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable); GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable); _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee) .ToProperty(this, x => x.AssignedUser); _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone) .ToProperty(this, x => x.AssignedMilestone); _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels) .ToProperty(this, x => x.AssignedLabels); _isClosed = this.WhenAnyValue(x => x.Issue.State) .Select(x => x == Octokit.ItemState.Closed) .ToProperty(this, x => x.IsClosed); _markdownDescription = this.WhenAnyValue(x => x.Issue) .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : x.Body)) .Where(x => x != null) .Select(x => GetMarkdownDescription().ToObservable()) .Switch() .ToProperty(this, x => x.MarkdownDescription, null, RxApp.MainThreadScheduler); LoadCommand = ReactiveCommand.CreateAsyncTask(t => Load(applicationService)); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToOwnerCommand .Select(_ => this.CreateViewModel <UserViewModel>()) .Select(x => x.Init(Issue.User.Login)) .Subscribe(NavigateTo); ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => { try { var updatedIssue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate { State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open }); _issueUpdatedObservable.OnNext(updatedIssue); } catch (Exception e) { var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open"; throw new Exception("Unable to " + close + " the item. " + e.Message, e); } RetrieveEvents().ToBackground(x => InternalEvents.Reset(x)); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(s); var comment = (await applicationService.Client.ExecuteAsync(request)).Data; InternalEvents.Add(new IssueCommentItemViewModel(comment)); _commentAddedSubject.OnNext(comment); }, alertDialogFactory); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Issue).Select(x => x != null), sender => { var menu = actionMenuFactory.Create(); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(Issue.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", AddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show(sender)); }); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.Issue = Issue; vm.SaveCommand.Subscribe(_issueUpdatedObservable.OnNext); NavigateTo(vm); }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType <string>().Subscribe(GoToUrl); GoToUrlCommand.OfType <Uri>().Subscribe(x => GoToUrl(x.AbsoluteUri)); var hasHtmlObservable = this.WhenAnyValue(x => x.HtmlUrl).Select(x => x != null); ShareCommand = ReactiveCommand.Create(hasHtmlObservable); ShareCommand.Subscribe(sender => actionMenuFactory.ShareUrl(sender, HtmlUrl)); GoToHtmlUrlCommand = ReactiveCommand.Create(hasHtmlObservable); GoToHtmlUrlCommand.Subscribe(_ => GoToUrl(HtmlUrl.AbsoluteUri)); }