示例#1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var commentsElement = new HtmlElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;

            ViewModel.Comments.Changed
            .Select(_ => new Unit())
            .StartWith(new Unit())
            .Subscribe(x =>
            {
                var comments     = ViewModel.Comments.Select(c => new Comment(c.Avatar.ToUri(), c.Actor, c.Body, c.UtcCreatedAt.Humanize())).ToList();
                var commentModel = new CodeHub.WebViews.CommentModel(comments, (int)UIFont.PreferredSubheadline.PointSize);
                var razorView    = new CommentsView {
                    Model = commentModel
                };
                var html = razorView.GenerateString();
                commentsElement.Value = html;

                if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0)
                {
                    _commentsSection.Add(commentsElement);
                }
                TableView.ReloadData();
            });

            ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().Subscribe(commitModel =>
            {
                var detailSection = new Section();
                Root.Reset(_headerSection, detailSection);

                var user = commitModel.GenerateCommiterName();
                detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message)
                {
                    CaptionColor    = Theme.MainTextColor,
                    ValueColor      = Theme.MainTextColor,
                    BackgroundColor = UIColor.White
                });

                if (ViewModel.ShowRepository)
                {
                    var repo = new StringElement(ViewModel.RepositoryName)
                    {
                        Font      = StringElement.DefaultDetailFont,
                        TextColor = StringElement.DefaultDetailColor,
                        Image     = Octicon.Repo.ToImage()
                    };
                    repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                    detailSection.Add(repo);
                }

                var paths = commitModel.Files.GroupBy(y => {
                    var filename = "/" + y.Filename;
                    return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
                }).OrderBy(y => y.Key);

                foreach (var p in paths)
                {
                    var fileSection = new Section(p.Key);
                    foreach (var x in p)
                    {
                        var y       = x;
                        var file    = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
                        var sse     = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
                        sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                        fileSection.Add(sse);
                    }
                    Root.Add(fileSection);
                }

                Root.Add(_commentsSection);
            });
        }
示例#2
0
        public void Render(CommitModel commitModel)
        {
            var headerSection = new Section(HeaderView)
            {
                _split
            };
            var detailSection = new Section();

            Root.Reset(headerSection, detailSection);

            var user = "******";

            if (commitModel.Commit.Author != null)
            {
                user = commitModel.Commit.Author.Name;
            }
            if (commitModel.Commit.Committer != null)
            {
                user = commitModel.Commit.Committer.Name;
            }

            detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message)
            {
                CaptionColor    = Theme.CurrentTheme.MainTextColor,
                ValueColor      = Theme.CurrentTheme.MainTextColor,
                BackgroundColor = UIColor.White
            });

            if (ViewModel.ShowRepository)
            {
                var repo = new StyledStringElement(ViewModel.RepositoryName)
                {
                    Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = StyledStringElement.DefaultDetailFont,
                    TextColor = StyledStringElement.DefaultDetailColor,
                    Image     = Images.Repo
                };
                repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                detailSection.Add(repo);
            }

            var paths = commitModel.Files.GroupBy(y => {
                var filename = "/" + y.Filename;
                return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
            }).OrderBy(y => y.Key);

            foreach (var p in paths)
            {
                var fileSection = new Section(p.Key);
                foreach (var x in p)
                {
                    var y    = x;
                    var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
                    var sse  = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
                    sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                    fileSection.Add(sse);
                }
                Root.Add(fileSection);
            }

            Root.Add(_commentSection);

            var addComment = new StyledStringElement("Add Comment")
            {
                Image = Images.Pencil
            };

            addComment.Tapped += () => ViewModel.GoToCommentCommand.ExecuteIfCan();
            Root.Add(new Section {
                addComment
            });
        }
