11using System ;
22using CodeFramework . iOS . Views ;
33using CodeHub . Core . ViewModels . Issues ;
4- using GitHubSharp . Models ;
54using MonoTouch . UIKit ;
65using CodeFramework . iOS . ViewControllers ;
76using 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