protected BaseEventsViewModel(IApplicationService applicationService) { ApplicationService = applicationService; 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 = CreateViewModel<RepositoryViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; ShowViewModel(vm); }); GoToGistCommand = ReactiveCommand.Create(); GoToGistCommand.OfType<EventModel.GistEvent>().Subscribe(x => { var vm = CreateViewModel<GistViewModel>(); vm.Id = x.Gist.Id; vm.Gist = x.Gist; ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => this.RequestModel(CreateRequest(0, 100), t as bool?, response => { //this.CreateMore(response, m => { }, events.AddRange); events.Reset(response.Data); })); }
private void GoToRepository(EventModel.RepoModel repo) { var repoId = new RepositoryIdentifier(repo.Name); var vm = this.CreateViewModel<RepositoryViewModel>(); vm.Init(repoId.Owner, repoId.Name); NavigateTo(vm); }
private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = new RepositoryIdentifier(repoModel.Name); var vm = CreateViewModel<ChangesetsViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.Branch = branch; ShowViewModel(vm); }
internal IssueItemViewModel(Issue issue) { var isPullRequest = issue.PullRequest != null && issue.PullRequest.HtmlUrl != null; var s1 = issue.Url.AbsolutePath.Substring(issue.Url.AbsolutePath.IndexOf("/repos/", StringComparison.Ordinal) + 7); var repoId = new RepositoryIdentifier(s1.Substring(0, s1.IndexOf("/issues", StringComparison.Ordinal))); RepositoryFullName = repoId.Owner + "/" + repoId.Name; RepositoryName = repoId.Name; RepositoryOwner = repoId.Owner; IsPullRequest = isPullRequest; Title = issue.Title; Number = issue.Number; State = issue.State.ToString(); Comments = issue.Comments; Assignee = issue.Assignee != null ? issue.Assignee.Login : "******"; UpdatedAt = issue.UpdatedAt ?? DateTimeOffset.Now; GoToCommand = ReactiveCommand.Create(); }
internal IssueItemViewModel(IssueModel issue) { var isPullRequest = issue.PullRequest != null && !(string.IsNullOrEmpty(issue.PullRequest.HtmlUrl)); var s1 = issue.Url.Substring(issue.Url.IndexOf("/repos/", StringComparison.Ordinal) + 7); var repoId = new RepositoryIdentifier(s1.Substring(0, s1.IndexOf("/issues", StringComparison.Ordinal))); RepositoryFullName = repoId.Owner + "/" + repoId.Name; RepositoryName = repoId.Name; RepositoryOwner = repoId.Owner; IsPullRequest = isPullRequest; Title = issue.Title; Number = (int)issue.Number; State = issue.State; Comments = issue.Comments; Assignee = issue.Assignee != null ? issue.Assignee.Login : "******"; UpdatedAt = issue.UpdatedAt; GoToCommand = ReactiveCommand.Create(); }
public PushNotificationAction Handle(PushNotificationRequest command) { try { var data = command.Attributes; var username = data["u"]; var repoId = new RepositoryIdentifier(data["r"]); BaseViewModel baseViewModel; if (data.ContainsKey("c")) { baseViewModel = _serviceConstructor .Construct<CommitViewModel>() .Init(repoId.Owner, repoId.Name, data["c"]); } else if (data.ContainsKey("i")) { baseViewModel = _serviceConstructor .Construct<CodeHub.Core.ViewModels.Issues.IssueViewModel>() .Init(repoId.Owner, repoId.Name, int.Parse(data["i"])); } else if (data.ContainsKey("p")) { baseViewModel = _serviceConstructor .Construct<CodeHub.Core.ViewModels.PullRequests.PullRequestViewModel>() .Init(repoId.Owner, repoId.Name, int.Parse(data["p"])); } else { baseViewModel = _serviceConstructor .Construct<CodeHub.Core.ViewModels.Repositories.RepositoryViewModel>() .Init(repoId.Owner, repoId.Name); } return new PushNotificationAction(username, baseViewModel); } catch (Exception e) { this.Log().ErrorException("Unable to handle push notification", e); return null; } }
private void GoToBranches(RepositoryIdentifier repoId) { var vm = this.CreateViewModel<BranchesAndTagsViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.SelectedFilter = BranchesAndTagsViewModel.ShowIndex.Branches; NavigateTo(vm); }
private void GoToCommits(EventModel.RepoModel repoModel, string branch) { var repoId = new RepositoryIdentifier(repoModel.Name); var vm = this.CreateViewModel<CommitsViewModel>(); NavigateTo(vm.Init(repoId.Owner, repoId.Name, branch)); }
private void GoToChangeset(RepositoryIdentifier repo, string sha) { if (repo == null || string.IsNullOrEmpty(repo.Name) || string.IsNullOrEmpty(repo.Owner)) return; var vm = this.CreateViewModel<CommitViewModel>(); vm.RepositoryOwner = repo.Owner; vm.RepositoryName = repo.Name; vm.Node = sha; NavigateTo(vm); }
private void GoToPullRequests(RepositoryIdentifier repo) { if (repo == null || string.IsNullOrEmpty(repo.Name) || string.IsNullOrEmpty(repo.Owner)) return; var vm = this.CreateViewModel<PullRequestsViewModel>(); vm.RepositoryOwner = repo.Owner; vm.RepositoryName = repo.Name; NavigateTo(vm); }
private void GoToPullRequest(RepositoryIdentifier repo, int id) { if (repo == null || string.IsNullOrEmpty(repo.Name) || string.IsNullOrEmpty(repo.Owner)) return; var vm = this.CreateViewModel<PullRequestViewModel>(); vm.Init(repo.Owner, repo.Name, id); NavigateTo(vm); }
private void GoToPullRequest(RepositoryIdentifier repo, long id) { if (repo == null || string.IsNullOrEmpty(repo.Name) || string.IsNullOrEmpty(repo.Owner)) return; var vm = CreateViewModel<PullRequestViewModel>(); vm.RepositoryOwner = repo.Owner; vm.RepositoryName = repo.Name; vm.PullRequestId = id; ShowViewModel(vm); }
private void GoToTags(EventModel.RepoModel eventModel) { var repoId = new RepositoryIdentifier(eventModel.Name); var vm = this.CreateViewModel<BranchesAndTagsViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.SelectedFilter = BranchesAndTagsViewModel.ShowIndex.Tags; NavigateTo(vm); }
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()); }
private SourceItemViewModel CreateSourceItemViewModel(ContentModel content) { return new SourceItemViewModel(content.Name, GetSourceItemType(content), x => { switch (x.Type) { case SourceItemType.File: { var vm = this.CreateViewModel<SourceViewModel>(); vm.Branch = Branch; vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.TrueBranch = TrueBranch; vm.Name = content.Name; vm.HtmlUrl = content.HtmlUrl; vm.Path = content.Path; vm.PushAccess = PushAccess; NavigateTo(vm); break; } case SourceItemType.Directory: { var vm = this.CreateViewModel<SourceTreeViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.Branch = Branch; vm.RepositoryName = RepositoryName; vm.TrueBranch = TrueBranch; vm.Path = content.Path; vm.PushAccess = PushAccess; NavigateTo(vm); break; } case SourceItemType.Submodule: { var nameAndSlug = content.GitUrl.Substring(content.GitUrl.IndexOf("/repos/", StringComparison.OrdinalIgnoreCase) + 7); var repoId = new RepositoryIdentifier(nameAndSlug.Substring(0, nameAndSlug.IndexOf("/git", StringComparison.OrdinalIgnoreCase))); var vm = this.CreateViewModel<SourceTreeViewModel>(); vm.RepositoryOwner = repoId.Owner; vm.RepositoryName = repoId.Name; vm.Branch = content.Sha; NavigateTo(vm); break; } } }); }
private void GoToIssue(RepositoryIdentifier repo, long id) { if (repo == null || string.IsNullOrEmpty(repo.Name) || string.IsNullOrEmpty(repo.Owner)) return; var vm = this.CreateViewModel<IssueViewModel>(); vm.Init(repo.Owner, repo.Name, (int)id); NavigateTo(vm); }
public SourceTreeViewModel(IApplicationService applicationService) { //Filter = applicationService.Account.Filters.GetFilter<SourceFilterModel>("SourceViewModel"); var content = new ReactiveList<ContentModel>(); Content = content.CreateDerivedCollection(x => x); GoToSubmoduleCommand = ReactiveCommand.Create(); 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 = ReactiveCommand.Create(); 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 vm = CreateViewModel<SourceViewModel>(); vm.Branch = Branch; vm.Username = Username; vm.Repository = Repository; vm.TrueBranch = TrueBranch; vm.Items = otherFiles; vm.CurrentItemIndex = Array.FindIndex(otherFiles, f => string.Equals(f.GitUrl, x.GitUrl, StringComparison.OrdinalIgnoreCase)); ShowViewModel(vm); }); GoToSourceTreeCommand = ReactiveCommand.Create(); 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 = ReactiveCommand.CreateAsyncTask(t => content.SimpleCollectionLoad( applicationService.Client.Users[Username].Repositories[Repository].GetContent( Path ?? string.Empty, Branch ?? "master"), t as bool?)); }
private void GoToIssue(RepositoryIdentifier repo, long id) { if (repo == null || string.IsNullOrEmpty(repo.Name) || string.IsNullOrEmpty(repo.Owner)) return; var vm = CreateViewModel<IssueViewModel>(); vm.RepositoryOwner = repo.Owner; vm.RepositoryName = repo.Name; vm.IssueId = id; }