protected IssueModifyViewModel(string username, string repository) { var alertDialogService = Locator.Current.GetService <IAlertDialogService>(); Username = username; Repository = repository; Kind = "bug"; Priority = "major"; Milestones = new IssueMilestonesViewModel(username, repository); Versions = new IssueVersionsViewModel(username, repository); Components = new IssueComponentsViewModel(username, repository); Assignee = new IssueAssigneeViewModel(username, repository); SaveCommand = ReactiveCommand.CreateFromTask( t => Save(), this.WhenAnyValue(x => x.IssueTitle).Select(y => !string.IsNullOrEmpty(y))); SaveCommand.BindCommand(DismissCommand); DiscardCommand = ReactiveCommand.CreateFromTask(async t => { if (Content?.Length > 0 || IssueTitle?.Length > 0) { var result = await alertDialogService.PromptYesNo( "Discard Changes", "Are you sure you want to discard your changes?"); if (!result) { return; } } DismissCommand.ExecuteNow(); }); }
public NewCommentViewModel( Func <string, Task> doneAction, IAlertDialogService alertDialogService = null) { alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); DoneCommand = ReactiveCommand.CreateFromTask(async _ => { await doneAction(Text); DismissCommand.ExecuteNow(); Text = string.Empty; }, this.WhenAnyValue(x => x.Text).Select(x => x?.Length > 0)); DiscardCommand = ReactiveCommand.CreateFromTask(async _ => { if (Text?.Length > 0) { var result = await alertDialogService.PromptYesNo( "Discard Comment", "Are you sure you want to discard this comment?"); if (!result) { return; } } Text = string.Empty; DismissCommand.ExecuteNow(); }); }
public IssueViewModel( string username, string repository, int issueId, IApplicationService applicationService = null, IMarkdownService markdownService = null, IMessageService messageService = null, IAlertDialogService alertDialogService = null, IActionMenuService actionMenuService = null) { _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>(); messageService = messageService ?? Locator.Current.GetService <IMessageService>(); markdownService = markdownService ?? Locator.Current.GetService <IMarkdownService>(); alertDialogService = alertDialogService ?? Locator.Current.GetService <IAlertDialogService>(); actionMenuService = actionMenuService ?? Locator.Current.GetService <IActionMenuService>(); Title = "Issue #" + issueId; Username = username; Repository = repository; IssueId = issueId; GoToWebCommand = ReactiveCommand.Create <string>( url => NavigateTo(new WebBrowserViewModel(url))); GoToReporterCommand = ReactiveCommand.Create( () => NavigateTo(new UserViewModel(Issue.ReportedBy.Username)), this.WhenAnyValue(x => x.Issue.ReportedBy.Username).Select(x => x != null)); GoToAssigneeCommand = ReactiveCommand.Create( () => NavigateTo(new UserViewModel(Issue.Responsible.Username)), this.WhenAnyValue(x => x.Issue.Responsible.Username).Select(x => x != null)); GoToEditCommand = ReactiveCommand.Create( () => NavigateTo(new IssueEditViewModel(username, repository, Issue)), this.WhenAnyValue(x => x.Issue).Select(x => x != null)); this.WhenAnyValue(x => x.Issue) .Select(x => x?.Responsible?.Username ?? "Unassigned") .ToProperty(this, x => x.Assigned, out _assigned, "Unassigned"); this.WhenAnyValue(x => x.Issue.Content) .Select(x => string.IsNullOrEmpty(x) ? null : markdownService.ConvertMarkdown(x)) .ToProperty(this, x => x.Description, out _description); this.WhenAnyValue(x => x.Description) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.ShowDescription, out _showDescription); Comments = _comments.CreateDerivedCollection(x => new CommentItemViewModel(x.AuthorInfo.Username, new Utils.Avatar(x.AuthorInfo.Avatar), x.UtcCreatedOn.Humanize(), markdownService.ConvertMarkdown(x.Content))); LoadCommand = ReactiveCommand.CreateFromTask(async t => { var issueTask = applicationService.Client.Issues.Get(username, repository, issueId); applicationService.Client.Issues.GetComments(username, repository, issueId) .ToBackground(x => _comments.Reset(x.Where(y => !string.IsNullOrEmpty(y.Content)))); Issue = await issueTask; }); DeleteCommand = ReactiveCommand.CreateFromTask(async _ => { try { var prompt = await alertDialogService.PromptYesNo( "Are you sure?", "You are about to permanently delete issue #" + Issue.LocalId + "."); if (prompt) { await applicationService.Client.Issues.Delete(username, repository, Issue.LocalId); messageService.Send(new IssueDeleteMessage(Issue)); DismissCommand.ExecuteNow(); } } catch (Exception e) { this.Log().ErrorException("Error deleting issue", e); } }); ShowMenuCommand = ReactiveCommand.CreateFromTask(sender => { var menu = actionMenuService.Create(); menu.AddButton("Edit", _ => GoToEditCommand.ExecuteNow()); menu.AddButton("Delete", _ => DeleteCommand.ExecuteNow()); return(menu.Show(sender)); }); _issueMessageBus = messageService.Listen <IssueUpdateMessage>(x => { if (x.Issue.LocalId == issueId) { Issue = x.Issue; } }); }