Exemplo n.º 1
0
        public UserExploreViewModel(ISessionService applicationService)
        {
            Title = "Explore Users";

            Items = InternalItems.CreateDerivedCollection(x =>
                                                          new UserItemViewModel(x.Login, x.AvatarUrl, false, () => {
                var vm = this.CreateViewModel <UserViewModel>();
                vm.Init(x.Login, x);
                NavigateTo(vm);
            }));

            var canSearch = this.WhenAnyValue(x => x.SearchKeyword).Select(x => !string.IsNullOrEmpty(x));

            SearchCommand = ReactiveCommand.CreateAsyncTask(canSearch, async t => {
                try
                {
                    InternalItems.Clear();
                    var request  = new SearchUsersRequest(SearchKeyword);
                    var response = await applicationService.GitHubClient.Search.SearchUsers(request);
                    InternalItems.Reset(response.Items);
                }
                catch (Exception e)
                {
                    var msg = string.Format("Unable to search for {0}. Please try again.", SearchKeyword.Humanize());
                    throw new Exception(msg, e);
                }
            });
        }
Exemplo n.º 2
0
 public ReleasesViewModel(ISessionService applicationService)
 {
     Title       = "Releases";
     Items       = InternalItems.CreateDerivedCollection(CreateItemViewModel, x => !x.Draft);
     LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
                                                   InternalItems.Reset(await applicationService.GitHubClient.Release.GetAll(RepositoryOwner, RepositoryName)));
 }
Exemplo n.º 3
0
        public RepositoryExploreViewModel(ISessionService applicationService)
        {
            ShowRepositoryDescription = applicationService.Account.ShowRepositoryDescriptionInList;
            Title = "Explore Repositories";

            var gotoRepository = new Action <RepositoryItemViewModel>(x => {
                var vm = this.CreateViewModel <RepositoryViewModel>();
                vm.Init(x.Owner, x.Name, x.Repository);
                NavigateTo(vm);
            });

            Items = InternalItems.CreateDerivedCollection(x =>
                                                          new RepositoryItemViewModel(x, true, gotoRepository));

            var canSearch = this.WhenAnyValue(x => x.SearchKeyword).Select(x => !string.IsNullOrEmpty(x));

            SearchCommand = ReactiveCommand.CreateAsyncTask(canSearch, async t => {
                try
                {
                    InternalItems.Clear();
                    var request  = new SearchRepositoriesRequest(SearchKeyword);
                    var response = await applicationService.GitHubClient.Search.SearchRepo(request);
                    InternalItems.Reset(response.Items);
                }
                catch (Exception e)
                {
                    var msg = string.Format("Unable to search for {0}. Please try again.", SearchKeyword.Humanize());
                    throw new Exception(msg, e);
                }
            });
        }
Exemplo n.º 4
0
        public PullRequestsViewModel(ISessionService sessionService)
        {
            _sessionService = sessionService;
            Title           = "Pull Requests";

            Items = InternalItems.CreateDerivedCollection(x => {
                var vm = new PullRequestItemViewModel(x);
                vm.GoToCommand.Subscribe(_ => {
                    var prViewModel = this.CreateViewModel <PullRequestViewModel>();
                    prViewModel.Init(RepositoryOwner, RepositoryName, x.Number, x);
                    NavigateTo(prViewModel);

                    prViewModel.WhenAnyValue(y => y.Issue.State)
                    .DistinctUntilChanged()
                    .Skip(1)
                    .Subscribe(y => LoadCommand.ExecuteIfCan());
                });
                return(vm);
            },
                                                          filter: x => x.Title.ContainsKeyword(SearchKeyword),
                                                          signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                InternalItems.Reset(await RetrievePullRequests());
            });

            this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => {
                InternalItems.Clear();
                LoadCommand.ExecuteIfCan();
            });
        }
Exemplo n.º 5
0
        public LanguagesViewModel()
        {
            Title = "Languages";

            DismissCommand = ReactiveCommand.Create();
            DismissCommand.Subscribe(_ => this.Dismiss());

            Items = InternalItems.CreateDerivedCollection(
                x => new LanguageItemViewModel(x.Name, x.Slug),
                filter: x => x.Name.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            Items
            .Changed.Select(_ => Unit.Default)
            .Merge(this.WhenAnyValue(x => x.SelectedLanguage).Select(_ => Unit.Default))
            .Select(_ => SelectedLanguage)
            .Where(x => x != null)
            .Subscribe(x => {
                foreach (var l in Items)
                {
                    l.Selected = l.Slug == x.Slug;
                }
            });

            this.WhenAnyValue(x => x.SelectedLanguage)
            .IsNotNull()
            .Subscribe(_ => Dismiss());

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var languageRepository = new LanguageRepository();
                var langs = await languageRepository.GetLanguages();
                langs.Insert(0, LanguageRepository.DefaultLanguage);
                InternalItems.Reset(langs);
            });
        }
