public BranchesAndTagsViewModel(IApplicationService applicationService) { Items = new ReactiveCollection<ViewObject>(); GoToSourceCommand = new ReactiveCommand(); GoToSourceCommand.OfType<BranchModel>().Subscribe(x => { var vm = CreateViewModel<SourceTreeViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.Branch = x.Name; vm.TrueBranch = true; ShowViewModel(vm); }); GoToSourceCommand.OfType<TagModel>().Subscribe(x => { var vm = CreateViewModel<SourceTreeViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.Branch = x.Commit.Sha; ShowViewModel(vm); }); this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); LoadCommand.RegisterAsyncTask(t => { if (SelectedFilter == ShowIndex.Branches) { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches(); return this.RequestModel(request, t as bool?, response => { this.CreateMore(response, m => Items.MoreTask = m, d => Items.AddRange(d.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x }))); Items.Reset(response.Data.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x })); }); } else { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetTags(); return this.RequestModel(request, t as bool?, response => { this.CreateMore(response, m => Items.MoreTask = m, d => Items.AddRange(d.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x }))); Items.Reset(response.Data.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x })); }); } }); }
public ProjectsViewModel(IApplicationService applicationService, IAccountsService accountsService) { Account = accountsService.ActiveAccount; GoToProjectCommand = new ReactiveCommand(); Projects = new ReactiveCollection <Project>(new [] { CreatePersonalProject(accountsService.ActiveAccount) }); LoadCommand.RegisterAsyncTask(async x => { var getAllProjects = applicationService.StashClient.Projects.GetAll(); using (Projects.SuppressChangeNotifications()) { Projects.Clear(); Projects.Add(CreatePersonalProject(accountsService.ActiveAccount)); Projects.AddRange(await getAllProjects.ExecuteAsyncAll()); } }); GoToProjectCommand.OfType <Project>().Subscribe(x => { var vm = this.CreateViewModel <RepositoriesViewModel>(); vm.ProjectKey = x.Key; vm.Name = x.Name; ShowViewModel(vm); }); }
public PullRequestFilesViewModel(IApplicationService applicationService) { Files = new ReactiveCollection<CommitModel.CommitFileModel> { GroupFunc = y => { var filename = "/" + y.Filename; return filename.Substring(0, filename.LastIndexOf("/", StringComparison.Ordinal) + 1); } }; GoToSourceCommand = new ReactiveCommand(); GoToSourceCommand.OfType<CommitModel.CommitFileModel>().Subscribe(x => { var vm = CreateViewModel<SourceViewModel>(); // vm.Name = x.Filename.Substring(x.Filename.LastIndexOf("/", StringComparison.Ordinal) + 1); // vm.Path = x.Filename; // vm.GitUrl = x.ContentsUrl; // vm.ForceBinary = x.Patch == null; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(t => Files.SimpleCollectionLoad( applicationService.Client.Users[Username].Repositories[Repository].PullRequests[PullRequestId] .GetFiles(), t as bool?)); }
public PullRequestsViewModel(IApplicationService applicationService) { PullRequests = new ReactiveCollection<PullRequestModel>(); GoToPullRequestCommand = new ReactiveCommand(); 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.RegisterAsyncTask(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?); }); }
public AccountsViewModel(IAccountsService accountsService) { _accountsService = accountsService; Accounts = new ReactiveList<GitHubAccount>(accountsService); LoginCommand = ReactiveCommand.Create(); GoToAddAccountCommand = ReactiveCommand.Create(); DeleteAccountCommand = ReactiveCommand.Create(); DeleteAccountCommand.OfType<GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) ActiveAccount = null; accountsService.Remove(x); Accounts.Remove(x); }); LoginCommand.OfType<GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) DismissCommand.ExecuteIfCan(); else { ActiveAccount = x; MessageBus.Current.SendMessage(new LogoutMessage()); DismissCommand.ExecuteIfCan(); } }); GoToAddAccountCommand.Subscribe(_ => ShowViewModel(CreateViewModel<NewAccountViewModel>())); this.WhenActivated(d => Accounts.Reset(accountsService)); }
protected BaseUserCollectionViewModel() { Users = new ReactiveCollection<BasicUserModel>(); GoToUserCommand = new ReactiveCommand(); GoToUserCommand.OfType<BasicUserModel>().Subscribe(x => { var vm = CreateViewModel<ProfileViewModel>(); vm.Username = x.Login; ShowViewModel(vm); }); }
public AccountsViewModel(IAccountsService accountsService) { _accountsService = accountsService; Title = "Accounts"; _accounts = new ReactiveList <GitHubAccount>(accountsService.OrderBy(x => x.Username)); this.WhenActivated(d => _accounts.Reset(accountsService.OrderBy(x => x.Username))); Accounts = _accounts.CreateDerivedCollection(CreateAccountItem); this.WhenAnyValue(x => x.ActiveAccount) .Subscribe(x => { foreach (var account in Accounts) { account.Selected = Equals(account.Account, x); } }); DeleteAccountCommand = ReactiveCommand.Create(); DeleteAccountCommand.OfType <GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) { ActiveAccount = null; } accountsService.Remove(x); _accounts.Remove(x); }); LoginCommand = ReactiveCommand.Create(); LoginCommand.OfType <GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) { DismissCommand.ExecuteIfCan(); } else { ActiveAccount = x; MessageBus.Current.SendMessage(new LogoutMessage()); DismissCommand.ExecuteIfCan(); } }); DismissCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ActiveAccount).Select(x => x != null)) .WithSubscription(x => base.DismissCommand.ExecuteIfCan(x)); GoToAddAccountCommand = ReactiveCommand.Create() .WithSubscription(_ => ShowViewModel(CreateViewModel <NewAccountViewModel>())); }
protected GistsViewModel() { Gists = new ReactiveCollection<GistModel>(); GoToGistCommand = new ReactiveCommand(); GoToGistCommand.OfType<GistModel>().Subscribe(x => { var vm = CreateViewModel<GistViewModel>(); vm.Id = x.Id; vm.Gist = x; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(t => Gists.SimpleCollectionLoad(CreateRequest(), t as bool?)); }
public TeamsViewModel(IApplicationService applicationService) { Teams = new ReactiveCollection<TeamShortModel>(); GoToTeamCommand = new ReactiveCommand(); GoToTeamCommand.OfType<TeamShortModel>().Subscribe(x => { var vm = CreateViewModel<TeamMembersViewModel>(); vm.Id = x.Id; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(x => Teams.SimpleCollectionLoad(applicationService.Client.Organizations[OrganizationName].GetTeams(), x as bool?)); }
public OrganizationsViewModel(IApplicationService applicationService) { Organizations = new ReactiveCollection<BasicUserModel>(); GoToOrganizationCommand = new ReactiveCommand(); GoToOrganizationCommand.OfType<BasicUserModel>().Subscribe(x => { var vm = CreateViewModel<OrganizationViewModel>(); vm.Name = x.Login; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(t => Organizations.SimpleCollectionLoad(applicationService.Client.Users[Username].GetOrganizations(), t as bool?)); }
public ChangesetBranchesViewModel(IApplicationService applicationService) { Branches = new ReactiveCollection<BranchModel>(); GoToBranchCommand = new ReactiveCommand(); GoToBranchCommand.OfType<BranchModel>().Subscribe(x => { var vm = CreateViewModel<ChangesetsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(t => Branches.SimpleCollectionLoad( applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches(), t as bool?)); }
public BuildStatusesViewModel(IApplicationService applicationService) { BuildStatues = new ReactiveCollection <BuildStatus>(); GoToBuildStatusCommand = new ReactiveCommand(); GoToBuildStatusCommand.OfType <BuildStatus>().Subscribe(x => { var vm = CreateViewModel <WebBrowserViewModel>(); vm.Url = x.Url; ShowViewModel(vm); }); LoadCommand.RegisterAsyncTask(async _ => { BuildStatues.Reset((await applicationService.StashClient.BuildStatus[Node].GetStatus().ExecuteAsync()).Data.Values); }); }
public AccountsViewModel(IAccountsService accountsService) { _accountsService = accountsService; _accounts = new ReactiveList<GitHubAccount>(accountsService.OrderBy(x => x.Username)); this.WhenActivated(d => _accounts.Reset(accountsService.OrderBy(x => x.Username))); Accounts = _accounts.CreateDerivedCollection(CreateAccountItem); this.WhenAnyValue(x => x.ActiveAccount) .Subscribe(x => { foreach (var account in Accounts) account.Selected = Equals(account.Account, x); }); DeleteAccountCommand = ReactiveCommand.Create(); DeleteAccountCommand.OfType<GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) ActiveAccount = null; accountsService.Remove(x); _accounts.Remove(x); }); LoginCommand = ReactiveCommand.Create(); LoginCommand.OfType<GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) DismissCommand.ExecuteIfCan(); else { ActiveAccount = x; MessageBus.Current.SendMessage(new LogoutMessage()); DismissCommand.ExecuteIfCan(); } }); DismissCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ActiveAccount).Select(x => x != null)) .WithSubscription(x => base.DismissCommand.ExecuteIfCan(x)); GoToAddAccountCommand = ReactiveCommand.Create() .WithSubscription(_ => ShowViewModel(CreateViewModel<NewAccountViewModel>())); }
protected BaseEventsViewModel(IApplicationService applicationService) { ApplicationService = applicationService; Title = "Events"; _gotoUrlCommand = new Action <string>(x => { var vm = this.CreateViewModel <WebBrowserViewModel>(); vm.Url = x; NavigateTo(vm); }); var events = new ReactiveList <EventModel>(); Events = events.CreateDerivedCollection(CreateEventTextBlocks); ReportRepository = true; _gotoRepositoryCommand = ReactiveCommand.Create(); _gotoRepositoryCommand.OfType <EventModel.RepoModel>().Subscribe(x => { var repoId = new RepositoryIdentifier(x.Name); var vm = this.CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; NavigateTo(vm); }); _gotoGistCommand = ReactiveCommand.Create(); _gotoGistCommand.OfType <EventModel.GistEvent>().Subscribe(x => { var vm = this.CreateViewModel <GistViewModel>(); vm.Id = x.Gist.Id; vm.Gist = x.Gist; NavigateTo(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => this.RequestModel(CreateRequest(0, 100), t as bool?, response => { //this.CreateMore(response, m => { }, events.AddRange); events.Reset(response.Data); })); }
protected RepositoriesViewModel(IApplicationService applicationService, string filterKey = "RepositoryController") { ApplicationService = applicationService; Repositories = new ReactiveCollection<RepositoryModel>(); Filter = applicationService.Account.Filters.GetFilter<RepositoriesFilterModel>(filterKey); GoToRepositoryCommand = new ReactiveCommand(); GoToRepositoryCommand.OfType<RepositoryModel>().Subscribe(x => { var vm = CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = x.Owner.Login; vm.RepositoryName = x.Name; ShowViewModel(vm); }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); // _repositories.FilteringFunction = x => Repositories.Filter.Ascending ? x.OrderBy(y => y.Name) : x.OrderByDescending(y => y.Name); // _repositories.GroupingFunction = CreateGroupedItems; }
protected RepositoriesViewModel(IApplicationService applicationService, string filterKey = "RepositoryController") { ApplicationService = applicationService; Repositories = new ReactiveList <RepositoryModel>(); //Filter = applicationService.Account.Filters.GetFilter<RepositoriesFilterModel>(filterKey); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <RepositoryModel>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = x.Owner.Login; vm.RepositoryName = x.Name; ShowViewModel(vm); }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); // _repositories.FilteringFunction = x => Repositories.Filter.Ascending ? x.OrderBy(y => y.Name) : x.OrderByDescending(y => y.Name); // _repositories.GroupingFunction = CreateGroupedItems; }
public CommitsBranchViewModel(IApplicationService applicationService) { GoToCommitsCommand = new ReactiveCommand(); Branches = new ReactiveCollection <Branch>(); LoadCommand.RegisterAsyncTask(async x => { var response = await applicationService.StashClient.Projects[ProjectKey].Repositories[RepositorySlug].Branches.GetAll().ExecuteAsync(); Branches.Reset(response.Data.Values); }); GoToCommitsCommand.OfType <Branch>().Subscribe(x => { var vm = CreateViewModel <CommitsViewModel>(); vm.ProjectKey = ProjectKey; vm.RepositorySlug = RepositorySlug; vm.Branch = x.Id; vm.Title = x.DisplayId; ShowViewModel(vm); }); }
public PullRequestChangesViewModel(IApplicationService applicationService) { Changes = new ReactiveList <Change>(); LoadCommand.RegisterAsyncTask(async _ => { Changes.Reset(await applicationService.StashClient.Projects[ProjectKey].Repositories[RepositorySlug].PullRequests[PullRequestId].GetAllChanges().ExecuteAsyncAll()); }); GoToDiffCommand = new ReactiveCommand(); GoToDiffCommand.OfType <Change>().Subscribe(x => { var vm = CreateViewModel <PullRequestDiffViewModel>(); vm.ProjectKey = ProjectKey; vm.RepositorySlug = RepositorySlug; vm.PullRequestId = PullRequestId; vm.Path = x.Path.ToString; vm.Name = x.Path.Name; ShowViewModel(vm); }); }
public InterestsViewModel(IApplicationService applicationService, IFeaturesService featuresService) { ApplicationService = applicationService; var interests = new ReactiveList <Interest>(); Interests = interests; DeleteInterestCommand = ReactiveCommand.Create(); DeleteInterestCommand.OfType <Interest>().Subscribe(ApplicationService.Account.Interests.Remove); GoToStumbleInterestCommand = ReactiveCommand.Create(); GoToStumbleInterestCommand.OfType <Interest>().Subscribe(x => { var vm = CreateViewModel <StumbleViewModel>(); vm.Interest = x; ShowViewModel(vm); }); GoToAddInterestCommand = ReactiveCommand.Create(); GoToAddInterestCommand.Subscribe(_ => { if (ApplicationService.Account.Interests.Count() >= 3 && !featuresService.ProEditionEnabled) { var vm = CreateViewModel <PurchaseProViewModel>(); ShowViewModel(vm); } else { var vm = CreateViewModel <AddInterestViewModel>(); ShowViewModel(vm); } }); this.WhenActivated(d => { interests.Reset(ApplicationService.Account.Interests.Query.OrderBy(x => x.Keyword)); }); }
public AccountsViewModel(IAccountsService accountsService) { _accountsService = accountsService; Accounts = new ReactiveList <IAccount>(accountsService); LoginCommand = new ReactiveCommand(); GoToAddAccountCommand = new ReactiveCommand(); DeleteAccountCommand = new ReactiveCommand(); DeleteAccountCommand.OfType <IAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) { ActiveAccount = null; } accountsService.Remove(x); Accounts.Remove(x); }); LoginCommand.OfType <IAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) { DismissCommand.ExecuteIfCan(); } else { ActiveAccount = x; MessageBus.Current.SendMessage(new LogoutMessage()); DismissCommand.ExecuteIfCan(); } }); GoToAddAccountCommand.Subscribe(_ => ShowViewModel(CreateViewModel(typeof(IAddAccountViewModel)))); LoadCommand = new ReactiveCommand(); LoadCommand.Subscribe(x => Accounts.Reset(accountsService)); }
public RepositoriesTrendingViewModel(IApplicationService applicationService, IJsonHttpClientService jsonHttpClient) { _applicationService = applicationService; _jsonHttpClient = jsonHttpClient; Languages = new ReactiveList<LanguageModel>(); Repositories = new ReactiveCollection<RepositoryModel>(); GoToRepositoryCommand = new ReactiveCommand(); GoToRepositoryCommand.OfType<RepositoryModel>().Subscribe(x => { var vm = CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; ShowViewModel(vm); }); SelectedTime = Times[0]; SelectedLanguage = _defaultLanguage; GetLanguages().FireAndForget(); this.WhenAnyValue(x => x.SelectedTime, x => x.SelectedLanguage, (x, y) => Unit.Default) .Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan()); LoadCommand.RegisterAsyncTask(async t => { var query = "?"; if (SelectedLanguage != null && SelectedLanguage.Slug != null) query += string.Format("language={0}&", SelectedLanguage.Slug); if (SelectedTime != null && SelectedTime.Slug != null) query += string.Format("since={0}", SelectedTime.Slug); var repos = await _jsonHttpClient.Get<List<RepositoryModel>>(TrendingUrl + query); Repositories.Reset(repos); }); }
public NotificationsViewModel(IApplicationService applicationService) { _applicationService = applicationService; _notifications = new ReactiveList <NotificationModel>(); Notifications = _notifications.CreateDerivedCollection(x => x); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating); return(this.RequestModel(req, t as bool?, response => _notifications.Reset(response.Data))); }); GoToNotificationCommand = ReactiveCommand.Create(); GoToNotificationCommand.OfType <NotificationModel>().Subscribe(GoToNotification); ReadAllCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.ShownIndex).Select(x => x != 2), async t => { try { if (!Notifications.Any()) { return; } await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead()); _notifications.Clear(); } catch (Exception e) { throw new Exception("Unable to mark all notifications as read. Please try again.", e); } }); ReadRepositoriesCommand = ReactiveCommand.CreateAsyncTask(async t => { try { var repo = t as string; if (repo == null) { return; } var repoId = new RepositoryIdentifier(repo); await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name)); _notifications.RemoveAll(Notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList()); } catch (Exception e) { throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e); } }); this.WhenAnyValue(x => x.ShownIndex).Subscribe(x => { switch (x) { case 0: Filter = NotificationsFilterModel.CreateUnreadFilter(); break; case 1: Filter = NotificationsFilterModel.CreateParticipatingFilter(); break; default: Filter = NotificationsFilterModel.CreateAllFilter(); break; } }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan()); }
public NotificationsViewModel(IApplicationService applicationService) { _applicationService = applicationService; Notifications = new ReactiveCollection<NotificationModel> {GroupFunc = x => x.Repository.FullName}; LoadCommand.RegisterAsyncTask(t => { var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating); return this.RequestModel(req, t as bool?, response => Notifications.Reset(response.Data)); }); GoToNotificationCommand = new ReactiveCommand(); GoToNotificationCommand.OfType<NotificationModel>().Subscribe(GoToNotification); ReadAllCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ShownIndex, x => x != 2)); ReadAllCommand.RegisterAsyncTask(async t => { try { if (!Notifications.Any()) return; await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead()); Notifications.Clear(); } catch (Exception e) { throw new Exception("Unable to mark all notifications as read. Please try again.", e); } }); ReadRepositoriesCommand = new ReactiveCommand(); ReadRepositoriesCommand.RegisterAsyncTask(async t => { try { var repo = t as string; if (repo == null) return; var repoId = new CodeFramework.Core.Utils.RepositoryIdentifier(repo); await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name)); Notifications.RemoveAll(Notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList()); } catch (Exception e) { throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e); } }); this.WhenAnyValue(x => x.ShownIndex).Subscribe(x => { switch (x) { case 0: Filter = NotificationsFilterModel.CreateUnreadFilter(); break; case 1: Filter = NotificationsFilterModel.CreateParticipatingFilter(); break; default: Filter = NotificationsFilterModel.CreateAllFilter(); break; } }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan()); }
public NotificationsViewModel(IApplicationService applicationService) { _applicationService = applicationService; var whenNotificationsChange = _notifications.Changed.Select(_ => Unit.Default) .Merge(_notifications.ItemChanged.Select(_ => Unit.Default)); _groupedNotifications = whenNotificationsChange.Select(_ => _notifications.GroupBy(x => x.Repository.FullName) .Select(x => new NotificationGroupViewModel(x.Key, new ReactiveList<NotificationModel>(x), __ => { }))) .ToProperty(this, t => t.GroupedNotifications); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating); return this.RequestModel(req, t as bool?, response => _notifications.Reset(response.Data)); }); GoToNotificationCommand = ReactiveCommand.Create(); GoToNotificationCommand.OfType<NotificationModel>().Subscribe(GoToNotification); var canReadAll = _notifications.CountChanged.Select(x => x > 0).CombineLatest( this.WhenAnyValue(x => x.ShownIndex).Select(x => x != 2), (x, y) => x & y); ReadAllCommand = ReactiveCommand.CreateAsyncTask(canReadAll, async t => { try { if (!_notifications.Any()) return; await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead()); _notifications.Clear(); } catch (Exception e) { throw new Exception("Unable to mark all notifications as read. Please try again.", e); } }); ReadRepositoriesCommand = ReactiveCommand.CreateAsyncTask(async t => { try { var repo = t as string; if (repo == null) return; var repoId = new RepositoryIdentifier(repo); await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name)); _notifications.RemoveAll(_notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList()); } catch (Exception e) { throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e); } }); this.WhenAnyValue(x => x.ShownIndex).Subscribe(x => { switch (x) { case 0: Filter = NotificationsFilterModel.CreateUnreadFilter(); break; case 1: Filter = NotificationsFilterModel.CreateParticipatingFilter(); break; default: Filter = NotificationsFilterModel.CreateAllFilter(); break; } }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan()); }
public NotificationsViewModel(IApplicationService applicationService) { _applicationService = applicationService; Title = "Notifications"; var whenNotificationsChange = _notifications.Changed.Select(_ => Unit.Default) .Merge(_notifications.ItemChanged.Select(_ => Unit.Default)); _groupedNotifications = whenNotificationsChange.Select(_ => _notifications.GroupBy(x => x.Repository.FullName) .Select(x => new NotificationGroupViewModel(x.Key, new ReactiveList <NotificationModel>(x), __ => { }))) .ToProperty(this, t => t.GroupedNotifications); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating); return(this.RequestModel(req, t as bool?, response => _notifications.Reset(response.Data))); }); GoToNotificationCommand = ReactiveCommand.Create(); GoToNotificationCommand.OfType <NotificationModel>().Subscribe(GoToNotification); var canReadAll = _notifications.CountChanged.Select(x => x > 0).CombineLatest( this.WhenAnyValue(x => x.ShownIndex).Select(x => x != 2), (x, y) => x & y); ReadAllCommand = ReactiveCommand.CreateAsyncTask(canReadAll, async t => { try { if (!_notifications.Any()) { return; } await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead()); _notifications.Clear(); } catch (Exception e) { throw new Exception("Unable to mark all notifications as read. Please try again.", e); } }); ReadRepositoriesCommand = ReactiveCommand.CreateAsyncTask(async t => { try { var repo = t as string; if (repo == null) { return; } var repoId = new RepositoryIdentifier(repo); await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name)); _notifications.RemoveAll(_notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList()); } catch (Exception e) { throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e); } }); this.WhenAnyValue(x => x.ShownIndex).Subscribe(x => { switch (x) { case 0: Filter = NotificationsFilterModel.CreateUnreadFilter(); break; case 1: Filter = NotificationsFilterModel.CreateParticipatingFilter(); break; default: Filter = NotificationsFilterModel.CreateAllFilter(); break; } }); this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan()); }
public SourceTreeViewModel(IApplicationService applicationService) { Filter = applicationService.Account.Filters.GetFilter<SourceFilterModel>("SourceViewModel"); Content = new ReactiveCollection<ContentModel>(); GoToSubmoduleCommand = new ReactiveCommand(); GoToSubmoduleCommand.OfType<ContentModel>().Subscribe(x => { var nameAndSlug = x.GitUrl.Substring(x.GitUrl.IndexOf("/repos/", StringComparison.OrdinalIgnoreCase) + 7); var repoId = new RepositoryIdentifier(nameAndSlug.Substring(0, nameAndSlug.IndexOf("/git", StringComparison.OrdinalIgnoreCase))); var vm = CreateViewModel<SourceTreeViewModel>(); vm.Username = repoId.Owner; vm.Repository = repoId.Name; vm.Branch = x.Sha; ShowViewModel(vm); }); GoToSourceCommand = new ReactiveCommand(); GoToSourceCommand.OfType<ContentModel>().Subscribe(x => { var otherFiles = Content .Where(y => string.Equals(y.Type, "file", StringComparison.OrdinalIgnoreCase)) .Where(y => y.Size.HasValue && y.Size.Value > 0) .Select(y => new SourceViewModel.SourceItemModel { Name = y.Name, Path = y.Path, HtmlUrl = y.HtmlUrl, GitUrl = y.GitUrl }).ToArray(); var navObject = new SourceViewModel.NavObject { Branch = Branch, Username = Username, Repository = Repository, TrueBranch = TrueBranch, Items = otherFiles, CurrentItemIndex = Array.FindIndex(otherFiles, f => string.Equals(f.GitUrl, x.GitUrl, StringComparison.OrdinalIgnoreCase)) }; var vm = CreateViewModel<SourceViewModel>(navObject); ShowViewModel(vm); }); GoToSourceTreeCommand = new ReactiveCommand(); GoToSourceTreeCommand.OfType<ContentModel>().Subscribe(x => { var vm = CreateViewModel<SourceTreeViewModel>(); vm.Username = Username; vm.Branch = Branch; vm.Repository = Repository; vm.TrueBranch = TrueBranch; vm.Path = x.Path; ShowViewModel(vm); }); this.WhenAnyValue(x => x.Filter).Subscribe(filter => { if (filter == null) { Content.OrderFunc = null; } else { Content.OrderFunc = x => { switch (filter.OrderBy) { case SourceFilterModel.Order.FoldersThenFiles: x = x.OrderBy(y => y.Type).ThenBy(y => y.Name); break; default: x = x.OrderBy(y => y.Name); break; } return filter.Ascending ? x : x.Reverse(); }; } }); LoadCommand.RegisterAsyncTask(t => Content.SimpleCollectionLoad( applicationService.Client.Users[Username].Repositories[Repository].GetContent( Path ?? string.Empty, Branch ?? "master"), t as bool?)); }
public CommitViewModel(IApplicationService applicationService) { Changes = new ReactiveList <Change>(); Branches = new ReactiveList <Branch>(); LoadCommand.RegisterAsyncTask(async _ => { applicationService.StashClient.BranchUtilities.GetBranches(ProjectKey, RepositorySlug, Node) .ExecuteAsync().ContinueInBackground(x => Branches.Reset(x.Data.Values)); applicationService.StashClient.BuildStatus[Node].GetStatus() .ExecuteAsync().ContinueInBackground(x => BuildStatus = x.Data.Values.ToArray()); Commit = (await applicationService.StashClient.Projects[ProjectKey].Repositories[RepositorySlug].Commits[Node].Get().ExecuteAsync()).Data; Changes.Reset(await applicationService.StashClient.Projects[ProjectKey].Repositories[RepositorySlug].Commits[Node].GetAllChanges().ExecuteAsyncAll()); }); GoToBuildStatusCommand = new ReactiveCommand(this.WhenAnyValue(x => x.BuildStatus, x => x != null && x.Length > 0)); GoToBuildStatusCommand.Subscribe(_ => { var vm = CreateViewModel <BuildStatusesViewModel>(); vm.Node = Node; ShowViewModel(vm); }); GoToParentCommitCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Commit, x => x != null && x.Parents != null && x.Parents.Count > 0)); GoToParentCommitCommand.Subscribe(_ => { // if (Commit.Parents.Count > 1) // { // // Oh shit... More than one... // } // else { var firstParent = Commit.Parents.FirstOrDefault(); var vm = CreateViewModel <CommitViewModel>(); vm.ProjectKey = ProjectKey; vm.RepositorySlug = RepositorySlug; vm.Node = firstParent.Id; ShowViewModel(vm); } }); GoToBranchesCommand = new ReactiveCommand(this.Branches.CountChanged.Select(x => x > 0)); GoToBranchesCommand.Subscribe(_ => { // if (Branches.Count > 1) // { // // Oh shit... More than one... // } // else { var firstParent = Branches.FirstOrDefault(); var vm = CreateViewModel <CommitsViewModel>(); vm.ProjectKey = ProjectKey; vm.RepositorySlug = RepositorySlug; vm.Branch = firstParent.Id; vm.Title = firstParent.DisplayId; ShowViewModel(vm); } }); GoToCommentsCommand = new ReactiveCommand(); GoToDiffCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Commit, x => x != null)); GoToDiffCommand.OfType <Change>().Subscribe(x => { var vm = CreateViewModel <CommitDiffViewModel>(); vm.ProjectKey = ProjectKey; vm.RepositorySlug = RepositorySlug; vm.Node = Node; vm.Path = x.Path.ToString; vm.Name = x.Path.Name; ShowViewModel(vm); }); }
public PullRequestViewModel(IApplicationService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuService) { _applicationService = applicationService; _markdownService = markdownService; Comments = new ReactiveList <Octokit.IssueComment>(); Events = new ReactiveList <Octokit.IssueEvent>(); this.WhenAnyValue(x => x.Id).Subscribe(x => Title = "Pull Request #" + x); _canMerge = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged) .ToProperty(this, x => x.CanMerge); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { var req = new Octokit.MergePullRequest(null); var response = await _applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) { throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); } LoadCommand.ExecuteIfCan(); }); ToggleStateCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), async t => { var newState = PullRequest.State == Octokit.ItemState.Open ? Octokit.ItemState.Closed : Octokit.ItemState.Open; try { var req = new Octokit.PullRequestUpdate { State = newState }; PullRequest = await _applicationService.GitHubClient.PullRequest.Update(RepositoryOwner, RepositoryName, Id, req); } catch (Exception e) { throw new Exception("Unable to " + (newState == Octokit.ItemState.Closed ? "close" : "open") + " the item. " + e.Message, e); } }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType <string>().Subscribe(x => { var vm = this.CreateViewModel <WebBrowserViewModel>(); vm.Url = x; NavigateTo(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null)); GoToHtmlUrlCommand.Select(_ => PullRequest.HtmlUrl).Subscribe(x => GoToUrlCommand.ExecuteIfCan(x.AbsolutePath)); GoToCommitsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <PullRequestCommitsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.PullRequestId = Id; NavigateTo(vm); }); GoToFilesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <PullRequestFilesViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.PullRequestId = Id; NavigateTo(vm); }); // // ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))) // .WithSubscription(_ => shareService.ShareUrl(PullRequest.HtmlUrl)); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; //vm.Issue = Issue; // vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x); NavigateTo(vm); }); // // GoToLabelsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => // { // var vm = this.CreateViewModel<IssueLabelsViewModel>(); // vm.RepositoryOwner = RepositoryOwner; // vm.RepositoryName = RepositoryName; // vm.Id = Id; // vm.SaveOnSelect = true; //// vm.SelectedLabels.Reset(Issue.Labels); //// vm.WhenAnyValue(x => x.Labels).Skip(1).Subscribe(x => //// { //// Issue.Labels = x.ToList(); //// this.RaisePropertyChanged("Issue"); //// }); // NavigateTo(vm); // }); // GoToMilestoneCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => // { // var vm = this.CreateViewModel<IssueMilestonesViewModel>(); // vm.RepositoryOwner = RepositoryOwner; // vm.RepositoryName = RepositoryName; // vm.IssueId = Id; // vm.SaveOnSelect = true; //// vm.SelectedMilestone = Issue.Milestone; //// vm.WhenAnyValue(x => x.SelectedMilestone).Skip(1).Subscribe(x => //// { //// Issue.Milestone = x; //// this.RaisePropertyChanged("Issue"); //// }); // NavigateTo(vm); // }); // // GoToAssigneeCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => // { // var vm = this.CreateViewModel<IssueAssignedToViewModel>(); // vm.RepositoryOwner = RepositoryOwner; // vm.RepositoryName = RepositoryName; // vm.IssueId = Id; // //vm.SaveOnSelect = true; //// vm.SelectedUser = Issue.Assignee; //// vm.WhenAnyValue(x => x.SelectedUser).Skip(1).Subscribe(x => //// { //// Issue.Assignee = x; //// this.RaisePropertyChanged("Issue"); //// }); // NavigateTo(vm); // }); GoToAddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueCommentViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.SaveCommand.Subscribe(Comments.Add); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(PullRequest.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", GoToAddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); _markdownDescription = this.WhenAnyValue(x => x.PullRequest).IsNotNull() .Select(x => _markdownService.Convert(x.Body)) .ToProperty(this, x => x.MarkdownDescription); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var pullRequest = _applicationService.GitHubClient.PullRequest.Get(RepositoryOwner, RepositoryName, Id); var comments = _applicationService.GitHubClient.PullRequest.Comment.GetAll(RepositoryOwner, RepositoryName, Id); var events = _applicationService.GitHubClient.Issue.Events.GetForIssue(RepositoryOwner, RepositoryName, Id); var issue = _applicationService.GitHubClient.Issue.Get(RepositoryOwner, RepositoryName, Id); await Task.WhenAll(pullRequest, issue, comments, events); PullRequest = pullRequest.Result; Issue = issue.Result; }); }