Skip to content
This repository was archived by the owner on Jul 2, 2022. It is now read-only.

Commit 9f01897

Browse files
committed
Working on upgrading pull request view
1 parent 3a50b4d commit 9f01897

7 files changed

Lines changed: 110 additions & 74 deletions

File tree

CodeHub.Core/ViewModels/Issues/IssueViewModel.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,18 @@ public CollectionViewModel<IssueCommentModel> Comments
102102
{
103103
get { return _comments; }
104104
}
105+
106+
private readonly CollectionViewModel<IssueEventModel> _events = new CollectionViewModel<IssueEventModel>();
107+
public CollectionViewModel<IssueEventModel> Events
108+
{
109+
get { return _events; }
110+
}
105111

106112
protected override Task Load(bool forceCacheInvalidation)
107113
{
108-
var t1 = this.RequestModel(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].Get(), forceCacheInvalidation, response => Issue = response.Data);
109-
Comments.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].GetComments(), forceCacheInvalidation).FireAndForget();
114+
var t1 = this.RequestModel(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].Get(), forceCacheInvalidation, response => Issue = response.Data);
115+
Comments.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].GetComments(), forceCacheInvalidation).FireAndForget();
116+
Events.SimpleCollectionLoad(this.GetApplication().Client.Users[Username].Repositories[Repository].Issues[Id].GetEvents(), forceCacheInvalidation).FireAndForget();
110117
return t1;
111118
}
112119

CodeHub.Core/ViewModels/PullRequests/PullRequestViewModel.cs

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,14 @@
22
using System.Threading.Tasks;
33
using System.Windows.Input;
44
using Cirrious.MvvmCross.ViewModels;
5-
using CodeFramework.Core.ViewModels;
65
using GitHubSharp.Models;
76

87
namespace CodeHub.Core.ViewModels.PullRequests
98
{
10-
public class PullRequestViewModel : LoadableViewModel
9+
public class PullRequestViewModel : CodeHub.Core.ViewModels.Issues.IssueViewModel
1110
{
1211
private PullRequestModel _model;
1312
private bool _merged;
14-
private readonly CollectionViewModel<IssueCommentModel> _comments = new CollectionViewModel<IssueCommentModel>();
15-
16-
public string User
17-
{
18-
get;
19-
private set;
20-
}
21-
22-
public string Repo
23-
{
24-
get;
25-
private set;
26-
}
27-
28-
public long PullRequestId
29-
{
30-
get;
31-
private set;
32-
}
3313

3414
public bool Merged
3515
{
@@ -45,53 +25,33 @@ public PullRequestModel PullRequest
4525
_model = value;
4626
RaisePropertyChanged(() => PullRequest);
4727
}
48-
}
49-
50-
public CollectionViewModel<IssueCommentModel> Comments
51-
{
52-
get { return _comments; }
5328
}
5429

5530
public ICommand GoToCommitsCommand
5631
{
57-
get { return new MvxCommand(() => ShowViewModel<PullRequestCommitsViewModel>(new PullRequestCommitsViewModel.NavObject { Username = User, Repository = Repo, PullRequestId = PullRequestId })); }
32+
get { return new MvxCommand(() => ShowViewModel<PullRequestCommitsViewModel>(new PullRequestCommitsViewModel.NavObject { Username = User, Repository = Repository, PullRequestId = Id })); }
5833
}
5934

6035
public ICommand GoToFilesCommand
6136
{
62-
get { return new MvxCommand(() => ShowViewModel<PullRequestFilesViewModel>(new PullRequestFilesViewModel.NavObject { Username = User, Repository = Repo, PullRequestId = PullRequestId })); }
37+
get { return new MvxCommand(() => ShowViewModel<PullRequestFilesViewModel>(new PullRequestFilesViewModel.NavObject { Username = User, Repository = Repository, PullRequestId = Id })); }
6338
}
6439

65-
public void Init(NavObject navObject)
66-
{
67-
User = navObject.Username;
68-
Repo = navObject.Repository;
69-
PullRequestId = navObject.Id;
70-
}
71-
7240
protected override Task Load(bool forceDataRefresh)
73-
{
74-
var pullRequest = this.GetApplication().Client.Users[User].Repositories[Repo].PullRequests[PullRequestId].Get();
75-
var commentsRequest = this.GetApplication().Client.Users[User].Repositories[Repo].Issues[PullRequestId].GetComments();
76-
41+
{
42+
var subTask = base.Load(forceDataRefresh);
43+
var pullRequest = this.GetApplication().Client.Users[User].Repositories[Repository].PullRequests[Id].Get();
7744
var t1 = this.RequestModel(pullRequest, forceDataRefresh, response => PullRequest = response.Data);
78-
Comments.SimpleCollectionLoad(commentsRequest, forceDataRefresh).FireAndForget();
79-
return t1;
80-
}
81-
82-
public async Task AddComment(string text)
83-
{
84-
var comment = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[User].Repositories[Repo].Issues[PullRequestId].CreateComment(text));
85-
Comments.Items.Add(comment.Data);
45+
return Task.WhenAll(subTask, t1);
8646
}
8747

8848
public async Task Merge()
8949
{
90-
var response = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[User].Repositories[Repo].PullRequests[PullRequestId].Merge());
50+
var response = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[User].Repositories[Repository].PullRequests[Id].Merge());
9151
if (!response.Data.Merged)
9252
throw new Exception(response.Data.Message);
9353