示例#3
0
        public void Render()
        {
            if (ViewModel.Commits == null || ViewModel.Commit == null)
            {
                return;
            }

            var titleMsg  = (ViewModel.Commit.Message ?? string.Empty).Split(new [] { '\n' }, 2).FirstOrDefault();
            var avatarUrl = ViewModel.Commit.Author?.User?.Links?.Avatar?.Href;
            var node      = ViewModel.Node.Substring(0, ViewModel.Node.Length > 10 ? 10 : ViewModel.Node.Length);

            Title              = node;
            HeaderView.Text    = titleMsg ?? node;
            HeaderView.SubText = "Commited " + (ViewModel.Commit.Date).Humanize();
            HeaderView.SetImage(new Avatar(avatarUrl).ToUrl(128), Images.Avatar);
            RefreshHeaderView();

            var split = new SplitButtonElement();

            split.AddButton("Comments", ViewModel.Comments.Items.Count.ToString());
            split.AddButton("Participants", ViewModel.Commit.Participants.Count.ToString());
            split.AddButton("Approvals", ViewModel.Commit.Participants.Count(x => x.Approved).ToString());

            var commitModel = ViewModel.Commits;
            var root        = new RootElement(Title)
            {
                UnevenRows = Root.UnevenRows
            };

            root.Add(new Section {
                split
            });

            var detailSection = new Section();

            root.Add(detailSection);

            var user = ViewModel.Commit.Author?.User?.DisplayName ?? ViewModel.Commit.Author.Raw ?? "Unknown";

            detailSection.Add(new MultilinedElement(user, ViewModel.Commit.Message)
            {
                CaptionColor    = Theme.CurrentTheme.MainTextColor,
                ValueColor      = Theme.CurrentTheme.MainTextColor,
                BackgroundColor = UIColor.White
            });

            if (ViewModel.ShowRepository)
            {
                var repo = new StyledStringElement(ViewModel.Repository)
                {
                    Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = StyledStringElement.DefaultDetailFont,
                    TextColor = StyledStringElement.DefaultDetailColor,
                    Image     = AtlassianIcon.Devtoolsrepository.ToImage()
                };
                repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                detailSection.Add(repo);
            }

            if (_viewSegment.SelectedSegment == 0)
            {
                var paths = ViewModel.Commits.GroupBy(y =>
                {
                    var filename = "/" + y.File;
                    return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
                }).OrderBy(y => y.Key);

                foreach (var p in paths)
                {
                    var fileSection = new Section(p.Key);
                    foreach (var x in p)
                    {
                        var y    = x;
                        var file = x.File.Substring(x.File.LastIndexOf('/') + 1);
                        var sse  = new ChangesetElement(file, x.Type, x.Diffstat.Added, x.Diffstat.Removed);
                        sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                        fileSection.Add(sse);
                    }
                    root.Add(fileSection);
                }
            }
            else if (_viewSegment.SelectedSegment == 1)
            {
                var commentSection = new Section();
                foreach (var comment in ViewModel.Comments)
                {
                    var name   = comment.User.DisplayName ?? comment.User.Username;
                    var imgUri = new Avatar(comment.User.Links?.Avatar?.Href);
                    commentSection.Add(new NameTimeStringElement(name, comment.Content.Raw, comment.CreatedOn, imgUri.ToUrl(), Images.Avatar));
                }

                if (commentSection.Elements.Count > 0)
                {
                    root.Add(commentSection);
                }

                var addComment = new StyledStringElement("Add Comment")
                {
                    Image = AtlassianIcon.Addcomment.ToImage()
                };
                addComment.Tapped += AddCommentTapped;
                root.Add(new Section {
                    addComment
                });
            }
            else if (_viewSegment.SelectedSegment == 2)
            {
                var likeSection = new Section();
                likeSection.AddAll(ViewModel.Commit.Participants.Where(x => x.Approved).Select(l => {
                    var el     = new UserElement(l.User.DisplayName, string.Empty, string.Empty, l.User.Links.Avatar.Href);
                    el.Tapped += () => ViewModel.GoToUserCommand.Execute(l.User.Username);
                    return(el);
                }));

                if (likeSection.Elements.Count > 0)
                {
                    root.Add(likeSection);
                }

                StyledStringElement approveButton;
                if (ViewModel.Commit.Participants.Any(x => x.User.Username.Equals(ViewModel.GetApplication().Account.Username) && x.Approved))
                {
                    approveButton = new StyledStringElement("Unapprove")
                    {
                        Image = AtlassianIcon.Approve.ToImage()
                    };
                    approveButton.Tapped += () => this.DoWorkAsync("Unapproving...", ViewModel.Unapprove);
                }
                else
                {
                    approveButton = new StyledStringElement("Approve")
                    {
                        Image = AtlassianIcon.Approve.ToImage()
                    };
                    approveButton.Tapped += () => this.DoWorkAsync("Approving...", ViewModel.Approve);
                }
                root.Add(new Section {
                    approveButton
                });
            }

            Root = root;
        }
