| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- //
- // SubTask.swift
- // Todos
- //
- // Created by Sam Jaffe on 3/5/26.
- //
- import Foundation
- import SwiftData
- @Model
- final class SubTask: Codable {
- var sortOrder: Int = 0
- var name: String = ""
- var task: Task?
- var notes: String = ""
- var status: Status = Status.todo
- init(parent: Task? = nil) {
- self.task = parent
- self.sortOrder = parent?.subtasks.count ?? 0
- }
- func yaml(_ indent: Int = 0) -> String {
- let hdr = String(repeating: " ", count: indent)
- let subhdr = hdr + " # "
- var rval = hdr + "- [\(status.rawValue)] \(name)\n"
- if !notes.isEmpty {
- rval += subhdr + notes.replacingOccurrences(of: "\n", with: "\n" + subhdr) + "\n"
- }
- return rval
- }
- enum CodingKeys: CodingKey { case name, notes, status }
- required init(from decoder: any Decoder) throws {
- let container = try decoder.container(keyedBy: CodingKeys.self)
- name = try container.decode(String.self, forKey: .name)
- 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)
- try container.encode(notes, forKey: .notes)
- try container.encode(status, forKey: .status)
- }
- }
|