94-
var pullRequest = this.GetApplication().Client.Users[User].Repositories[Repo].PullRequests[PullRequestId].Get();
54+
var pullRequest = this.GetApplication().Client.Users[User].Repositories[Repository].PullRequests[Id].Get();
9555
await this.RequestModel(pullRequest, true, r => PullRequest = r.Data);
9656
}
9757

@@ -107,11 +67,8 @@ private bool CanMerge()
10767
return (PullRequest.Merged != null && PullRequest.Merged.Value == false && (PullRequest.Mergable == null || PullRequest.Mergable.Value));
10868
}
10969

110-
public class NavObject
70+
public class NavObject : CodeHub.Core.ViewModels.Issues.IssueViewModel.NavObject
11171
{
112-
public string Username { get; set; }
113-
public string Repository { get; set; }
114-
public long Id { get; set; }
11572
}
11673
}
11774
}

CodeHub.iOS/CodeHub.iOS.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
<WarningLevel>4</WarningLevel>
106106
<ConsolePause>False</ConsolePause>
107107
<CodesignKey>iPhone Distribution</CodesignKey>
108-
<CodesignProvision>F7DD164D-5C4E-4322-AF9C-CF33ACD388D4</CodesignProvision>
108+
<CodesignProvision>Automatic:AppStore</CodesignProvision>
109109
<MtouchUseLlvm>true</MtouchUseLlvm>
110110
<MtouchUseThumb>true</MtouchUseThumb>
111111
<IpaPackageName>

CodeHub.iOS/Views/Issues/IssueView.cs

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using CodeFramework.iOS.Utils;
99
using CodeFramework.iOS.Elements;
1010
using System.Linq;
11+
using System.Collections.Generic;
1112

1213
namespace CodeHub.iOS.Views.Issues
1314
{
@@ -27,7 +28,7 @@ public class IssueView : ViewModelDrivenDialogViewController
2728
public IssueView()
2829
{
2930
Root.UnevenRows = true;
30-
_header = new HeaderView() { ShadowImage = false };
31+
_header = new HeaderView();
3132
}
3233

3334
public override void ViewDidLoad()
@@ -46,6 +47,7 @@ public override void ViewDidLoad()
4647
NavigationItem.RightBarButtonItem.Enabled = false;
4748
ViewModel.Bind(x => x.Issue, RenderIssue);
4849
ViewModel.BindCollection(x => x.Comments, (e) => RenderComments());
50+
ViewModel.BindCollection(x => x.Events, (e) => RenderComments());
4951
}
5052

5153
public override void ViewWillAppear(bool animated)
@@ -54,17 +56,56 @@ public override void ViewWillAppear(bool animated)
5456
Title = "Issue #" + ViewModel.Id;
5557
}
5658

