11@model LearningHub .Nhs .WebUI .Models .Search .SearchResultViewModel
2+ @inject Microsoft .Extensions .Configuration .IConfiguration Configuration ;
23
34@using System .Linq ;
45@using System .Web ;
1011@using LearningHub .Nhs .Models .Search .SearchClick ;
1112
1213@{
13- var resourceResult = Model .ResourceSearchResult ;
14- var pagingModel = Model .ResourceResultPaging ;
15- var index = pagingModel .CurrentPage * pagingModel .PageSize ;
16- var searchString = HttpUtility .UrlEncode (Model .SearchString );
17-
18- string GetUrl (int resourceReferenceId , int itemIndex , int nodePathId , SearchClickPayloadModel payload )
19- {
20- var searchSignal = payload ? .SearchSignal ;
21- string groupId = HttpUtility .UrlEncode (Model .GroupId .ToString ());
22- string searchSignalQueryEncoded = HttpUtility .UrlEncode (HttpUtility .UrlDecode (searchSignal ? .Query ));
23-
24- return $@" /search/record-resource-click?url=/Resource/{resourceReferenceId }&nodePathId={nodePathId }&itemIndex={payload ? .HitNumber }
14+ var resourceResult = Model .ResourceSearchResult ;
15+ var pagingModel = Model .ResourceResultPaging ;
16+ var index = pagingModel .CurrentPage * pagingModel .PageSize ;
17+ var searchString = HttpUtility .UrlEncode (Model .SearchString );
18+
19+ string GetUrl (int resourceReferenceId , int itemIndex , int nodePathId , SearchClickPayloadModel payload )
20+ {
21+ var searchSignal = payload ? .SearchSignal ;
22+ string groupId = HttpUtility .UrlEncode (Model .GroupId .ToString ());
23+ string searchSignalQueryEncoded = HttpUtility .UrlEncode (HttpUtility .UrlDecode (searchSignal ? .Query ));
24+
25+ return $@" /search/record-resource-click?url=/Resource/{resourceReferenceId }&nodePathId={nodePathId }&itemIndex={payload ? .HitNumber }
2526&pageIndex={pagingModel .CurrentPage }&totalNumberOfHits={payload ? .SearchSignal ? .Stats ? .TotalHits }&searchText={searchString }&resourceReferenceId={resourceReferenceId }
2627&groupId={groupId }&searchId={searchSignal ? .SearchId }&timeOfSearch={searchSignal ? .TimeOfSearch }&userQuery={HttpUtility .UrlEncode (searchSignal .UserQuery )}
2728&query={searchSignalQueryEncoded }&title={payload ? .DocumentFields ? .Title }" ;
28- }
29+ }
30+
31+ string GetMoodleCourseUrl (string courseId )
32+ {
33+ var prefix = " M" ;
34+ if (courseId .StartsWith (prefix ))
35+ {
36+ courseId = courseId .Replace (prefix , " " ); ;
37+ }
38+
39+ var apiBaseUrl = Configuration [" MoodleAPIConfig:BaseUrl" ];
40+ string path = $" course/view.php" ;
41+ string returnUrl = $@" {apiBaseUrl }/{path }?id={courseId }" ;
2942
30- bool showCatalogueFieldsInResources = ViewBag .ShowCatalogueFieldsInResources == null || ViewBag .ShowCatalogueFieldsInResources == true ;
31- bool resourceAccessLevelFilterSelected = resourceResult .SearchResourceAccessLevelFilters .Any (f => f .Selected );
43+ return returnUrl ;
44+ }
45+
46+ bool showCatalogueFieldsInResources = ViewBag .ShowCatalogueFieldsInResources == null || ViewBag .ShowCatalogueFieldsInResources == true ;
47+ bool resourceAccessLevelFilterSelected = resourceResult .SearchResourceAccessLevelFilters .Any (f => f .Selected );
3248}
3349
3450@foreach ( var item in resourceResult .DocumentModel )
3551{
36- var provider = item .Providers ? .FirstOrDefault ();
37-
38- <div class =" resource-item nhsuk-list-item--border nhsuk-u-padding-bottom-4 nhsuk-u-margin-bottom-4" >
39- <h3 class =" nhsuk-heading-xs nhsuk-u-margin-bottom-2" >
40- <a class =" nhsuk-card__link" href =" @GetUrl(item.ResourceReferenceId, index, item.NodePathId??0, item.Click.Payload)" >@item.Title </a >
41- </h3 >
42-
43- @if (provider != null )
44- {
45- <div >
46- <div class =" provider-details" >
47- <img src =" ~/images/provider-logos/@provider.Logo" alt =" @provider.Name" class =" logo" />
48- <span class =" title" >@ProviderHelper.GetProviderString(provider.Name) </span >
49- </div >
50- </div >
51- }
52- @if (item .CatalogueRestrictedAccess && ! Model .HideRestrictedBadge && showCatalogueFieldsInResources )
53- {
54- <p class =" nhsuk-body-s nhsuk-u-margin-bottom-2 nhsuk-u-font-weight-bold" >
55- @( (item .CatalogueHasAccess || this .User .IsInRole (" Administrator" )) ? " Access Granted" : " Access restricted" )
56- </p >
57- }
58-
59- @if (! resourceAccessLevelFilterSelected )
60- {
61- <div class =" nhsuk-body-s nhsuk-u-margin-bottom-2" >
62- <div class =" nhsuk-u-margin-right-4" >
63- <strong >Audience access level : </strong >
64- @ResourceAccessLevelHelper.GetResourceAccessLevelText((ResourceAccessibilityEnum)item.ResourceAccessLevel)
65- </div >
66- </div >
67- }
68-
69-
70- <div class =" resource-info nhsuk-body-s nhsuk-u-margin-bottom-2" >
71- <div class =" nhsuk-u-margin-right-4" >
72- <strong >Type : </strong >
73- @UtilityHelper.GetPrettifiedResourceTypeName(UtilityHelper.ToEnum <ResourceTypeEnum >(item .ResourceType ), 0 )
74- </div >
75- <div >
76- @await Html .PartialAsync (" ../Shared/_StarRating.cshtml" , item .Rating )
77- </div >
78- </div >
79-
80- <p class =" nhsuk-body-s nhsuk-u-margin-bottom-2 resource-description line-clamp-3" >
81- @item.Description
82- </p >
83-
84- <div class =" resource-author" >
85- @if (! string .IsNullOrWhiteSpace (item .CatalogueBadgeUrl ) && showCatalogueFieldsInResources )
86- {
87- <img class =" resource-catalogue-badge" src =" /search/image/@item.CatalogueBadgeUrl" alt =" Provider's catalogue badge" />
88- }
89-
90- @if (! string .IsNullOrEmpty (item .CatalogueName ) && ! this .Model .CatalogueId .HasValue && showCatalogueFieldsInResources )
91- {
92- <div class =" nhsuk-u-margin-right-3" >
93- <a href =" @(" /Catalogue /" + item.CatalogueUrl)" class =" catalogue-resource-search-result-name" >@item.CatalogueName </a >
94- </div >
95- }
96-
97- <div >
98- @UtilityHelper.GetAttribution(item.Authors)
99- @if (! string .IsNullOrEmpty (item .AuthoredDate ))
100- {
101- @UtilityHelper.GetInOn(item.AuthoredDate)
102- @: @item.AuthoredDate
103- }
104- </div >
105- </div >
106- </div >
107- index ++ ;
52+ var provider = item .Providers ? .FirstOrDefault ();
53+
54+ <div class =" resource-item nhsuk-list-item--border nhsuk-u-padding-bottom-4 nhsuk-u-margin-bottom-4" >
55+ <h3 class =" nhsuk-heading-xs nhsuk-u-margin-bottom-2" >
56+ @if (item .ResourceType == " moodle" )
57+ {
58+ <a class =" nhsuk-card__link" href =" @GetMoodleCourseUrl(item.Id)" >@item.Title </a >
59+ }
60+ else
61+ {
62+ <a class =" nhsuk-card__link" href =" @GetUrl(item.ResourceReferenceId, index, item.NodePathId??0, item.Click.Payload)" >@item.Title </a >
63+ }
64+ </h3 >
65+
66+ @if (provider != null )
67+ {
68+ <div >
69+ <div class =" provider-details" >
70+ <img src =" ~/images/provider-logos/@provider.Logo" alt =" @provider.Name" class =" logo" />
71+ <span class =" title" >@ProviderHelper.GetProviderString(provider.Name) </span >
72+ </div >
73+ </div >
74+ }
75+ @if (item .CatalogueRestrictedAccess && ! Model .HideRestrictedBadge && showCatalogueFieldsInResources )
76+ {
77+ <p class =" nhsuk-body-s nhsuk-u-margin-bottom-2 nhsuk-u-font-weight-bold" >
78+ @( (item .CatalogueHasAccess || this .User .IsInRole (" Administrator" )) ? " Access Granted" : " Access restricted" )
79+ </p >
80+ }
81+
82+ @if (! resourceAccessLevelFilterSelected )
83+ {
84+ <div class =" nhsuk-body-s nhsuk-u-margin-bottom-2" >
85+ <div class =" nhsuk-u-margin-right-4" >
86+ <strong >Audience access level : </strong >
87+ @ResourceAccessLevelHelper.GetResourceAccessLevelText((ResourceAccessibilityEnum)item.ResourceAccessLevel)
88+ </div >
89+ </div >
90+ }
91+
92+
93+ <div class =" resource-info nhsuk-body-s nhsuk-u-margin-bottom-2" >
94+ <div class =" nhsuk-u-margin-right-4" >
95+ <strong >Type : </strong >
96+ @UtilityHelper.GetPrettifiedResourceTypeNameMoodle(UtilityHelper.ToEnum <ResourceTypeEnumMoodle >(item .ResourceType ), 0 )
97+ </div >
98+ <div >
99+ @if (item .ResourceType != " moodle" )
100+ {
101+ @await Html .PartialAsync (" ../Shared/_StarRating.cshtml" , item .Rating )
102+ }
103+ </div >
104+ </div >
105+
106+ <p class =" nhsuk-body-s nhsuk-u-margin-bottom-2 resource-description line-clamp-3" >
107+ @item.Description
108+ </p >
109+
110+ <div class =" resource-author" >
111+ @if (! string .IsNullOrWhiteSpace (item .CatalogueBadgeUrl ) && showCatalogueFieldsInResources )
112+ {
113+ <img class =" resource-catalogue-badge" src =" /search/image/@item.CatalogueBadgeUrl" alt =" Provider's catalogue badge" />
114+ }
115+
116+ @if (! string .IsNullOrEmpty (item .CatalogueName ) && ! this .Model .CatalogueId .HasValue && showCatalogueFieldsInResources )
117+ {
118+ <div class =" nhsuk-u-margin-right-3" >
119+ <a href =" @(" /Catalogue /" + item.CatalogueUrl)" class =" catalogue-resource-search-result-name" >@item.CatalogueName </a >
120+ </div >
121+ }
122+
123+ <div >
124+ @UtilityHelper.GetAttribution(item.Authors)
125+ @if (! string .IsNullOrEmpty (item .AuthoredDate ))
126+ {
127+ @UtilityHelper.GetInOn(item.AuthoredDate)
128+ @: @item.AuthoredDate
129+ }
130+ </div >
131+ </div >
132+ </div >
133+ index ++ ;
108134}
0 commit comments