111 lines
2.1 KiB
Swift
111 lines
2.1 KiB
Swift
import Foundation
|
|
|
|
final class Page: ObservableObject {
|
|
|
|
unowned let content: Content
|
|
|
|
/**
|
|
The unique id of the entry
|
|
*/
|
|
@Published
|
|
var id: String
|
|
|
|
@Published
|
|
var isDraft: Bool
|
|
|
|
@Published
|
|
var createdDate: Date
|
|
|
|
@Published
|
|
var startDate: Date
|
|
|
|
@Published
|
|
var hasEndDate: Bool
|
|
|
|
@Published
|
|
var endDate: Date
|
|
|
|
@Published
|
|
var german: LocalizedPage
|
|
|
|
@Published
|
|
var english: LocalizedPage
|
|
|
|
@Published
|
|
var tags: [Tag]
|
|
|
|
/**
|
|
Additional images required by the element.
|
|
|
|
These images are specified as: `source_name destination_name width (height)`.
|
|
*/
|
|
@Published
|
|
var images: Set<String> = []
|
|
|
|
init(content: Content,
|
|
id: String,
|
|
isDraft: Bool,
|
|
createdDate: Date,
|
|
startDate: Date,
|
|
endDate: Date?,
|
|
german: LocalizedPage,
|
|
english: LocalizedPage,
|
|
tags: [Tag]) {
|
|
self.content = content
|
|
self.id = id
|
|
self.isDraft = isDraft
|
|
self.createdDate = createdDate
|
|
self.startDate = startDate
|
|
self.hasEndDate = endDate != nil
|
|
self.endDate = endDate ?? startDate
|
|
self.german = german
|
|
self.english = english
|
|
self.tags = tags
|
|
}
|
|
|
|
func localized(in language: ContentLanguage) -> LocalizedPage {
|
|
switch language {
|
|
case .german: return german
|
|
case .english: return english
|
|
}
|
|
}
|
|
|
|
func update(id newId: String) -> Bool {
|
|
guard content.storage.move(page: id, to: newId) else {
|
|
print("Failed to move file of page \(id)")
|
|
return false
|
|
}
|
|
id = newId
|
|
return true
|
|
}
|
|
}
|
|
|
|
extension Page: Identifiable {
|
|
|
|
}
|
|
|
|
extension Page: Equatable {
|
|
|
|
static func == (lhs: Page, rhs: Page) -> Bool {
|
|
lhs.id == rhs.id
|
|
}
|
|
}
|
|
|
|
extension Page: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
hasher.combine(id)
|
|
}
|
|
}
|
|
|
|
extension Page: Comparable {
|
|
|
|
static func < (lhs: Page, rhs: Page) -> Bool {
|
|
lhs.id < rhs.id
|
|
}
|
|
}
|
|
|
|
extension Page: DateItem {
|
|
|
|
}
|