model_XD 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +18 -0
- data/README.md +35 -0
- data/Rakefile +16 -0
- data/lib/Converter.rb +11 -0
- data/lib/Converter_json.rb +14 -0
- data/lib/Converter_txt.rb +26 -0
- data/lib/Converter_yaml.rb +14 -0
- data/lib/Data_list.rb +66 -0
- data/lib/Data_list_student_short.rb +17 -0
- data/lib/Data_table.rb +25 -0
- data/lib/Student.rb +106 -0
- data/lib/StudentBase.rb +50 -0
- data/lib/Student_list.rb +65 -0
- data/lib/Student_short.rb +40 -0
- data/lib/database/scripts/create_table.sql +10 -0
- data/lib/database/scripts/insert_data.sql +4 -0
- data/lib/database/student_list_db.rb +41 -0
- data/lib/database/students_db.rb +82 -0
- data/lib/model_XD/version.rb +5 -0
- data/lib/model_XD.rb +8 -0
- data/lib/mvcStudentXD.rb +8 -0
- data/lib/student_edit_form_controller.rb +56 -0
- data/lib/student_input_form.rb +72 -0
- data/lib/student_input_form_controller.rb +47 -0
- data/lib/student_list_adapter.rb +95 -0
- data/lib/student_list_adv.rb +35 -0
- data/lib/student_list_controller.rb +96 -0
- data/lib/tab_students.rb +152 -0
- data/sig/model_XD.rbs +4 -0
- metadata +79 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative './udents_db.rb'
|
|
3
|
+
|
|
4
|
+
class StudentListDB
|
|
5
|
+
attr_accessor :database
|
|
6
|
+
|
|
7
|
+
@@instance = nil
|
|
8
|
+
|
|
9
|
+
def self.instance
|
|
10
|
+
@@instance ||= StudentListDB.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
self.database = StudentDB.new()
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def get_student(id)
|
|
19
|
+
Student.from_hash(database.select_by_id(id).transform_keys(&:to_sym))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def remove_student(id)
|
|
23
|
+
database.remove_by_id(id)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def replace_student(id, student)
|
|
27
|
+
database.replace_by_id(id, student)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def add_student(student)
|
|
31
|
+
database.add_student(student.to_hash)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def get_students_pag(k, n, data)
|
|
35
|
+
database.get_students_pag(k, n, data)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def count
|
|
39
|
+
database.count
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# #encoding: UTF-8
|
|
3
|
+
require 'mysql2'
|
|
4
|
+
require_relative '../../lib/st_student_short'
|
|
5
|
+
require_relative '../../lib/st'
|
|
6
|
+
require_relative '../../lib/'
|
|
7
|
+
require_relative '../../lib/_short'
|
|
8
|
+
class StudentDB
|
|
9
|
+
|
|
10
|
+
attr_accessor :db_connection
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
self.db_connection = Mysql2::Client.new(:host => "localhost", :username => "dimas", :password => "qwe123")
|
|
14
|
+
self.db_connection.query('CREATE DATABASE IF NOT EXISTS stud_db')
|
|
15
|
+
self.db_connection.query('USE stud_db')
|
|
16
|
+
self.db_connection.query('DROP TABLE IF EXISTS student')
|
|
17
|
+
self.db_connection.query(File.read('C:/Users/Dmitry/RubymineProjects/RubyLabs/mvcStudentXD/lib/database/scripts/create_table.sql'))
|
|
18
|
+
self.insert_data
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def insert_data
|
|
22
|
+
db_connection.query(File.read('C:/Users/Dmitry/RubymineProjects/RubyLabs/mvcStudentXD/lib/database/scripts/insert_data.sql'))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def select_by_id(id)
|
|
26
|
+
db_connection.query("SELECT * FROM student WHERE id = #{id}").map{|x| x}[0]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def remove_by_id(id)
|
|
30
|
+
db_connection.query("DELETE FROM student WHERE id = #{id}")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def parseNil(attr)
|
|
34
|
+
if attr == nil
|
|
35
|
+
"NULL"
|
|
36
|
+
else
|
|
37
|
+
attr
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def add_student(student_data)
|
|
42
|
+
|
|
43
|
+
db_connection.query("""
|
|
44
|
+
INSERT INTO student (last_name, first_name, parental_name, git, phone, email, telegram) VALUES
|
|
45
|
+
ROW(
|
|
46
|
+
\"#{parseNil(student_data[:last_name])}\",
|
|
47
|
+
\"#{parseNil(student_data[:first_name])}\",
|
|
48
|
+
\"#{parseNil(student_data[:parental_name])}\",
|
|
49
|
+
\"#{parseNil(student_data[:git])}\",
|
|
50
|
+
\"#{parseNil(student_data[:phone])}\",
|
|
51
|
+
\"#{parseNil(student_data[:email])}\",
|
|
52
|
+
\"#{parseNil(student_data[:telegram])}\"
|
|
53
|
+
)
|
|
54
|
+
""")
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def replace_by_id(id, student_data)
|
|
58
|
+
self.remove_by_id(id)
|
|
59
|
+
self.add_student(student_data.to_hash)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def get_students_pag(k, n, existing_data = nil)
|
|
63
|
+
rows = db_connection.query("SELECT * FROM student ORDER BY id LIMIT #{n} OFFSET #{(k-1)*n}")
|
|
64
|
+
data_list = DataListStudentShort.new
|
|
65
|
+
rows.each do |row|
|
|
66
|
+
row_sym = row.transform_keys{|key| key.to_sym}
|
|
67
|
+
data_list.append(StudentShort.from_student_class(Student.from_hash(row_sym)))
|
|
68
|
+
end
|
|
69
|
+
return data_list if existing_data.nil?
|
|
70
|
+
existing_data.replace_objects(data_list.objects)
|
|
71
|
+
existing_data
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def count
|
|
75
|
+
result = db_connection.query("SELECT count(*) FROM student")
|
|
76
|
+
result.first.values.first
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
students_db = StudentDB.new
|
|
82
|
+
students_db.insert_data
|
data/lib/model_XD.rb
ADDED
data/lib/mvcStudentXD.rb
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class StudentEditFormController
|
|
4
|
+
def initialize(parent_controller, existing_student_id)
|
|
5
|
+
@parent_controller = parent_controller
|
|
6
|
+
@existing_student_id = existing_student_id
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def set_view(view)
|
|
10
|
+
@view = view
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def on_view_created
|
|
14
|
+
begin
|
|
15
|
+
@student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance))
|
|
16
|
+
rescue Mysql2::Error::ConnectionError
|
|
17
|
+
on_db_conn_error
|
|
18
|
+
end
|
|
19
|
+
@existing_student = @student_list.get_student(@existing_student_id)
|
|
20
|
+
@view.make_readonly(:git, :telegram, :email, :phone)
|
|
21
|
+
print("IM IN ONVIEW EDIT")
|
|
22
|
+
populate_fields(@existing_student)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def populate_fields(student)
|
|
26
|
+
@view.set_value(:last_name, student.last_name)
|
|
27
|
+
@view.set_value(:first_name, student.first_name)
|
|
28
|
+
@view.set_value(:parental_name, student.parental_name)
|
|
29
|
+
@view.set_value(:git, student.git)
|
|
30
|
+
@view.set_value(:telegram, student.telegram)
|
|
31
|
+
@view.set_value(:email, student.email)
|
|
32
|
+
@view.set_value(:phone, student.phone)
|
|
33
|
+
print("IM IN Populate EDIT")
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def process_fields(fields)
|
|
37
|
+
begin
|
|
38
|
+
new_student = Student.from_hash(fields)
|
|
39
|
+
print("IM IN PROCESS EDIT")
|
|
40
|
+
@student_list.replace_student(@existing_student_id, new_student)
|
|
41
|
+
|
|
42
|
+
@view.close
|
|
43
|
+
rescue ArgumentError => e
|
|
44
|
+
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
|
45
|
+
api.call(0, e.message, 'Error', 0)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def on_db_conn_error
|
|
52
|
+
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
|
53
|
+
api.call(0, "No connection to DB", "Error", 0)
|
|
54
|
+
@view.close
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'glimmer-dsl-libui'
|
|
4
|
+
require_relative 'student_input_form_controller'
|
|
5
|
+
require_relative 'StudentBase'
|
|
6
|
+
require 'win32api'
|
|
7
|
+
|
|
8
|
+
class StudentInputForm
|
|
9
|
+
include Glimmer
|
|
10
|
+
|
|
11
|
+
def initialize(controller, existing_student = nil)
|
|
12
|
+
@existing_student = existing_student.to_hash unless existing_student.nil?
|
|
13
|
+
@controller = controller
|
|
14
|
+
@entries = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def on_create
|
|
18
|
+
@controller.on_view_created
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create
|
|
22
|
+
@root_container = window('Универ', 300, 150) {
|
|
23
|
+
resizable false
|
|
24
|
+
|
|
25
|
+
vertical_box {
|
|
26
|
+
@student_form = form {
|
|
27
|
+
stretchy false
|
|
28
|
+
|
|
29
|
+
fields = [[:last_name, 'Фамилия', false], [:first_name, 'Имя', false], [:parental_name, 'Отчество', false], [:git, 'Гит', true], [:telegram, 'Телеграм', true], [:email, 'Почта', true], [:phone, 'Телефон', true]]
|
|
30
|
+
|
|
31
|
+
fields.each do |field|
|
|
32
|
+
@entries[field[0]] = entry {
|
|
33
|
+
label field[1]
|
|
34
|
+
text @existing_student[field[0]] unless @existing_student.nil?
|
|
35
|
+
|
|
36
|
+
read_only field[2] unless @existing_student.nil?
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
button('Сохранить') {
|
|
42
|
+
stretchy false
|
|
43
|
+
|
|
44
|
+
on_clicked {
|
|
45
|
+
values = @entries.transform_values { |v| v.text.force_encoding("utf-8").strip }
|
|
46
|
+
values.transform_values! { |v| v.empty? ? nil : v}
|
|
47
|
+
print
|
|
48
|
+
print values
|
|
49
|
+
@controller.process_fields(values)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
on_create
|
|
55
|
+
@root_container
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def set_value(field, value)
|
|
59
|
+
return unless @entries.include?(field)
|
|
60
|
+
@entries[field].text = value
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def make_readonly(*fields)
|
|
64
|
+
fields.each do |field|
|
|
65
|
+
@entries[field].read_only = true
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def close
|
|
70
|
+
@root_container.destroy
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'win32api'
|
|
4
|
+
|
|
5
|
+
class StudentInputFormController
|
|
6
|
+
def initialize(parent_controller)
|
|
7
|
+
@parent_controller = parent_controller
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def set_view(view)
|
|
11
|
+
@view = view
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def on_view_created
|
|
15
|
+
begin
|
|
16
|
+
@student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance))
|
|
17
|
+
rescue Mysql2::Error::ConnectionError
|
|
18
|
+
on_db_conn_error
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def process_fields(fields)
|
|
23
|
+
begin
|
|
24
|
+
last_name = fields.delete(:last_name)
|
|
25
|
+
first_name = fields.delete(:first_name)
|
|
26
|
+
parental_name = fields.delete(:parental_name)
|
|
27
|
+
|
|
28
|
+
return if last_name.nil? || first_name.nil? || parental_name.nil?
|
|
29
|
+
|
|
30
|
+
student = Student.new(last_name, first_name, parental_name, **fields)
|
|
31
|
+
|
|
32
|
+
@student_list.add_student(student)
|
|
33
|
+
|
|
34
|
+
@view.close
|
|
35
|
+
rescue ArgumentError => e
|
|
36
|
+
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
|
37
|
+
api.call(0, e.message, 'Error', 0)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def on_db_conn_error
|
|
43
|
+
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
|
44
|
+
api.call(0, "No connection to DB", "Error", 0)
|
|
45
|
+
@view.close
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
require_relative 'Student_list'
|
|
3
|
+
class StudentsListAdapter
|
|
4
|
+
private_class_method :new
|
|
5
|
+
def get_student(id)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def remove_student(id)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def replace_student(id, student)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_students_pag(k, n, data)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_student(student)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def count
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
class StudentsListDBAdapter < StudentsListAdapter
|
|
25
|
+
private
|
|
26
|
+
attr_accessor :database_list
|
|
27
|
+
|
|
28
|
+
public_class_method :new
|
|
29
|
+
|
|
30
|
+
public
|
|
31
|
+
def initialize(database_list)
|
|
32
|
+
self.database_list = database_list
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def get_student(id)
|
|
36
|
+
database_list.get_student(id)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def remove_student(id)
|
|
40
|
+
database_list.remove_student(id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def replace_student(id, student)
|
|
44
|
+
database_list.replace_student(id, student)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def get_students_pag(from, to, data)
|
|
48
|
+
database_list.get_students_pag(from, to, data)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def add_student(student)
|
|
52
|
+
database_list.add_student(student)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def count
|
|
56
|
+
database_list.count
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
class StudentsListConverterAdapter < StudentsListAdapter
|
|
61
|
+
private
|
|
62
|
+
attr_accessor :file_list
|
|
63
|
+
|
|
64
|
+
public_class_method :new
|
|
65
|
+
|
|
66
|
+
public
|
|
67
|
+
def initialize(file_list, filename)
|
|
68
|
+
self.file_list = file_list
|
|
69
|
+
self.file_list.read_file(filename)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def get_student(id)
|
|
73
|
+
file_list.get_student(id)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def remove_student(id)
|
|
77
|
+
file_list.remove_student(id)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def replace_student(id, student)
|
|
81
|
+
file_list.replace_student(id, student)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def get_students_pag(k, n, data=nil)
|
|
85
|
+
file_list.get_students_pag(k, n, data)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def add_student(student)
|
|
89
|
+
file_list.add_student(student)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def count
|
|
93
|
+
file_list.count
|
|
94
|
+
end
|
|
95
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class StudentListAdv
|
|
4
|
+
private
|
|
5
|
+
attr_accessor :students_list_adapter
|
|
6
|
+
public
|
|
7
|
+
def initialize(students_list_adapter)
|
|
8
|
+
self.students_list_adapter = students_list_adapter
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def get_student(id)
|
|
12
|
+
students_list_adapter.get_student(id)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def remove_student(id)
|
|
16
|
+
students_list_adapter.remove_student(id)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def replace_student(id, student)
|
|
20
|
+
students_list_adapter.replace_student(id, student)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def get_students_pag(k, n, data)
|
|
24
|
+
students_list_adapter.get_students_pag(k, n, data)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def add_student(student)
|
|
28
|
+
students_list_adapter.add_student(student)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def count
|
|
32
|
+
students_list_adapter.count
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
require_relative 'student_list_adv'
|
|
5
|
+
require_relative 'student_list_adapter'
|
|
6
|
+
require_relative 'database/student_list_db'
|
|
7
|
+
require_relative 'Converter_json'
|
|
8
|
+
require_relative 'Converter'
|
|
9
|
+
require_relative 'Student_list'
|
|
10
|
+
require_relative 'student_edit_form_controller'
|
|
11
|
+
require 'win32api'
|
|
12
|
+
require 'mysql2'
|
|
13
|
+
class StudentListController
|
|
14
|
+
def initialize(view)
|
|
15
|
+
@view = view
|
|
16
|
+
@data_list = DataListStudentShort.new
|
|
17
|
+
@data_list.add_listener(@view)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def on_view_created
|
|
21
|
+
begin
|
|
22
|
+
@student_list = StudentListAdv.new(StudentsListDBAdapter.new(StudentListDB.instance))
|
|
23
|
+
rescue Mysql2::Error::ConnectionError
|
|
24
|
+
on_db_conn_error
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def add_student(student)
|
|
29
|
+
@student_list.add_student(student)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def get_student(id)
|
|
33
|
+
@student_list.get_student(id)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def remove_student(id)
|
|
37
|
+
@student_list.remove_student(id)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def replace_student(id, student)
|
|
41
|
+
@student_list.replace_student(id, student)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def get_students_pag(k, n)
|
|
45
|
+
students_list_adapter.get_students_pag(k, n)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def count
|
|
49
|
+
@student_list.count
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def delete_selected(current_page, per_page, selected_row)
|
|
53
|
+
begin
|
|
54
|
+
student_num = (current_page - 1) * per_page + selected_row
|
|
55
|
+
@data_list.select_element(student_num)
|
|
56
|
+
student_id = @data_list.selected_id
|
|
57
|
+
@student_list.remove_student(student_id)
|
|
58
|
+
rescue
|
|
59
|
+
on_db_conn_error
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def show_modal_add
|
|
64
|
+
controller = StudentInputFormController.new(self)
|
|
65
|
+
view = StudentInputForm.new(controller)
|
|
66
|
+
controller.set_view(view)
|
|
67
|
+
view.create.show
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def show_modal_edit(current_page, per_page, selected_row)
|
|
71
|
+
student_num = (current_page - 1) * per_page + selected_row
|
|
72
|
+
@data_list.select_element(student_num)
|
|
73
|
+
student_id = @data_list.selected_id
|
|
74
|
+
controller = StudentEditFormController.new(self, student_id)
|
|
75
|
+
view = StudentInputForm.new(controller)
|
|
76
|
+
controller.set_view(view)
|
|
77
|
+
view.create.show
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def refresh_data(page, per_page)
|
|
81
|
+
begin
|
|
82
|
+
@data_list = @student_list.get_students_pag(page, per_page, @data_list)
|
|
83
|
+
@view.update_student_count(@student_list.count)
|
|
84
|
+
rescue
|
|
85
|
+
on_db_conn_error
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
def on_db_conn_error
|
|
91
|
+
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
|
92
|
+
api.call(0, "No connection to DB", "Error", 0)
|
|
93
|
+
exit(false)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
data/lib/tab_students.rb
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# frozen_string_literal: true
|
|
4
|
+
require 'glimmer-dsl-libui'
|
|
5
|
+
require_relative 'student_list_controller'
|
|
6
|
+
require_relative 'student_input_form'
|
|
7
|
+
|
|
8
|
+
class TabStudents
|
|
9
|
+
include Glimmer
|
|
10
|
+
STUDENTS_PER_PAGE = 20
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@controller = StudentListController.new(self)
|
|
14
|
+
@current_page = 1
|
|
15
|
+
@total_count = 0
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def on_create
|
|
19
|
+
@controller.on_view_created
|
|
20
|
+
@controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Метод наблюдателя datalist
|
|
24
|
+
def on_datalist_changed(new_table)
|
|
25
|
+
arr = new_table.to_2d_array
|
|
26
|
+
@table.model_array = arr
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def update_student_count(new_cnt)
|
|
30
|
+
@total_count = new_cnt
|
|
31
|
+
@page_label.text = "#{@current_page} / #{(@total_count / STUDENTS_PER_PAGE.to_f).ceil}"
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def create
|
|
35
|
+
root = horizontal_box {
|
|
36
|
+
# Секция 1
|
|
37
|
+
vertical_box {
|
|
38
|
+
stretchy false
|
|
39
|
+
|
|
40
|
+
form {
|
|
41
|
+
stretchy false
|
|
42
|
+
|
|
43
|
+
@filter_last_name_initials = entry {
|
|
44
|
+
label 'ФИО'
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@filters = {}
|
|
48
|
+
fields = [[:git, 'Github'], [:email, 'Почта'], [:phone, 'Телефон'], [:telegram, 'Телеграм']]
|
|
49
|
+
|
|
50
|
+
fields.each do |field|
|
|
51
|
+
@filters[field[0]] = {}
|
|
52
|
+
|
|
53
|
+
@filters[field[0]][:combobox] = combobox {
|
|
54
|
+
label "#{field[1]}?"
|
|
55
|
+
items ['Не важно', 'Есть', 'Нет']
|
|
56
|
+
selected 0
|
|
57
|
+
|
|
58
|
+
on_selected do
|
|
59
|
+
if @filters[field[0]][:combobox].selected == 1
|
|
60
|
+
@filters[field[0]][:entry].read_only = false
|
|
61
|
+
else
|
|
62
|
+
@filters[field[0]][:entry].text = ''
|
|
63
|
+
@filters[field[0]][:entry].read_only = true
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@filters[field[0]][:entry] = entry {
|
|
69
|
+
label field[1]
|
|
70
|
+
read_only true
|
|
71
|
+
}
|
|
72
|
+
end
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
# Секция 2
|
|
77
|
+
vertical_box {
|
|
78
|
+
@table = refined_table(
|
|
79
|
+
table_editable: false,
|
|
80
|
+
filter: lambda do |row_hash, query|
|
|
81
|
+
utf8_query = query.force_encoding("utf-8")
|
|
82
|
+
row_hash['Фамилия И. О'].include?(utf8_query)
|
|
83
|
+
end,
|
|
84
|
+
table_columns: {
|
|
85
|
+
'#' => :text,
|
|
86
|
+
'Фамилия И. О' => :text,
|
|
87
|
+
'Гит' => :text,
|
|
88
|
+
'Контакт' => :text,
|
|
89
|
+
},
|
|
90
|
+
per_page: STUDENTS_PER_PAGE
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
@pages = horizontal_box {
|
|
94
|
+
stretchy false
|
|
95
|
+
|
|
96
|
+
button("<") { stretchy true }
|
|
97
|
+
button("<") {
|
|
98
|
+
stretchy true
|
|
99
|
+
|
|
100
|
+
on_clicked do
|
|
101
|
+
@current_page = [@current_page - 1, 1].max
|
|
102
|
+
@controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
@page_label = label("...") { stretchy false }
|
|
107
|
+
button(">") { stretchy true }
|
|
108
|
+
button(">") {
|
|
109
|
+
stretchy true
|
|
110
|
+
|
|
111
|
+
on_clicked do
|
|
112
|
+
@current_page = [@current_page + 1, (@total_count / STUDENTS_PER_PAGE.to_f).ceil].min
|
|
113
|
+
@controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
|
|
114
|
+
end
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# Секция 3
|
|
120
|
+
vertical_box {
|
|
121
|
+
stretchy true
|
|
122
|
+
|
|
123
|
+
button('Добавить') {
|
|
124
|
+
stretchy false
|
|
125
|
+
|
|
126
|
+
on_clicked {
|
|
127
|
+
@controller.show_modal_add
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
button('Изменить') {
|
|
131
|
+
stretchy false
|
|
132
|
+
|
|
133
|
+
on_clicked {
|
|
134
|
+
@controller.show_modal_edit(@current_page, STUDENTS_PER_PAGE, @table.selection) unless @table.selection.nil?
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
button('Удалить') {
|
|
138
|
+
stretchy false
|
|
139
|
+
|
|
140
|
+
on_clicked {
|
|
141
|
+
@controller.delete_selected(@current_page, STUDENTS_PER_PAGE, @table.selection) unless @table.selection.nil?
|
|
142
|
+
@controller.refresh_data(@current_page, STUDENTS_PER_PAGE)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
button('Обновить') { stretchy false }
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
on_create
|
|
149
|
+
root
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|