示例#4
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var commentsElement = new HtmlElement("comments");

            commentsElement.UrlRequested = ViewModel.GoToUrlCommand.ExecuteIfCan;

            ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().SubscribeSafe(x =>
            {
                HeaderView.ImageUri = x.GenerateGravatarUrl();
                HeaderView.SubText  = "Commited " + x.Commit.Committer.Date.LocalDateTime.Humanize();
                RefreshHeaderView();
            });

            ViewModel.Comments.Changed.Select(_ => new Unit()).StartWith(new Unit()).Subscribe(x =>
            {
                var commentModels = ViewModel.Comments.Select(c =>
                                                              new Comment(c.User.AvatarUrl, c.User.Login, c.Body, c.CreatedAt.UtcDateTime.Humanize()));
                var razorView = new CommentsView {
                    Model = commentModels
                };
                var html = razorView.GenerateString();
                commentsElement.Value = html;

                if (commentsElement.GetRootElement() == null && ViewModel.Comments.Count > 0)
                {
                    _commentSection.Add(commentsElement);
                }
                TableView.ReloadData();
            });

            ViewModel.WhenAnyValue(x => x.Commit).IsNotNull().Subscribe(commitModel =>
            {
                var detailSection = new Section();
                Root.Reset(_headerSection, detailSection);

                var user = commitModel.GenerateCommiterName();
                detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message)
                {
                    CaptionColor    = Theme.MainTextColor,
                    ValueColor      = Theme.MainTextColor,
                    BackgroundColor = UIColor.White
                });

                if (ViewModel.ShowRepository)
                {
                    var repo = new StyledStringElement(ViewModel.RepositoryName)
                    {
                        Accessory = UIKit.UITableViewCellAccessory.DisclosureIndicator,
                        Lines     = 1,
                        Font      = StyledStringElement.DefaultDetailFont,
                        TextColor = StyledStringElement.DefaultDetailColor,
                        Image     = Images.Repo
                    };
                    repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                    detailSection.Add(repo);
                }

                var paths = commitModel.Files.GroupBy(y => {
                    var filename = "/" + y.Filename;
                    return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
                }).OrderBy(y => y.Key);

                foreach (var p in paths)
                {
                    var fileSection = new Section(p.Key);
                    foreach (var x in p)
                    {
                        var y       = x;
                        var file    = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
                        var sse     = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
                        sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                        fileSection.Add(sse);
                    }
                    Root.Add(fileSection);
                }

                Root.Add(_commentSection);

                var addComment = new StyledStringElement("Add Comment")
                {
                    Image = Images.Pencil
                };
                addComment.Tapped += () => ViewModel.GoToCommentCommand.ExecuteIfCan();
                Root.Add(new Section {
                    addComment
                });
            });
        }
