From 9568e7ec23b2f07a8c445b5900c7882de914affa Mon Sep 17 00:00:00 2001 From: Nick Beckley Date: Sun, 8 Nov 2026 23:28:59 +0000 Subject: [PATCH] Expose authorised recorded book metrics without Timeline default filling --- PlotLine/Data/Repositories.cs | 7 +++++ .../Sql/244_WritingContextRecordedMetrics.sql | 28 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 PlotLine/Sql/244_WritingContextRecordedMetrics.sql diff --git a/PlotLine/Data/Repositories.cs b/PlotLine/Data/Repositories.cs index 25d45bf1..0c7618ab 100644 --- a/PlotLine/Data/Repositories.cs +++ b/PlotLine/Data/Repositories.cs @@ -89,6 +89,7 @@ public interface ISceneRepository Task UpdatePovCharacterAsync(int sceneId, int? povCharacterId, string source = "Author", decimal? confidence = null, string? evidence = null, string? suggestedName = null, bool overwriteAuthor = false); Task SaveFloorPlanLinkAsync(int sceneId, int? floorPlanId, int? initialFloorPlanFloorId); Task SavePurposesAsync(int sceneId, IEnumerable purposeIds); + Task> ListRecordedMetricsByBookAsync(int bookId, int userId); Task SaveMetricValuesAsync(int sceneId, IEnumerable metricValues); Task SaveMetricValueAsync(int sceneId, int metricTypeId, int value); Task ArchiveAsync(int sceneId); @@ -2644,6 +2645,12 @@ public sealed class SceneRepository(ISqlConnectionFactory connectionFactory) : I commandType: CommandType.StoredProcedure); } + public async Task> ListRecordedMetricsByBookAsync(int bookId,int userId) + { + using var connection=connectionFactory.CreateConnection(); + return (await connection.QueryAsync("dbo.SceneMetric_ListRecordedForBook",new{BookID=bookId,UserID=userId},commandType:CommandType.StoredProcedure)).ToList(); + } + public async Task SaveMetricValuesAsync(int sceneId, IEnumerable metricValues) { using var connection = connectionFactory.CreateConnection(); diff --git a/PlotLine/Sql/244_WritingContextRecordedMetrics.sql b/PlotLine/Sql/244_WritingContextRecordedMetrics.sql new file mode 100644 index 00000000..8129d45a --- /dev/null +++ b/PlotLine/Sql/244_WritingContextRecordedMetrics.sql @@ -0,0 +1,28 @@ +-- Read-only projection: actual saved values, including custom metrics; no Timeline default filling. +SET ANSI_NULLS ON; +SET QUOTED_IDENTIFIER ON; +GO +CREATE OR ALTER PROCEDURE dbo.SceneMetric_ListRecordedForBook + @BookID int, + @UserID int +AS +BEGIN + SET NOCOUNT ON; + DECLARE @ProjectID int; + SELECT @ProjectID=b.ProjectID + FROM dbo.Books b + WHERE b.BookID=@BookID + AND EXISTS(SELECT 1 FROM dbo.ProjectUserAccess a WHERE a.ProjectID=b.ProjectID AND a.UserID=@UserID AND a.IsActive=1); + IF @ProjectID IS NULL THROW 51000,'Book access denied',1; + + SELECT stored.SceneID,stored.MetricTypeID,metric.MetricName,metric.MinValue,metric.MaxValue, + metric.DefaultValue,metric.SortOrder,metric.IsActive,stored.Value,stored.Notes + FROM dbo.SceneMetricValues stored + INNER JOIN dbo.SceneMetricTypes metric ON metric.MetricTypeID=stored.MetricTypeID + INNER JOIN dbo.Scenes scene ON scene.SceneID=stored.SceneID + INNER JOIN dbo.Chapters chapter ON chapter.ChapterID=scene.ChapterID + WHERE chapter.BookID=@BookID AND chapter.IsArchived=0 AND scene.IsArchived=0 + AND metric.IsActive=1 AND (metric.ProjectID IS NULL OR metric.ProjectID=@ProjectID) + ORDER BY metric.SortOrder,metric.MetricName,chapter.SortOrder,chapter.ChapterNumber,scene.SortOrder,scene.SceneNumber,scene.SceneID; +END; +GO