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

Commit 3ddef24

Browse files
committed
Improvements for PullRequest & IssueView comments
1 parent 9f01897 commit 3ddef24

5 files changed

Lines changed: 145 additions & 223 deletions

File tree

CodeHub.Core/ViewModels/PullRequests/PullRequestViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,29 @@ public PullRequestModel PullRequest
2929

3030
public ICommand GoToCommitsCommand
3131
{
32-
get { return new MvxCommand(() => ShowViewModel<PullRequestCommitsViewModel>(new PullRequestCommitsViewModel.NavObject { Username = User, Repository = Repository, PullRequestId = Id })); }
32+
get { return new MvxCommand(() => ShowViewModel<PullRequestCommitsViewModel>(new PullRequestCommitsViewModel.NavObject { Username = Username, Repository = Repository, PullRequestId = Id })); }
3333
}
3434

3535
public ICommand GoToFilesCommand
3636
{
37-
get { return new MvxCommand(() => ShowViewModel<PullRequestFilesViewModel>(new PullRequestFilesViewModel.NavObject { Username = User, Repository = Repository, PullRequestId = Id })); }
37+
get { return new MvxCommand(() => ShowViewModel<PullRequestFilesViewModel>(new PullRequestFilesViewModel.NavObject { Username = Username, Repository = Repository, PullRequestId = Id })); }
3838
}
3939

4040
protected override Task Load(bool forceDataRefresh)
4141
{
4242
var subTask = base.Load(forceDataRefresh);
43-
var pullRequest = this.GetApplication().Client.Users[User].Repositories[Repository].PullRequests[Id].Get();
43+
var pullRequest = this.GetApplication().Client.Users[Username].Repositories[Repository].PullRequests[Id].Get();
4444
var t1 = this.RequestModel(pullRequest, forceDataRefresh, response => PullRequest = response.Data);
4545
return Task.WhenAll(subTask, t1);
4646
}
4747

4848
public async Task Merge()
4949
{
50-
var response = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[User].Repositories[Repository].PullRequests[Id].Merge());
50+
var response = await this.GetApplication().Client.ExecuteAsync(this.GetApplication().Client.Users[Username].Repositories[Repository].PullRequests[Id].Merge());
5151
if (!response.Data.Merged)
5252
throw new Exception(response.Data.Message);
5353

54-
var pullRequest = this.GetApplication().Client.Users[User].Repositories[Repository].PullRequests[Id].Get();
54+
var pullRequest = this.GetApplication().Client.Users[Username].Repositories[Repository].PullRequests[Id].Get();
5555
await this.RequestModel(pullRequest, true, r => PullRequest = r.Data);
5656
}
5757