示例#5
0
        public void Render()
        {
            if (ViewModel.Commits == null || ViewModel.Changeset == null)
            {
                return;
            }

            var commitModel = ViewModel.Commits;
            var root        = new RootElement(Title)
            {
                UnevenRows = Root.UnevenRows
            };

            _header.Subtitle = "Commited ".t() + (ViewModel.Changeset.Utctimestamp).ToDaysAgo();
            var headerSection = new Section(_header);

            root.Add(headerSection);

            var detailSection = new Section();

            root.Add(detailSection);

            var user = "******";

            if (ViewModel.Changeset.Author != null)
            {
                user = ViewModel.Changeset.Author;
            }

            detailSection.Add(new MultilinedElement(user, ViewModel.Changeset.Message)
            {
                CaptionColor    = Theme.CurrentTheme.MainTextColor,
                ValueColor      = Theme.CurrentTheme.MainTextColor,
                BackgroundColor = UIColor.White
            });

            if (ViewModel.ShowRepository)
            {
                var repo = new StyledStringElement(ViewModel.Repository)
                {
                    Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = StyledStringElement.DefaultDetailFont,
                    TextColor = StyledStringElement.DefaultDetailColor,
                    Image     = Images.Repo
                };
                repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                detailSection.Add(repo);
            }

            if (_viewSegment.SelectedSegment == 0)
            {
                var paths = ViewModel.Commits.GroupBy(y =>
                {
                    var filename = "/" + y.File;
                    return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
                }).OrderBy(y => y.Key);

                foreach (var p in paths)
                {
                    var fileSection = new Section(p.Key);
                    foreach (var x in p)
                    {
                        var y    = x;
                        var file = x.File.Substring(x.File.LastIndexOf('/') + 1);
                        var sse  = new ChangesetElement(file, x.Type, x.Diffstat.Added, x.Diffstat.Removed);
                        sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                        fileSection.Add(sse);
                    }
                    root.Add(fileSection);
                }
            }
            else if (_viewSegment.SelectedSegment == 1)
            {
                var commentSection = new Section();
                foreach (var comment in ViewModel.Comments.Where(x => !x.Deleted && string.IsNullOrEmpty(x.Filename)))
                {
                    commentSection.Add(new CommentElement
                    {
                        Name            = comment.DisplayName,
                        Time            = comment.UtcCreatedOn.ToDaysAgo(),
                        String          = comment.Content,
                        Image           = Images.Anonymous,
                        ImageUri        = new Uri(comment.UserAvatarUrl),
                        BackgroundColor = UIColor.White
                    });
                }

                if (commentSection.Elements.Count > 0)
                {
                    root.Add(commentSection);
                }

                var addComment = new StyledStringElement("Add Comment".t())
                {
                    Image = Images.Pencil
                };
                addComment.Tapped += AddCommentTapped;
                root.Add(new Section {
                    addComment
                });
            }
            else if (_viewSegment.SelectedSegment == 2)
            {
                var likeSection = new Section();
                likeSection.AddAll(ViewModel.Participants.Where(x => x.Approved).Select(l => {
                    var el     = new UserElement(l.Username, string.Empty, string.Empty, l.Avatar);
                    el.Tapped += () => ViewModel.GoToUserCommand.Execute(l.Username);
                    return(el);
                }));

                if (likeSection.Elements.Count > 0)
                {
                    root.Add(likeSection);
                }

                StyledStringElement approveButton;
                if (ViewModel.Participants.Any(x => x.Username.Equals(ViewModel.GetApplication().Account.Username) && x.Approved))
                {
                    approveButton = new StyledStringElement("Unapprove".t())
                    {
                        Image = Images.Cancel
                    };
                    approveButton.Tapped += () => this.DoWorkAsync("Unapproving...", ViewModel.Unapprove);
                }
                else
                {
                    approveButton = new StyledStringElement("Approve".t())
                    {
                        Image = Images.Accept
                    };
                    approveButton.Tapped += () => this.DoWorkAsync("Approving...", ViewModel.Approve);
                }
                root.Add(new Section {
                    approveButton
                });
            }

            Root = root;
        }
示例#6
0
        public void Render()
        {
            var commitModel = ViewModel.Changeset;

            if (commitModel == null)
            {
                return;
            }

            var root = new RootElement(Title)
            {
                UnevenRows = Root.UnevenRows
            };

            _header.Subtitle = "Commited ".t() + (commitModel.Commit.Committer.Date).ToDaysAgo();
            var headerSection = new Section(_header);

            root.Add(headerSection);

            var detailSection = new Section();

            root.Add(detailSection);

            var user = "******";

            if (commitModel.Commit.Author != null)
            {
                user = commitModel.Commit.Author.Name;
            }
            if (commitModel.Commit.Committer != null)
            {
                user = commitModel.Commit.Committer.Name;
            }

            detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message)
            {
                CaptionColor    = Theme.CurrentTheme.MainTextColor,
                ValueColor      = Theme.CurrentTheme.MainTextColor,
                BackgroundColor = UIColor.White
            });

            if (ViewModel.ShowRepository)
            {
                var repo = new StyledStringElement(ViewModel.Repository)
                {
                    Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = StyledStringElement.DefaultDetailFont,
                    TextColor = StyledStringElement.DefaultDetailColor,
                    Image     = Images.Repo
                };
                repo.Tapped += () => ViewModel.GoToRepositoryCommand.Execute(null);
                detailSection.Add(repo);
            }

            var paths = commitModel.Files.GroupBy(y => {
                var filename = "/" + y.Filename;
                return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
            }).OrderBy(y => y.Key);

            foreach (var p in paths)
            {
                var fileSection = new Section(p.Key);
                foreach (var x in p)
                {
                    var y    = x;
                    var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
                    var sse  = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
                    sse.Tapped += () => ViewModel.GoToFileCommand.Execute(y);
                    fileSection.Add(sse);
                }
                root.Add(fileSection);
            }
