public IssuesViewModel(IApplicationService applicationService) { _mineFilter = IssuesFilterModel.CreateMineFilter(applicationService.Account.Username); _filterSelection = this.WhenAnyValue(x => x.Filter) .Select(x => { if (x == null || _openFilter.Equals(x)) { return(IssueFilterSelection.Open); } if (_closedFilter.Equals(x)) { return(IssueFilterSelection.Closed); } if (_mineFilter.Equals(x)) { return(IssueFilterSelection.Mine); } return(IssueFilterSelection.Custom); }) .ToProperty(this, Xamarin => Xamarin.FilterSelection); GoToNewIssueCommand = ReactiveCommand.Create(); GoToNewIssueCommand.Subscribe(_ => { var vm = CreateViewModel <IssueAddViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.CreatedIssue.IsNotNull().Subscribe(IssuesCollection.Add); ShowViewModel(vm); }); GoToCustomFilterCommand = ReactiveCommand.Create(); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var direction = Filter.Ascending ? "asc" : "desc"; var state = Filter.Open ? "open" : "closed"; var sort = Filter.SortType == BaseIssuesFilterModel.Sort.None ? null : Filter.SortType.ToString().ToLower(); var labels = string.IsNullOrEmpty(Filter.Labels) ? null : Filter.Labels; var assignee = string.IsNullOrEmpty(Filter.Assignee) ? null : Filter.Assignee; var creator = string.IsNullOrEmpty(Filter.Creator) ? null : Filter.Creator; var mentioned = string.IsNullOrEmpty(Filter.Mentioned) ? null : Filter.Mentioned; var milestone = Filter.Milestone == null ? null : Filter.Milestone.Value; var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues.GetAll( sort: sort, labels: labels, state: state, direction: direction, assignee: assignee, creator: creator, mentioned: mentioned, milestone: milestone); return(IssuesCollection.SimpleCollectionLoad(request, t as bool?)); }); }
public IssuesViewModel(IApplicationService applicationService) { _applicationService = applicationService; _mineFilter = IssuesFilterModel.CreateMineFilter(applicationService.Account.Username); Filter = _openFilter; Title = "Issues"; _filterSelection = this.WhenAnyValue(x => x.Filter) .Select(x => { if (x == null || _openFilter.Equals(x)) { return(IssueFilterSelection.Open); } if (_closedFilter.Equals(x)) { return(IssueFilterSelection.Closed); } if (_mineFilter.Equals(x)) { return(IssueFilterSelection.Mine); } return(IssueFilterSelection.Custom); }) .ToProperty(this, x => x.FilterSelection); GoToNewIssueCommand = ReactiveCommand.Create(); GoToNewIssueCommand.Subscribe(_ => { var vm = this.CreateViewModel <IssueAddViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.CreatedIssue.IsNotNull().Subscribe(IssuesBacking.Add); NavigateTo(vm); }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(_ => { IssuesBacking.Clear(); LoadCommand.ExecuteIfCan(); }); GoToCustomFilterCommand = ReactiveCommand.Create(); }