public IssueLabelsViewModel( Func <Task <IReadOnlyList <Label> > > loadLabels, Func <Task <Issue> > loadIssue, Func <IssueUpdate, Task <Issue> > updateIssue, IGraphicService graphicService) { var labels = new ReactiveList <Label>(); Labels = labels.CreateDerivedCollection(x => { var vm = new IssueLabelItemViewModel(graphicService, x); vm.IsSelected = _selectedLabels.Any(y => string.Equals(y.Name, x.Name)); vm.GoToCommand .Select(_ => x) .Where(y => vm.IsSelected && !_selectedLabels.Contains(y)) .Subscribe(_selectedLabels.Add); vm.GoToCommand .Select(_ => x) .Where(y => !vm.IsSelected) .Subscribe(y => _selectedLabels.Remove(y)); return(vm); }); SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t => { if (!_selectedLabels.All(_issue.Labels.Contains)) { return(updateIssue(new IssueUpdate { Labels = _selectedLabels.Select(x => x.Name).ToList() })); } return(Task.FromResult(0)); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { _issue = await loadIssue(); _selectedLabels.Clear(); foreach (var l in _issue.Labels) { _selectedLabels.Add(l); } labels.Reset(await loadLabels()); }); }
public GraphicViewModel(IGraphicService graphicService) { _graphicService = graphicService; if (_graphicService != null) { _graphicService.GetGraphic( (item, error) => { if (error != null) { logger.Error("GraphicViewModel|Exception GetGraphic raised: " + error); return; } logger.Info("GraphicViewModel|Load Graphic window"); }); GraphicRelayCommands(); } }
internal IssueLabelItemViewModel(IGraphicService graphicService, LabelModel label) { Label = label; Name = label.Name; var color = label.Color; var red = color.Substring(0, 2); var green = color.Substring(2, 2); var blue = color.Substring(4, 2); var redB = Convert.ToByte(red, 16); var greenB = Convert.ToByte(green, 16); var blueB = Convert.ToByte(blue, 16); Color = Color.FromArgb(byte.MaxValue, redB, greenB, blueB); Image = graphicService.CreateLabelImage(Color); SelectCommand = ReactiveCommand.Create(); }
internal IssueLabelItemViewModel(IGraphicService graphicService, Octokit.Label label) { Name = label.Name; var color = label.Color; var red = color.Substring(0, 2); var green = color.Substring(2, 2); var blue = color.Substring(4, 2); var redB = Convert.ToByte(red, 16); var greenB = Convert.ToByte(green, 16); var blueB = Convert.ToByte(blue, 16); Color = Color.FromArgb(byte.MaxValue, redB, greenB, blueB); Image = graphicService.CreateLabelImage(Color); GoToCommand = ReactiveCommand.Create() .WithSubscription(_ => IsSelected = !IsSelected); }
public GraphicsController(IGraphicService graphicService) : base(graphicService) { }
public IssueLabelsViewModel(IApplicationService applicationService, IGraphicService graphicService) { var labels = new ReactiveList <LabelModel>(); SelectedLabels = new ReactiveList <LabelModel>(); Labels = labels.CreateDerivedCollection(x => { var vm = new IssueLabelItemViewModel(graphicService, x); vm.SelectCommand.Subscribe(_ => { var selected = SelectedLabels.FirstOrDefault(y => string.Equals(y.Name, x.Name)); if (selected != null) { SelectedLabels.Remove(selected); vm.Selected = false; } else { SelectedLabels.Add(x); vm.Selected = true; } }); return(vm); }); SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(async t => { var selectedLabels = t as IEnumerable <LabelModel>; if (selectedLabels != null) { SelectedLabels.Reset(selectedLabels); } //If nothing has changed, dont do anything... if (OriginalLabels != null && OriginalLabels.Count() == SelectedLabels.Count() && OriginalLabels.Intersect(SelectedLabels).Count() == SelectedLabels.Count()) { DismissCommand.ExecuteIfCan(); return; } if (SaveOnSelect) { // try // { // var labels = (SelectedLabels != null && SelectedLabels.Count > 0) // ? SelectedLabels.Select(y => y.Name).ToArray() : null; // var updateReq = // applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId] // .UpdateLabels(labels); // await applicationService.Client.ExecuteAsync(updateReq); // } // catch (Exception e) // { // throw new Exception("Unable to save labels! Please try again.", e); // } } DismissCommand.ExecuteIfCan(); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => labels.LoadAll(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Labels.GetAll())); }
public IssueViewModel(IApplicationService applicationService, IActionMenuFactory actionMenuFactory, IMarkdownService markdownService, IGraphicService graphicsService) { _applicationService = applicationService; var issuePresenceObservable = this.WhenAnyValue(x => x.Issue).Select(x => x != null); GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable) .WithSubscription(_ => Assignees.LoadCommand.ExecuteIfCan()); GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable) .WithSubscription(_ => Labels.LoadCommand.ExecuteIfCan()); GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable) .WithSubscription(_ => Milestones.LoadCommand.ExecuteIfCan()); this.WhenAnyValue(x => x.Id) .Subscribe(x => Title = "Issue #" + x); _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); _markdownDescription = this.WhenAnyValue(x => x.Issue) .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : markdownService.Convert(x.Body))) .ToProperty(this, x => x.MarkdownDescription); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); ShareCommand.Subscribe(_ => actionMenuFactory.ShareUrl(Issue.HtmlUrl)); var events = new ReactiveList <IIssueEventItemViewModel>(); Events = events.CreateDerivedCollection(x => x); AddCommentCommand = ReactiveCommand.Create(); AddCommentCommand.Subscribe(_ => { var vm = this.CreateViewModel <IssueCommentViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.SaveCommand.Subscribe(x => events.Add(new IssueCommentItemViewModel(x))); NavigateTo(vm); }); ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => { try { Issue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate { State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open }); } catch (Exception e) { var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open"; throw new Exception("Unable to " + close + " the item. " + e.Message, e); } }); GoToEditCommand = ReactiveCommand.Create(issuePresenceObservable); GoToEditCommand.Subscribe(_ => { 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); }); Assignees = new IssueAssigneeViewModel( () => applicationService.GitHubClient.Issue.Assignee.GetForRepository(RepositoryOwner, RepositoryName), () => Task.FromResult(Issue), UpdateIssue); Milestones = new IssueMilestonesViewModel( () => applicationService.GitHubClient.Issue.Milestone.GetForRepository(RepositoryOwner, RepositoryName), () => Task.FromResult(Issue), UpdateIssue); Labels = new IssueLabelsViewModel( () => applicationService.GitHubClient.Issue.Labels.GetForRepository(RepositoryOwner, RepositoryName), () => Task.FromResult(Issue), UpdateIssue, graphicsService); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var issueRequest = applicationService.GitHubClient.Issue.Get(RepositoryOwner, RepositoryName, Id) .ContinueWith(x => Issue = x.Result, new CancellationToken(), TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); var eventsRequest = applicationService.GitHubClient.Issue.Events.GetForIssue(RepositoryOwner, RepositoryName, Id); var commentsRequest = applicationService.GitHubClient.Issue.Comment.GetForIssue(RepositoryOwner, RepositoryName, Id); await Task.WhenAll(issueRequest, eventsRequest, commentsRequest); var tempList = new List <IIssueEventItemViewModel>(eventsRequest.Result.Count + commentsRequest.Result.Count); tempList.AddRange(eventsRequest.Result.Select(x => new IssueEventItemViewModel(x))); tempList.AddRange(commentsRequest.Result.Select(x => new IssueCommentItemViewModel(x))); events.Reset(tempList.OrderBy(x => x.CreatedAt)); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Issue).Select(x => x != null), _ => { var menu = actionMenuFactory.Create(Title); menu.AddButton(Issue.State == Octokit.ItemState.Open ? "Close" : "Open", ToggleStateCommand); // // // var editButton = _actionSheet.AddButton("Edit"); // var commentButton = _actionSheet.AddButton("Comment"); // var shareButton = _actionSheet.AddButton("Share"); // var showButton = _actionSheet.AddButton("Show in GitHub"); return(menu.Show()); }); }