//
//			var fileSection = new Section();
//            commitModel.Files.ForEach(x => {
//                var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
//                var sse = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
//                sse.Tapped += () => ViewModel.GoToFileCommand.Execute(x);
//                fileSection.Add(sse);
//            });

//            if (fileSection.Elements.Count > 0)
//                root.Add(fileSection);
//

            var commentSection = new Section();

            foreach (var comment in ViewModel.Comments)
            {
                //The path should be empty to indicate it's a comment on the entire commit, not a specific file
                if (!string.IsNullOrEmpty(comment.Path))
                {
                    continue;
                }

                commentSection.Add(new CommentElement {
                    Name            = comment.User.Login,
                    Time            = comment.CreatedAt.ToDaysAgo(),
                    String          = comment.Body,
                    Image           = Images.Anonymous,
                    ImageUri        = new Uri(comment.User.AvatarUrl),
                    BackgroundColor = UIColor.White,
                });
            }

            if (commentSection.Elements.Count > 0)
            {
                root.Add(commentSection);
            }

            var addComment = new StyledStringElement("Add Comment".t())
            {
                Image = Images.Pencil
            };

            addComment.Tapped += AddCommentTapped;
            root.Add(new Section {
                addComment
            });
            Root = root;
        }
        public void Render()
        {
            var commitModel = ViewModel.Changeset;

            if (commitModel == null)
            {
                return;
            }

            var root = new RootElement(Title)
            {
                UnevenRows = Root.UnevenRows
            };

            _header.Subtitle = "Commited ".t() + (commitModel.Commit.Committer.Date).ToDaysAgo();
            var headerSection = new Section(_header);

            root.Add(headerSection);

            var detailSection = new Section();

            root.Add(detailSection);

            var user = "******";

            if (commitModel.Author != null)
            {
                user = commitModel.Author.Login;
            }
            if (commitModel.Commit.Author != null)
            {
                user = commitModel.Commit.Author.Name;
            }

            detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message)
            {
                CaptionColor    = Theme.CurrentTheme.MainTextColor,
                ValueColor      = Theme.CurrentTheme.MainTextColor,
                BackgroundColor = UIColor.White
            });

            if (Repo != null)
            {
                var repo = new StyledStringElement(Repo.Name)
                {
                    Accessory = MonoTouch.UIKit.UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = StyledStringElement.DefaultDetailFont,
                    TextColor = StyledStringElement.DefaultDetailColor,
                    Image     = Images.Repo
                };
                repo.Tapped += () => NavigationController.PushViewController(new RepositoryViewController(Repo.Owner, Repo.Name), true);
                detailSection.Add(repo);
            }

            if (_viewSegment.SelectedSegment == 0)
            {
                var fileSection = new Section();
                commitModel.Files.ForEach(x => {
                    var file    = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
                    var sse     = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
                    sse.Tapped += () => {
                        string parent = null;
                        if (commitModel.Parents != null && commitModel.Parents.Count > 0)
                        {
                            parent = commitModel.Parents[0].Sha;
                        }

                        // This could mean it's a binary or it's just been moved with no changes...
                        if (x.Patch == null)
                        {
                            NavigationController.PushViewController(new RawContentViewController(x.RawUrl, x.BlobUrl), true);
                        }
                        else
                        {
                            NavigationController.PushViewController(new ChangesetDiffViewController(ViewModel.User, ViewModel.Repository, commitModel.Sha, x)
                            {
                                Comments = ViewModel.Comments.Items.ToList()
                            }, true);
                        }
                    };
                    fileSection.Add(sse);
                });

                if (fileSection.Elements.Count > 0)
                {
                    root.Add(fileSection);
                }
            }
            else if (_viewSegment.SelectedSegment == 1)
            {
                var commentSection = new Section();
                foreach (var comment in ViewModel.Comments)
                {
                    //The path should be empty to indicate it's a comment on the entire commit, not a specific file
                    if (!string.IsNullOrEmpty(comment.Path))
                    {
                        continue;
                    }

                    commentSection.Add(new CommentElement {
                        Name            = comment.User.Login,
                        Time            = comment.CreatedAt.ToDaysAgo(),
                        String          = comment.Body,
                        Image           = Images.Anonymous,
                        ImageUri        = new Uri(comment.User.AvatarUrl),
                        BackgroundColor = UIColor.White,
                    });
                }

                if (commentSection.Elements.Count > 0)
                {
                    root.Add(commentSection);
                }

                var addComment = new StyledStringElement("Add Comment".t())
                {
                    Image = Images.Pencil
                };
                addComment.Tapped += AddCommentTapped;
                root.Add(new Section {
                    addComment
                });
            }

            Root = root;
        }
