Class: StudentListController

Inherits:
Object
  • Object
show all
Defined in:
lib/source/controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view) ⇒ StudentListController

Returns a new instance of StudentListController.



21
22
23
24
25
26
27
# File 'lib/source/controller.rb', line 21

def initialize(view)
  LoggerHolder.instance.debug('StudentListController: init start')
  @view = view
  @data_list = DataListStudentShort.new([])
  @data_list.add_observer(@view)
  LoggerHolder.instance.debug('StudentListController: init done')
end

Instance Attribute Details

#viewObject (readonly)

Returns the value of attribute view.



20
21
22
# File 'lib/source/controller.rb', line 20

def view
  @view
end

Instance Method Details

#delete_selected(current_page, per_page, selected_row) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/source/controller.rb', line 84

def delete_selected(current_page, per_page, selected_row)
  #begin
  #student_num = (current_page - 1) * per_page + selected_row
  student_num = selected_row
  puts student_num
  @data_list.select_elem(student_num)
  student_id = @data_list.selected_id
  @student_list.delete_student(student_id)
  #rescue
  #on_db_conn_error
  #end
end

#on_db_conn_errorObject



112
113
114
115
116
# File 'lib/source/controller.rb', line 112

def on_db_conn_error
  api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
  api.call(0, "No connection to DB", "Error", 0)
  exit(false)
end

#on_view_createdObject

Метод инициализирует экземпляр класса StudentList с помощью StudentListDBAdapter.



30
31
32
33
34
35
36
37
38
39
# File 'lib/source/controller.rb', line 30

def on_view_created
  #@student_list = StudentList.new(StudentFileAdapter.new(StudentListJson.new, './Lab_2/students.json'))
  begin
    @student_list=StudentList.new(StudentListDBAdapter.new)
    LoggerHolder.instance.debug('StudentListController: view create')
  rescue
    on_db_conn_error
  end

end

#refresh_data(k, n) ⇒ Object

Oбновляет данные списка студентов. Получает короткий список из БД с помощью get_k_n_student_short_list. Обновляет экземпляр @data_list новым списком. Обновляет счетчик студентов на представлении @view с помощью метода update_student_count.



101
102
103
104
105
106
107
108
109
110
# File 'lib/source/controller.rb', line 101

def refresh_data(k, n)
  #Сформировать список исключительных ситуаций, который может возникнуть при выполнении включения программ
  #begin
  #raise StandardError, "Error DB"
  @data_list = @student_list.get_k_n_student_short_list(k, n, @data_list)
  @view.update_student_count(@student_list.count_student)
  # rescue
  #    on_db_conn_error
  # end
end

#show_add_studentObject



45
46
47
48
49
50
51
# File 'lib/source/controller.rb', line 45

def show_add_student()
  LoggerHolder.instance.debug('StudentListController: show add student')
  controller = StudentCreateFormController.new(self)
  view = StudentCreateForm.new(controller)
  controller.view=view
  view.create.show
end

#show_contact_student(current_page, per_page, selected_row) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/source/controller.rb', line 74

def show_contact_student(current_page, per_page, selected_row)
  LoggerHolder.instance.debug('StudentListController: show edit git')
  student_num = selected_row
  @data_list.select_elem(student_num)
  student_id = @data_list.selected_id
  controller = StudentContactFormController.new(self, student_id)
  view = StudentCreateForm.new(controller)
  controller.view=view
  view.create.show
end

#show_edit_student(current_page, per_page, selected_row) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/source/controller.rb', line 53

def show_edit_student(current_page, per_page, selected_row)
  LoggerHolder.instance.debug('StudentListController: show edit name')
  student_num =  selected_row
  @data_list.select_elem(student_num)
  student_id = @data_list.selected_id
  controller = StudentEditFormController.new(self, student_id)
  view = StudentCreateForm.new(controller)
  controller.view=view
  view.create.show
end

#show_git_student(current_page, per_page, selected_row) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/source/controller.rb', line 63

def show_git_student(current_page, per_page, selected_row)
  LoggerHolder.instance.debug('StudentListController: show edit git')
  student_num = selected_row
  @data_list.select_elem(student_num)
  student_id = @data_list.selected_id
  controller = StudentGitFormController.new(self, student_id)
  view = StudentCreateForm.new(controller)
  controller.view=view
  view.create.show
end

#show_viewObject

Отображает представление view.



42
43
44
# File 'lib/source/controller.rb', line 42

def show_view
  @view.create.show
end