CodeHub.iOS/Views/Issues/IssueView.cs

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using CodeFramework.iOS.Views;
33
using CodeHub.Core.ViewModels.Issues;
4-
using GitHubSharp.Models;
54
using MonoTouch.UIKit;
65
using CodeFramework.iOS.ViewControllers;
76
using MonoTouch.Dialog;
@@ -14,10 +13,13 @@ namespace CodeHub.iOS.Views.Issues
1413
{
1514
public class IssueView : ViewModelDrivenDialogViewController
1615
{
17-
private readonly HeaderView _header;
18-
private WebElement _descriptionElement;
19-
private WebElement2 _commentsElement;
20-
16+
protected readonly HeaderView _header;
17+
protected WebElement _descriptionElement;
18+
protected WebElement2 _commentsElement;
19+
protected StyledStringElement _milestoneElement;
20+
protected StyledStringElement _assigneeElement;
21+
protected StyledStringElement _labelsElement;
22+
protected StyledStringElement _addCommentElement;
2123

2224
public new IssueViewModel ViewModel
2325
{
@@ -43,9 +45,39 @@ public override void ViewDidLoad()
4345
_commentsElement = new WebElement2(content2);
4446
_commentsElement.UrlRequested = ViewModel.GoToUrlCommand.Execute;
4547

48+
_milestoneElement = new StyledStringElement("Milestone", "No Milestone", UITableViewCellStyle.Value1) {Image = Images.Milestone, Accessory = UITableViewCellAccessory.DisclosureIndicator};
49+
_milestoneElement.Tapped += () => ViewModel.GoToMilestoneCommand.Execute(null);
50+
51+
_assigneeElement = new StyledStringElement("Assigned", "Unassigned".t(), UITableViewCellStyle.Value1) {Image = Images.Person, Accessory = UITableViewCellAccessory.DisclosureIndicator };
52+
_assigneeElement.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null);
53+
54+
_labelsElement = new StyledStringElement("Labels", "None", UITableViewCellStyle.Value1) {Image = Images.Tag, Accessory = UITableViewCellAccessory.DisclosureIndicator};
55+
_labelsElement.Tapped += () => ViewModel.GoToLabelsCommand.Execute(null);
56+
57+
_addCommentElement = new StyledStringElement("Add Comment") { Image = Images.Pencil };
58+
_addCommentElement.Tapped += AddCommentTapped;
59+
4660
NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Compose, (s, e) => ViewModel.GoToEditCommand.Execute(null));
4761
NavigationItem.RightBarButtonItem.Enabled = false;
48-
ViewModel.Bind(x => x.Issue, RenderIssue);
62+
ViewModel.Bind(x => x.IsLoading, x =>
63+
{
64+
if (!x)
65+
{
66+
NavigationItem.RightBarButtonItem.Enabled = ViewModel.Issue != null;
67+
}
68+
});
69+
70+
ViewModel.Bind(x => x.Issue, x =>
71+
{
72+
_assigneeElement.Value = x.Assignee != null ? x.Assignee.Login : "Unassigned".t();
73+
_milestoneElement.Value = x.Milestone != null ? x.Milestone.Title : "No Milestone";
74+
_labelsElement.Value = x.Labels.Count == 0 ? "None" : string.Join(", ", x.Labels.Select(i => i.Name));
75+
_descriptionElement.Value = ViewModel.MarkdownDescription;
76+
_header.Title = x.Title;
77+
_header.Subtitle = "Updated " + x.UpdatedAt.ToDaysAgo();
78+
Render();
79+
});
80+
4981
ViewModel.BindCollection(x => x.Comments, (e) => RenderComments());
5082
ViewModel.BindCollection(x => x.Events, (e) => RenderComments());
5183
}
@@ -70,16 +102,18 @@ private IEnumerable<CommentModel> CreateCommentList()
70102
AvatarUrl = x.Actor.AvatarUrl,
71103
Login = x.Actor.Login,
72104
CreatedAt = x.CreatedAt,
73-
Body = CreateEventBody(x.Event, x.Actor, x.CommitId)
74-
}));
105+
Body = CreateEventBody(x.Event, x.CommitId)
106+
})
107+
.Where(x => !string.IsNullOrEmpty(x.Body)));
75108

76109
return items.OrderBy(x => x.CreatedAt);
77110
}
78111

79-
private string CreateEventBody(string eventType, BasicUserModel actor, string commitId)
112+
private static string CreateEventBody(string eventType, string commitId)
80113
{
114+
commitId = commitId ?? string.Empty;
81115
var smallCommit = commitId;
82-
if (smallCommit == null)
116+
if (string.IsNullOrEmpty(smallCommit))
83117
smallCommit = "Unknown";
84118
else if (smallCommit.Length > 7)
85119
smallCommit = commitId.Substring(0, 7);
@@ -89,9 +123,9 @@ private string CreateEventBody(string eventType, BasicUserModel actor, string co
89123
if (eventType == "reopened")
90124
return "<p><span class=\"label label-success\">Reopened</span> this issue.</p>";
91125
if (eventType == "merged")
92-
return "<p><span class=\"label label-info\">Merged</span> commit <a>" + commitId + "</a></p>";
126+
return "<p><span class=\"label label-info\">Merged</span> commit " + smallCommit + "</p>";
93127
if (eventType == "referenced")
94-
return "<p><span class=\"label label-default\">Referenced</span> commit <a>" + smallCommit + "</a></p>";
128+
return "<p><span class=\"label label-default\">Referenced</span> commit " + smallCommit + "</p>";
95129
return string.Empty;
96130
}
97131

@@ -109,64 +143,33 @@ public void RenderComments()
109143
InvokeOnMainThread(() => {
110144
_commentsElement.Value = data;
111145
if (_commentsElement.GetImmediateRootElement() == null)
112-
RenderIssue();
146+
Render();
113147
});
114148
}
115149

