Example #1
0
        public OrganizationViewModel(IApplicationService applicationService)
        {
            GoToMembersCommand = ReactiveCommand.Create();
            GoToMembersCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel <OrganizationMembersViewModel>();
                vm.OrganizationName = Name;
                ShowViewModel(vm);
            });

            GoToTeamsCommand = ReactiveCommand.Create();
            GoToTeamsCommand.Subscribe(_ =>
            {
                var vm = CreateViewModel <TeamsViewModel>();
                vm.OrganizationName = Name;
                ShowViewModel(vm);
            });

            GoToFollowersCommand = ReactiveCommand.Create();
            GoToFollowersCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserFollowersViewModel>();
                vm.Username = Name;
                ShowViewModel(vm);
            });

            GoToEventsCommand = ReactiveCommand.Create();
            GoToEventsCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserEventsViewModel>();
                vm.Username = Name;
                ShowViewModel(vm);
            });

            GoToGistsCommand = ReactiveCommand.Create();
            GoToGistsCommand.Subscribe(_ =>
            {
                var vm      = CreateViewModel <UserGistsViewModel>();
                vm.Username = Name;
                ShowViewModel(vm);
            });

            GoToRepositoriesCommand = ReactiveCommand.Create();
            GoToRepositoriesCommand.Subscribe(_ =>
            {
                var vm  = CreateViewModel <OrganizationRepositoriesViewModel>();
                vm.Name = Name;
                ShowViewModel(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
                                                          this.RequestModel(applicationService.Client.Organizations[Name].Get(), t as bool?,
                                                                            response => Organization = response.Data));
        }
Example #2
0
        public OrganizationViewModel(ISessionService applicationService)
        {
            this.WhenAnyValue(x => x.Organization, x => x.Username,
                              (x, y) => x == null ? y : (string.IsNullOrEmpty(x.Name) ? x.Login : x.Name))
            .Select(x => x ?? "Organization")
            .Subscribe(x => Title = x);

            this.WhenAnyValue(x => x.Organization.AvatarUrl)
            .Select(x => new GitHubAvatar(x))
            .ToProperty(this, x => x.Avatar, out _avatar);

            GoToMembersCommand = ReactiveCommand.Create();
            GoToMembersCommand
            .Select(_ => this.CreateViewModel <OrganizationMembersViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToTeamsCommand = ReactiveCommand.Create();
            GoToTeamsCommand
            .Select(_ => this.CreateViewModel <TeamsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToFollowersCommand = ReactiveCommand.Create();
            GoToFollowersCommand
            .Select(_ => this.CreateViewModel <UserFollowersViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToFollowingCommand = ReactiveCommand.Create();
            GoToFollowingCommand
            .Select(_ => this.CreateViewModel <UserFollowingsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToEventsCommand = ReactiveCommand.Create();
            GoToEventsCommand
            .Select(_ => this.CreateViewModel <UserEventsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToGistsCommand = ReactiveCommand.Create();
            GoToGistsCommand
            .Select(_ => this.CreateViewModel <UserGistsViewModel>())
            .Select(x => x.Init(Username))
            .Subscribe(NavigateTo);

            GoToRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ =>
            {
                var vm  = this.CreateViewModel <OrganizationRepositoriesViewModel>();
                vm.Name = Username;
                NavigateTo(vm);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ =>
            {
                applicationService.GitHubClient.Organization.Team.GetAll(Username)
                .ToBackground(x => CanViewTeams = true);

                Organization = await applicationService.GitHubClient.Organization.Get(Username);
            });
        }
Example #3
0
        public MenuViewModel(
            IApplicationService applicationService = null,
            IAccountsService accountsService       = null)
        {
            _applicationService = applicationService = applicationService ?? Locator.Current.GetService <IApplicationService>();
            accountsService     = accountsService ?? Locator.Current.GetService <IAccountsService>();

            var account = applicationService.Account;

            Avatar   = new Avatar(account.AvatarUrl);
            Username = account.Username;
            var username = Username;

            Title = username;

            var repos = new ReactiveList <PinnedRepository>();

            PinnedRepositories = repos.CreateDerivedCollection(x =>
            {
                var vm = new PinnedRepositoryItemViewModel(x.Name, new Avatar(x.ImageUri));
                vm.DeleteCommand
                .Do(_ => account.PinnedRepositories.RemoveAll(y => y.Id == x.Id))
                .Subscribe(_ => repos.Remove(x));
                vm.GoToCommand
                .Select(_ => new RepositoryViewModel(x.Owner, x.Slug))
                .Subscribe(NavigateTo);
                return(vm);
            });

            RefreshCommand = ReactiveCommand.CreateFromTask(_ =>
            {
                repos.Reset(applicationService.Account.PinnedRepositories);
                return(Task.FromResult(Unit.Default));
            });

            var teams = new ReactiveList <User>();

            Teams = teams.CreateDerivedCollection(x =>
            {
                var viewModel = new TeamItemViewModel(x.Username);
                viewModel.GoToCommand
                .Select(_ => new TeamViewModel(x))
                .Subscribe(NavigateTo);
                return(viewModel);
            });

            TeamEvents = teams.CreateDerivedCollection(x =>
            {
                var viewModel = new TeamItemViewModel(x.Username);
                viewModel.GoToCommand
                .Select(_ => new UserEventsViewModel(x.Username))
                .Subscribe(NavigateTo);
                return(viewModel);
            });

            LoadCommand = ReactiveCommand.CreateFromTask(t =>
            {
                applicationService.Client
                .AllItems(x => x.Teams.GetAll())
                .ToBackground(teams.Reset);

                applicationService.Client.Groups
                .GetGroups(username)
                .ToBackground(groups => Groups.Reset(groups.Select(ToViewModel)));

                return(Task.FromResult(Unit.Default));
            });

            GoToProfileCommand
            .Select(_ => new UserViewModel(username))
            .Subscribe(NavigateTo);

            GoToMyEvents
            .Select(_ => new UserEventsViewModel(username))
            .Subscribe(NavigateTo);

            GoToStarredRepositoriesCommand
            .Select(_ => new RepositoriesStarredViewModel())
            .Subscribe(NavigateTo);

            GoToOwnedRepositoriesCommand
            .Select(_ => new UserRepositoriesViewModel(username))
            .Subscribe(NavigateTo);

            GoToSharedRepositoriesCommand
            .Select(_ => new RepositoriesSharedViewModel())
            .Subscribe(NavigateTo);

            GoToTeamsCommand
            .Select(_ => new TeamsViewModel())
            .Subscribe(NavigateTo);

            GoToSettingsCommand
            .Select(_ => new SettingsViewModel())
            .Subscribe(NavigateTo);

            GoToFeedbackCommand
            .Select(_ => new IssuesViewModel("thedillonb", "codebucket"))
            .Subscribe(NavigateTo);

            GoToGroupsCommand
            .Select(_ => new GroupsViewModel(username))
            .Subscribe(NavigateTo);

            GoToExploreRepositoriesCommand
            .Select(_ => new RepositoriesExploreViewModel())
            .Subscribe(NavigateTo);

            GoToDefaultTopView.Subscribe(_ =>
            {
                var startupViewName = applicationService.Account.DefaultStartupView;
                if (!string.IsNullOrEmpty(startupViewName))
                {
                    var props                       = from p in GetType().GetProperties()
                                           let attr = p.GetCustomAttributes(typeof(PotentialStartupViewAttribute), true)
                                                      where attr.Length == 1
                                                      select new { Property = p, Attribute = attr[0] as PotentialStartupViewAttribute };


                    var match = props.FirstOrDefault(x => string.Equals(startupViewName, x.Attribute.Name));
                    var cmd   = match?.Property.GetValue(this) as ReactiveCommand <Unit, Unit>;
                    if (cmd != null)
                    {
                        cmd.ExecuteNow();
                        return;
                    }
                }

                //Oh no... Look for the last resort DefaultStartupViewAttribute
                var deprop = (from p in GetType().GetProperties()
                              let attr = p.GetCustomAttributes(typeof(DefaultStartupViewAttribute), true)
                                         where attr.Length == 1
                                         select new { Property = p, Attribute = attr[0] as DefaultStartupViewAttribute }).FirstOrDefault();

                //That shouldn't happen...
                var bCmd = deprop?.Property.GetValue(this) as ReactiveCommand <Unit, Unit>;
                if (bCmd != null)
                {
                    bCmd.ExecuteNow();
                }
            });
        }