Exemplo n.º 1
0
        public PullRequestsViewModel(IApplicationService applicationService)
        {
            PullRequests = new ReactiveList <PullRequestModel>();

            GoToPullRequestCommand = ReactiveCommand.Create();
            GoToPullRequestCommand.OfType <PullRequestModel>().Subscribe(pullRequest =>
            {
                var vm             = CreateViewModel <PullRequestViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.PullRequestId   = pullRequest.Number;
                vm.PullRequest     = pullRequest;
                vm.WhenAnyValue(x => x.PullRequest).Skip(1).Subscribe(x =>
                {
                    var index = PullRequests.IndexOf(pullRequest);
                    if (index < 0)
                    {
                        return;
                    }
                    PullRequests[index] = x;
                    PullRequests.Reset();
                });
                ShowViewModel(vm);
            });

            this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var state   = SelectedFilter == 0 ? "open" : "closed";
                var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests.GetAll(state: state);
                return(PullRequests.SimpleCollectionLoad(request, t as bool?));
            });
        }
Exemplo n.º 2
0
        public PullRequestsViewModel(IApplicationService applicationService)
        {
            var pullRequests = new ReactiveList <PullRequestModel>();

            PullRequests = pullRequests.CreateDerivedCollection(
                x => new PullRequestItemViewModel(x, GoToPullRequestCommand),
                x => x.Title.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            GoToPullRequestCommand = ReactiveCommand.Create();
            GoToPullRequestCommand.OfType <PullRequestItemViewModel>().Subscribe(x =>
            {
                var vm             = CreateViewModel <PullRequestViewModel>();
                vm.RepositoryOwner = RepositoryOwner;
                vm.RepositoryName  = RepositoryName;
                vm.PullRequestId   = x.PullRequest.Number;
                vm.PullRequest     = x.PullRequest;
//		        vm.WhenAnyValue(x => x.PullRequest).Skip(1).Subscribe(x =>
//		        {
//                    var index = PullRequests.IndexOf(pullRequest);
//                    if (index < 0) return;
//                    PullRequests[index] = x;
//                    PullRequests.Reset();
//		        });
                ShowViewModel(vm);
            });

            this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var state   = SelectedFilter == 0 ? "open" : "closed";
                var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests.GetAll(state: state);
                return(pullRequests.SimpleCollectionLoad(request, t as bool?));
            });
        }