@@ -65,11 +65,12 @@ public ReviewPageModel(
6565 public string DiffRevisionId { get ; set ; }
6666 // Flag to decide whether to include documentation
6767 [ BindProperty ( Name = "doc" , SupportsGet = true ) ]
68- public bool ShowDocumentation { get ; set ; }
68+ public bool ? ShowDocumentation { get ; set ; }
6969 [ BindProperty ( Name = "diffOnly" , SupportsGet = true ) ]
7070 public bool ShowDiffOnly { get ; set ; }
7171 [ BindProperty ( Name = "notificationMessage" , SupportsGet = true ) ]
7272 public string NotificationMessage { get ; set ; }
73+ public UserPreferenceModel UserPreference { get ; set ; }
7374
7475 /// <summary>
7576 /// Handler for loading page
@@ -87,7 +88,7 @@ public async Task<IActionResult> OnGetAsync(string id, string revisionId = null)
8788 reviewManager : _reviewManager , preferenceCache : _preferenceCache , userProfileRepository : _userProfileRepository ,
8889 reviewRevisionsManager : _apiRevisionsManager , commentManager : _commentsManager , codeFileRepository : _codeFileRepository ,
8990 signalRHubContext : _signalRHubContext , user : User , reviewId : id , revisionId : revisionId , diffRevisionId : DiffRevisionId ,
90- showDocumentation : ShowDocumentation , showDiffOnly : ShowDiffOnly , diffContextSize : REVIEW_DIFF_CONTEXT_SIZE ,
91+ showDocumentation : ( ShowDocumentation ?? false ) , showDiffOnly : ShowDiffOnly , diffContextSize : REVIEW_DIFF_CONTEXT_SIZE ,
9192 diffContextSeperator : DIFF_CONTEXT_SEPERATOR ) ;
9293
9394 if ( ReviewContent . Directive == ReviewContentModelDirective . TryGetlegacyReview )
@@ -167,78 +168,11 @@ public async Task<PartialViewResult> OnGetCodeLineSectionAsync(
167168 sectionKeyA : sectionKeyA , sectionKeyB : sectionKeyB
168169 ) ;
169170
170- var userPrefernce = await _preferenceCache . GetUserPreferences ( User ) ?? new UserPreferenceModel ( ) ;
171-
172171 TempData [ "CodeLineSection" ] = codeLines ;
173- TempData [ "UserPreference" ] = userPrefernce ;
172+ TempData [ "UserPreference" ] = UserPreference ;
174173 return Partial ( "_CodeLinePartial" , sectionKey ) ;
175174 }
176175
177- /// <summary>
178- /// Get Revisions Partial
179- /// </summary>
180- /// <param name="reviewId"></param>
181- /// <param name="apiRevisionType"></param>
182- /// <param name="showDoc"></param>
183- /// <param name="showDiffOnly"></param>
184- /// <returns></returns>
185- public async Task < PartialViewResult > OnGetAPIRevisionsPartialAsync ( string reviewId , APIRevisionType apiRevisionType , bool showDoc = false , bool showDiffOnly = false )
186- {
187- var revisions = await _apiRevisionsManager . GetAPIRevisionsAsync ( reviewId ) ;
188- revisions = revisions . Where ( r => r . APIRevisionType == apiRevisionType ) . OrderByDescending ( c => c . CreatedOn ) . ToList ( ) ;
189- ( IEnumerable < APIRevisionListItemModel > revisions , APIRevisionListItemModel activeRevision , APIRevisionListItemModel diffRevision , bool forDiff , bool showDocumentation , bool showDiffOnly ) revisionSelectModel = (
190- revisions : revisions ,
191- activeRevision : default ( APIRevisionListItemModel ) ,
192- diffRevision : default ( APIRevisionListItemModel ) ,
193- forDiff : false ,
194- showDocumentation : showDoc ,
195- showDiffOnly : showDiffOnly
196- ) ;
197- return Partial ( "_RevisionSelectPickerPartial" , revisionSelectModel ) ;
198- }
199-
200- /// <summary>
201- /// Get Diff Revisions Partial
202- /// </summary>
203- /// <param name="reviewId"></param>
204- /// <param name="apiRevisionId"></param>
205- /// <param name="apiRevisionType"></param>
206- /// <param name="showDoc"></param>
207- /// <param name="showDiffOnly"></param>
208- /// <returns></returns>
209- public async Task < PartialViewResult > OnGetAPIDiffRevisionsPartialAsync ( string reviewId , string apiRevisionId , APIRevisionType apiRevisionType , bool showDoc = false , bool showDiffOnly = false )
210- {
211- var apiRevisions = await _apiRevisionsManager . GetAPIRevisionsAsync ( reviewId ) ;
212- if ( apiRevisions . IsNullOrEmpty ( ) )
213- {
214- var notifcation = new NotificationModel ( ) { Message = $ "This review has no valid apiRevisons", Level = NotificatonLevel . Warning } ;
215- await _signalRHubContext . Clients . Group ( User . GetGitHubLogin ( ) ) . SendAsync ( "RecieveNotification" , notifcation ) ;
216- }
217-
218- APIRevisionListItemModel activeRevision = default ( APIRevisionListItemModel ) ;
219-
220- if ( ! Guid . TryParse ( apiRevisionId , out _ ) )
221- {
222- activeRevision = await _apiRevisionsManager . GetLatestAPIRevisionsAsync ( reviewId , apiRevisions ) ;
223- }
224- else
225- {
226- activeRevision = apiRevisions . FirstOrDefault ( r => r . Id == apiRevisionId ) ;
227- }
228-
229- var revisionsForDiff = apiRevisions . Where ( r => r . APIRevisionType == apiRevisionType && r . Id != activeRevision . Id ) . OrderByDescending ( c => c . CreatedOn ) . ToList ( ) ;
230-
231- ( IEnumerable < APIRevisionListItemModel > revisions , APIRevisionListItemModel activeRevision , APIRevisionListItemModel diffRevision , bool forDiff , bool showDocumentation , bool showDiffOnly ) revisionSelectModel = (
232- revisions : revisionsForDiff ,
233- activeRevision : activeRevision ,
234- diffRevision : default ( APIRevisionListItemModel ) ,
235- forDiff : true ,
236- showDocumentation : showDoc ,
237- showDiffOnly : showDiffOnly
238- ) ;
239- return Partial ( "_RevisionSelectPickerPartial" , revisionSelectModel ) ;
240- }
241-
242176 /// <summary>
243177 /// Toggle Review State
244178 /// </summary>
@@ -374,9 +308,21 @@ public async Task<IEnumerable<PullRequestModel>> GetPRsOfAssoicatedReviews()
374308 /// <returns></returns>
375309 private async Task GetReviewPageModelPropertiesAsync ( string id , string revisionId = null , string diffRevisionId = null , bool diffOnly = false )
376310 {
311+ UserPreference = await _preferenceCache . GetUserPreferences ( User ) ?? new UserPreferenceModel ( ) ;
377312 Comments = await _commentsManager . GetReviewCommentsAsync ( id ) ;
378313 DiffRevisionId = ( DiffRevisionId == null ) ? diffRevisionId : DiffRevisionId ;
379314 ShowDiffOnly = ( ShowDiffOnly == false ) ? diffOnly : ShowDiffOnly ;
315+
316+ if ( ShowDocumentation . HasValue )
317+ {
318+ UserPreference . ShowDocumentation = ShowDocumentation . Value ;
319+ _preferenceCache . UpdateUserPreference ( UserPreference , User ) ;
320+ }
321+ else
322+ {
323+ ShowDocumentation = UserPreference . ShowDocumentation ;
324+ }
325+
380326 }
381327 }
382328}
0 commit comments