Skip to content

Commit 2a5d639

Browse files
Merge pull request #542 from TechnologyEnhancedLearning/Develop/Fixes/TD-4336-mplement-Code-Changes-in-Web-UI-My-contributions-Page
TD-4336: Implement Code Changes in Web UI-My contributions Page
2 parents 69e6d8a + d91cb75 commit 2a5d639

File tree

13 files changed

+231
-6
lines changed

13 files changed

+231
-6
lines changed

LearningHub.Nhs.WebUI/Controllers/Api/HierarchyController.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ public async Task<IActionResult> GetNodeContentsForCatalogueEditor(int nodePathI
109109
return this.Ok(viewModels);
110110
}
111111

112+
/// <summary>
113+
/// Check Catalogue has external reference.
114+
/// </summary>
115+
/// <param name="nodeId">The node id.</param>
116+
/// <returns>The <see cref="IActionResult"/>.</returns>
117+
[HttpGet]
118+
[Route("CheckCatalogueHasExternalReference/{nodeId}")]
119+
public async Task<bool> CheckCatalogueHasExternalReference(int nodeId)
120+
{
121+
var val = await this.hierarchyService.CheckCatalogueHasExternalReference(nodeId);
122+
return val;
123+
}
124+
112125
/// <summary>
113126
/// Gets the contents of a node path (catalogue/folder/course) - i.e. returns a list of subfolders and resources. Only returns the
114127
/// items from the first level down. Doesn't recurse through subfolders.

LearningHub.Nhs.WebUI/Interfaces/IHierarchyService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,12 @@ public interface IHierarchyService
236236
/// <param name="referenceExternalResourceViewModel">The referenceExternalResourceViewModel<see cref="ReferenceExternalResourceViewModel"/>.</param>
237237
/// <returns>IActionResult.</returns>
238238
Task<ApiResponse> HierarchyEditReferenceExternalResource(ReferenceExternalResourceViewModel referenceExternalResourceViewModel);
239+
240+
/// <summary>
241+
/// Check catalogue has external reference.
242+
/// </summary>
243+
/// <param name="nodeId">The nodeId<see cref="int"/>.</param>
244+
/// <returns>The <see cref="Task"/>.</returns>
245+
Task<bool> CheckCatalogueHasExternalReference(int nodeId);
239246
}
240247
}

LearningHub.Nhs.WebUI/Scripts/vuesrc/content-structure-editor/contentStructureState.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class State {
2323
updatedNode: NodeContentEditorModel = null;
2424
inError: boolean = false;
2525
lastErrorMessage: string = "";
26+
hasExternalReference: boolean = false;
2627
}
2728

