Tweak admin theme changes

- Fix SQLite posts-by-tag query
- Fix "on disk" check for default theme
This commit is contained in:
Daniel J. Summers 2024-01-20 17:58:24 -05:00
parent 5ce84e18ca
commit d1a9606c5c
5 changed files with 24 additions and 10 deletions

View File

@ -145,7 +145,7 @@ type SQLitePostData(conn: SqliteConnection, log: ILogger) =
let tagSql, tagParams = inJsonArray Table.Post (nameof Post.Empty.Tags) "tag" [ tag ] let tagSql, tagParams = inJsonArray Table.Post (nameof Post.Empty.Tags) "tag" [ tag ]
conn.customList conn.customList
$"{publishedPostByWebLog} AND {tagSql} $"{publishedPostByWebLog} AND {tagSql}
ORDER BY p.published_on DESC ORDER BY {publishField} DESC
LIMIT {postsPerPage + 1} OFFSET {(pageNbr - 1) * postsPerPage}" LIMIT {postsPerPage + 1} OFFSET {(pageNbr - 1) * postsPerPage}"
(webLogParam webLogId :: tagParams) (webLogParam webLogId :: tagParams)
fromData<Post> fromData<Post>

View File

@ -205,12 +205,13 @@ type DisplayTheme = {
/// Create a display theme from a theme /// Create a display theme from a theme
static member FromTheme inUseFunc (theme: 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 { Id = string theme.Id
Name = theme.Name Name = theme.Name
Version = theme.Version Version = theme.Version
TemplateCount = List.length theme.Templates TemplateCount = List.length theme.Templates
IsInUse = inUseFunc theme.Id IsInUse = inUseFunc theme.Id
IsOnDisk = File.Exists $"{theme.Id}-theme.zip" } IsOnDisk = File.Exists fileName }
/// Information about an uploaded file used for display /// Information about an uploaded file used for display

View File

@ -175,8 +175,9 @@ let displayThemeTests = testList "DisplayTheme.FromTheme" [
Expect.isTrue model.IsInUse "IsInUse should have been set" Expect.isTrue model.IsInUse "IsInUse should have been set"
Expect.isFalse model.IsOnDisk "IsOnDisk should not 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" { test "succeeds when a non-default theme is not in use and is on disk" {
let file = File.Create "another-theme.zip" let dir = Directory.CreateDirectory "themes"
let file = File.Create "./themes/another-theme.zip"
try try
let model = DisplayTheme.FromTheme (fun _ -> false) { theme with Id = ThemeId "another" } let model = DisplayTheme.FromTheme (fun _ -> false) { theme with Id = ThemeId "another" }
Expect.isFalse model.IsInUse "IsInUse should not have been set" Expect.isFalse model.IsInUse "IsInUse should not have been set"
@ -184,7 +185,19 @@ let displayThemeTests = testList "DisplayTheme.FromTheme" [
finally finally
file.Close() file.Close()
file.Dispose() 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"
} }
] ]

View File

@ -28,7 +28,7 @@
<div class="col py-3 d-flex align-self-center justify-content-center"> <div class="col py-3 d-flex align-self-center justify-content-center">
<div class="form-check form-switch"> <div class="form-check form-switch">
<input type=checkbox name=IsPodcast id=isPodcast class=form-check-input value=true <input type=checkbox name=IsPodcast id=isPodcast class=form-check-input value=true
{%- if model.is_podcast %} checked {% endif %}onclick="Admin.checkPodcast()"> {%- if model.is_podcast %} checked{% endif %} onclick="Admin.checkPodcast()">
<label for=isPodcast class=form-check-label>This Is a Podcast Feed</label> <label for=isPodcast class=form-check-label>This Is a Podcast Feed</label>
</div> </div>
</div> </div>
@ -42,7 +42,7 @@
<div class="col-1 d-flex justify-content-end pb-3"> <div class="col-1 d-flex justify-content-end pb-3">
<div class="form-check form-check-inline me-0"> <div class="form-check form-check-inline me-0">
<input type=radio name=SourceType id=sourceTypeCat class=form-check-input value=category <input type=radio name=SourceType id=sourceTypeCat class=form-check-input value=category
{%- unless typ == "tag" %} checked {% endunless -%}onclick="Admin.customFeedBy('category')"> {%- unless typ == "tag" %} checked{% endunless %} onclick="Admin.customFeedBy('category')">
<label for=sourceTypeCat class="form-check-label d-none">Category</label> <label for=sourceTypeCat class="form-check-label d-none">Category</label>
</div> </div>
</div> </div>
@ -67,14 +67,14 @@
<div class="col-1 d-flex justify-content-end pb-3"> <div class="col-1 d-flex justify-content-end pb-3">
<div class="form-check form-check-inline me-0"> <div class="form-check form-check-inline me-0">
<input type=radio name=SourceType id=sourceTypeTag class=form-check-input value=tag <input type=radio name=SourceType id=sourceTypeTag class=form-check-input value=tag
{%- if typ == "tag" %} checked {% endif %}onclick="Admin.customFeedBy('tag')"> {%- if typ == "tag" %} checked{% endif %} onclick="Admin.customFeedBy('tag')">
<label for="sourceTypeTag" class="form-check-label d-none">Tag</label> <label for="sourceTypeTag" class="form-check-label d-none">Tag</label>
</div> </div>
</div> </div>
<div class="col-11 pb-3"> <div class="col-11 pb-3">
<div class=form-floating> <div class=form-floating>
<input type=text name=SourceValue id=sourceValueTag class=form-control placeholder=Tag <input type=text name=SourceValue id=sourceValueTag class=form-control placeholder=Tag
{%- unless typ == "tag" %} disabled {% endunless %}required {%- unless typ == "tag" %} disabled{% endunless %} required
{%- if typ == "tag" %} value="{{ model.source_value }}"{% endif %}> {%- if typ == "tag" %} value="{{ model.source_value }}"{% endif %}>
<label for=sourceValueTag>Tag</label> <label for=sourceValueTag>Tag</label>
</div> </div>

View File

@ -145,7 +145,7 @@
</div> </div>
<div class="form-check form-switch pb-2"> <div class="form-check form-switch pb-2">
<input type=checkbox name=IsTagEnabled id=tagEnabled class=form-check-input value=true <input type=checkbox name=IsTagEnabled id=tagEnabled class=form-check-input value=true
{%- if rss_model.tag_enabled %} checked{% endif %}> {%- if rss_model.is_tag_enabled %} checked{% endif %}>
<label for=tagEnabled class=form-check-label>Posts by Tag</label> <label for=tagEnabled class=form-check-label>Posts by Tag</label>
</div> </div>
</fieldset> </fieldset>