Improve display of results
This commit is contained in:
@ -22,57 +22,76 @@ final class PageGenerationResults: ObservableObject {
|
||||
private unowned let delegate: GenerationResults
|
||||
|
||||
/// The files that could not be accessed
|
||||
@Published
|
||||
private(set) var inaccessibleFiles: Set<FileResource>
|
||||
|
||||
/// The files that could not be parsed, with the error message produced
|
||||
@Published
|
||||
private(set) var unparsableFiles: [FileResource : Set<String>]
|
||||
|
||||
/// The missing files directly used by this page, and the source of the file
|
||||
@Published
|
||||
private(set) var missingFiles: [String: Set<String>]
|
||||
|
||||
/// The missing files linked to from other files.
|
||||
@Published
|
||||
private(set) var missingLinkedFiles: [String : Set<FileResource>]
|
||||
|
||||
/// The missing tags linked to by this page, and the source of the link
|
||||
@Published
|
||||
private(set) var missingLinkedTags: [String : Set<String>]
|
||||
|
||||
/// The missing pages linked to by this page, and the source of the link
|
||||
@Published
|
||||
private(set) var missingLinkedPages: [String : Set<String>]
|
||||
|
||||
/// The footer scripts or html to add to the end of the body
|
||||
@Published
|
||||
private(set) var requiredFooters: Set<String>
|
||||
|
||||
/// The known header elements to include in the page
|
||||
@Published
|
||||
private(set) var requiredHeaders: Set<KnownHeaderElement>
|
||||
|
||||
/// The known icons that need to be included as hidden SVGs
|
||||
@Published
|
||||
private(set) var requiredIcons: Set<PageIcon>
|
||||
|
||||
/// The pages linked to by the page
|
||||
@Published
|
||||
private(set) var linkedPages: Set<Page>
|
||||
|
||||
/// The tags linked to by this page
|
||||
@Published
|
||||
private(set) var linkedTags: Set<Tag>
|
||||
|
||||
/// The links to external content in this page
|
||||
@Published
|
||||
private(set) var externalLinks: Set<String>
|
||||
|
||||
/// The files used by this page, but not necessarily required in the output folder
|
||||
@Published
|
||||
private(set) var usedFiles: Set<FileResource>
|
||||
|
||||
/// The files that need to be copied
|
||||
@Published
|
||||
private(set) var requiredFiles: Set<FileResource>
|
||||
|
||||
/// The image versions required for this page
|
||||
@Published
|
||||
private(set) var imagesToGenerate: Set<ImageVersion>
|
||||
|
||||
@Published
|
||||
private(set) var invalidCommands: [(command: CommandType?, markdown: String)]
|
||||
|
||||
@Published
|
||||
private(set) var invalidBlocks: [(block: ContentBlock?, markdown: String)]
|
||||
|
||||
@Published
|
||||
private(set) var warnings: Set<String>
|
||||
|
||||
/// The files that could not be saved to the output folder
|
||||
@Published
|
||||
private(set) var unsavedOutputFiles: [String: Set<ItemReference>] = [:]
|
||||
|
||||
private(set) var pageIsEmpty: Bool
|
||||
@ -105,159 +124,167 @@ final class PageGenerationResults: ObservableObject {
|
||||
redirect = nil
|
||||
}
|
||||
|
||||
func onMain(_ operation: @escaping () -> Void) {
|
||||
DispatchQueue.main.async {
|
||||
operation()
|
||||
}
|
||||
}
|
||||
|
||||
func reset() {
|
||||
inaccessibleFiles = []
|
||||
unparsableFiles = [:]
|
||||
missingFiles = [:]
|
||||
missingLinkedFiles = [:]
|
||||
missingLinkedTags = [:]
|
||||
missingLinkedPages = [:]
|
||||
requiredHeaders = []
|
||||
requiredFooters = []
|
||||
requiredIcons = []
|
||||
linkedPages = []
|
||||
linkedTags = []
|
||||
externalLinks = []
|
||||
usedFiles = []
|
||||
requiredFiles = []
|
||||
imagesToGenerate = []
|
||||
invalidCommands = []
|
||||
invalidBlocks = []
|
||||
warnings = []
|
||||
unsavedOutputFiles = [:]
|
||||
pageIsEmpty = false
|
||||
redirect = nil
|
||||
onMain {
|
||||
self.inaccessibleFiles = []
|
||||
self.unparsableFiles = [:]
|
||||
self.missingFiles = [:]
|
||||
self.missingLinkedFiles = [:]
|
||||
self.missingLinkedTags = [:]
|
||||
self.missingLinkedPages = [:]
|
||||
self.requiredHeaders = []
|
||||
self.requiredFooters = []
|
||||
self.requiredIcons = []
|
||||
self.linkedPages = []
|
||||
self.linkedTags = []
|
||||
self.externalLinks = []
|
||||
self.usedFiles = []
|
||||
self.requiredFiles = []
|
||||
self.imagesToGenerate = []
|
||||
self.invalidCommands = []
|
||||
self.invalidBlocks = []
|
||||
self.warnings = []
|
||||
self.unsavedOutputFiles = [:]
|
||||
self.pageIsEmpty = false
|
||||
self.redirect = nil
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Adding entries
|
||||
|
||||
func inaccessibleContent(file: FileResource) {
|
||||
inaccessibleFiles.insert(file)
|
||||
onMain { self.inaccessibleFiles.insert(file) }
|
||||
delegate.inaccessibleContent(file: file)
|
||||
}
|
||||
|
||||
func invalid(command: CommandType?, _ markdown: Substring) {
|
||||
let markdown = String(markdown)
|
||||
invalidCommands.append((command, markdown))
|
||||
onMain { self.invalidCommands.append((command, markdown)) }
|
||||
delegate.invalidCommand(markdown)
|
||||
}
|
||||
|
||||
func invalid(block: ContentBlock?, _ markdown: Substring) {
|
||||
let markdown = String(markdown)
|
||||
invalidBlocks.append((block, markdown))
|
||||
onMain { self.invalidBlocks.append((block, markdown)) }
|
||||
delegate.invalidBlock(markdown)
|
||||
}
|
||||
|
||||
func missing(page: String, source: String) {
|
||||
missingLinkedPages[page, default: []].insert(source)
|
||||
onMain { self.missingLinkedPages[page, default: []].insert(source) }
|
||||
delegate.missing(page: page)
|
||||
}
|
||||
|
||||
func missing(tag: String, source: String) {
|
||||
missingLinkedTags[tag, default: []].insert(source)
|
||||
onMain { self.missingLinkedTags[tag, default: []].insert(source) }
|
||||
delegate.missing(tag: tag)
|
||||
}
|
||||
|
||||
func missing(file: String, source: String) {
|
||||
missingFiles[file, default: []].insert(source)
|
||||
onMain { self.missingFiles[file, default: []].insert(source) }
|
||||
delegate.missing(file: file)
|
||||
}
|
||||
|
||||
func require(image: ImageVersion) {
|
||||
imagesToGenerate.insert(image)
|
||||
onMain { self.imagesToGenerate.insert(image) }
|
||||
used(file: image.image)
|
||||
delegate.generate(image)
|
||||
}
|
||||
|
||||
func require(imageSet: ImageSet) {
|
||||
let jobs = imageSet.jobs
|
||||
imagesToGenerate.formUnion(jobs)
|
||||
onMain { self.imagesToGenerate.formUnion(jobs) }
|
||||
used(file: imageSet.image)
|
||||
delegate.generate(jobs)
|
||||
}
|
||||
|
||||
func invalidFormat(file: FileResource, error: String) {
|
||||
unparsableFiles[file, default: []].insert(error)
|
||||
onMain { self.unparsableFiles[file, default: []].insert(error) }
|
||||
delegate.unparsable(file: file)
|
||||
}
|
||||
|
||||
func missing(file: String, containedIn sourceFile: FileResource) {
|
||||
missingLinkedFiles[file, default: []].insert(sourceFile)
|
||||
onMain { self.missingLinkedFiles[file, default: []].insert(sourceFile) }
|
||||
delegate.missing(file: file)
|
||||
}
|
||||
|
||||
func used(file: FileResource) {
|
||||
usedFiles.insert(file)
|
||||
onMain { self.usedFiles.insert(file) }
|
||||
// TODO: Notify delegate
|
||||
}
|
||||
|
||||
func require(file: FileResource) {
|
||||
requiredFiles.insert(file)
|
||||
usedFiles.insert(file)
|
||||
onMain { self.requiredFiles.insert(file) }
|
||||
used(file: file)
|
||||
delegate.require(file: file)
|
||||
}
|
||||
|
||||
func require(files: [FileResource]) {
|
||||
requiredFiles.formUnion(files)
|
||||
usedFiles.formUnion(files)
|
||||
onMain { self.requiredFiles.formUnion(files) }
|
||||
onMain { self.usedFiles.formUnion(files) }
|
||||
delegate.require(files: files)
|
||||
}
|
||||
|
||||
func require(footer: String) {
|
||||
requiredFooters.insert(footer)
|
||||
onMain { self.requiredFooters.insert(footer) }
|
||||
}
|
||||
|
||||
func require(header: KnownHeaderElement) {
|
||||
requiredHeaders.insert(header)
|
||||
onMain { self.requiredHeaders.insert(header) }
|
||||
}
|
||||
|
||||
func require(headers: KnownHeaderElement...) {
|
||||
requiredHeaders.formUnion(headers)
|
||||
onMain { self.requiredHeaders.formUnion(headers) }
|
||||
}
|
||||
|
||||
func require(icon: PageIcon) {
|
||||
requiredIcons.insert(icon)
|
||||
onMain { self.requiredIcons.insert(icon) }
|
||||
}
|
||||
|
||||
func require(icons: PageIcon...) {
|
||||
requiredIcons.formUnion(icons)
|
||||
onMain { self.requiredIcons.formUnion(icons) }
|
||||
}
|
||||
|
||||
func require(icons: [PageIcon]) {
|
||||
requiredIcons.formUnion(icons)
|
||||
onMain { self.requiredIcons.formUnion(icons) }
|
||||
}
|
||||
|
||||
func linked(to page: Page) {
|
||||
linkedPages.insert(page)
|
||||
onMain { self.linkedPages.insert(page) }
|
||||
}
|
||||
|
||||
func linked(to tag: Tag) {
|
||||
linkedTags.insert(tag)
|
||||
onMain { self.linkedTags.insert(tag) }
|
||||
}
|
||||
|
||||
func externalLink(to url: String) {
|
||||
externalLinks.insert(url)
|
||||
onMain { self.externalLinks.insert(url) }
|
||||
delegate.externalLink(url)
|
||||
}
|
||||
|
||||
func warning(_ warning: String) {
|
||||
warnings.insert(warning)
|
||||
onMain { self.warnings.insert(warning) }
|
||||
delegate.warning(warning)
|
||||
}
|
||||
|
||||
func unsavedOutput(_ path: String, source: ItemReference) {
|
||||
unsavedOutputFiles[path, default: []].insert(source)
|
||||
onMain { self.unsavedOutputFiles[path, default: []].insert(source) }
|
||||
delegate.unsaved(path)
|
||||
}
|
||||
|
||||
func markPageAsEmpty() {
|
||||
guard case .page(let page) = itemId.itemType else { return }
|
||||
pageIsEmpty = true
|
||||
onMain { self.pageIsEmpty = true }
|
||||
delegate.empty(.init(language: itemId.language, pageId: page.id))
|
||||
}
|
||||
|
||||
func redirect(from originalUrl: String, to newUrl: String) {
|
||||
redirect = (originalUrl, newUrl)
|
||||
onMain { self.redirect = (originalUrl, newUrl) }
|
||||
delegate.redirect(from: originalUrl, to: newUrl)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user