shnaider_code 1.1.6 → 2.0.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 +4 -4
- data/lib/shnaider_code/version.rb +2 -2
- data/lib/shnaider_code.rb +1 -1
- data/lib/source/attr_limited_regex_accessor.rb +43 -0
- data/lib/source/controllers/create_student_controller.rb +8 -0
- data/lib/source/controllers/edit_student_controller.rb +10 -0
- data/lib/source/controllers/view_controller.rb +106 -0
- data/lib/source/data_construct_pattern/data_construct_pattarn.rb +25 -0
- data/lib/source/data_list.rb +59 -0
- data/lib/source/data_list_student_short.rb +28 -0
- data/lib/source/data_table.rb +21 -0
- data/lib/source/database/scripts/create_table.sql +10 -0
- data/lib/source/database/scripts/fill_data.sql +14 -0
- data/lib/source/database/students_db.rb +78 -0
- data/lib/source/database/students_list_db.rb +36 -0
- data/lib/source/student/abstract_student.rb +26 -0
- data/lib/source/student/student.rb +120 -0
- data/lib/source/student/student_short.rb +59 -0
- data/lib/source/student_list_format.rb +50 -0
- data/lib/source/students_list.rb +43 -0
- data/lib/source/students_list_adapter.rb +89 -0
- data/lib/source/students_list_format_strategy.rb +59 -0
- data/lib/source/students_tests.rb +72 -0
- data/shnaider_code.gemspec +1 -1
- metadata +21 -25
- data/Gemfile +0 -13
- data/lib/source/controllers/student_input_form/student_input_form_controller_create.rb +0 -59
- data/lib/source/controllers/student_input_form/student_input_form_controller_edit.rb +0 -68
- data/lib/source/controllers/tab_students_controller.rb +0 -82
- data/lib/source/db_config/config.yaml +0 -5
- data/lib/source/db_config/migrations/001_create_table_student.sql +0 -12
- data/lib/source/db_config/mock_data/fill_student.sql +0 -6
- data/lib/source/models/student.rb +0 -103
- data/lib/source/models/student_base.rb +0 -100
- data/lib/source/models/student_short.rb +0 -50
- data/lib/source/repositories/adapters/db_source_adapter.rb +0 -54
- data/lib/source/repositories/adapters/file_source_adapter.rb +0 -37
- data/lib/source/repositories/containers/data_list.rb +0 -74
- data/lib/source/repositories/containers/data_list_student_short.rb +0 -18
- data/lib/source/repositories/containers/data_table.rb +0 -35
- data/lib/source/repositories/data_sources/db_data_source.rb +0 -37
- data/lib/source/repositories/data_sources/file_data_source.rb +0 -75
- data/lib/source/repositories/data_sources/transformers/data_transformer_base.rb +0 -15
- data/lib/source/repositories/data_sources/transformers/data_transformer_json.rb +0 -16
- data/lib/source/repositories/data_sources/transformers/data_transformer_yaml.rb +0 -16
- data/lib/source/repositories/student_repository.rb +0 -32
- data/lib/source/util/logger_holder.rb +0 -24
- data/shnaider_code-1.1.4.gem +0 -0
- data/sig/shnaider_code.rbs +0 -4
@@ -0,0 +1,50 @@
|
|
1
|
+
module McDelta
|
2
|
+
class StudentListFormat
|
3
|
+
attr_private_accessor :students
|
4
|
+
attr_accessor :formater
|
5
|
+
|
6
|
+
def initialize(formater)
|
7
|
+
self.formater = formater
|
8
|
+
end
|
9
|
+
|
10
|
+
def read_from(filename)
|
11
|
+
self.students = formater.read_from(filename)
|
12
|
+
end
|
13
|
+
|
14
|
+
def write_to(filename)
|
15
|
+
formater.write_to(filename, self.students)
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_student(id)
|
19
|
+
self.students.detect { |x|
|
20
|
+
x.id == id .to_s
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_student(student)
|
25
|
+
self.students << student
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete_student(id)
|
29
|
+
index = students.index(students.detect { |x| x.id == id.to_s })
|
30
|
+
self.students.delete_at(index)
|
31
|
+
end
|
32
|
+
|
33
|
+
def replace_student(id, student)
|
34
|
+
self.students.map! { |x| x.id == id.to_s ? student : x }
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_students_slice(k, count)
|
38
|
+
from = [k * count, self.students.count].min
|
39
|
+
to = [self.students.count, from + count].min
|
40
|
+
end
|
41
|
+
|
42
|
+
def count()
|
43
|
+
self.students.count
|
44
|
+
end
|
45
|
+
|
46
|
+
def sort()
|
47
|
+
self.students.sort_by(&:fio_info)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "source/attr_limited_regex_accessor.rb"
|
2
|
+
|
3
|
+
module McDelta
|
4
|
+
class StudentsList
|
5
|
+
attr_private_accessor :students_list_adapter
|
6
|
+
|
7
|
+
def initialize(adapter)
|
8
|
+
self.students_list_adapter = 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(from, to, data)
|
24
|
+
values = students_list_adapter.get_students(from, to)
|
25
|
+
|
26
|
+
if data == nil
|
27
|
+
data = DataList.new(list: values)
|
28
|
+
else
|
29
|
+
data.list = values
|
30
|
+
end
|
31
|
+
|
32
|
+
data.list
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_student(student)
|
36
|
+
students_list_adapter.add_student(student)
|
37
|
+
end
|
38
|
+
|
39
|
+
def count
|
40
|
+
students_list_adapter.count()
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module McDelta
|
2
|
+
class StudentsListAdapter
|
3
|
+
def get_student(id)
|
4
|
+
end
|
5
|
+
|
6
|
+
def remove_student(id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def replace_student(id, student, data)
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_students(from, to, data)
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_student(student)
|
16
|
+
end
|
17
|
+
|
18
|
+
def count
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class StudentsListDBAdapter < StudentsListAdapter
|
23
|
+
attr_private_accessor :database_list
|
24
|
+
|
25
|
+
def initialize(database_list)
|
26
|
+
self.database_list = database_list
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_student(id)
|
30
|
+
database_list.get_student(id)
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove_student(id)
|
34
|
+
database_list.remove_student(id)
|
35
|
+
end
|
36
|
+
|
37
|
+
def replace_student(id, student)
|
38
|
+
database_list.replace_student(id, student)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_students(from, to)
|
42
|
+
database_list.get_students_slice(from, to)
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_student(student)
|
46
|
+
database_list.add_student(student)
|
47
|
+
end
|
48
|
+
|
49
|
+
def count
|
50
|
+
database_list.count()
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class StudentsListFormatterAdapter < StudentsListAdapter
|
55
|
+
attr_private_accessor :formatter
|
56
|
+
|
57
|
+
def initialize(formatter, filename)
|
58
|
+
self.formatter = formatter
|
59
|
+
formatter.read_from(filename)
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_student(id)
|
63
|
+
formatter.get_student(id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def remove_student(id)
|
67
|
+
formatter.delete_student(id)
|
68
|
+
end
|
69
|
+
|
70
|
+
def replace_student(id, student)
|
71
|
+
formatter.replace_student(id, student)
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_students(from, to)
|
75
|
+
count = to - from
|
76
|
+
k = from / count
|
77
|
+
|
78
|
+
formatter.get_students_slice(k, count)
|
79
|
+
end
|
80
|
+
|
81
|
+
def add_student(student)
|
82
|
+
formatter.add_student(student)
|
83
|
+
end
|
84
|
+
|
85
|
+
def count
|
86
|
+
formatter.count()
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module McDelta
|
5
|
+
class StudentsListFormatStrategy
|
6
|
+
def read_from(filename)
|
7
|
+
require 'method not implemented'
|
8
|
+
end
|
9
|
+
|
10
|
+
def write_to(filename, students)
|
11
|
+
require 'method not implemented'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class TxtStudentsListFormatStrategy < StudentsListFormatStrategy
|
16
|
+
def read_from(filename)
|
17
|
+
File.read(filename)
|
18
|
+
.split("\n")
|
19
|
+
.map { |v| Student.from_string(v) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_to(filename, students)
|
23
|
+
File.open(filename, 'w') { |file|
|
24
|
+
file.write(
|
25
|
+
students.map { |student|
|
26
|
+
student.get_info
|
27
|
+
}
|
28
|
+
.join("\n")
|
29
|
+
)
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class JsonStudentsListFormatStrategy < StudentsListFormatStrategy
|
35
|
+
def read_from(filename)
|
36
|
+
file = File.read(filename)
|
37
|
+
json = JSON.parse(file)
|
38
|
+
json.map { |x| Student.from_json(x) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def write_to(filename, students)
|
42
|
+
File.open(filename, 'w') do |f|
|
43
|
+
f.write(JSON.generate(students.map { |x| x.as_json }))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class YamlStudentsListFormatStrategy < StudentsListFormatStrategy
|
49
|
+
def read_from(filename)
|
50
|
+
YAML.load_file(filename)
|
51
|
+
end
|
52
|
+
|
53
|
+
def write_to(filename, students)
|
54
|
+
File.open(filename, 'w') do |file|
|
55
|
+
file.write(students.to_yaml)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require "test/unit"
|
2
|
+
require "source/students_list.rb"
|
3
|
+
require "source/attr_limited_regex_accessor.rb"
|
4
|
+
require "source/students_list_adapter.rb"
|
5
|
+
require "source/database/students_list_db.rb"
|
6
|
+
require "source/student/student.rb"
|
7
|
+
require "source/data_list.rb"
|
8
|
+
|
9
|
+
module McDelta
|
10
|
+
class StudentsTests < Test::Unit::TestCase
|
11
|
+
def test_add
|
12
|
+
@students = StudentsList.new(
|
13
|
+
StudentsListDBAdapter.new(
|
14
|
+
StudentsListDB
|
15
|
+
)
|
16
|
+
)
|
17
|
+
|
18
|
+
@start_count = @students.count
|
19
|
+
|
20
|
+
@students.add_student(
|
21
|
+
Student.new(
|
22
|
+
lastname: "AAA",
|
23
|
+
firstname: "BBB",
|
24
|
+
patronymic: "CCC",
|
25
|
+
params: {
|
26
|
+
email: "test@email.com"
|
27
|
+
}
|
28
|
+
)
|
29
|
+
)
|
30
|
+
|
31
|
+
assert_equal(1, @students.count - @start_count)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_delete
|
35
|
+
@students = StudentsList.new(
|
36
|
+
StudentsListDBAdapter.new(
|
37
|
+
StudentsListDB
|
38
|
+
)
|
39
|
+
)
|
40
|
+
|
41
|
+
@students.add_student(
|
42
|
+
Student.new(
|
43
|
+
lastname: "AAA",
|
44
|
+
firstname: "BBB",
|
45
|
+
patronymic: "CCC",
|
46
|
+
params: {
|
47
|
+
email: "test@email.com"
|
48
|
+
}
|
49
|
+
)
|
50
|
+
)
|
51
|
+
|
52
|
+
@students.add_student(
|
53
|
+
Student.new(
|
54
|
+
lastname: "AAA",
|
55
|
+
firstname: "BBB",
|
56
|
+
patronymic: "CCC",
|
57
|
+
params: {
|
58
|
+
email: "test@email.com"
|
59
|
+
}
|
60
|
+
)
|
61
|
+
)
|
62
|
+
|
63
|
+
@current_count = @students.count
|
64
|
+
|
65
|
+
@students_list = @students.get_students(0, 10, nil)
|
66
|
+
|
67
|
+
@students.remove_student(@students_list[0].id)
|
68
|
+
|
69
|
+
assert_equal(1, @current_count - @students.count)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/shnaider_code.gemspec
CHANGED
@@ -2,7 +2,7 @@ require_relative "lib/shnaider_code/version"
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = "shnaider_code"
|
5
|
-
spec.version =
|
5
|
+
spec.version = ShnaiderCode::VERSION
|
6
6
|
spec.authors = ["Iya"]
|
7
7
|
spec.email = ["iya@gmail.com"]
|
8
8
|
spec.summary = "Student App"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shnaider_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iya
|
@@ -31,33 +31,29 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
-
- Gemfile
|
35
34
|
- lib/shnaider_code.rb
|
36
35
|
- lib/shnaider_code/version.rb
|
37
|
-
- lib/source/
|
38
|
-
- lib/source/controllers/
|
39
|
-
- lib/source/controllers/
|
40
|
-
- lib/source/
|
41
|
-
- lib/source/
|
42
|
-
- lib/source/
|
43
|
-
- lib/source/
|
44
|
-
- lib/source/
|
45
|
-
- lib/source/
|
46
|
-
- lib/source/
|
47
|
-
- lib/source/
|
48
|
-
- lib/source/
|
49
|
-
- lib/source/
|
50
|
-
- lib/source/
|
51
|
-
- lib/source/
|
52
|
-
- lib/source/
|
53
|
-
- lib/source/
|
54
|
-
- lib/source/
|
55
|
-
- lib/source/
|
56
|
-
- lib/source/
|
57
|
-
- lib/source/util/logger_holder.rb
|
58
|
-
- shnaider_code-1.1.4.gem
|
36
|
+
- lib/source/attr_limited_regex_accessor.rb
|
37
|
+
- lib/source/controllers/create_student_controller.rb
|
38
|
+
- lib/source/controllers/edit_student_controller.rb
|
39
|
+
- lib/source/controllers/view_controller.rb
|
40
|
+
- lib/source/data_construct_pattern/data_construct_pattarn.rb
|
41
|
+
- lib/source/data_list.rb
|
42
|
+
- lib/source/data_list_student_short.rb
|
43
|
+
- lib/source/data_table.rb
|
44
|
+
- lib/source/database/scripts/create_table.sql
|
45
|
+
- lib/source/database/scripts/fill_data.sql
|
46
|
+
- lib/source/database/students_db.rb
|
47
|
+
- lib/source/database/students_list_db.rb
|
48
|
+
- lib/source/student/abstract_student.rb
|
49
|
+
- lib/source/student/student.rb
|
50
|
+
- lib/source/student/student_short.rb
|
51
|
+
- lib/source/student_list_format.rb
|
52
|
+
- lib/source/students_list.rb
|
53
|
+
- lib/source/students_list_adapter.rb
|
54
|
+
- lib/source/students_list_format_strategy.rb
|
55
|
+
- lib/source/students_tests.rb
|
59
56
|
- shnaider_code.gemspec
|
60
|
-
- sig/shnaider_code.rbs
|
61
57
|
homepage: https://github.com/bushmrz/learning-patterns-with-ruby
|
62
58
|
licenses:
|
63
59
|
- MIT
|
data/Gemfile
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "mysql2"
|
6
|
-
gem "glimmer-dsl-libui",'~> 0.7.4'
|
7
|
-
gem 'win32api'
|
8
|
-
gem "minitest"
|
9
|
-
gem 'rubocop', group: 'development'
|
10
|
-
gem 'shnaider_code'
|
11
|
-
gem 'sinatra', '~> 3.0', '>= 3.0.6'
|
12
|
-
gem 'thin', '~> 1.8', '>= 1.8.2'
|
13
|
-
|
@@ -1,59 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'source/util/logger_holder'
|
3
|
-
require 'win32api'
|
4
|
-
|
5
|
-
class StudentInputFormControllerCreate
|
6
|
-
def initialize(parent_controller)
|
7
|
-
@parent_controller = parent_controller
|
8
|
-
LoggerHolder.instance.debug('StudentInputFormControllerCreate: initialized')
|
9
|
-
end
|
10
|
-
|
11
|
-
def set_view(view)
|
12
|
-
@view = view
|
13
|
-
LoggerHolder.instance.debug('StudentInputFormControllerCreate: view set')
|
14
|
-
end
|
15
|
-
|
16
|
-
def refresh
|
17
|
-
@parent_controller.refresh_data(1, 20)
|
18
|
-
end
|
19
|
-
|
20
|
-
def on_view_created
|
21
|
-
begin
|
22
|
-
@student_rep = StudentRepository.new(DBSourceAdapter.new)
|
23
|
-
rescue Mysql2::Error::ConnectionError => e
|
24
|
-
on_db_conn_error(e)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def process_fields(fields)
|
29
|
-
begin
|
30
|
-
last_name = fields.delete(:last_name)
|
31
|
-
first_name = fields.delete(:first_name)
|
32
|
-
father_name = fields.delete(:father_name)
|
33
|
-
|
34
|
-
return if last_name.nil? || first_name.nil? || father_name.nil?
|
35
|
-
|
36
|
-
student = Student.new(last_name, first_name, father_name, **fields)
|
37
|
-
|
38
|
-
@student_rep.add_student(student)
|
39
|
-
|
40
|
-
LoggerHolder.instance.debug('StudentInputFormControllerCreate: adding student to DB')
|
41
|
-
|
42
|
-
@view.close
|
43
|
-
rescue ArgumentError => e
|
44
|
-
LoggerHolder.instance.debug("StudentInputFormControllerCreate: wrong fields: #{e.message}")
|
45
|
-
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
46
|
-
api.call(0, e.message, 'Error', 0)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
|
-
def on_db_conn_error(error)
|
53
|
-
LoggerHolder.instance.debug('StudentInputFormControllerCreate: DB connection error:')
|
54
|
-
LoggerHolder.instance.error(error.message)
|
55
|
-
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
56
|
-
api.call(0, "No connection to DB", "Error", 0)
|
57
|
-
@view.close
|
58
|
-
end
|
59
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'source/util/logger_holder'
|
4
|
-
require 'win32api'
|
5
|
-
|
6
|
-
class StudentInputFormControllerEdit
|
7
|
-
def initialize(parent_controller, existing_student_id)
|
8
|
-
@parent_controller = parent_controller
|
9
|
-
@existing_student_id = existing_student_id
|
10
|
-
LoggerHolder.instance.debug('StudentInputFormControllerEdit: initialized')
|
11
|
-
end
|
12
|
-
|
13
|
-
def set_view(view)
|
14
|
-
@view = view
|
15
|
-
LoggerHolder.instance.debug('StudentInputFormControllerEdit: view set')
|
16
|
-
end
|
17
|
-
|
18
|
-
def refresh
|
19
|
-
@parent_controller.refresh_data(1, 20)
|
20
|
-
end
|
21
|
-
|
22
|
-
def on_view_created
|
23
|
-
begin
|
24
|
-
@student_rep = StudentRepository.new(DBSourceAdapter.new)
|
25
|
-
rescue Mysql2::Error::ConnectionError => e
|
26
|
-
on_db_conn_error(e)
|
27
|
-
end
|
28
|
-
@existing_student = @student_rep.student_by_id(@existing_student_id)
|
29
|
-
#@view.make_readonly(:git, :telegram, :email, :phone)
|
30
|
-
populate_fields(@existing_student)
|
31
|
-
end
|
32
|
-
|
33
|
-
def populate_fields(student)
|
34
|
-
@view.set_value(:last_name, student.last_name)
|
35
|
-
@view.set_value(:first_name, student.first_name)
|
36
|
-
@view.set_value(:father_name, student.father_name)
|
37
|
-
@view.set_value(:git, student.git)
|
38
|
-
@view.set_value(:telegram, student.telegram)
|
39
|
-
@view.set_value(:email, student.email)
|
40
|
-
@view.set_value(:phone, student.phone)
|
41
|
-
end
|
42
|
-
|
43
|
-
def process_fields(fields)
|
44
|
-
begin
|
45
|
-
new_student = Student.from_hash(fields)
|
46
|
-
|
47
|
-
LoggerHolder.instance.debug('StudentInputFormControllerEdit: replacing student in DB')
|
48
|
-
|
49
|
-
@student_rep.replace_student(@existing_student_id, new_student)
|
50
|
-
|
51
|
-
@view.close
|
52
|
-
rescue ArgumentError => e
|
53
|
-
LoggerHolder.instance.debug("StudentInputFormControllerEdit: wrong fields: #{e.message}")
|
54
|
-
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
55
|
-
api.call(0, e.message, 'Error', 0)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def on_db_conn_error(error)
|
62
|
-
LoggerHolder.instance.debug('StudentInputFormControllerEdit: DB connection error:')
|
63
|
-
LoggerHolder.instance.error(error.message)
|
64
|
-
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
65
|
-
api.call(0, "No connection to DB", "Error", 0)
|
66
|
-
@view.close
|
67
|
-
end
|
68
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require './LabStudents/views/main_window'
|
4
|
-
require 'source/repositories/student_repository'
|
5
|
-
require 'source/repositories/adapters/db_source_adapter'
|
6
|
-
require 'source/repositories/containers/data_list_student_short'
|
7
|
-
require './LabStudents/views/student_input_form'
|
8
|
-
require 'source/controllers/student_input_form/student_input_form_controller_create'
|
9
|
-
require 'source/controllers/student_input_form/student_input_form_controller_edit'
|
10
|
-
require 'source/util/logger_holder'
|
11
|
-
require 'win32api'
|
12
|
-
|
13
|
-
class TabStudentsController
|
14
|
-
def initialize(view)
|
15
|
-
LoggerHolder.instance.debug('TabStudentsController: init start')
|
16
|
-
@view = view
|
17
|
-
@data_list = DataListStudentShort.new([])
|
18
|
-
@data_list.add_listener(@view)
|
19
|
-
LoggerHolder.instance.debug('TabStudentsController: init done')
|
20
|
-
end
|
21
|
-
|
22
|
-
def on_view_created
|
23
|
-
begin
|
24
|
-
@student_rep = StudentRepository.new(DBSourceAdapter.new)
|
25
|
-
LoggerHolder.instance.debug('TabStudentsController: created student repository')
|
26
|
-
rescue Mysql2::Error::ConnectionError => e
|
27
|
-
on_db_conn_error(e)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def show_modal_add
|
32
|
-
LoggerHolder.instance.debug('TabStudentsController: showing modal (add)')
|
33
|
-
controller = StudentInputFormControllerCreate.new(self)
|
34
|
-
view = StudentInputForm.new(controller)
|
35
|
-
controller.set_view(view)
|
36
|
-
view.create.show
|
37
|
-
end
|
38
|
-
|
39
|
-
def show_modal_edit(current_page, per_page, selected_row)
|
40
|
-
LoggerHolder.instance.debug('TabStudentsController: showing modal (edit)')
|
41
|
-
student_num = (current_page - 1) * per_page + selected_row
|
42
|
-
@data_list.select_element(student_num)
|
43
|
-
student_id = @data_list.selected_id
|
44
|
-
controller = StudentInputFormControllerEdit.new(self, student_id)
|
45
|
-
view = StudentInputForm.new(controller)
|
46
|
-
controller.set_view(view)
|
47
|
-
view.create.show
|
48
|
-
end
|
49
|
-
|
50
|
-
def delete_selected(current_page, per_page, selected_row)
|
51
|
-
begin
|
52
|
-
LoggerHolder.instance.debug('TabStudentsController: deleting selected student')
|
53
|
-
student_num = (current_page - 1) * per_page + selected_row
|
54
|
-
@data_list.select_element(student_num)
|
55
|
-
student_id = @data_list.selected_id
|
56
|
-
@student_rep.remove_student(student_id)
|
57
|
-
rescue Mysql2::Error::ConnectionError => e
|
58
|
-
on_db_conn_error(e)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def refresh_data(page, per_page)
|
63
|
-
begin
|
64
|
-
LoggerHolder.instance.debug('TabStudentsController: refreshing data...')
|
65
|
-
@data_list = @student_rep.paginated_short_students(page, per_page, @data_list)
|
66
|
-
@view.update_student_count(@student_rep.student_count)
|
67
|
-
rescue Mysql2::Error::ConnectionError => e
|
68
|
-
on_db_conn_error(e)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def on_db_conn_error(error)
|
75
|
-
LoggerHolder.instance.error('TabStudentsController: DB connection error:')
|
76
|
-
LoggerHolder.instance.error(error.message)
|
77
|
-
api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
|
78
|
-
api.call(0, "No connection to DB", "Error", 0)
|
79
|
-
# TODO: Возможность переключения на JSON помимо exit
|
80
|
-
exit(false)
|
81
|
-
end
|
82
|
-
end
|
@@ -1,12 +0,0 @@
|
|
1
|
-
create table student (
|
2
|
-
id int auto_increment,
|
3
|
-
last_name varchar(128) not null,
|
4
|
-
first_name varchar(128) not null,
|
5
|
-
father_name varchar(128) not null,
|
6
|
-
phone varchar(20) null,
|
7
|
-
telegram varchar(100) null,
|
8
|
-
email varchar(100) null,
|
9
|
-
git varchar(100) null,
|
10
|
-
constraint student_pk
|
11
|
-
primary key (id)
|
12
|
-
);
|
@@ -1,6 +0,0 @@
|
|
1
|
-
insert into student(last_name, first_name, father_name, phone, telegram, email, git) values
|
2
|
-
("Шнайдер", "Ия", "Ниевна", NULL, NULL, NULL, "bushmrz"),
|
3
|
-
("Худокмырлов", "Дмитрий", "Александрович", "78005553535", NULL, NULL, "kittenqz"),
|
4
|
-
("Шнайдер", "Ий", " Ниевич", NULL, NULL, NULL, "invisible"),
|
5
|
-
("Сайксова", "Риночка", "Рири", NULL, "slowrunner3000", NULL, NULL),
|
6
|
-
("Кузнецов", "Максим", "Александрович", "+7-900-900-90-90", "maxonhol", "maximilian@ya.ru", "maxonspb");
|