Version 2.1 #41

Merged
danieljsummers merged 123 commits from version-2.1 into main 2024-03-27 00:13:28 +00:00
2 changed files with 147 additions and 141 deletions
Showing only changes of commit cbe391fa89 - Show all commits

View File

@ -99,8 +99,7 @@ type DisplayCustomFeed = {
{ Id = string feed.Id
Source = source
Path = string feed.Path
IsPodcast = Option.isSome feed.Podcast
}
IsPodcast = Option.isSome feed.Podcast }
/// Details about a page used to display page lists
@ -138,8 +137,8 @@ type DisplayPage = {
} with
/// Create a minimal display page (no text or metadata) from a database page
static member FromPageMinimal (webLog: WebLog) (page: Page) = {
Id = string page.Id
static member FromPageMinimal (webLog: WebLog) (page: Page) =
{ Id = string page.Id
AuthorId = string page.AuthorId
Title = page.Title
Permalink = string page.Permalink
@ -148,8 +147,7 @@ type DisplayPage = {
IsInPageList = page.IsInPageList
IsDefault = string page.Id = webLog.DefaultPage
Text = ""
Metadata = []
}
Metadata = [] }
/// Create a display page from a database page
static member FromPage webLog page =
@ -173,11 +171,10 @@ type DisplayRevision = {
} with
/// Create a display revision from an actual revision
static member FromRevision (webLog: WebLog) (rev : Revision) = {
AsOf = rev.AsOf.ToDateTimeUtc()
static member FromRevision (webLog: WebLog) (rev : Revision) =
{ AsOf = rev.AsOf.ToDateTimeUtc()
AsOfLocal = webLog.LocalTime rev.AsOf
Format = rev.Text.SourceType
}
Format = rev.Text.SourceType }
open System.IO
@ -205,14 +202,13 @@ type DisplayTheme = {
} with
/// Create a display theme from a theme
static member FromTheme inUseFunc (theme: Theme) = {
Id = string theme.Id
static member FromTheme inUseFunc (theme: Theme) =
{ 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 $"{theme.Id}-theme.zip" }
/// Information about an uploaded file used for display
@ -242,8 +238,7 @@ type DisplayUpload = {
Name = name
Path = path.Replace(name, "")
UpdatedOn = Some (webLog.LocalTime upload.UpdatedOn)
Source = string source
}
Source = string source }
/// View model to display a user's information
@ -278,8 +273,8 @@ type DisplayUser = {
} with
/// Construct a displayed user from a web log user
static member FromUser (webLog: WebLog) (user: WebLogUser) = {
Id = string user.Id
static member FromUser (webLog: WebLog) (user: WebLogUser) =
{ Id = string user.Id
Email = user.Email
FirstName = user.FirstName
LastName = user.LastName
@ -287,8 +282,7 @@ type DisplayUser = {
Url = defaultArg user.Url ""
AccessLevel = string user.AccessLevel
CreatedOn = webLog.LocalTime user.CreatedOn
LastSeenOn = user.LastSeenOn |> Option.map webLog.LocalTime |> Option.toNullable
}
LastSeenOn = user.LastSeenOn |> Option.map webLog.LocalTime |> Option.toNullable }
/// View model for editing categories
@ -311,13 +305,12 @@ type EditCategoryModel = {
} with
/// Create an edit model from an existing category
static member FromCategory (cat: Category) = {
CategoryId = string cat.Id
static member FromCategory (cat: Category) =
{ CategoryId = string cat.Id
Name = cat.Name
Slug = cat.Slug
Description = defaultArg cat.Description ""
ParentId = cat.ParentId |> Option.map string |> Option.defaultValue ""
}
ParentId = cat.ParentId |> Option.map string |> Option.defaultValue "" }
/// Is this a new category?
member this.IsNew =
@ -392,8 +385,8 @@ type EditCustomFeedModel = {
} with
/// An empty custom feed model
static member Empty = {
Id = ""
static member Empty =
{ Id = ""
SourceType = "category"
SourceValue = ""
Path = ""
@ -413,8 +406,7 @@ type EditCustomFeedModel = {
FundingUrl = ""
FundingText = ""
PodcastGuid = ""
Medium = ""
}
Medium = "" }
/// Create a model from a custom feed
static member FromFeed (feed: CustomFeed) =
@ -494,13 +486,12 @@ type EditMyInfoModel = {
} with
/// Create an edit model from a user
static member FromUser (user: WebLogUser) = {
FirstName = user.FirstName
static member FromUser (user: WebLogUser) =
{ FirstName = user.FirstName
LastName = user.LastName
PreferredName = user.PreferredName
NewPassword = ""
NewPasswordConfirm = ""
}
NewPasswordConfirm = "" }
/// View model to edit a page
@ -549,8 +540,7 @@ type EditPageModel = {
Source = latest.Text.SourceType
Text = latest.Text.Text
MetaNames = page.Metadata |> List.map _.Name |> Array.ofList
MetaValues = page.Metadata |> List.map _.Value |> Array.ofList
}
MetaValues = page.Metadata |> List.map _.Value |> Array.ofList }
/// Whether this is a new page
member this.IsNew =
@ -730,8 +720,7 @@ type EditPostModel = {
SeasonNumber = defaultArg episode.SeasonNumber 0
SeasonDescription = defaultArg episode.SeasonDescription ""
EpisodeNumber = defaultArg (episode.EpisodeNumber |> Option.map string) ""
EpisodeDescription = defaultArg episode.EpisodeDescription ""
}
EpisodeDescription = defaultArg episode.EpisodeDescription "" }
/// Whether this is a new post
member this.IsNew =
@ -821,20 +810,18 @@ type EditRedirectRuleModel = {
} with
/// Create a model from an existing rule
static member FromRule idx (rule: RedirectRule) = {
RuleId = idx
static member FromRule idx (rule: RedirectRule) =
{ RuleId = idx
From = rule.From
To = rule.To
IsRegex = rule.IsRegex
InsertAtTop = false
}
InsertAtTop = false }
/// Update a rule with the values from this model
member this.ToRule() = {
From = this.From
member this.ToRule() =
{ From = this.From
To = this.To
IsRegex = this.IsRegex
}
IsRegex = this.IsRegex }
/// View model to edit RSS settings

View File

@ -831,6 +831,24 @@ let editPostModelTests = testList "EditPostModel" [
]
]
/// Unit tests for the EditRedirectRuleModel type
let editRedirectRuleModelTests = testList "EditRedirectRuleModel" [
test "FromRule succeeds" {
let model = EditRedirectRuleModel.FromRule 15 { From = "here"; To = "there"; IsRegex = true }
Expect.equal model.RuleId 15 "RuleId not filled properly"
Expect.equal model.From "here" "From not filled properly"
Expect.equal model.To "there" "To not filled properly"
Expect.isTrue model.IsRegex "IsRegex should have been set"
Expect.isFalse model.InsertAtTop "InsertAtTop should not have been set"
}
test "ToRule succeeds" {
let rule = { RuleId = 10; From = "me"; To = "you"; IsRegex = false; InsertAtTop = false }.ToRule()
Expect.equal rule.From "me" "From not filled properly"
Expect.equal rule.To "you" "To not filled properly"
Expect.isFalse rule.IsRegex "IsRegex should not have been set"
}
]
/// All tests in the Domain.ViewModels file
let all = testList "ViewModels" [
addBaseToRelativeUrlsTests
@ -845,4 +863,5 @@ let all = testList "ViewModels" [
editMyInfoModelTests
editPageModelTests
editPostModelTests
editRedirectRuleModelTests
]