Exemplo n.º 6
0
        protected BaseEventsViewModel(ISessionService sessionService)
        {
            SessionService = sessionService;
            Title          = "Events";

            Items            = InternalItems.CreateDerivedCollection(CreateEventTextBlocks);
            ReportRepository = true;

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
                                                          InternalItems.SimpleCollectionLoad(CreateRequest(),
                                                                                             x => LoadMoreCommand = x == null ? null : ReactiveCommand.CreateAsyncTask(_ => x())));
        }
Exemplo n.º 7
0
        public PublicGistsViewModel(ISessionService sessionService)
        {
            _sessionService = sessionService;

            Title = "Public Gists";

            Items = InternalItems.CreateDerivedCollection(x => CreateGistItemViewModel(x));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                InternalItems.Reset(await RetrieveGists());
            });
        }
Exemplo n.º 8
0
        protected BaseUsersViewModel(ISessionService sessionService)
        {
            SessionService = sessionService;

            Items = InternalItems.CreateDerivedCollection(x => CreateItemViewModel(x),
                                                          x => x.Login.StartsWith(SearchKeyword ?? string.Empty, StringComparison.OrdinalIgnoreCase),
                                                          signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                InternalItems.Reset(await RetrieveUsers());
            });
        }
Exemplo n.º 9
0
        public CommitBranchesViewModel(ISessionService applicationService)
        {
            Title = "Branches";

            Items = InternalItems.CreateDerivedCollection(
                x => CreateItemViewModel(x),
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
                                                          InternalItems.Reset(await applicationService.GitHubClient.Repository.GetAllBranches(RepositoryOwner, RepositoryName)));
        }
Exemplo n.º 10
0
        protected BaseGistsViewModel(ISessionService sessionService)
        {
            SessionService = sessionService;

            Items = InternalItems
                    .CreateDerivedCollection(x => CreateGistItemViewModel(x))
                    .CreateDerivedCollection(x => x,
                                             filter: x => x.Description.ContainsKeyword(SearchKeyword) || x.Title.ContainsKeyword(SearchKeyword),
                                             signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                InternalItems.Reset(await RetrieveGists());
            });
        }
Exemplo n.º 11
0
        protected BaseCommitsViewModel(ISessionService sessionService)
        {
            SessionService = sessionService;
            Title          = "Commits";

            Items = InternalItems.CreateDerivedCollection(
                x => x,
                x => x.Description.ContainsKeyword(SearchKeyword) || x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var ret = await RetrieveCommits();
                InternalItems.Reset(ret.Select(x => new CommitItemViewModel(x, GoToCommit)));
            });
        }
Exemplo n.º 12
0
        protected BaseRepositoriesViewModel(ISessionService sessionService)
        {
            SessionService      = sessionService;
            ShowRepositoryOwner = true;
            Title = "Repositories";

            Items = InternalItems.CreateDerivedCollection(
                x => x,
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                var ret = await RetrieveRepositories();
                InternalItems.Reset(ret.Select(x => new RepositoryItemViewModel(x, ShowRepositoryOwner, GoToRepository)));
            });
        }
Exemplo n.º 13
0
        public OrganizationsViewModel(ISessionService applicationService)
        {
            Title = "Organizations";

            Items = InternalItems.CreateDerivedCollection(
                x => new UserItemViewModel(x.Login, x.AvatarUrl, true, () => {
                var vm = this.CreateViewModel <OrganizationViewModel>();
                vm.Init(x.Login, x);
                NavigateTo(vm);
            }),
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
                                                          InternalItems.Reset(await applicationService.GitHubClient.Organization.GetAll(Username)));
        }
Exemplo n.º 14
0
        public TeamsViewModel(ISessionService applicationService)
        {
            Title = "Teams";

            Items = InternalItems.CreateDerivedCollection(
                x => new TeamItemViewModel(x.Name, () =>
            {
                var vm = this.CreateViewModel <TeamMembersViewModel>();
                vm.Init(x.Id);
                NavigateTo(vm);
            }),
                filter: x => x.Name.ContainsKeyword(SearchKeyword),
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
                                                          InternalItems.Reset(await applicationService.GitHubClient.Organization.Team.GetAll(OrganizationName)));
        }
Exemplo n.º 15
0
        protected BaseIssuesViewModel(ISessionService sessionService)
        {
            _sessionService = sessionService;

            Items = InternalItems.CreateDerivedCollection(
                x => CreateItemViewModel(x),
                filter: IssueFilter,
                signalReset: this.WhenAnyValue(x => x.SearchKeyword));

            Items.Changed.Subscribe(_ => {
                GroupedIssues = Items.GroupBy(x => x.RepositoryFullName)
                                .Select(x => new IssueGroupViewModel(x.Key, x)).ToList();
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t => {
                InternalItems.Reset(await RetrieveIssues());
            });
        }