Class: StudentListController
- Inherits:
-
Object
- Object
- StudentListController
- Defined in:
- lib/student_list_controller.rb
Instance Method Summary collapse
- #add_student(student) ⇒ Object
- #count ⇒ Object
- #delete_selected(current_page, per_page, selected_row) ⇒ Object
- #get_student(id) ⇒ Object
- #get_students_pag(k, n) ⇒ Object
-
#initialize(view) ⇒ StudentListController
constructor
A new instance of StudentListController.
- #on_view_created ⇒ Object
- #refresh_data(page, per_page) ⇒ Object
- #remove_student(id) ⇒ Object
- #replace_student(id, student) ⇒ Object
- #show_modal_add ⇒ Object
- #show_modal_edit(current_page, per_page, selected_row) ⇒ Object
Constructor Details
#initialize(view) ⇒ StudentListController
Returns a new instance of StudentListController.
14 15 16 17 18 |
# File 'lib/student_list_controller.rb', line 14 def initialize(view) @view = view @data_list = DataListStudentShort.new @data_list.add_listener(@view) end |
Instance Method Details
#add_student(student) ⇒ Object
28 29 30 |
# File 'lib/student_list_controller.rb', line 28 def add_student(student) @student_list.add_student(student) end |
#count ⇒ Object
48 49 50 |
# File 'lib/student_list_controller.rb', line 48 def count @student_list.count end |
#delete_selected(current_page, per_page, selected_row) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/student_list_controller.rb', line 52 def delete_selected(current_page, per_page, selected_row) begin student_num = (current_page - 1) * per_page + selected_row @data_list.select_element(student_num) student_id = @data_list.selected_id @student_list.remove_student(student_id) rescue on_db_conn_error end end |
#get_student(id) ⇒ Object
32 33 34 |
# File 'lib/student_list_controller.rb', line 32 def get_student(id) @student_list.get_student(id) end |
#get_students_pag(k, n) ⇒ Object
44 45 46 |
# File 'lib/student_list_controller.rb', line 44 def get_students_pag(k, n) students_list_adapter.get_students_pag(k, n) end |
#on_view_created ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/student_list_controller.rb', line 20 def on_view_created begin @student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance)) rescue Mysql2::Error::ConnectionError on_db_conn_error end end |
#refresh_data(page, per_page) ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/student_list_controller.rb', line 80 def refresh_data(page, per_page) begin @data_list = @student_list.get_students_pag(page, per_page, @data_list) @view.update_student_count(@student_list.count) rescue on_db_conn_error end end |
#remove_student(id) ⇒ Object
36 37 38 |
# File 'lib/student_list_controller.rb', line 36 def remove_student(id) @student_list.remove_student(id) end |
#replace_student(id, student) ⇒ Object
40 41 42 |
# File 'lib/student_list_controller.rb', line 40 def replace_student(id, student) @student_list.replace_student(id, student) end |
#show_modal_add ⇒ Object
63 64 65 66 67 68 |
# File 'lib/student_list_controller.rb', line 63 def show_modal_add controller = StudentInputFormController.new(self) view = StudentInputForm.new(controller) controller.set_view(view) view.create.show end |
#show_modal_edit(current_page, per_page, selected_row) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/student_list_controller.rb', line 70 def show_modal_edit(current_page, per_page, selected_row) student_num = (current_page - 1) * per_page + selected_row @data_list.select_element(student_num) student_id = @data_list.selected_id controller = StudentEditFormController.new(self, student_id) view = StudentInputForm.new(controller) controller.set_view(view) view.create.show end |