From d1a9606c5ca642a6c737b17109c8a4f683800cb4 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 20 Jan 2024 17:58:24 -0500 Subject: [PATCH] Tweak admin theme changes - Fix SQLite posts-by-tag query - Fix "on disk" check for default theme --- src/MyWebLog.Data/SQLite/SQLitePostData.fs | 2 +- src/MyWebLog.Domain/ViewModels.fs | 3 ++- src/MyWebLog.Tests/ViewModelsTests.fs | 19 ++++++++++++++++--- src/admin-theme/custom-feed-edit.liquid | 8 ++++---- src/admin-theme/settings.liquid | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/MyWebLog.Data/SQLite/SQLitePostData.fs b/src/MyWebLog.Data/SQLite/SQLitePostData.fs index e5ab713..d2d5f0d 100644 --- a/src/MyWebLog.Data/SQLite/SQLitePostData.fs +++ b/src/MyWebLog.Data/SQLite/SQLitePostData.fs @@ -145,7 +145,7 @@ type SQLitePostData(conn: SqliteConnection, log: ILogger) = let tagSql, tagParams = inJsonArray Table.Post (nameof Post.Empty.Tags) "tag" [ tag ] conn.customList $"{publishedPostByWebLog} AND {tagSql} - ORDER BY p.published_on DESC + ORDER BY {publishField} DESC LIMIT {postsPerPage + 1} OFFSET {(pageNbr - 1) * postsPerPage}" (webLogParam webLogId :: tagParams) fromData diff --git a/src/MyWebLog.Domain/ViewModels.fs b/src/MyWebLog.Domain/ViewModels.fs index b7620c9..f0036ee 100644 --- a/src/MyWebLog.Domain/ViewModels.fs +++ b/src/MyWebLog.Domain/ViewModels.fs @@ -205,12 +205,13 @@ type DisplayTheme = { /// Create a display theme from a theme static member FromTheme inUseFunc (theme: Theme) = + let fileName = if string theme.Id = "default" then "default-theme.zip" else $"./themes/{theme.Id}-theme.zip" { Id = string theme.Id Name = theme.Name Version = theme.Version TemplateCount = List.length theme.Templates IsInUse = inUseFunc theme.Id - IsOnDisk = File.Exists $"{theme.Id}-theme.zip" } + IsOnDisk = File.Exists fileName } /// Information about an uploaded file used for display diff --git a/src/MyWebLog.Tests/ViewModelsTests.fs b/src/MyWebLog.Tests/ViewModelsTests.fs index 44847e4..6bc7ecf 100644 --- a/src/MyWebLog.Tests/ViewModelsTests.fs +++ b/src/MyWebLog.Tests/ViewModelsTests.fs @@ -175,8 +175,9 @@ let displayThemeTests = testList "DisplayTheme.FromTheme" [ Expect.isTrue model.IsInUse "IsInUse should have been set" Expect.isFalse model.IsOnDisk "IsOnDisk should not have been set" } - test "succeeds when the theme is not in use as is on disk" { - let file = File.Create "another-theme.zip" + test "succeeds when a non-default theme is not in use and is on disk" { + let dir = Directory.CreateDirectory "themes" + let file = File.Create "./themes/another-theme.zip" try let model = DisplayTheme.FromTheme (fun _ -> false) { theme with Id = ThemeId "another" } Expect.isFalse model.IsInUse "IsInUse should not have been set" @@ -184,7 +185,19 @@ let displayThemeTests = testList "DisplayTheme.FromTheme" [ finally file.Close() file.Dispose() - File.Delete "another-theme.zip" + File.Delete "./themes/another-theme.zip" + dir.Delete() + } + test "succeeds when the default theme is on disk" { + let file = File.Create "./default-theme.zip" + try + Expect.isTrue + (DisplayTheme.FromTheme (fun _ -> false) { theme with Id = ThemeId "default" }).IsOnDisk + "IsOnDisk should have been set" + finally + file.Close() + file.Dispose() + File.Delete "./default-theme.zip" } ] diff --git a/src/admin-theme/custom-feed-edit.liquid b/src/admin-theme/custom-feed-edit.liquid index 507e8cf..20d4297 100644 --- a/src/admin-theme/custom-feed-edit.liquid +++ b/src/admin-theme/custom-feed-edit.liquid @@ -28,7 +28,7 @@
+ {%- if model.is_podcast %} checked{% endif %} onclick="Admin.checkPodcast()">
@@ -42,7 +42,7 @@
+ {%- unless typ == "tag" %} checked{% endunless %} onclick="Admin.customFeedBy('category')">
@@ -67,14 +67,14 @@
+ {%- if typ == "tag" %} checked{% endif %} onclick="Admin.customFeedBy('tag')">
diff --git a/src/admin-theme/settings.liquid b/src/admin-theme/settings.liquid index e9a03cc..ec70201 100644 --- a/src/admin-theme/settings.liquid +++ b/src/admin-theme/settings.liquid @@ -145,7 +145,7 @@
+ {%- if rss_model.is_tag_enabled %} checked{% endif %}>