From 89c5c9fb11cb6d9de98ed074d187d424bb439dcb Mon Sep 17 00:00:00 2001 From: Auldrin Possa Date: Mon, 28 Apr 2025 16:05:46 +0100 Subject: [PATCH] TD-Framework competency group id null check added. Ordering of competencies and competency groups updated after delete operation --- ...281045_Alter_ReorderFrameworkCompetency.cs | 19 +++++++ ...115_UpdateFrameworkCompetenciesOrdering.cs | 21 +++++++ .../Properties/Resources.Designer.cs | 44 +++++++++++++++ .../Properties/Resources.resx | 6 ++ ...-Alter_ReorderFrameworkCompetency_Down.sql | Bin 0 -> 5404 bytes ...47-Alter_ReorderFrameworkCompetency_Up.sql | Bin 0 -> 6064 bytes .../DataServices/FrameworkDataService.cs | 53 +++++++++++++++--- .../FrameworksController/Competencies.cs | 4 +- .../Services/FrameworkService.cs | 12 ++-- 9 files changed, 142 insertions(+), 17 deletions(-) create mode 100644 DigitalLearningSolutions.Data.Migrations/202504281045_Alter_ReorderFrameworkCompetency.cs create mode 100644 DigitalLearningSolutions.Data.Migrations/202504281115_UpdateFrameworkCompetenciesOrdering.cs create mode 100644 DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Down.sql create mode 100644 DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Up.sql diff --git a/DigitalLearningSolutions.Data.Migrations/202504281045_Alter_ReorderFrameworkCompetency.cs b/DigitalLearningSolutions.Data.Migrations/202504281045_Alter_ReorderFrameworkCompetency.cs new file mode 100644 index 0000000000..2759e056ac --- /dev/null +++ b/DigitalLearningSolutions.Data.Migrations/202504281045_Alter_ReorderFrameworkCompetency.cs @@ -0,0 +1,19 @@ + + +namespace DigitalLearningSolutions.Data.Migrations +{ + using FluentMigrator; + + [Migration(202504281045)] + public class Alter_ReorderFrameworkCompetency : Migration + { + public override void Up() + { + Execute.Sql(Properties.Resources.TD_5447_Alter_ReorderFrameworkCompetency_Up); + } + public override void Down() + { + Execute.Sql(Properties.Resources.TD_5447_Alter_ReorderFrameworkCompetency_Down); + } + } +} diff --git a/DigitalLearningSolutions.Data.Migrations/202504281115_UpdateFrameworkCompetenciesOrdering.cs b/DigitalLearningSolutions.Data.Migrations/202504281115_UpdateFrameworkCompetenciesOrdering.cs new file mode 100644 index 0000000000..e64cdd3f6f --- /dev/null +++ b/DigitalLearningSolutions.Data.Migrations/202504281115_UpdateFrameworkCompetenciesOrdering.cs @@ -0,0 +1,21 @@ +namespace DigitalLearningSolutions.Data.Migrations +{ + using FluentMigrator; + [Migration(202504281115)] + public class UpdateFrameworkCompetenciesOrdering : ForwardOnlyMigration + { + public override void Up() + { + Execute.Sql(@"WITH Ranked AS ( +    SELECT ID, +            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY SysStartTime) AS NewOrder +    FROM FrameworkCompetencies + Where FrameworkCompetencyGroupID is null + ) + UPDATE fc + SET fc.Ordering = r.NewOrder + FROM FrameworkCompetencies fc + JOIN Ranked r ON fc.ID = r.ID;"); + } + } +} diff --git a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs index ea8a97cc31..f5949119d4 100644 --- a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs +++ b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.Designer.cs @@ -2436,6 +2436,50 @@ internal static string TD_5412_Alter_SendExpiredTBCReminders_Up { } } + /// + /// Looks up a localized string similar to /****** Object: StoredProcedure [dbo].[ReorderFrameworkCompetency] Script Date: 24/04/2025 09:23:17 ******/ + ///SET ANSI_NULLS ON + ///GO + /// + ///SET QUOTED_IDENTIFIER ON + ///GO + /// + ///-- ============================================= + ///-- Author: Kevin Whittaker + ///-- Create date: 04/01/2021 + ///-- Description: Reorders the FrameworkCompetencies in a given FrameworkCompetencyGroup - moving the given competency up or down. + ///-- ============================================= + ///ALTER PROCEDURE [dbo].[ReorderFrameworkCompetency] + /// [rest of string was truncated]";. + /// + internal static string TD_5447_Alter_ReorderFrameworkCompetency_Down { + get { + return ResourceManager.GetString("TD_5447_Alter_ReorderFrameworkCompetency_Down", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to /****** Object: StoredProcedure [dbo].[ReorderFrameworkCompetency] Script Date: 24/04/2025 09:23:17 ******/ + ///SET ANSI_NULLS ON + ///GO + /// + ///SET QUOTED_IDENTIFIER ON + ///GO + /// + ///-- ============================================= + ///-- Author: Kevin Whittaker + ///-- Create date: 04/01/2021 + ///-- Description: Reorders the FrameworkCompetencies in a given FrameworkCompetencyGroup - moving the given competency up or down. + ///-- ============================================= + ///ALTER PROCEDURE [dbo].[ReorderFrameworkCompetency] + /// [rest of string was truncated]";. + /// + internal static string TD_5447_Alter_ReorderFrameworkCompetency_Up { + get { + return ResourceManager.GetString("TD_5447_Alter_ReorderFrameworkCompetency_Up", resourceCulture); + } + } + /// /// Looks up a localized string similar to /****** Object: StoredProcedure [dbo].[SendExpiredTBCReminders] Script Date: 16/04/2025 10:50:12 ******/ ///SET ANSI_NULLS ON diff --git a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx index df856a17ae..c0b77842ad 100644 --- a/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx +++ b/DigitalLearningSolutions.Data.Migrations/Properties/Resources.resx @@ -481,4 +481,10 @@ ..\Scripts\TD-5514-Alter_SendExpiredTBCReminders_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16 + + ..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Down.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16 + + + ..\Scripts\TD-5447-Alter_ReorderFrameworkCompetency_Up.sql;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-16 + \ No newline at end of file diff --git a/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Down.sql b/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Down.sql new file mode 100644 index 0000000000000000000000000000000000000000..56bac72b67185f300a00e14ae970694687d73d1a GIT binary patch literal 5404 zcmeI0>rWFw6vgk?n)pBLH$XrhYK$m`+5!@RB9CBVjNwtBLR-=ngnwTBotZA%Z3kE$ zg@l;RcJI#2ow;-Fxo0Q+`)ABvbX<{@Y}f_@)P*ZQ{7$_Vtir^S$3Hykq7C3 zSC5F5g`PA~*wpzI7OF$BS4vj4GoC^;ay?BrcI0}R^tIaP3cqT5zrIRU#~%MZ#;N9N z)I|g%754#_B3tAxxOkKiU&+#3`8M0k&AE|^IkboOZdL8yb58Xm4O?IiMc81b2&;GY zgcaB4U;0@f+I*YES^1FEwP%L1v);xj%bZ!f3S^|=awF7M$b=Z5UP;_Lay*l&&Daw5 zS#WGRE4SUJSbS6E(_TkhbiJM)hw!Y4Ul<8_mB7b;*JB>eIc-|X7-y{UoAwzdcqL0> z%8HUayq}iP=)Tur4e_J{VIe*yYYL~IYj!_>m529b#q_43eA1Jug6Sh z7tIh-Q_Veqwyp5%&r6DPhMEo4#z*=lQscrJt6BXCBCV}jr$~PEt;>c+%%50|yR+(b z|FU>HSvMF!|7s?xSFDM%7n!7njU9+hOejBy!83uKezpP`{o%<>)KtoJ^X0g9)47A z_d}=0U6nnIPWLKU2+xqtUd=Z3rulRmwe6=;d!-3|Rr{;aPg{o{m%E|w+*9PPPJQ7M UR)4wM{bj!I^F(s8i2n)v2Qm#|<^TWy literal 0 HcmV?d00001 diff --git a/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Up.sql b/DigitalLearningSolutions.Data.Migrations/Scripts/TD-5447-Alter_ReorderFrameworkCompetency_Up.sql new file mode 100644 index 0000000000000000000000000000000000000000..bd170f6b9e0f0c81bacc0630a5b44e302d11e068 GIT binary patch literal 6064 zcmeI0>rWFw6vgjXO#C1A8=@c&HAWOeZBZM6B9CBVjNwrbp@p;s;h$H3XQtymx|9Ve zY9yO>W@qNk+&TB$Gt>U~K5q9DPh>UQw69jTE$i5{MLa9i4y{Gowk=T}(x>{dYm4k7 z^-Wqo*+c5f^l9`qWy@ak*{}xnZ?1LU%9IT|qNT&9$y{exY8}7U78ZN-cX+R0t5Nb} z${yReO}OtV$|-w7>x4a{cgh~|J!wyAN$zIc?%EyvpR-kZO14P7YM&|BY@TO@)*5db z^@f_tq{Vy2)v%qzlh0UIs4endWnWe5%jejS*%&=D1AFA7U!z16I`+k3J8eTe@4)K> z1e+C(ixX^*v=pg)v} ze4F*Cvp*J@aD1Dr6qWioOg>6SvE%9 z8N^~Ca|m~va63kQu#qjnOmR-^(z8UZM&5{pYt-jxyN;aGeujSWXq%nJ7#+cfkh#jh z7BP=(2P}k1K(b9OC_@D5z1pDoi)VhV*@AIYrg1jIS#*)85eMmj zSC5F5g`PA~*c|dLER=_0uavBAr<6i8ay@N0cHny2^mV%E3cp5ozdlQq#~%M3#wq8T zJxisSUeeZ{G-fsL}bq|rgRmsS36S;TgIFE5U2gOUz znCC&>?JJ#K;*OuwW30Q5xSprJLUsN@g&P+u$oLlGLI0FxZs%P2Z&yVx=kz{XP-1;+Gy^2>-Yr{@L`7bdf_?#`n z9(r@HKe{pZvNPUvoOS+*ugQ4#k8NId$s!qR{eti<$<~Xrtb&HEV_PKCUf^~1bPDm9 zMRmM-r*A^HSr-sWt7s8DN&fOsykiaZTu;w<9lD&&jqo1!aM`ST;7*YwBg2e0oplfX zs;nEt**1~VgFkb&^`3ZnxZj>`Aq%o)zdZBmn|B8qNku-)Ij9W#zs|0|Gpq9M5Vu(s en4c~CWtDzC 0) + { + connection.Execute( + @"WITH Ranked AS ( +    SELECT ID, +            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY Ordering) AS NewOrder +    FROM FrameworkCompetencyGroups + Where FrameworkID = @frameworkID + ) + UPDATE fcg + SET fcg.Ordering = r.NewOrder + FROM FrameworkCompetencyGroups fcg + JOIN Ranked r ON fcg.ID = r.ID;", + new { frameworkId } + ); + } + else { logger.LogWarning( "Not deleting framework competency group as db update failed. " + @@ -1219,7 +1237,7 @@ public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int c } } - public void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId) + public void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId) { var competencyId = connection.QuerySingle( @"SELECT CompetencyID FROM FrameworkCompetencies WHERE ID = @frameworkCompetencyId", @@ -1243,7 +1261,24 @@ public void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId) @"DELETE FROM FrameworkCompetencies WHERE ID = @frameworkCompetencyId", new { frameworkCompetencyId } ); - if (numberOfAffectedRows < 1) + if (numberOfAffectedRows > 0) + { + connection.Execute( + @"WITH Ranked AS ( +    SELECT ID, +            ROW_NUMBER() OVER (PARTITION BY FrameworkID ORDER BY Ordering) AS NewOrder +    FROM FrameworkCompetencies + Where (FrameworkCompetencyGroupID = @frameworkCompetencyGroupID) OR (FrameworkCompetencyGroupID IS NULL AND @frameworkCompetencyGroupID IS NULL) AND + FrameworkID = @frameworkID + ) + UPDATE fc + SET fc.Ordering = r.NewOrder + FROM FrameworkCompetencies fc + JOIN Ranked r ON fc.ID = r.ID;", + new { frameworkCompetencyGroupId, frameworkId } + ); + } + else { logger.LogWarning( "Not deleting framework competency as db update failed. " + diff --git a/DigitalLearningSolutions.Web/Controllers/FrameworksController/Competencies.cs b/DigitalLearningSolutions.Web/Controllers/FrameworksController/Competencies.cs index 6afd88f86a..0893c7f7c6 100644 --- a/DigitalLearningSolutions.Web/Controllers/FrameworksController/Competencies.cs +++ b/DigitalLearningSolutions.Web/Controllers/FrameworksController/Competencies.cs @@ -102,7 +102,7 @@ public IActionResult DeleteFrameworkCompetencyGroup(int frameworkId, int compete var adminId = GetAdminId(); - frameworkService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, adminId); + frameworkService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, frameworkId, adminId); return new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId })); } @@ -235,7 +235,7 @@ public IActionResult DeleteFrameworkCompetency(int frameworkId, int frameworkCom { var userRole = frameworkService.GetAdminUserRoleForFrameworkId(GetAdminId(), frameworkId); if (userRole < 2) return StatusCode(403); - frameworkService.DeleteFrameworkCompetency(frameworkCompetencyId, GetAdminId()); + frameworkService.DeleteFrameworkCompetency(frameworkCompetencyId, frameworkCompetencyGroupId, frameworkId, GetAdminId()); return frameworkCompetencyGroupId != null ? new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId, frameworkCompetencyGroupId }) + "#fcgroup-" + frameworkCompetencyGroupId.ToString()) : new RedirectResult(Url.Action("ViewFramework", new { tabname = "Structure", frameworkId }) + "#fc-ungrouped"); } [Route("/Frameworks/{frameworkId}/Competency/{frameworkCompetencyGroupId:int=0}/{frameworkCompetencyId}/Preview/")] diff --git a/DigitalLearningSolutions.Web/Services/FrameworkService.cs b/DigitalLearningSolutions.Web/Services/FrameworkService.cs index b407be417f..6e2c1790e9 100644 --- a/DigitalLearningSolutions.Web/Services/FrameworkService.cs +++ b/DigitalLearningSolutions.Web/Services/FrameworkService.cs @@ -247,9 +247,9 @@ string direction void RemoveCustomFlag(int flagId); void RemoveCollaboratorFromFramework(int frameworkId, int id); - void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int adminId); + void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int frameworkId, int adminId); - void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId); + void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId); void DeleteFrameworkDefaultQuestion( int frameworkId, @@ -316,14 +316,14 @@ public void DeleteCompetencyLearningResource(int competencyLearningResourceId, i frameworkDataService.DeleteCompetencyLearningResource(competencyLearningResourceId, adminId); } - public void DeleteFrameworkCompetency(int frameworkCompetencyId, int adminId) + public void DeleteFrameworkCompetency(int frameworkCompetencyId, int? frameworkCompetencyGroupId, int frameworkId, int adminId) { - frameworkDataService.DeleteFrameworkCompetency(frameworkCompetencyId, adminId); + frameworkDataService.DeleteFrameworkCompetency(frameworkCompetencyId, frameworkCompetencyGroupId, frameworkId, adminId); } - public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int adminId) + public void DeleteFrameworkCompetencyGroup(int frameworkCompetencyGroupId, int competencyGroupId, int frameworkId, int adminId) { - frameworkDataService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, adminId); + frameworkDataService.DeleteFrameworkCompetencyGroup(frameworkCompetencyGroupId, competencyGroupId, frameworkId, adminId); } public void DeleteFrameworkDefaultQuestion(int frameworkId, int assessmentQuestionId, int adminId, bool deleteFromExisting)