@@ -249,62 +249,31 @@ public async Task<IActionResult> IndexAsync(string reference, string tab, int? n
249249 }
250250 }
251251
252- if ( tab == "browse" )
252+ if ( nodeId . HasValue )
253253 {
254- if ( nodeId . HasValue )
255- {
256- // if nodeId has a value it means the user is looking at a subfolder of the catalogue.
257- // Get the folder name and description, plus folder path data needed for the breadcrumbs.
258- viewModel . NodeDetails = await this . hierarchyService . GetNodeDetails ( nodeId . Value ) ;
259- viewModel . NodePathNodes = await this . hierarchyService . GetNodePathNodes ( viewModel . NodeDetails . NodePathId ) ;
260- }
261- else
262- {
263- // Otherwise user is looking at catalogue root.
264- nodeId = catalogue . NodeId ;
254+ // if nodeId has a value it means the user is looking at a subfolder of the catalogue.
255+ // Get the folder name and description, plus folder path data needed for the breadcrumbs.
256+ viewModel . NodeDetails = await this . hierarchyService . GetNodeDetails ( nodeId . Value ) ;
257+ viewModel . NodePathNodes = await this . hierarchyService . GetNodePathNodes ( viewModel . NodeDetails . NodePathId ) ;
258+ }
259+ else
260+ {
261+ // Otherwise user is looking at catalogue root.
262+ nodeId = catalogue . NodeId ;
265263
266- viewModel . NodePathNodes = new List < NodeViewModel >
264+ viewModel . NodePathNodes = new List < NodeViewModel >
267265 {
268266 new NodeViewModel { Name = catalogue . Name } ,
269267 } ;
270- }
271-
272- bool includeEmptyFolder = viewModel . UserGroups . Any ( x => x . RoleId == ( int ) RoleEnum . LocalAdmin || x . RoleId == ( int ) RoleEnum . Editor || x . RoleId == ( int ) RoleEnum . Previewer ) || this . User . IsInRole ( "Administrator" ) ;
273- var nodeContents = await this . hierarchyService . GetNodeContentsForCatalogueBrowse ( nodeId . Value , includeEmptyFolder ) ;
274- viewModel . NodeContents = nodeContents ;
275268 }
276- else if ( tab == "search" )
277- {
278- if ( viewModel . SearchResults == null )
279- {
280- viewModel . SearchResults = new Models . Search . SearchResultViewModel ( ) ;
281- }
282269
283- if ( search . Term != null )
284- {
285- search . CatalogueId = catalogue . NodeId ;
286- search . SearchId ??= 0 ;
287- search . GroupId = ! string . IsNullOrWhiteSpace ( search . GroupId ) && Guid . TryParse ( search . GroupId , out Guid groupId ) ? groupId . ToString ( ) : Guid . NewGuid ( ) . ToString ( ) ;
270+ bool includeEmptyFolder = viewModel . UserGroups . Any ( x => x . RoleId == ( int ) RoleEnum . LocalAdmin || x . RoleId == ( int ) RoleEnum . Editor || x . RoleId == ( int ) RoleEnum . Previewer ) || this . User . IsInRole ( "Administrator" ) ;
271+ var nodeContents = await this . hierarchyService . GetNodeContentsForCatalogueBrowse ( nodeId . Value , includeEmptyFolder ) ;
272+ viewModel . NodeContents = nodeContents ;
288273
289- var searchResult = await this . searchService . PerformSearch ( this . User , search ) ;
290- searchResult . CatalogueId = catalogue . NodeId ;
291- searchResult . CatalogueUrl = catalogue . Url ;
292- if ( search . SearchId == 0 && searchResult . ResourceSearchResult != null )
293- {
294- var searchId = await this . searchService . RegisterSearchEventsAsync (
295- search ,
296- SearchFormActionTypeEnum . SearchWithinCatalogue ,
297- searchResult . ResourceSearchResult . TotalHits ) ;
298-
299- searchResult . ResourceSearchResult . SearchId = searchId ;
300- }
301-
302- viewModel . SearchResults = searchResult ;
303- }
304- }
305- else if ( tab == "courses" )
274+ int categoryId = moodleCategoryId ?? await this . categoryService . GetCatalogueVersionCategoryAsync ( catalogue . Id ) ;
275+ if ( categoryId > 0 )
306276 {
307- int categoryId = moodleCategoryId ?? await this . categoryService . GetCatalogueVersionCategoryAsync ( catalogue . Id ) ;
308277 var response = await this . categoryService . GetCoursesByCategoryIdAsync ( categoryId ) ;
309278 viewModel . Courses = response . Courses ;
310279
@@ -353,6 +322,40 @@ public async Task<IActionResult> IndexAsync(string reference, string tab, int? n
353322 } ;
354323 }
355324 }
325+ else
326+ {
327+ viewModel . Catalogue . SelectedCategoryId = 0 ;
328+ }
329+
330+ if ( tab == "search" )
331+ {
332+ if ( viewModel . SearchResults == null )
333+ {
334+ viewModel . SearchResults = new Models . Search . SearchResultViewModel ( ) ;
335+ }
336+
337+ if ( search . Term != null )
338+ {
339+ search . CatalogueId = catalogue . NodeId ;
340+ search . SearchId ??= 0 ;
341+ search . GroupId = ! string . IsNullOrWhiteSpace ( search . GroupId ) && Guid . TryParse ( search . GroupId , out Guid groupId ) ? groupId . ToString ( ) : Guid . NewGuid ( ) . ToString ( ) ;
342+
343+ var searchResult = await this . searchService . PerformSearch ( this . User , search ) ;
344+ searchResult . CatalogueId = catalogue . NodeId ;
345+ searchResult . CatalogueUrl = catalogue . Url ;
346+ if ( search . SearchId == 0 && searchResult . ResourceSearchResult != null )
347+ {
348+ var searchId = await this . searchService . RegisterSearchEventsAsync (
349+ search ,
350+ SearchFormActionTypeEnum . SearchWithinCatalogue ,
351+ searchResult . ResourceSearchResult . TotalHits ) ;
352+
353+ searchResult . ResourceSearchResult . SearchId = searchId ;
354+ }
355+
356+ viewModel . SearchResults = searchResult ;
357+ }
358+ }
356359
357360 return this . View ( viewModel ) ;
358361 }
0 commit comments