59+
private IEnumerable<CommentModel> CreateCommentList()
60+
{
61+
var items = ViewModel.Comments.Select(x => new CommentModel
62+
{
63+
AvatarUrl = x.User.AvatarUrl,
64+
Login = x.User.Login,
65+
CreatedAt = x.CreatedAt,
66+
Body = ViewModel.ConvertToMarkdown(x.Body)
67+
})
68+
.Concat(ViewModel.Events.Select(x => new CommentModel
69+
{
70+
AvatarUrl = x.Actor.AvatarUrl,
71+
Login = x.Actor.Login,
72+
CreatedAt = x.CreatedAt,
73+
Body = CreateEventBody(x.Event, x.Actor, x.CommitId)
74+
}));
75+
76+
return items.OrderBy(x => x.CreatedAt);
77+
}
78+
79+
private string CreateEventBody(string eventType, BasicUserModel actor, string commitId)
80+
{
81+
var smallCommit = commitId;
82+
if (smallCommit == null)
83+
smallCommit = "Unknown";
84+
else if (smallCommit.Length > 7)
85+
smallCommit = commitId.Substring(0, 7);
86+
87+
if (eventType == "closed")
88+
return "<p><span class=\"label label-danger\">Closed</span> this issue.</p>";
89+
if (eventType == "reopened")
90+
return "<p><span class=\"label label-success\">Reopened</span> this issue.</p>";
91+
if (eventType == "merged")
92+
return "<p><span class=\"label label-info\">Merged</span> commit <a>" + commitId + "</a></p>";
93+
if (eventType == "referenced")
94+
return "<p><span class=\"label label-default\">Referenced</span> commit <a>" + smallCommit + "</a></p>";
95+
return string.Empty;
96+
}
97+
5798
public void RenderComments()
5899
{
59-
var comments = ViewModel.Comments.Select(x => new {
60-
avatarUrl = x.User.AvatarUrl,
61-
login = x.User.Login,
62-
updated_at = x.CreatedAt.ToDaysAgo(),
63-
body = ViewModel.ConvertToMarkdown(x.Body)
64-
});
65-
66-
var s = Cirrious.CrossCore.Mvx.Resolve<CodeFramework.Core.Services.IJsonSerializationService>();
67-
var data = s.Serialize(comments);
100+
var s = Cirrious.CrossCore.Mvx.Resolve<CodeFramework.Core.Services.IJsonSerializationService>();
101+
102+
var data = s.Serialize(CreateCommentList().Select(x => new {
103+
avatarUrl = x.AvatarUrl,
104+
login = x.Login,
105+
created_at = x.CreatedAt.ToDaysAgo(),
106+
body = x.Body
107+
}));
108+
68109
InvokeOnMainThread(() => {
69110
_commentsElement.Value = data;
70111
if (_commentsElement.GetImmediateRootElement() == null)
@@ -156,6 +197,14 @@ public override UIView InputAccessoryView
156197
return u;
157198
}
158199
}
200+
201+
private class CommentModel
202+
{
203+
public string AvatarUrl { get; set; }
204+
public string Login { get; set; }
205+
public DateTimeOffset CreatedAt { get; set; }
206+
public string Body { get; set; }
207+
}
159208
}
160209
}
161210

CodeHub.iOS/Views/PullRequests/PullRequestView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class PullRequestView : ViewModelDrivenDialogViewController
2424
public PullRequestView()
2525
{
2626
Root.UnevenRows = true;
27-
_header = new HeaderView() { ShadowImage = false };
27+
_header = new HeaderView();
2828
_split1 = new SplitElement(new SplitElement.Row { Image1 = Images.Cog, Image2 = Images.Merge });
2929
_split2 = new SplitElement(new SplitElement.Row { Image1 = Images.Person, Image2 = Images.Create });
3030
}

CodeHub.iOS/WebCell/comments.html

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
while (temp.firstChild) { frag.appendChild(temp.firstChild); } return frag;
77
}
88
function addComment(data) {
9-
var html = "<div class='comment'><img src='" + data.avatar_url + "'><div><h1>" + data.login + "</h1><span>" + data.updated_at + "</span><div class='mark'>" + data.body + "</div></div></div>";
9+
var html = "<div class='comment'><img src='" + data.avatar_url + "'><div><h1>" + data.login + "</h1><span>" + data.created_at + "</span><div class='mark'>" + data.body + "</div></div></div>";
1010
document.getElementById('main').appendChild(create(html));
1111
}
1212
function size() { return document.getElementById('main').scrollHeight + 0; }
@@ -33,8 +33,7 @@
3333

3434
.comment {
3535
border-top: 1px solid #c8c8c8;
36-
box-sizing: border-box;
37-
padding: 8px 6px;
36+
padding: 8px 6px 2px;
3837
}
3938

4039
.comment > img{
@@ -48,7 +47,6 @@
4847
padding-left: 40px;
4948
box-sizing: border-box;
5049
width: 100%;
51-
overflow-x:hidden;
5250
}
5351

5452
.comment > div > h1 {
@@ -61,14 +59,14 @@
6159

6260
.comment > div > span {
6361
font-size: 10px;
64-
margin: 0px 0 0px 0;
62+
margin: 0;
6563
color: #404040;
6664
white-space: nowrap;
6765
overflow: hidden;
6866
}
6967

7068
.comment > div > div {
71-
margin: 10px 0 0px 0;
69+
margin: 0;
7270
word-wrap: break-word;
7371
}
7472

@@ -147,4 +145,29 @@
147145
font-size: 1.6em;
148146
border-bottom: 1px solid #ddd;
149147
}
148+
149+
.mark .label {
150+
display: inline;
151+
padding: .2em .6em .2em;
152+
font-size: 85%;
153+
font-weight: 700;
154+
line-height: 1;
155+
color: #fff;
156+
text-align: center;
157+
white-space: nowrap;
158+
vertical-align: baseline;
159+
border-radius: .25em;
160+
}
161+
.label-danger {
162+
background-color: #d9534f;
163+
}
164+
.label-success {
165+
background-color: #5cb85c;
166+
}
167+
.label-info {
168+
background-color: #6e5494;
169+
}
170+
.label-default {
171+
background-color: #999;
172+
}
150173
</style></head><body><div id="main"></div></body></html>

0 commit comments

Comments
 (0)