Skip to content

Commit 69e6d8a

Browse files
authored
Merge pull request #543 from TechnologyEnhancedLearning/Develop/Fixes/TD-4584-Adding-content-to-or-re-aranging-content-within-a-referenced-path
Td-4584: Adding content to, or re-aranging content within, a referenc…
2 parents e9cc68e + 2db916b commit 69e6d8a

File tree

5 files changed

+101
-20
lines changed

5 files changed

+101
-20
lines changed

AdminUI/LearningHub.Nhs.AdminUI/Scripts/vuesrc/content-structure/contentStructureState.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ const actions = <ActionTree<State, any>>{
457457
await refreshNodeContents(payload.destinationNode, true).then(async x => {
458458
await refreshNodeContents(state.editingTreeNode.parent, true).then(y => {
459459
});
460+
refreshHierarchyEdit(state);
460461
state.rootNode.children.forEach(async (child) => {
461462
if (child.nodeId != null) {
462463
await refreshNodeContents(child, false);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,12 @@ const actions = <ActionTree<State, any>>{
454454
await refreshNodeContents(payload.destinationNode, true).then(async x => {
455455
await refreshNodeContents(state.editingTreeNode.parent, true).then(y => {
456456
});
457+
refreshHierarchyEdit(state);
458+
state.rootNode.children.forEach(async (child) => {
459+
if (child.nodeId != null) {
460+
await refreshNodeContents(child, false);
461+
}
462+
});
457463
});
458464
}).catch(e => {
459465
state.inError = true;
@@ -492,8 +498,9 @@ const actions = <ActionTree<State, any>>{
492498
state.inError = false;
493499
contentStructureData.removeReferenceNode(payload.node.hierarchyEditDetailId).then(async response => {
494500
await refreshNodeContents(payload.node.parent, false);
495-
await refreshNodeContents(payload.node.parent.parent, false);
496-
await refreshNodeIfMatchingNodeId(payload.node.parent, state.editingTreeNode.nodeId, state.editingTreeNode.hierarchyEditDetailId);
501+
if (payload.node.parent.parent != null) {
502+
await refreshNodeContents(payload.node.parent.parent, false);
503+
}
497504
}).catch(e => {
498505
state.inError = true;
499506
state.lastErrorMessage = "Error removing resource refrence.";

WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveNode.sql

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
-- 20-05-2024 DB Added the creation of a new NodePath record for the moved node and update child nodes.
1212
-- 29-05-2024 DB Clear the NodePathId for moved nodes. NodePaths can not be updated incase susequent references are made to the original path.
1313
-- 07-08-2024 SA Remove all instance of the referenced path when moving a referenced folder
14+
-- 23-08-2024 SA Moving a folder into a referenced folder should affect all instances of the referenced folder.
1415
-------------------------------------------------------------------------------
1516
CREATE PROCEDURE [hierarchy].[HierarchyEditMoveNode]
1617
(
@@ -279,9 +280,51 @@ BEGIN
279280
AND rrdv.Deleted = 0
280281
AND hed.Deleted = 0
281282

282-
-- Remove all instance of the referenced path when moving a referenced folder
283+
-- Remove all instance of the referenced path when moving a referenced folder
283284

284285
EXEC hierarchy.HierarchyEditRemoveNodeReferencesOnMoveNode @HierarchyEditDetailId,@UserId,@UserTimezoneOffset
286+
287+
-- Moving a folder into a referenced folder should affect all instances of the referenced folder.
288+
289+
DECLARE @CurrentNodeId INT,
290+
@ReferenceHierarchyEditDetailId INT
291+
292+
SELECT @CurrentNodeId = hed.NodeId
293+
FROM [hierarchy].[HierarchyEditDetail] hed
294+
WHERE hed.Id = @MoveToHierarchyEditDetailId
295+
AND HierarchyEditId = @HierarchyEditId
296+
297+
-- Declare the cursor
298+
299+
DECLARE NodeCursor CURSOR FOR
300+
SELECT Id AS ReferenceHierarchyEditDetailId
301+
FROM hierarchy.HierarchyEditDetail
302+
WHERE NodeId = @CurrentNodeId
303+
AND Id != @MoveToHierarchyEditDetailId
304+
AND HierarchyEditId = @HierarchyEditId
305+
AND deleted = 0
306+
-- Open the cursor
307+
OPEN NodeCursor;
308+
309+
-- Fetch the first row from the cursor
310+
FETCH NEXT FROM NodeCursor
311+
INTO @ReferenceHierarchyEditDetailId;
312+
313+
-- Loop until no more rows are returned
314+
WHILE @@FETCH_STATUS = 0
315+
BEGIN
316+
-- Execute the script to add new folder references in all referenced instances
317+
EXEC [hierarchy].[HierarchyEditReferenceNode] @HierarchyEditDetailId, @ReferenceHierarchyEditDetailId, @UserId,@UserTimezoneOffset
318+
319+
-- Fetch the next row from the cursor
320+
FETCH NEXT FROM NodeCursor
321+
INTO @ReferenceHierarchyEditDetailId;
322+
END
323+
324+
-- Close and deallocate the cursor
325+
CLOSE NodeCursor;
326+
DEALLOCATE NodeCursor;
327+
285328
------------------------------------------------------------
286329
-- Refresh HierarchyEditNodeResourceLookup
287330
------------------------------------------------------------

WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditMoveResource.sql

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
--
88
-- 11-01-2022 KD Initial Revision.
99
-- 08-08-2024 SA Remove all instance of the referenced path when moving a referenced resource
10+
-- 23-08-2024 SA Moving a resource into a referenced folder should affect all instances of the referenced folder
1011
-------------------------------------------------------------------------------
1112
CREATE PROCEDURE [hierarchy].[HierarchyEditMoveResource]
1213
(
@@ -175,6 +176,48 @@ BEGIN
175176
-- Remove all instance of the referenced path when moving a referenced resource
176177

177178
EXEC hierarchy.HierarchyEditRemoveResourceReferencesOnMoveResource @HierarchyEditDetailId,@ParentNodeId,@UserId,@UserTimezoneOffset
179+
180+
-- Moving a resource into a referenced folder should affect all instances of the referenced folder
181+
182+
DECLARE @CurrentNodeId INT,
183+
@ReferenceHierarchyEditDetailId INT
184+
185+
SELECT @CurrentNodeId = hed.NodeId
186+
FROM [hierarchy].[HierarchyEditDetail] hed
187+
WHERE hed.Id = @MoveToHierarchyEditDetailId
188+
AND HierarchyEditId = @HierarchyEditId
189+
190+
-- Declare the cursor
191+
192+
DECLARE NodeCursor CURSOR FOR
193+
SELECT Id AS ReferenceHierarchyEditDetailId
194+
FROM hierarchy.HierarchyEditDetail
195+
WHERE NodeId = @CurrentNodeId
196+
AND Id != @MoveToHierarchyEditDetailId
197+
AND HierarchyEditId = @HierarchyEditId
198+
AND deleted = 0
199+
-- Open the cursor
200+
OPEN NodeCursor;
201+
202+
-- Fetch the first row from the cursor
203+
FETCH NEXT FROM NodeCursor
204+
INTO @ReferenceHierarchyEditDetailId;
205+
206+
-- Loop until no more rows are returned
207+
WHILE @@FETCH_STATUS = 0
208+
BEGIN
209+
-- Execute the update statement for the current row
210+
EXEC [hierarchy].[HierarchyEditReferenceResource] @HierarchyEditDetailId, @ReferenceHierarchyEditDetailId, @UserId,@UserTimezoneOffset
211+
212+
-- Fetch the next row from the cursor
213+
FETCH NEXT FROM NodeCursor
214+
INTO @ReferenceHierarchyEditDetailId;
215+
END
216+
217+
-- Close and deallocate the cursor
218+
CLOSE NodeCursor;
219+
DEALLOCATE NodeCursor;
220+
178221
------------------------------------------------------------
179222
-- Refresh HierarchyEditNodeResourceLookup
180223
------------------------------------------------------------

WebAPI/LearningHub.Nhs.Database/Stored Procedures/Hierarchy/HierarchyEditPublish.sql

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
-- 03-06-2024 DB Publish NodePathDisplayVersion records.
1919
-- 13-06-2024 DB Publish ResourceReferenceDisplayVersion records.
2020
-- 26-07-2024 SA Remove references to be implemented
21+
-- 27-08-2024 SA Moving a folder into a referenced folder should affect all instances of the referenced folder.[added
22+
-- condition to avoid duplicate entries in to NodeLink table]
2123
-------------------------------------------------------------------------------
2224
CREATE PROCEDURE [hierarchy].[HierarchyEditPublish]
2325
(
@@ -62,7 +64,7 @@ BEGIN
6264
----------------------------------------------------------
6365
-- Create new NodeLinks (arising from Create or Reference Node)
6466
INSERT INTO [hierarchy].[NodeLink] ([ParentNodeId],[ChildNodeId],[DisplayOrder],[Deleted],[CreateUserId],[CreateDate],[AmendUserId],[AmendDate])
65-
SELECT
67+
SELECT DISTINCT
6668
ParentNodeId,
6769
NodeId AS ChildNodeId,
6870
DisplayOrder,
@@ -230,7 +232,7 @@ BEGIN
230232

231233
-- Create moved NodeResource/s in their new locations
232234
INSERT INTO [hierarchy].[NodeResource] ([NodeId],[ResourceId],[DisplayOrder],[VersionStatusId],[PublicationId],[Deleted],[CreateUserId],[CreateDate],[AmendUserId],[AmendDate])
233-
SELECT ParentNodeId, ResourceId, DisplayOrder, 2 /* Published */, @PublicationId, 0, CreateUserId, CreateDate, AmendUserId, AmendDate
235+
SELECT DISTINCT ParentNodeId, ResourceId, DisplayOrder, 2 /* Published */, @PublicationId, 0, @AmendUserId, @AmendDate, @AmendUserId, @AmendDate
234236
FROM hierarchy.HierarchyEditDetail
235237
WHERE HierarchyEditId = @HierarchyEditId
236238
AND HierarchyEditDetailTypeId = 5 -- Node Resource
@@ -284,21 +286,6 @@ BEGIN
284286
AND hed.Deleted = 0
285287
AND nr.Deleted = 0
286288

287-
-- Update NodeResource Deleted status , if the reference is removed.
288-
UPDATE
289-
nr
290-
SET
291-
Deleted = 1,
292-
AmendUserId = @AmendUserId,
293-
AmendDate = @AmendDate
294-
FROM
295-
hierarchy.HierarchyEditDetail hed
296-
INNER JOIN
297-
hierarchy.NodeResource nr ON hed.NodeResourceId = nr.Id
298-
WHERE
299-
HierarchyEditId = @HierarchyEditId
300-
AND hed.Deleted =1
301-
302289
----------------------------------------------------------
303290
-- NodeVersion
304291
----------------------------------------------------------

0 commit comments

Comments
 (0)