2829
const state = new State();
@@ -51,6 +52,13 @@ function loadNodeContents(state: State) {
5152
state.rootNode.childrenLoaded = false;
5253
state.rootNode.inEdit = state.editMode == EditModeEnum.Structure;
5354
state.rootNode.showInTreeView = false;
55+
}).then(async y => {
56+
await contentStructureData.checkCatalogueHasExternalReference(state.catalogue.nodeId).then(response => {
57+
state.hasExternalReference = response;
58+
})
59+
.catch(e => {
60+
console.log(e);
61+
});
5462
}).then(async y => {
5563
await contentStructureData.getNodeContentsForCatalogueEditor(state.catalogue.rootNodePathId).then(response => {
5664
state.rootNode.children = response;

LearningHub.Nhs.WebUI/Scripts/vuesrc/content-structure-editor/treeItem.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
</a>
8383
<div class="dropdown-menu" aria-labelledby="dropdownNodeItems">
8484
<a class="dropdown-item" v-if="canEditResource" @click="onEditResource">Edit</a>
85-
<a class="dropdown-item" v-if="canMoveResourceUp" @click="onMoveResourceUp">Move up</a>
86-
<a class="dropdown-item" v-if="canMoveResourceDown" @click="onMoveResourceDown">Move down</a>
87-
<a class="dropdown-item" v-if="canMoveResource" @click="onInitiateMoveResource">Move</a>
85+
<a class="dropdown-item" v-if="canMoveResourceUp && !hasExternalCatalogueReference" @click="onMoveResourceUp">Move up</a>
86+
<a class="dropdown-item" v-if="canMoveResourceDown && !hasExternalCatalogueReference" @click="onMoveResourceDown">Move down</a>
87+
<a class="dropdown-item" v-if="canMoveResource && !hasExternalCatalogueReference" @click="onInitiateMoveResource">Move</a>
8888
<a class="dropdown-item" v-if="canDuplicateResource" @click="onDuplicateResource">Duplicate</a>
8989
<a class="dropdown-item" v-if="canDeleteResource" @click="confirmDeleteResource" data-toggle="modal" data-target="#showDeleteConfirm">Delete</a>
9090
</div>
@@ -248,6 +248,9 @@
248248
}
249249
else return 0;
250250
},
251+
hasExternalCatalogueReference(): boolean {
252+
return this.$store.state.contentStructureState.hasExternalReference;
253+
},
251254
},
252255
mounted() {
253256
Vue.set(this, "isVisible", this.item.showInTreeView);
@@ -288,7 +291,7 @@
288291
}
289292
}
290293
}
291-
294+
292295
// Load the data.
293296
if (!this.isOpen && (!this.item.childrenLoaded || this.isError)) {
294297
this.isOpen = true;

LearningHub.Nhs.WebUI/Scripts/vuesrc/data/contentStructure.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,16 @@ const getNodeContentsForCatalogueEditor = async function (nodePathId: number): P
4242
throw e;
4343
});
4444
};
45-
45+
const checkCatalogueHasExternalReference = async function (nodeId: number): Promise<boolean> {
46+
return await axios.get<boolean>('/api/hierarchy/CheckCatalogueHasExternalReference/' + nodeId + `?timestamp=${new Date().getTime()}`)
47+
.then(response => {
48+
return response.data;
49+
})
50+
.catch(e => {
51+
console.log('CheckCatalogueHasExternalReference:' + e);
52+
throw e;
53+
});
54+
};
4655
const getNodeContentsAdmin = async function (nodePathId: number, readOnly: boolean): Promise<NodeContentAdminModel[]> {
4756
return await axios.get<NodeContentAdminModel[]>('/api/hierarchy/GetNodeContentsAdmin/' + nodePathId + '/' + readOnly + `?timestamp=${new Date().getTime()}`)
4857
.then(response => {
@@ -464,5 +473,6 @@ export const contentStructureData = {
464473
getReferencableCatalogues,
465474
hierarchyEditReferenceExternalResource,
466475
referenceExternalNode,
467-
removeReferenceNode
476+
removeReferenceNode,
477+
checkCatalogueHasExternalReference
468478
}

LearningHub.Nhs.WebUI/Services/HierarchyService.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace LearningHub.Nhs.WebUI.Services
22
{
3+
using System;
34
using System.Collections.Generic;
45
using System.Threading.Tasks;
56
using LearningHub.Nhs.Models.Common;
@@ -337,5 +338,33 @@ public async Task<ApiResponse> HierarchyEditReferenceExternalResource(ReferenceE
337338
{
338339
return await this.facade.PostAsync<ApiResponse, ReferenceExternalResourceViewModel>("Hierarchy/HierarchyEditReferenceExternalResource", referenceExternalResourceViewModel);
339340
}
341+
342+
/// <summary>
343+
/// Check catalogue has external reference.
344+
/// </summary>
345+
/// <param name="nodeId">nodeId<see cref="Task"/>.</param>
346+
/// <returns>IActionResult.</returns>
347+
public async Task<bool> CheckCatalogueHasExternalReference(int nodeId)
348+
{
349+
var request = $"Hierarchy/CheckCatalogueHasExternalReference/{nodeId}";
350+
351+
var client = await this.LearningHubHttpClient.GetClientAsync();
352+
var response = await client.GetAsync(request).ConfigureAwait(false);
353+
var hasExternalCatalogueReference = false;
354+
355+
if (response.IsSuccessStatusCode)
356+
{
357+
var result = await response.Content.ReadAsStringAsync();
358+
hasExternalCatalogueReference = bool.Parse(result);
359+
}
360+
else if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized
361+
||
362+
response.StatusCode == System.Net.HttpStatusCode.Forbidden)
363+
{
364+
throw new Exception("AccessDenied");
365+
}
366+
367+
return hasExternalCatalogueReference;
368+
}
340369
}
341370
}

WebAPI/LearningHub.Nhs.API/Controllers/HierarchyController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ public async Task<IActionResult> GetNodeContentsForCatalogueEditor(int nodePathI
103103
return this.Ok(await this.hierarchyService.GetNodeContentsForCatalogueEditor(nodePathId));
104104
}
105105

106+
/// <summary>
107+
/// Check Catalogue has external reference.
108+
/// </summary>
109+
/// <param name="nodeId">The node id.</param>
110+
/// <returns>The <see cref="IActionResult"/>.</returns>
111+
[HttpGet]
112+
[Route("checkCatalogueHasExternalReference/{nodeId}")]
113+
public async Task<IActionResult> CheckCatalogueHasExternalReference(int nodeId)
114+
{
115+
return this.Ok(await this.hierarchyService.CheckCatalogueHasExternalReference(nodeId));
116+
}
117+
106118
/// <summary>
107119
/// Gets the contents of a node path (catalogue/folder/course) - i.e. returns a list of subfolders and resources. Only returns the
108120
/// items from the first level down. Doesn't recurse through subfolders.

WebAPI/LearningHub.Nhs.Database/LearningHub.Nhs.Database.sqlproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@
543543
<Build Include="Stored Procedures\Resources\GetScormContentServerDetailsForLHExternalReference.sql" />
544544
<None Include="Scripts\Post-Deploy\Scripts\Content_Referencing_DataSetup.sql" />
545545
<None Include="Scripts\Pre-Deploy\Scripts\Content Referencing Initialise.sql" />
546+
<Build Include="Stored Procedures\Hierarchy\CheckCatalogueHasExternalReference.sql" />
546547
</ItemGroup>
547548
<ItemGroup>
548549
<None Include="Scripts\Pre-Deploy\Scripts\Card5766_AuthorTableChanges.PreDeployment.sql" />
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
-------------------------------------------------------------------------------
2+
-- Author Sarathlal
3+
-- Created 29 August 2024
4+
-- Purpose Return if Node has an external reference
5+
--
6+
-- Modification History
7+
--
8+
-- 29-08-2024 SS Initial Revision.
9+
10+
-------------------------------------------------------------------------------
11+
CREATE PROCEDURE [hierarchy].[CheckCatalogueHasExternalReference]
12+
(
13+
@CatalogueNodeId int,
14+
@HasExternalCatalogueReference bit OUTPUT
15+
)
16+
AS
17+
18+
BEGIN
19+
;WITH
20+
cteNode(NodeId, ParentNodeId, PrimaryCatalogueNodeId, InitialNodePath)
21+
AS
22+
(
23+
SELECT
24+
n.Id AS NodeId,
25+
ParentNodeId = NULL,
26+
nv.PrimaryCatalogueNodeId,
27+
CAST(n.Id AS nvarchar(128)) AS InitialNodePath
28+
FROM
29+
hierarchy.NodePath np
30+
INNER JOIN
31+
hierarchy.[Node] n ON np.NodeId = n.Id
32+
INNER JOIN
33+
hierarchy.NodeVersion nv ON n.CurrentNodeVersionId = nv.Id
34+
WHERE
35+
nv.NodeId=@catalogueNodeId
36+
AND nv.VersionStatusId = 2 -- Published
37+
AND np.Deleted = 0
38+
AND n.Deleted = 0
39+
AND nv.Deleted = 0
40+
41+
UNION ALL
42+
43+
SELECT
44+
ChildNodeId AS NodeId,
45+
nl.ParentNodeId,
46+
nv.PrimaryCatalogueNodeId,
47+
CAST(cte.InitialNodePath + '\' + CAST(ChildNodeId AS nvarchar(8)) AS nvarchar(128)) AS InitialNodePath
48+
FROM
49+
hierarchy.NodeLink nl
50+
INNER JOIN
51+
hierarchy.[Node] n ON nl.ChildNodeId = n.Id
52+
INNER JOIN
53+
cteNode cte ON nl.ParentNodeId = cte.NodeId
54+
INNER JOIN
55+
hierarchy.NodeVersion nv ON n.CurrentNodeVersionId = nv.Id
56+
WHERE
57+
n.CurrentNodeVersionId IS NOT NULL
58+
AND nv.VersionStatusId = 2 -- Published
59+
AND n.Deleted = 0
60+
AND nl.Deleted = 0
61+
62+
),
63+
64+
cteResource
65+
AS (
66+
SELECT cte.PrimaryCatalogueNodeId
67+
FROM
68+
cteNode cte
69+
UNION
70+
71+
SELECT
72+
rv.PrimaryCatalogueNodeId AS PrimaryCatalogueNodeId
73+
FROM
74+
hierarchy.NodePath np
75+
INNER JOIN
76+
hierarchy.NodeResource nr ON np.NodeId = nr.NodeId
77+
INNER JOIN
78+
resources.[Resource] r ON nr.ResourceId = r.Id
79+
INNER JOIN
80+
resources.ResourceVersion rv ON rv.resourceId = nr.ResourceId
81+
INNER JOIN
82+
resources.ResourceReference rr ON rr.ResourceId = nr.ResourceId AND rr.NodePathId = np.Id AND rr.Deleted = 0
83+
84+
WHERE
85+
np.CatalogueNodeId = @CatalogueNodeId
86+
and rv.PrimaryCatalogueNodeId <>np.CatalogueNodeId
87+
AND r.CurrentResourceVersionId IS not NULL
88+
AND nr.VersionStatusId=2
89+
AND nr.Deleted = 0
90+
AND r.Deleted = 0
91+
AND rv.Deleted = 0
92+
)
93+
SELECT @HasExternalCatalogueReference=case when count(distinct cte.PrimaryCatalogueNodeId ) > 1 then 1 ELSE 0 END
94+
95+
FROM
96+
cteResource cte
97+
END
98+
GO

WebAPI/LearningHub.Nhs.Repository.Interface/Hierarchy/INodeRepository.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,12 @@ public interface INodeRepository : IGenericRepository<Node>
5050
/// <param name="readOnly">Set to true if read only data set is required.</param>
5151
/// <returns>The <see cref="Task"/>.</returns>
5252
Task<List<NodeContentAdminDto>> GetNodeContentsAdminAsync(int nodeId, bool readOnly);
53+
54+
/// <summary>
55+
/// Check catalogue has external reference.
56+
/// </summary>
57+
/// <param name="nodeId">The node id.</param>
58+
/// <returns>The <see cref="Task"/>.</returns>
59+
Task<bool> CheckCatalogueHasExternalReference(int nodeId);
5360
}
5461
}

0 commit comments

Comments
 (0)