|
|
@@ -8,52 +8,52 @@
|
|
|
import Foundation
|
|
|
import SwiftData
|
|
|
|
|
|
-enum Status : String, CaseIterable, Identifiable, Codable {
|
|
|
+enum Status: String, CaseIterable, Identifiable, Codable {
|
|
|
case Todo = " "
|
|
|
case Complete = "V"
|
|
|
case InProgress = "C"
|
|
|
case Hiatus = "H"
|
|
|
case Waiting = "R"
|
|
|
-
|
|
|
+
|
|
|
var id: Self { self }
|
|
|
var description: String { self.rawValue }
|
|
|
var isStrong: Bool {
|
|
|
self == .Complete || self == .Hiatus || self == .Waiting
|
|
|
}
|
|
|
var label: String {
|
|
|
- switch (self) {
|
|
|
- case .Todo: return "square.and.pencil"
|
|
|
- case .Complete: return "checkmark"
|
|
|
- case .InProgress: return "ellipsis.circle"
|
|
|
- case .Hiatus: return "clock.badge.questionmark"
|
|
|
- case .Waiting: return "airplane.circle"
|
|
|
+ switch self {
|
|
|
+ case .Todo: return "square.and.pencil"
|
|
|
+ case .Complete: return "checkmark"
|
|
|
+ case .InProgress: return "ellipsis.circle"
|
|
|
+ case .Hiatus: return "clock.badge.questionmark"
|
|
|
+ case .Waiting: return "airplane.circle"
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Model
|
|
|
-final class SubTask : Codable {
|
|
|
+final class SubTask: Codable {
|
|
|
var name: String
|
|
|
var task: Task?
|
|
|
var notes: String = ""
|
|
|
var status: Status = Status.Todo
|
|
|
-
|
|
|
+
|
|
|
init(name: String, parent: Task? = nil) {
|
|
|
self.name = name
|
|
|
self.task = parent
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func yaml(_ indent: Int = 0) -> String {
|
|
|
- let h1 = String(repeating: " ", count: indent)
|
|
|
- let h2 = String(repeating: " ", count: indent + 1)
|
|
|
- var rval = h1 + "- [\(status.rawValue)] \(name)\n"
|
|
|
+ let hdr = String(repeating: " ", count: indent)
|
|
|
+ let subhdr = hdr + " # "
|
|
|
+ var rval = hdr + "- [\(status.rawValue)] \(name)\n"
|
|
|
if !notes.isEmpty {
|
|
|
- rval += h2 + "# " + notes.replacingOccurrences(of: "\n", with: "\n" + h2 + "# ") + "\n"
|
|
|
+ rval += subhdr + notes.replacingOccurrences(of: "\n", with: "\n" + subhdr) + "\n"
|
|
|
}
|
|
|
return rval
|
|
|
}
|
|
|
|
|
|
- enum CodingKeys : CodingKey { case name, notes, status }
|
|
|
+ enum CodingKeys: CodingKey { case name, notes, status }
|
|
|
|
|
|
required init(from decoder: any Decoder) throws {
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
@@ -71,7 +71,7 @@ final class SubTask : Codable {
|
|
|
}
|
|
|
|
|
|
@Model
|
|
|
-final class Tag : Codable {
|
|
|
+final class Tag: Codable {
|
|
|
var id: String
|
|
|
var task: Task?
|
|
|
|
|
|
@@ -95,7 +95,7 @@ final class Tag : Codable {
|
|
|
}
|
|
|
|
|
|
@Model
|
|
|
-final class Task : Codable {
|
|
|
+final class Task: Codable {
|
|
|
var name: String
|
|
|
var project: Project?
|
|
|
var category: String = ""
|
|
|
@@ -105,26 +105,26 @@ final class Task : Codable {
|
|
|
var subtasks: [SubTask] = []
|
|
|
var notes: String = ""
|
|
|
var status: Status = Status.Todo
|
|
|
-
|
|
|
+
|
|
|
init(name: String, parent: Project? = nil) {
|
|
|
self.name = name
|
|
|
self.project = parent
|
|
|
self.category = parent?.category ?? ""
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func yaml(_ indent: Int = 0) -> String {
|
|
|
- let h1 = String(repeating: " ", count: indent)
|
|
|
- let h2 = String(repeating: " ", count: indent + 1)
|
|
|
- var rval = h1 + "[\(status.rawValue)] \(name) "
|
|
|
+ let hdr = String(repeating: " ", count: indent)
|
|
|
+ let subhdr = hdr + " # "
|
|
|
+ var rval = hdr + "[\(status.rawValue)] \(name) "
|
|
|
rval += "(\(tags.map(\.id).joined(separator: " ")))\n"
|
|
|
if !notes.isEmpty {
|
|
|
- rval += h2 + "# " + notes.replacingOccurrences(of: "\n", with: "\n" + h2 + "# ") + "\n"
|
|
|
+ rval += subhdr + notes.replacingOccurrences(of: "\n", with: "\n" + subhdr) + "\n"
|
|
|
}
|
|
|
rval += subtasks.map({ $0.yaml(indent + 1) }).joined()
|
|
|
return rval
|
|
|
}
|
|
|
-
|
|
|
- enum CodingKeys : CodingKey { case name, category, tags, subtasks, notes, status }
|
|
|
+
|
|
|
+ enum CodingKeys: CodingKey { case name, category, tags, subtasks, notes, status }
|
|
|
|
|
|
required init(from decoder: any Decoder) throws {
|
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
@@ -135,7 +135,7 @@ final class Task : Codable {
|
|
|
notes = try container.decode(String.self, forKey: .notes)
|
|
|
status = try container.decode(Status.self, forKey: .status)
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
func encode(to encoder: any Encoder) throws {
|
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
|
try container.encode(name, forKey: .name)
|