Class: TaskListController

Inherits:
Object
  • Object
show all
Defined in:
lib/task/controllers/task_list_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ TaskListController

Returns a new instance of TaskListController.



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/task/controllers/task_list_controller.rb', line 13

def initialize(view)
  @view = view
  @state_notifier = ListStateNotifier.new
  @state_notifier.add_listener(@view)
  @task_rep = TaskDbDataSource.new

  @sort_columns = %w[TaskID UserID ManagerID Date Description Completed]
  @sort_by = @sort_columns.first

  @completed_filter_columns = [nil, 'Done', 'Undone']
  @completed_filter = @completed_filter_columns.first
end

Instance Attribute Details

#state_notifierObject (readonly)

Returns the value of attribute state_notifier.



12
13
14
# File 'lib/task/controllers/task_list_controller.rb', line 12

def state_notifier
  @state_notifier
end

Instance Method Details

#delete_selected(current_page, per_page, selected_row) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/task/controllers/task_list_controller.rb', line 55

def delete_selected(current_page, per_page, selected_row)
  begin
    item = @state_notifier.get(selected_row)
    @task_rep.delete(item.task_id)
    @state_notifier.delete(item)
  rescue
    api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
    api.call(0, "You cannot delete the user because he is associated with some user or manager", "Error", 0)
  end
end

#filter_completed(page, per_page, filter_index) ⇒ Object



80
81
82
83
# File 'lib/task/controllers/task_list_controller.rb', line 80

def filter_completed(page, per_page, filter_index)
  @completed_filter = @completed_filter_columns[filter_index]
  refresh_data(page, per_page)
end

#on_view_createdObject



28
29
30
31
32
33
34
# File 'lib/task/controllers/task_list_controller.rb', line 28

def on_view_created
  # begin
  #   @student_rep = StudentRepository.new(DBSourceAdapter.new)
  # rescue Mysql2::Error::ConnectionError
  #   on_db_conn_error
  # end
end

#refresh_data(page, per_page) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/task/controllers/task_list_controller.rb', line 66

def refresh_data(page, per_page)
  print "\n"
  print "completed filter:#{@completed_filter}"
  print "\n"
  items = @task_rep.get_list(per_page, page, @sort_by, 'ASC', @completed_filter)
  @state_notifier.set_all(items)
  @view.update_student_count(@task_rep.count)
end

#show_modal_addObject



40
41
42
43
44
45
# File 'lib/task/controllers/task_list_controller.rb', line 40

def show_modal_add
  controller = TaskInputFormControllerCreate.new(self)
  view = TaskInputFormFactory.create_create_form(controller)
  controller.set_view(view)
  view.create.show
end

#show_modal_edit(current_page, per_page, selected_row) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/task/controllers/task_list_controller.rb', line 47

def show_modal_edit(current_page, per_page, selected_row)
  item = @state_notifier.get(selected_row)
  controller = TaskInputFormControllerEdit.new(self, item)
  view = TaskInputFormFactory.create_edit_form(controller, item)
  controller.set_view(view)
  view.create.show
end

#show_viewObject



36
37
38
# File 'lib/task/controllers/task_list_controller.rb', line 36

def show_view
  @view.create.show
end

#sort(page, per_page, sort_index) ⇒ Object



75
76
77
78
# File 'lib/task/controllers/task_list_controller.rb', line 75

def sort(page, per_page, sort_index)
  @sort_by = @sort_columns[sort_index]
  refresh_data(page, per_page)
end