@@ -11,6 +11,7 @@ namespace LearningHub.Nhs.WebUI.Controllers
1111 using LearningHub . Nhs . Models . Content ;
1212 using LearningHub . Nhs . Models . Enums . Content ;
1313 using LearningHub . Nhs . Models . Extensions ;
14+ using LearningHub . Nhs . Models . Moodle . API ;
1415 using LearningHub . Nhs . WebUI . Configuration ;
1516 using LearningHub . Nhs . WebUI . Filters ;
1617 using LearningHub . Nhs . WebUI . Helpers ;
@@ -202,39 +203,31 @@ public IActionResult HomepageWithAuthentication()
202203 /// <summary>
203204 /// Index.
204205 /// </summary>
206+ /// <param name="dashboardTrayLearningResourceType">The resource type.</param>
205207 /// <param name="myLearningDashboard">The my learning dashboard type.</param>
206208 /// <param name="resourceDashboard">The resource dashboard type.</param>
207209 /// <param name="catalogueDashboard">The catalogue dashboard type.</param>
208210 /// <returns>Home page.</returns>
209- public async Task < IActionResult > Index ( string myLearningDashboard = "my-in-progress" , string resourceDashboard = "popular-resources " , string catalogueDashboard = "popular-catalogues" )
211+ public async Task < IActionResult > Index ( string dashboardTrayLearningResourceType = "all" , string myLearningDashboard = "my-in-progress" , string resourceDashboard = "my-recent-completed " , string catalogueDashboard = "popular-catalogues" )
210212 {
211213 if ( this . User ? . Identity . IsAuthenticated == true )
212214 {
213215 this . Logger . LogInformation ( "User is authenticated: User is {fullname} and userId is: {lhuserid}" , this . User . Identity . GetCurrentName ( ) , this . User . Identity . GetCurrentUserId ( ) ) ;
214216 if ( this . User . IsInRole ( "Administrator" ) || this . User . IsInRole ( "BlueUser" ) || this . User . IsInRole ( "ReadOnly" ) || this . User . IsInRole ( "BasicUser" ) )
215217 {
216- var learningTask = this . dashboardService . GetMyAccessLearningsAsync ( myLearningDashboard , 1 ) ;
218+ var learningTask = this . dashboardService . GetMyCoursesAndElearning ( dashboardTrayLearningResourceType , myLearningDashboard , 1 ) ;
217219 var resourcesTask = this . dashboardService . GetResourcesAsync ( resourceDashboard , 1 ) ;
218220 var cataloguesTask = this . dashboardService . GetCataloguesAsync ( catalogueDashboard , 1 ) ;
219221 var userGroupsTask = this . userGroupService . UserHasCatalogueContributionPermission ( ) ;
220222
221- var enrolledCoursesTask = Task . FromResult ( new List < MoodleCourseResponseViewModel > ( ) ) ;
222- var enableMoodle = Task . Run ( ( ) => this . featureManager . IsEnabledAsync ( FeatureFlags . EnableMoodle ) ) . Result ;
223- this . ViewBag . EnableMoodle = enableMoodle ;
224- this . ViewBag . ValidMoodleUser = this . CurrentMoodleUserId > 0 ;
225- if ( enableMoodle && myLearningDashboard == "my-enrolled-courses" )
226- {
227- enrolledCoursesTask = this . dashboardService . GetEnrolledCoursesFromMoodleAsync ( this . CurrentMoodleUserId , 1 ) ;
228- }
229-
230223 await Task . WhenAll ( learningTask , resourcesTask , cataloguesTask , userGroupsTask ) ;
231224
232225 var model = new DashboardViewModel ( )
233226 {
234227 MyLearnings = await learningTask ,
235228 Resources = await resourcesTask ,
236229 Catalogues = await cataloguesTask ,
237- EnrolledCourses = await enrolledCoursesTask ,
230+ DashboardTrayLearningResourceType = dashboardTrayLearningResourceType ,
238231 } ;
239232 var userHasContributePermission = await userGroupsTask ;
240233 this . ViewBag . userHasContributePermission = userHasContributePermission ;
@@ -261,15 +254,16 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
261254 /// <summary>
262255 /// Load the specified dashobard page.
263256 /// </summary>
257+ /// <param name="dashboardTrayLearningResourceType">dashboardTrayLearningResourceType.</param>
264258 /// <param name="dashBoardTray">dashBoardTray.</param>
265259 /// <param name="myLearningDashBoard">myLearningDashBoard.</param>
266260 /// <param name="resourceDashBoard">resourceDashBoard.</param>
267261 /// <param name="catalogueDashBoard">catalogueDashBoard.</param>
268262 /// <param name="pageNumber">pageNumber.</param>
269263 /// <returns>Dashboard page.</returns>
270264 [ Authorize ]
271- [ Route ( "/Home/loadpage/{dashBoardTray}/{myLearningDashBoard}/{resourceDashBoard}/{catalogueDashBoard}/{pageNumber:int}" ) ]
272- public async Task < IActionResult > LoadPage ( string dashBoardTray = "my-learning" , string myLearningDashBoard = "in-progress" , string resourceDashBoard = "popular-resources" , string catalogueDashBoard = "recent-catalogues" , int pageNumber = 1 )
265+ [ Route ( "/Home/loadpage/{dashboardTrayLearningResourceType}/{ dashBoardTray}/{myLearningDashBoard}/{resourceDashBoard}/{catalogueDashBoard}/{pageNumber:int}" ) ]
266+ public async Task < IActionResult > LoadPage ( string dashboardTrayLearningResourceType = "all" , string dashBoardTray = "my-learning" , string myLearningDashBoard = "in-progress" , string resourceDashBoard = "popular-resources" , string catalogueDashBoard = "recent-catalogues" , int pageNumber = 1 )
273267 {
274268 if ( this . User . IsInRole ( "Administrator" ) || this . User . IsInRole ( "BlueUser" ) || this . User . IsInRole ( "ReadOnly" ) || this . User . IsInRole ( "BasicUser" ) )
275269 {
@@ -278,21 +272,18 @@ public async Task<IActionResult> LoadPage(string dashBoardTray = "my-learning",
278272 MyLearnings = new Nhs . Models . Dashboard . DashboardMyLearningResponseViewModel { Type = myLearningDashBoard } ,
279273 Resources = new Nhs . Models . Dashboard . DashboardResourceResponseViewModel { Type = resourceDashBoard } ,
280274 Catalogues = new Nhs . Models . Dashboard . DashboardCatalogueResponseViewModel { Type = catalogueDashBoard } ,
275+ DashboardTrayLearningResourceType = dashboardTrayLearningResourceType ,
281276 } ;
282277
283- var enableMoodle = Task . Run ( ( ) => this . featureManager . IsEnabledAsync ( FeatureFlags . EnableMoodle ) ) . Result ;
284- this . ViewBag . EnableMoodle = enableMoodle ;
285- this . ViewBag . ValidMoodleUser = this . CurrentMoodleUserId > 0 ;
286-
287278 bool isAjax = this . HttpContext . Request . Headers [ "X-Requested-With" ] == "XMLHttpRequest" ;
288279
289280 if ( isAjax )
290281 {
291282 switch ( dashBoardTray )
292283 {
293284 case "my-learning" :
294- model . MyLearnings = await this . dashboardService . GetMyAccessLearningsAsync ( myLearningDashBoard , pageNumber ) ;
295- return this . PartialView ( "_MyAccessedLearningTray " , model ) ;
285+ model . MyLearnings = await this . dashboardService . GetMyCoursesAndElearning ( dashboardTrayLearningResourceType , myLearningDashBoard , pageNumber ) ;
286+ return this . PartialView ( "_MyCoursesAndElearning " , model ) ;
296287 case "resources" :
297288 model . Resources = await this . dashboardService . GetResourcesAsync ( resourceDashBoard , pageNumber ) ;
298289 return this . PartialView ( "_ResourceTray" , model ) ;
@@ -303,13 +294,14 @@ public async Task<IActionResult> LoadPage(string dashBoardTray = "my-learning",
303294 }
304295 else
305296 {
306- var learningTask = this . dashboardService . GetMyAccessLearningsAsync ( myLearningDashBoard , dashBoardTray == "my-learning" ? pageNumber : 1 ) ;
297+ var learningTask = this . dashboardService . GetMyCoursesAndElearning ( dashboardTrayLearningResourceType , myLearningDashBoard , dashBoardTray == "my-learning" ? pageNumber : 1 ) ;
307298 var resourcesTask = this . dashboardService . GetResourcesAsync ( resourceDashBoard , dashBoardTray == "resources" ? pageNumber : 1 ) ;
308299 var cataloguesTask = this . dashboardService . GetCataloguesAsync ( catalogueDashBoard , dashBoardTray == "catalogues" ? pageNumber : 1 ) ;
309300 await Task . WhenAll ( learningTask , resourcesTask , cataloguesTask ) ;
310301 model . MyLearnings = await learningTask ;
311302 model . Resources = await resourcesTask ;
312303 model . Catalogues = await cataloguesTask ;
304+ model . DashboardTrayLearningResourceType = dashboardTrayLearningResourceType ;
313305 return this . View ( "Dashboard" , model ) ;
314306 }
315307 }
@@ -449,5 +441,28 @@ private async Task<LandingPageViewModel> GetLandingPageContent(bool preview = fa
449441 return new LandingPageViewModel { PageSectionDetailViewModels = new List < PageSectionDetailViewModel > ( ) , PageViewModel = new PageViewModel { PageSections = new List < PageSectionViewModel > { } } } ;
450442 }
451443 }
444+
445+ /// <summary>
446+ /// Asynchronously retrieves the state of the Moodle feature and the current Moodle user ID.
447+ /// </summary>
448+ /// <remarks>The method checks if the Moodle feature is enabled and retrieves the current Moodle
449+ /// user ID. If the user ID is not already set, it attempts to obtain it asynchronously from the dashboard
450+ /// service.</remarks>
451+ /// <returns>A tuple containing a boolean indicating whether the Moodle feature is enabled and an integer representing
452+ /// the current Moodle user ID.</returns>
453+ private async Task < ( bool enableMoodle , int currentMoodleUserId ) > GetMoodleFeatureStateAsync ( )
454+ {
455+ var enableMoodle = Task . Run ( ( ) => this . featureManager . IsEnabledAsync ( FeatureFlags . EnableMoodle ) ) . Result ;
456+ this . ViewBag . EnableMoodle = enableMoodle ;
457+ int currentMoodleUserId = this . CurrentMoodleUserId ;
458+
459+ if ( currentMoodleUserId == 0 )
460+ {
461+ currentMoodleUserId = await this . dashboardService . GetMoodleUserIdAsync ( this . CurrentUserId ) ;
462+ }
463+
464+ this . ViewBag . ValidMoodleUser = currentMoodleUserId > 0 ;
465+ return ( enableMoodle , currentMoodleUserId ) ;
466+ }
452467 }
453468}
0 commit comments