| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- //
- // Task.swift
- // Todos
- //
- // Created by Sam Jaffe on 2/28/26.
- //
- import Foundation
- import SwiftData
- enum Status : String, CaseIterable, Identifiable, Codable {
- case Default = " "
- 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
- }
- }
- @Model
- final class SubTask {
- var name: String
- var notes: String = ""
- var status: Status = Status.Default
-
- init(name: String) {
- self.name = name
- }
-
- 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"
- if !notes.isEmpty {
- rval += h2 + "# " + notes.replacingOccurrences(of: "\n", with: "\n" + h2 + "# ")
- }
- return rval
- }
- }
- @Model
- final class Task {
- var name: String
- var tags: [String] = []
- var subtasks: [SubTask] = []
- var notes: String = ""
- var status: Status = Status.Default
-
- init(name: String) {
- self.name = name
- }
-
- func yaml(_ indent: Int = 0) -> String {
- let h1 = String(repeating: " ", count: indent)
- let h2 = String(repeating: " ", count: indent + 1)
- var rval = " [\(status.rawValue)] \(name) (\(tags.joined(separator: " ")))\n"
- if !notes.isEmpty {
- rval += h2 + "# " + notes.replacingOccurrences(of: "\n", with: "\n" + h2 + "# ")
- }
- rval += subtasks.map({ $0.yaml(indent + 1) }).joined()
- return rval
- }
- }
|