| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- //
- // Task.swift
- // Todos
- //
- // Created by Sam Jaffe on 2/28/26.
- //
- import Foundation
- import SwiftData
- 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"
- }
- }
- }
- @Model
- final class SubTask {
- var name: String
- var notes: String = ""
- var status: Status = Status.Todo
-
- 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
- }
- }
- struct Tag : Codable, Identifiable {
- var id: String
-
- func like(_ str: String) -> Bool {
- return id.caseInsensitiveCompare(str) == .orderedSame
- }
- }
- @Model
- final class Task {
- var name: String
- var tags: [Tag] = []
- var subtasks: [SubTask] = []
- var notes: String = ""
- var status: Status = Status.Todo
-
- 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) "
- rval += "(\(tags.map(\.id).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
- }
- }
|