116-
public void RenderIssue()
150+
protected virtual void Render()
117151
{
118-
if (ViewModel.Issue == null)
119-
return;
120-
121-
NavigationItem.RightBarButtonItem.Enabled = true;
152+
//Wait for the issue to load
153+
if (ViewModel.Issue == null)
154+
return;
122155

123-
var root = new RootElement(Title);
124-
_header.Title = ViewModel.Issue.Title;
125-
_header.Subtitle = "Updated " + ViewModel.Issue.UpdatedAt.ToDaysAgo();
156+
var root = new RootElement(Title);
126157
root.Add(new Section(_header));
127158

128-
129159
var secDetails = new Section();
160+
if (!string.IsNullOrEmpty(_descriptionElement.Value))
161+
secDetails.Add(_descriptionElement);
130162

131-
if (!string.IsNullOrEmpty(ViewModel.Issue.Body))
132-
{
133-
_descriptionElement.Value = ViewModel.MarkdownDescription;
134-
secDetails.Add(_descriptionElement);
135-
}
136-
137-
var milestone = ViewModel.Issue.Milestone;
138-
var milestoneStr = milestone != null ? milestone.Title : "No Milestone";
139-
var milestoneElement = new StyledStringElement("Milestone", milestoneStr, UITableViewCellStyle.Value1) {Image = Images.Milestone, Accessory = UITableViewCellAccessory.DisclosureIndicator};
140-
milestoneElement.Tapped += () => ViewModel.GoToMilestoneCommand.Execute(null);
141-
142-
var assigneeElement = new StyledStringElement("Assigned", ViewModel.Issue.Assignee != null ? ViewModel.Issue.Assignee.Login : "Unassigned".t(), UITableViewCellStyle.Value1) {
143-
Image = Images.Person,
144-
Accessory = UITableViewCellAccessory.DisclosureIndicator
145-
};
146-
assigneeElement.Tapped += () => ViewModel.GoToAssigneeCommand.Execute(null);
147-
148-
149-
var labels = ViewModel.Issue.Labels.Count == 0 ? "None" : string.Join(", ", ViewModel.Issue.Labels.Select(i => i.Name));
150-
var labelsElement = new StyledStringElement("Labels", labels, UITableViewCellStyle.Value1) {
151-
Image = Images.Tag,
152-
Accessory = UITableViewCellAccessory.DisclosureIndicator
153-
};
154-
labelsElement.Tapped += () => ViewModel.GoToLabelsCommand.Execute(null);
155-
156-
secDetails.Add(assigneeElement);
157-
secDetails.Add(milestoneElement);
158-
secDetails.Add(labelsElement);
163+
secDetails.Add(_assigneeElement);
164+
secDetails.Add(_milestoneElement);
165+
secDetails.Add(_labelsElement);
159166
root.Add(secDetails);
160167

161-
if (ViewModel.Comments.Any())
162-
{
168+
if (!string.IsNullOrEmpty(_commentsElement.Value))
163169
root.Add(new Section { _commentsElement });
164-
}
165170

166-
var addComment = new StyledStringElement("Add Comment") { Image = Images.Pencil };
167-
addComment.Tapped += AddCommentTapped;
168-
root.Add(new Section { addComment });
169-
Root = root;
171+
root.Add(new Section { _addCommentElement });
172+
Root = root;
170173
}
171174

172175
void AddCommentTapped()

0 commit comments

Comments
 (0)