Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CalenTask/Domain/TaskFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,27 @@ enum TaskFactory {
NotificationService.shared.sync(task: task)
return task
}

/// Crea una task dentro un progetto (opzionalmente sotto una fase), con
/// workspace e autore ereditati dal progetto. Inserisce ma non salva:
/// il salvataggio spetta al chiamante (creazioni in blocco).
@discardableResult
static func createInProject(
title: String,
project: Project,
phase: TodoTask? = nil,
sortOrder: Int,
in context: ModelContext
) -> TodoTask {
let task = TodoTask(
workspaceID: project.workspaceID,
title: title,
sortOrder: sortOrder,
createdByID: project.createdByID
)
context.insert(task)
task.project = project
task.parentTask = phase
return task
}
}
10 changes: 4 additions & 6 deletions CalenTask/Features/Planning/BatchTaskEntryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ struct BatchTaskEntryView: View {
let siblings = phase?.liveSubtasks ?? project.unphasedTasks
let baseOrder = (siblings.map(\.sortOrder).max() ?? -1) + 1
for (index, title) in lines.enumerated() {
let task = TodoTask(
workspaceID: project.workspaceID,
let task = TaskFactory.createInProject(
title: title,
project: project,
phase: phase,
sortOrder: baseOrder + index,
createdByID: project.createdByID
in: modelContext
)
modelContext.insert(task)
task.project = project
task.parentTask = phase
TagService.syncTags(for: task, in: modelContext)
}
do {
Expand Down
10 changes: 4 additions & 6 deletions CalenTask/Features/Planning/PhasePlannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,13 @@ private struct PlannerColumn: View {
private func addTask() {
let title = newTitle.trimmingCharacters(in: .whitespaces)
guard !title.isEmpty else { return }
let task = TodoTask(
workspaceID: project.workspaceID,
TaskFactory.createInProject(
title: title,
project: project,
phase: phase,
sortOrder: (liveTasks.map(\.sortOrder).max() ?? -1) + 1,
createdByID: project.createdByID
in: modelContext
)
modelContext.insert(task)
task.project = project
task.parentTask = phase
newTitle = ""
}
}
Expand Down
Loading