示例#8
0
        public void Render()
        {
            var commitModel = ViewModel.Changeset;

            if (commitModel == null)
            {
                return;
            }

            ICollection <Section> sections = new LinkedList <Section>();

            var additions = ViewModel.Changeset.Stats?.Additions ?? 0;
            var deletions = ViewModel.Changeset.Stats?.Deletions ?? 0;

            var split = new SplitButtonElement();

            split.AddButton("Additions", additions.ToString());
            split.AddButton("Deletions", deletions.ToString());
            split.AddButton("Parents", ViewModel.Changeset.Parents.Count().ToString());

            var headerSection = new Section()
            {
                split
            };

            sections.Add(headerSection);

            var detailSection = new Section();

            sections.Add(detailSection);

            var user = "******";

            if (commitModel.Commit.Author != null)
            {
                user = commitModel.Commit.Author.Name;
            }
            if (commitModel.Commit.Committer != null)
            {
                user = commitModel.Commit.Committer.Name;
            }

            detailSection.Add(new MultilinedElement(user, commitModel.Commit.Message));

            if (ViewModel.ShowRepository)
            {
                var repo = new StringElement(ViewModel.Repository)
                {
                    Accessory = UITableViewCellAccessory.DisclosureIndicator,
                    Lines     = 1,
                    Font      = UIFont.PreferredSubheadline,
                    TextColor = StringElement.DefaultDetailColor,
                    Image     = Octicon.Repo.ToImage()
                };
                repo.Clicked.Subscribe(_ => ViewModel.GoToRepositoryCommand.Execute(null));
                detailSection.Add(repo);
            }

            var paths = commitModel.Files.GroupBy(y => {
                var filename = "/" + y.Filename;
                return(filename.Substring(0, filename.LastIndexOf("/", System.StringComparison.Ordinal) + 1));
            }).OrderBy(y => y.Key);

            foreach (var p in paths)
            {
                var fileSection = new Section(p.Key);
                foreach (var x in p)
                {
                    var y    = x;
                    var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
                    var sse  = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
                    sse.Clicked.Subscribe(_ => ViewModel.GoToFileCommand.Execute(y));
                    fileSection.Add(sse);
                }
                sections.Add(fileSection);
            }
//
//            var fileSection = new Section();
//            commitModel.Files.ForEach(x => {
//                var file = x.Filename.Substring(x.Filename.LastIndexOf('/') + 1);
//                var sse = new ChangesetElement(file, x.Status, x.Additions, x.Deletions);
//                sse.Tapped += () => ViewModel.GoToFileCommand.Execute(x);
//                fileSection.Add(sse);
//            });

//            if (fileSection.Elements.Count > 0)
//                root.Add(fileSection);
//

            var commentSection = new Section();

            foreach (var comment in ViewModel.Comments)
            {
                //The path should be empty to indicate it's a comment on the entire commit, not a specific file
                if (!string.IsNullOrEmpty(comment.Path))
                {
                    continue;
                }

                commentSection.Add(new CommentElement(comment.User.Login, comment.Body, comment.CreatedAt, comment.User.AvatarUrl));
            }

            if (commentSection.Elements.Count > 0)
            {
                sections.Add(commentSection);
            }

            var addComment = new StringElement("Add Comment")
            {
                Image = Octicon.Pencil.ToImage()
            };

            addComment.Clicked.Subscribe(_ => AddCommentTapped());
            sections.Add(new Section {
                addComment
            });
            Root.Reset(sections);
        }