public OrganizationsViewModel(IApplicationService applicationService) { Organizations = new ReactiveList <BasicUserModel>(); GoToOrganizationCommand = ReactiveCommand.Create(); GoToOrganizationCommand.OfType <BasicUserModel>().Subscribe(x => { var vm = CreateViewModel <OrganizationViewModel>(); vm.Name = x.Login; ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => Organizations.SimpleCollectionLoad(applicationService.Client.Users[Username].GetOrganizations(), t as bool?)); }
public OrganizationsViewModel(IApplicationService applicationService) { var organizations = new ReactiveList <BasicUserModel>(); Organizations = organizations.CreateDerivedCollection( x => new UserItemViewModel(x.Login, x.AvatarUrl, true, GoToOrganizationCommand.ExecuteIfCan), x => x.Login.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); GoToOrganizationCommand = ReactiveCommand.Create(); GoToOrganizationCommand.OfType <UserItemViewModel>().Subscribe(x => { var vm = CreateViewModel <OrganizationViewModel>(); vm.Username = x.Name; ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => organizations.SimpleCollectionLoad(applicationService.Client.Users[Username].GetOrganizations(), t as bool?)); }
public MenuViewModel(IApplicationService applicationService, IAccountsService accountsService) : base(accountsService) { _applicationService = applicationService; GoToNotificationsCommand = ReactiveCommand.Create(); GoToNotificationsCommand.Subscribe(_ => { var vm = CreateViewModel <NotificationsViewModel>(); ShowViewModel(vm); }); GoToAccountsCommand = ReactiveCommand.Create(); GoToAccountsCommand.Subscribe(_ => CreateAndShowViewModel <AccountsViewModel>()); GoToProfileCommand = ReactiveCommand.Create(); GoToProfileCommand.Subscribe(_ => { var vm = CreateViewModel <UserViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToMyIssuesCommand = ReactiveCommand.Create(); GoToMyIssuesCommand.Subscribe(_ => CreateAndShowViewModel <MyIssuesViewModel>()); GoToUpgradesCommand = ReactiveCommand.Create(); GoToUpgradesCommand.Subscribe(_ => CreateAndShowViewModel <UpgradesViewModel>()); GoToAboutCommand = ReactiveCommand.Create(); GoToAboutCommand.Subscribe(_ => CreateAndShowViewModel <AboutViewModel>()); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <RepositoryIdentifier>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; ShowViewModel(vm); }); GoToSettingsCommand = ReactiveCommand.Create(); GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel <SettingsViewModel>()); GoToNewsCommand = ReactiveCommand.Create(); GoToNewsCommand.Subscribe(_ => CreateAndShowViewModel <NewsViewModel>()); GoToOrganizationsCommand = ReactiveCommand.Create(); GoToOrganizationsCommand.Subscribe(_ => { var vm = CreateViewModel <OrganizationsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToTrendingRepositoriesCommand = ReactiveCommand.Create(); GoToTrendingRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesTrendingViewModel>()); GoToExploreRepositoriesCommand = ReactiveCommand.Create(); GoToExploreRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesExploreViewModel>()); GoToOrganizationEventsCommand = ReactiveCommand.Create(); GoToOrganizationEventsCommand.OfType <string>().Subscribe(name => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = name; ShowViewModel(vm); }); GoToOrganizationCommand = ReactiveCommand.Create(); GoToOrganizationCommand.OfType <string>().Subscribe(name => { var vm = CreateViewModel <OrganizationViewModel>(); vm.Username = name; ShowViewModel(vm); }); GoToOwnedRepositoriesCommand = ReactiveCommand.Create(); GoToOwnedRepositoriesCommand.Subscribe(_ => { var vm = CreateViewModel <UserRepositoriesViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToStarredRepositoriesCommand = ReactiveCommand.Create().WithSubscription( _ => CreateAndShowViewModel <RepositoriesStarredViewModel>()); GoToPublicGistsCommand = ReactiveCommand.Create().WithSubscription( _ => CreateAndShowViewModel <PublicGistsViewModel>()); GoToStarredGistsCommand = ReactiveCommand.Create().WithSubscription( _ => CreateAndShowViewModel <StarredGistsViewModel>()); GoToMyGistsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <UserGistsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToMyEvents = ReactiveCommand.Create(); GoToMyEvents.Subscribe(_ => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(_ => { var notificationRequest = applicationService.Client.Notifications.GetAll(); notificationRequest.RequestFromCache = false; notificationRequest.CheckIfModified = false; var task2 = applicationService.Client.ExecuteAsync(notificationRequest) .ContinueWith(t => Notifications = t.Result.Data.Count, TaskScheduler.FromCurrentSynchronizationContext()); var task3 = applicationService.Client.ExecuteAsync(applicationService.Client.AuthenticatedUser.GetOrganizations()) .ContinueWith(t => Organizations = t.Result.Data.Select(y => y.Login).ToList(), TaskScheduler.FromCurrentSynchronizationContext()); return(Task.WhenAll(task2, task3)); }); }
public MenuViewModel(ISessionService sessionService, IAccountsRepository accountsService) { _sessionService = sessionService; this.WhenAnyValue(x => x.Account) .Select(x => new GitHubAvatar(x.AvatarUrl)) .ToProperty(this, x => x.Avatar, out _avatar); GoToNotificationsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <NotificationsViewModel>(); vm.NotificationCount.Subscribe(x => Notifications = x); NavigateTo(vm); }); GoToAccountsCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <AccountsViewModel>())); GoToProfileCommand = ReactiveCommand.Create(); GoToProfileCommand .Select(_ => this.CreateViewModel <UserViewModel>()) .Select(x => x.Init(Account.Username)) .Subscribe(NavigateTo); GoToMyIssuesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <MyIssuesViewModel>())); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <RepositoryIdentifier>() .Select(x => this.CreateViewModel <RepositoryViewModel>().Init(x.Owner, x.Name)) .Subscribe(NavigateTo); GoToSettingsCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <SettingsViewModel>())); GoToNewsCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <NewsViewModel>())); GoToOrganizationsCommand = ReactiveCommand.Create(); GoToOrganizationsCommand .Select(_ => this.CreateViewModel <OrganizationsViewModel>()) .Select(x => x.Init(Account.Username)) .Subscribe(NavigateTo); GoToTrendingRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <RepositoriesTrendingViewModel>())); GoToExploreRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <ExploreViewModel>())); GoToOrganizationEventsCommand = ReactiveCommand.Create(); GoToOrganizationEventsCommand .OfType <Octokit.Organization>() .Select(x => this.CreateViewModel <UserEventsViewModel>().Init(x.Login)) .Subscribe(NavigateTo); GoToOrganizationCommand = ReactiveCommand.Create(); GoToOrganizationCommand .OfType <Octokit.Organization>() .Select(x => this.CreateViewModel <OrganizationViewModel>().Init(x.Login)) .Subscribe(NavigateTo); GoToOwnedRepositoriesCommand = ReactiveCommand.Create(); GoToOwnedRepositoriesCommand .Select(_ => this.CreateViewModel <UserRepositoriesViewModel>()) .Select(x => x.Init(Account.Username)) .Subscribe(NavigateTo); GoToStarredRepositoriesCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <RepositoriesStarredViewModel>())); GoToWatchedRepositoriesCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <RepositoriesWatchedViewModel>())); GoToPublicGistsCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <PublicGistsViewModel>())); GoToStarredGistsCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <StarredGistsViewModel>())); GoToMyGistsCommand = ReactiveCommand.Create(); GoToMyGistsCommand .Select(_ => this.CreateViewModel <UserGistsViewModel>()) .Select(x => x.Init(Account.Username)) .Subscribe(NavigateTo); GoToMyEvents = ReactiveCommand.Create(); GoToMyEvents .Select(_ => this.CreateViewModel <UserEventsViewModel>()) .Select(x => x.Init(Account.Username)) .Subscribe(NavigateTo); GoToFeedbackCommand = ReactiveCommand.Create(); GoToFeedbackCommand.Subscribe(_ => { var vm = sessionService.Account.IsEnterprise ? (IBaseViewModel)this.CreateViewModel <EnterpriseSupportViewModel>() : this.CreateViewModel <SupportViewModel>(); NavigateTo(vm); }); DeletePinnedRepositoryCommand = ReactiveCommand.Create(); DeletePinnedRepositoryCommand.OfType <PinnedRepository>() .Subscribe(x => { sessionService.Account.PinnnedRepositories.Remove(x); accountsService.Update(sessionService.Account); }); ActivateCommand = ReactiveCommand.Create(); ActivateCommand.Subscribe(x => { var startupViewModel = sessionService.StartupViewModel; sessionService.StartupViewModel = null; if (startupViewModel != null) { NavigateTo(startupViewModel); } else { GoToDefaultTopView.ExecuteIfCan(); } }); LoadCommand = ReactiveCommand.CreateAsyncTask(_ => { // var notifications = sessionService.GitHubClient.Notification.GetAllForCurrent(); // notifications.ToBackground(x => Notifications = x.Count); //// // var organizations = sessionService.GitHubClient.Organization.GetAllForCurrent(); // organizations.ToBackground(x => Organizations = x); // // return Task.WhenAll(notifications, organizations); return(Task.FromResult(Unit.Default)); }); }
public MenuViewModel(IApplicationService applicationService, IAccountsService accountsService) { _applicationService = applicationService; _accountsService = accountsService; GoToNotificationsCommand = ReactiveCommand.Create(); GoToNotificationsCommand.Subscribe(_ => { var vm = this.CreateViewModel <NotificationsViewModel>(); NavigateTo(vm); }); GoToAccountsCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <AccountsViewModel>())); GoToProfileCommand = ReactiveCommand.Create(); GoToProfileCommand.Subscribe(_ => { var vm = this.CreateViewModel <UserViewModel>(); vm.Username = Account.Username; NavigateTo(vm); }); GoToMyIssuesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <MyIssuesViewModel>())); GoToUpgradesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <UpgradesViewModel>())); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <RepositoryIdentifier>().Subscribe(x => { var vm = this.CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; NavigateTo(vm); }); GoToSettingsCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <SettingsViewModel>())); GoToNewsCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <NewsViewModel>())); GoToOrganizationsCommand = ReactiveCommand.Create(); GoToOrganizationsCommand.Subscribe(_ => { var vm = this.CreateViewModel <OrganizationsViewModel>(); vm.Username = Account.Username; NavigateTo(vm); }); GoToTrendingRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <RepositoriesTrendingViewModel>())); GoToExploreRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <RepositoriesExploreViewModel>())); GoToOrganizationEventsCommand = ReactiveCommand.Create(); GoToOrganizationEventsCommand.OfType <Octokit.Organization>().Subscribe(x => { var vm = this.CreateViewModel <UserEventsViewModel>(); vm.Username = x.Login; NavigateTo(vm); }); GoToOrganizationCommand = ReactiveCommand.Create(); GoToOrganizationCommand.OfType <Octokit.Organization>().Subscribe(x => { var vm = this.CreateViewModel <OrganizationViewModel>(); vm.Username = x.Login; NavigateTo(vm); }); GoToOwnedRepositoriesCommand = ReactiveCommand.Create(); GoToOwnedRepositoriesCommand.Subscribe(_ => { var vm = this.CreateViewModel <UserRepositoriesViewModel>(); vm.Username = Account.Username; NavigateTo(vm); }); GoToStarredRepositoriesCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <RepositoriesStarredViewModel>())); GoToWatchedRepositoriesCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <RepositoriesWatchedViewModel>())); GoToPublicGistsCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <PublicGistsViewModel>())); GoToStarredGistsCommand = ReactiveCommand.Create().WithSubscription( _ => NavigateTo(this.CreateViewModel <StarredGistsViewModel>())); GoToMyGistsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <UserGistsViewModel>(); vm.Username = Account.Username; NavigateTo(vm); }); GoToMyEvents = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <UserEventsViewModel>(); vm.Username = Account.Username; NavigateTo(vm); }); GoToFeedbackCommand = ReactiveCommand.Create().WithSubscription(_ => NavigateTo(this.CreateViewModel <SupportViewModel>())); DeletePinnedRepositoryCommand = ReactiveCommand.Create(); DeletePinnedRepositoryCommand.OfType <PinnedRepository>() .Subscribe(x => { accountsService.ActiveAccount.PinnnedRepositories.Remove(x); accountsService.Update(accountsService.ActiveAccount); }); LoadCommand = ReactiveCommand.CreateAsyncTask(_ => { var notifications = applicationService.GitHubClient.Notification.GetAllForCurrent(); notifications.ToBackground(x => Notifications = x.Count); var organizations = applicationService.GitHubClient.Organization.GetAllForCurrent(); organizations.ToBackground(x => Organizations = x); return(Task.WhenAll(notifications, organizations)); }); }