Skip to content

Commit

Permalink
Use SaveTaskInteractor
Browse files Browse the repository at this point in the history
  • Loading branch information
cristibaluta committed May 3, 2016
1 parent df8bfdf commit 27e3715
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 42 deletions.
16 changes: 8 additions & 8 deletions External/CoreData/CoreDataRepository.swift
Expand Up @@ -86,14 +86,14 @@ extension CoreDataRepository {

private func taskFromCTask (ctask: CTask) -> Task {

var task = Task()
task.taskId = ctask.taskId
task.taskType = ctask.taskType
task.notes = ctask.notes
task.startDate = ctask.startDate
task.endDate = ctask.endDate

return task
return Task(startDate: ctask.startDate,
endDate: ctask.endDate,
notes: ctask.notes,
issueType: ctask.issueType,
issueId: ctask.issueId,
taskType: ctask.taskType,
taskId: ctask.taskId
)
}

private func tasksFromCTasks (ctasks: [CTask]) -> [Task] {
Expand Down
Expand Up @@ -2,4 +2,70 @@
<Bucket
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "External/CoreData/CoreDataRepository.swift"
timestampString = "483953133.70396"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "163"
endingLineNumber = "163"
landmarkName = "queryTasks(_:completion:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jirassic/Screens/Tasks/TasksViewController.swift"
timestampString = "483955481.286027"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "168"
endingLineNumber = "168"
landmarkName = "removeNewTaskController()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jirassic/Screens/Tasks/NewTaskViewController.swift"
timestampString = "483955560.566892"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "65"
endingLineNumber = "65"
landmarkName = "removeFromSuperview()"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Jirassic/Wireframe.swift"
timestampString = "483955708.839087"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "90"
endingLineNumber = "90"
landmarkName = "removeController(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
6 changes: 0 additions & 6 deletions Jirassic/Screens/Tasks/NewTaskViewController.swift
Expand Up @@ -55,12 +55,6 @@ class NewTaskViewController: NSViewController {
}
}

class func instanceFromStoryboard() -> NewTaskViewController {

let storyboard = NSStoryboard(name: "Main", bundle: nil)
return storyboard.instantiateControllerWithIdentifier("NewTaskViewController") as! NewTaskViewController
}

func removeFromSuperview() {
self.view.removeFromSuperview()
}
Expand Down
47 changes: 20 additions & 27 deletions Jirassic/Screens/Tasks/TasksViewController.swift
Expand Up @@ -17,6 +17,8 @@ class TasksViewController: NSViewController {
@IBOutlet private var _butRefresh: NSButton?
@IBOutlet private var _progressIndicator: NSProgressIndicator?
@IBOutlet private var butShare: NSButton?

var wireframe: Wireframe?

private var _noTasksViewController: NoTasksViewController?
private var _newTaskViewController: NewTaskViewController?
Expand All @@ -25,14 +27,6 @@ class TasksViewController: NSViewController {
var handleSettingsButton: (() -> ())?
var handleRefreshButton: (() -> ())?


// MARK: View controller lifecycle

class func instanceFromStoryboard() -> TasksViewController {
let storyboard = NSStoryboard(name: "Main", bundle: nil)
return storyboard.instantiateControllerWithIdentifier("TasksViewController") as! TasksViewController
}

override func awakeFromNib() {
view.layer = CALayer()
view.wantsLayer = true
Expand Down Expand Up @@ -128,7 +122,7 @@ class TasksViewController: NSViewController {
var newTaskViewController: NewTaskViewController {

if _newTaskViewController == nil {
_newTaskViewController = NewTaskViewController.instanceFromStoryboard()
_newTaskViewController = NewTaskViewController.instantiateFromStoryboard("Main")
_newTaskViewController?.onOptionChosen = { [weak self] (i: TaskSubtype) -> Void in

self?.splitView?.hidden = false
Expand All @@ -142,19 +136,17 @@ class TasksViewController: NSViewController {
} else if task.startDate != nil {
task.startDate = self!._newTaskViewController!.date
}
RCLog(task)
localRepository.saveTask(task, completion: {(success: Bool) -> Void in

self?.tasksScrollView?.addTask( task )

self?.setupDaysTableView()
self?.tasksScrollView?.tableView?.insertRowsAtIndexes(NSIndexSet(index: 0),
withAnimation: NSTableViewAnimationOptions.SlideUp)
self?.tasksScrollView?.tableView?.scrollRowToVisible(0)

self?.updateNoTasksState()
self?.removeNewTaskController()
})

SaveTaskInteractor(data: localRepository).saveTask(task)
self?.tasksScrollView?.addTask( task )

self?.setupDaysTableView()
self?.tasksScrollView?.tableView?.insertRowsAtIndexes(
NSIndexSet(index: 0), withAnimation: NSTableViewAnimationOptions.SlideUp)
self?.tasksScrollView?.tableView?.scrollRowToVisible(0)

self?.updateNoTasksState()
self?.removeNewTaskController()
}
_newTaskViewController?.onCancelChosen = {
self.splitView?.hidden = false
Expand Down Expand Up @@ -212,10 +204,9 @@ class TasksViewController: NSViewController {
func handleStartDayButton() {

let task = Task(dateSart: NSDate(), dateEnd: NSDate(), type: TaskType.Start)
localRepository.saveTask(task, completion: { [weak self] (success: Bool) -> Void in
self?.day.setLastTrackedDay(NSDate())
self?.reloadData()
})
SaveTaskInteractor(data: localRepository).saveTask(task)
self.day.setLastTrackedDay(NSDate())
self.reloadData()
}

func handleAddTaskButton (date: NSDate) {
Expand Down Expand Up @@ -249,7 +240,9 @@ extension TasksViewController {
func registerForNotifications() {

NSNotificationCenter.defaultCenter().addObserver(self,
selector: #selector(TasksViewController.newTaskWasAdded(_:)), name: kNewTaskWasAddedNotification, object: nil)
selector: #selector(TasksViewController.newTaskWasAdded(_:)),
name: kNewTaskWasAddedNotification,
object: nil)
}

func newTaskWasAdded (notif: NSNotification) {
Expand Down
2 changes: 1 addition & 1 deletion Jirassic/Wireframe.swift
Expand Up @@ -86,7 +86,7 @@ class Wireframe {
controller.view.constrainToSuperview()
}

class func removeController(controller: NSViewController) {
class func removeController (controller: NSViewController) {
controller.removeFromParentViewController()
controller.view.removeFromSuperview()
}
Expand Down

0 comments on commit 27e3715

Please sign in to comment.