starproxima_library 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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/Gemfile.lock +69 -0
  4. data/diagrams/add_uthor_seq.png +0 -0
  5. data/diagrams/add_uthor_seq.puml +42 -0
  6. data/diagrams/author.png +0 -0
  7. data/diagrams/author.puml +118 -0
  8. data/diagrams/core.png +0 -0
  9. data/diagrams/core.puml +103 -0
  10. data/diagrams/delete_author.png +0 -0
  11. data/diagrams/delete_author.puml +25 -0
  12. data/diagrams/edit_author.png +0 -0
  13. data/diagrams/edit_author.puml +48 -0
  14. data/diagrams/er.png +0 -0
  15. data/diagrams/er.puml +30 -0
  16. data/diagrams/publisher.png +0 -0
  17. data/diagrams/publisher.puml +118 -0
  18. data/diagrams/requirements.docx +0 -0
  19. data/diagrams/start.png +0 -0
  20. data/diagrams/start.puml +74 -0
  21. data/lib/author/author_db_data_source.rb +90 -0
  22. data/lib/author/controllers/author_controller.rb +57 -0
  23. data/lib/author/controllers/author_input_form_controller_create.rb +44 -0
  24. data/lib/author/controllers/author_input_form_controller_edit.rb +53 -0
  25. data/lib/author/controllers/author_list_controller.rb +107 -0
  26. data/lib/author/ui/author_input_form.rb +69 -0
  27. data/lib/author/ui/author_list_view.rb +170 -0
  28. data/lib/controllers/tab_students_controller.rb +43 -0
  29. data/lib/data_sources/book_db_data_source.rb +43 -0
  30. data/lib/data_sources/db_client.rb +34 -0
  31. data/lib/db_config/config.yaml +5 -0
  32. data/lib/db_config/library_config.yaml +5 -0
  33. data/lib/db_config/migrations/create_db.sql +3 -0
  34. data/lib/db_config/migrations/create_tables.sql +27 -0
  35. data/lib/db_config/mock_data/mock_data.sql +49 -0
  36. data/lib/logger.rb +27 -0
  37. data/lib/main.rb +6 -0
  38. data/lib/models/author.rb +32 -0
  39. data/lib/models/book.rb +31 -0
  40. data/lib/models/publisher.rb +37 -0
  41. data/lib/models/student.rb +102 -0
  42. data/lib/models/student_base.rb +100 -0
  43. data/lib/models/student_short.rb +50 -0
  44. data/lib/publisher/controllers/publisher_input_form_controller_create.rb +44 -0
  45. data/lib/publisher/controllers/publisher_input_form_controller_edit.rb +52 -0
  46. data/lib/publisher/controllers/publisher_list_controller.rb +99 -0
  47. data/lib/publisher/publisher_db_data_source.rb +63 -0
  48. data/lib/publisher/ui/publisher_input_form.rb +69 -0
  49. data/lib/publisher/ui/publisher_list_view.rb +168 -0
  50. data/lib/repositories/adapters/db_source_adapter.rb +54 -0
  51. data/lib/repositories/adapters/file_source_adapter.rb +37 -0
  52. data/lib/repositories/containers/data_list.rb +74 -0
  53. data/lib/repositories/containers/data_list_student_short.rb +18 -0
  54. data/lib/repositories/containers/data_table.rb +35 -0
  55. data/lib/repositories/data_sources/db_data_source.rb +32 -0
  56. data/lib/repositories/data_sources/file_data_source.rb +75 -0
  57. data/lib/repositories/data_sources/transformers/data_transformer_base.rb +15 -0
  58. data/lib/repositories/data_sources/transformers/data_transformer_json.rb +16 -0
  59. data/lib/repositories/data_sources/transformers/data_transformer_yaml.rb +16 -0
  60. data/lib/repositories/student_repository.rb +32 -0
  61. data/lib/state_holders/list_state_notifier.rb +60 -0
  62. data/lib/views/main_window.rb +32 -0
  63. data/lib/views/tab_students.rb +148 -0
  64. data/starproxima_library.gemspec +15 -0
  65. data/test/author_test.rb +51 -0
  66. data/test/book_test.rb +33 -0
  67. data/test/publisher_test.rb +39 -0
  68. data/test/state_notifier_test.rb +80 -0
  69. metadata +123 -0
@@ -0,0 +1,34 @@
1
+ require 'mysql2'
2
+
3
+ class DBClient
4
+ private_class_method :new
5
+ @instance_mutex = Mutex.new
6
+
7
+ def initialize
8
+ db_config = YAML.load_file('./lib/db_config/library_config.yaml').transform_keys(&:to_sym)
9
+ @client = Mysql2::Client.new(db_config)
10
+ @client.query_options.merge!(symbolize_keys: true)
11
+ end
12
+
13
+ def self.instance
14
+ return @instance if @instance
15
+
16
+ @instance_mutex.synchronize do
17
+ @instance ||= new
18
+ end
19
+
20
+ @instance
21
+ end
22
+
23
+ def prepare_exec(statement, *params)
24
+ @client.prepare(statement).execute(*params)
25
+ end
26
+
27
+ def query(statement)
28
+ @client.query(statement)
29
+ end
30
+
31
+ def last_id
32
+ @client.last_id
33
+ end
34
+ end
@@ -0,0 +1,5 @@
1
+ host: 'localhost'
2
+ port: 3306
3
+ username: 'root'
4
+ password: '123123'
5
+ database: 'university'
@@ -0,0 +1,5 @@
1
+ host: 'localhost'
2
+ port: 3306
3
+ username: 'root'
4
+ password: '123123'
5
+ database: 'library'
@@ -0,0 +1,3 @@
1
+ DROP DATABASE library;
2
+
3
+ CREATE DATABASE library;
@@ -0,0 +1,27 @@
1
+ USE library;
2
+
3
+ -- Table 1: Author
4
+ CREATE TABLE Author
5
+ (
6
+ AuthorID INT PRIMARY KEY AUTO_INCREMENT,
7
+ FirstName VARCHAR(50) NOT NULL,
8
+ LastName VARCHAR(50) NOT NULL,
9
+ FatherName VARCHAR(50)
10
+ );
11
+ -- Table 2: Publisher
12
+ CREATE TABLE Publisher
13
+ (
14
+ PublisherID INT PRIMARY KEY AUTO_INCREMENT,
15
+ Name VARCHAR(100) NOT NULL,
16
+ Email VARCHAR(255)
17
+ );
18
+ -- Table 3: Book
19
+ CREATE TABLE Book
20
+ (
21
+ BookID INT PRIMARY KEY AUTO_INCREMENT,
22
+ Title VARCHAR(255) NOT NULL,
23
+ AuthorID INT NOT NULL,
24
+ PublisherID INT NOT NULL,
25
+ FOREIGN KEY (AuthorID) REFERENCES Author (AuthorID),
26
+ FOREIGN KEY (PublisherID) REFERENCES Publisher (PublisherID)
27
+ );
@@ -0,0 +1,49 @@
1
+ USE library;
2
+
3
+ -- Insert 30 authors
4
+ INSERT INTO Author (FirstName, LastName, FatherName)
5
+ VALUES
6
+ ('John', 'Doe', 'Paul'),
7
+ ('Jane', 'Doe', NULL),
8
+ ('Robert', 'Johnson', 'Michael'),
9
+ ('Emily', 'Smith', NULL),
10
+ ('David', 'Lee', 'William'),
11
+ ('Sarah', 'Taylor', NULL),
12
+ ('Thomas', 'Brown', NULL),
13
+ ('Elizabeth', 'Wilson', 'Jennifer'),
14
+ ('Richard', 'Anderson', 'Matthew'),
15
+ ('Karen', 'Martin', NULL),
16
+ ('William', 'Thompson', NULL),
17
+ ('Nancy', 'Garcia', NULL),
18
+ ('Michael', 'Davis', 'Anthony'),
19
+ ('Mary', 'Miller', NULL),
20
+ ('Christopher', 'Jackson', NULL),
21
+ ('Jessica', 'Perez', 'Marie'),
22
+ ('Brian', 'Moore', NULL),
23
+ ('Megan', 'Allen', NULL),
24
+ ('Anthony', 'Young', NULL),
25
+ ('Laura', 'Harris', 'Christine'),
26
+ ('Kevin', 'King', NULL),
27
+ ('Stephanie', 'Scott', NULL),
28
+ ('Jason', 'Turner', 'Eric'),
29
+ ('Melissa', 'Walker', NULL),
30
+ ('Mark', 'Collins', NULL),
31
+ ('Tiffany', 'Nelson', NULL),
32
+ ('Eric', 'Gonzalez', NULL),
33
+ ('Amy', 'Carter', 'Jennifer'),
34
+ ('Matthew', 'Baker', NULL),
35
+ ('Samantha', 'Edwards', NULL);
36
+
37
+ -- Insert 10 publishers
38
+ INSERT INTO Publisher (Name, Email)
39
+ VALUES
40
+ ('Penguin Random House', 'info@penguinrandomhouse.com'),
41
+ ('HarperCollins Publishers', NULL),
42
+ ('Hachette Book Group', NULL),
43
+ ('Macmillan Publishers', 'info@macmillan.com'),
44
+ ('Simon & Schuster', 'info@simonandschuster.com'),
45
+ ('Oxford University Press', NULL),
46
+ ('Cambridge University Press', 'info@cambridge.org'),
47
+ ('Pearson Education', NULL),
48
+ ('Wiley', 'info@wiley.com'),
49
+ ('Bloomsbury Publishing', 'info@bloomsbury.com');
data/lib/logger.rb ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'logger'
4
+
5
+ ##
6
+ # Обертка для хранения объекта Logger
7
+
8
+ class LoggerHolder
9
+ private_class_method :new
10
+ @instance_mutex = Mutex.new
11
+
12
+ attr_reader :logger
13
+
14
+ def initialize
15
+ @logger = Logger.new(STDOUT)
16
+ end
17
+
18
+ def self.instance
19
+ return @instance.logger if @instance
20
+
21
+ @instance_mutex.synchronize do
22
+ @instance ||= new
23
+ end
24
+
25
+ @instance.logger
26
+ end
27
+ end
data/lib/main.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'logger'
4
+ require_relative 'views/main_window'
5
+ LoggerHolder.instance.level = Logger::DEBUG
6
+ MainWindow.new.create.show
@@ -0,0 +1,32 @@
1
+ class Author
2
+ attr_reader :author_id, :first_name, :last_name, :father_name
3
+
4
+ def initialize(author_id, first_name, last_name, father_name = nil)
5
+ validate_null('author_id', author_id)
6
+ validate_null('first_name', first_name)
7
+ validate_null('last_name', last_name)
8
+
9
+ validate_name_length(first_name, last_name, father_name)
10
+
11
+ @author_id = author_id
12
+ @first_name = first_name
13
+ @last_name = last_name
14
+ @father_name = father_name
15
+ end
16
+
17
+ private
18
+
19
+ def validate_null(name, value)
20
+ if value.nil?
21
+ raise ArgumentError, "Argument '#{name}' cannot be null"
22
+ end
23
+ end
24
+
25
+ def validate_name_length(first_name, last_name, father_name)
26
+ [first_name, last_name, father_name].each do |name|
27
+ if name && name.length > 50
28
+ raise ArgumentError, "Name exceeds 50 characters limit: #{name}"
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,31 @@
1
+ class Book
2
+ attr_reader :book_id, :title, :author_id, :publisher_id
3
+
4
+ def initialize(book_id, title, author_id, publisher_id)
5
+ validate_null('book_id', book_id)
6
+ validate_null('title', title)
7
+ validate_null('author_id', author_id)
8
+ validate_null('publisher_id', publisher_id)
9
+
10
+ validate_title_length(title)
11
+
12
+ @book_id = book_id
13
+ @title = title
14
+ @author_id = author_id
15
+ @publisher_id = publisher_id
16
+ end
17
+
18
+ private
19
+
20
+ def validate_null(name, value)
21
+ if value.nil?
22
+ raise ArgumentError, "Argument '#{name}' cannot be null"
23
+ end
24
+ end
25
+
26
+ def validate_title_length(title)
27
+ if title.length > 255
28
+ raise ArgumentError, "Title exceeds 255 characters limit: #{title}"
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,37 @@
1
+ class Publisher
2
+ EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
3
+
4
+ attr_reader :publisher_id, :name, :email
5
+
6
+ def initialize(publisher_id, name, email = nil)
7
+ validate_null('publisher_id', publisher_id)
8
+ validate_null('name', name)
9
+
10
+ validate_name_length(name)
11
+ validate_email(email)
12
+
13
+ @publisher_id = publisher_id
14
+ @name = name
15
+ @email = email
16
+ end
17
+
18
+ private
19
+
20
+ def validate_null(name, value)
21
+ if value.nil?
22
+ raise ArgumentError, "Argument '#{name}' cannot be null"
23
+ end
24
+ end
25
+
26
+ def validate_name_length(name)
27
+ if name.length > 100
28
+ raise ArgumentError, "Name exceeds 100 characters limit: #{name}"
29
+ end
30
+ end
31
+
32
+ def validate_email(email)
33
+ if email && !email.match?(EMAIL_REGEX)
34
+ raise ArgumentError, "Invalid email format: #{email}"
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require_relative 'student_base'
5
+
6
+ class Student < StudentBase
7
+ # Делаем new предка публичным
8
+ public_class_method :new
9
+
10
+ def self.from_hash(hash)
11
+ raise ArgumentError, 'Fields required: fist_name, last_name, father_name' unless hash.key?(:first_name) && hash.key?(:last_name) && hash.key?(:father_name)
12
+
13
+ first_name = hash.delete(:first_name)
14
+ last_name = hash.delete(:last_name)
15
+ father_name = hash.delete(:father_name)
16
+
17
+ Student.new(last_name, first_name, father_name, **hash)
18
+ end
19
+
20
+ # Конструктор из JSON строки
21
+ def self.from_json_str(str)
22
+ params = JSON.parse(str, { symbolize_names: true })
23
+ from_hash(params)
24
+ end
25
+
26
+ # Делаем публичными геттеры и сеттеры базового класса
27
+ public :phone, :telegram, :email, 'id=', 'phone=', 'telegram=', 'email=', 'git='
28
+
29
+ # Стандартные геттеры для полей
30
+ attr_reader :last_name, :first_name, :father_name
31
+
32
+ # Стандартный конструктор
33
+ def initialize(last_name, first_name, father_name, **options)
34
+ self.last_name = last_name
35
+ self.first_name = first_name
36
+ self.father_name = father_name
37
+ super(**options)
38
+ end
39
+
40
+ # Сеттеры с валидацией перед присваиванием
41
+ def last_name=(new_last_name)
42
+ raise ArgumentError, "Invalid argument: last_name=#{new_last_name}" unless Student.valid_name?(new_last_name)
43
+
44
+ @last_name = new_last_name
45
+ end
46
+
47
+ def first_name=(new_first_name)
48
+ raise ArgumentError, "Invalid argument: first_name=#{new_first_name}" unless Student.valid_name?(new_first_name)
49
+
50
+ @first_name = new_first_name
51
+ end
52
+
53
+ def father_name=(new_father_name)
54
+ raise ArgumentError, "Invalid argument: father_name=#{new_father_name}" unless Student.valid_name?(new_father_name)
55
+
56
+ @father_name = new_father_name
57
+ end
58
+
59
+ # Отдельный сеттер для массовой установки контактов
60
+ def set_contacts(phone: nil, telegram: nil, email: nil)
61
+ self.phone = phone if phone
62
+ self.telegram = telegram if telegram
63
+ self.email = email if email
64
+ end
65
+
66
+ # Имя пользователя в формате Фамилия И. О.
67
+ def last_name_and_initials
68
+ "#{last_name} #{first_name[0]}. #{father_name[0]}."
69
+ end
70
+
71
+ # Краткая информация о пользователе
72
+ def short_info
73
+ info = {}
74
+ info[:last_name_and_initials] = last_name_and_initials
75
+ info[:contact] = short_contact
76
+ info[:git] = git
77
+ JSON.generate(info)
78
+ end
79
+
80
+ # Методы приведения объекта к строке
81
+ def to_s
82
+ result = "#{last_name} #{first_name} #{father_name}"
83
+ %i[id phone telegram email git].each do |attr|
84
+ attr_val = send(attr)
85
+ result += ", #{attr}=#{attr_val}" unless attr_val.nil?
86
+ end
87
+ result
88
+ end
89
+
90
+ def to_hash
91
+ attrs = {}
92
+ %i[last_name first_name father_name id phone telegram email git].each do |attr|
93
+ attr_val = send(attr)
94
+ attrs[attr] = attr_val unless attr_val.nil?
95
+ end
96
+ attrs
97
+ end
98
+
99
+ def to_json_str
100
+ JSON.generate(to_hash)
101
+ end
102
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StudentBase
4
+ # Запрещаем создание базового класса (он "абстрактный")
5
+ private_class_method :new
6
+
7
+ # Валидаторы для полей
8
+ def self.valid_name?(name)
9
+ name.match(/(^[А-Я][а-я]+$)|(^[A-Z][a-z]+$)/)
10
+ end
11
+
12
+ def self.valid_phone?(phone)
13
+ phone.match(/^\+?[78] ?[(-]?\d{3} ?[)-]?[ -]?\d{3}[ -]?\d{2}[ -]?\d{2}$/)
14
+ end
15
+
16
+ def self.valid_profile_name?(profile_name)
17
+ profile_name.match(/^[a-zA-Z0-9_.]+$/)
18
+ end
19
+
20
+ def self.valid_email?(email)
21
+ email.match(/^(?:[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/)
22
+ end
23
+
24
+ # Стандартные геттеры и сеттеры для полей
25
+
26
+ protected
27
+
28
+ attr_writer :id
29
+ attr_reader :phone, :telegram, :email
30
+
31
+ public
32
+
33
+ attr_reader :id, :git
34
+
35
+ # Стандартный конструктор
36
+ def initialize(id: nil, phone: nil, telegram: nil, email: nil, git: nil)
37
+ self.id = id
38
+ self.phone = phone
39
+ self.telegram = telegram
40
+ self.email = email
41
+ self.git = git
42
+ end
43
+
44
+ # Краткая информация о первом доступном контакте пользователя
45
+ def short_contact
46
+ contact = {}
47
+ %i[telegram email phone].each do |attr|
48
+ attr_val = send(attr)
49
+ next if attr_val.nil?
50
+
51
+ contact[:type] = attr
52
+ contact[:value] = attr_val
53
+ return contact
54
+ end
55
+
56
+ nil
57
+ end
58
+
59
+ protected
60
+
61
+ # Сеттеры с валидацией перед присваиванием
62
+ def phone=(new_phone)
63
+ raise ArgumentError, "Invalid argument: phone=#{new_phone}" unless new_phone.nil? || StudentBase.valid_phone?(new_phone)
64
+
65
+ @phone = new_phone
66
+ end
67
+
68
+ def telegram=(new_telegram)
69
+ raise ArgumentError, "Invalid argument: telegram=#{new_telegram}" unless new_telegram.nil? || StudentBase.valid_profile_name?(new_telegram)
70
+
71
+ @telegram = new_telegram
72
+ end
73
+
74
+ def git=(new_git)
75
+ raise ArgumentError, "Invalid argument: git=#{new_git}" unless new_git.nil? || StudentBase.valid_profile_name?(new_git)
76
+
77
+ @git = new_git
78
+ end
79
+
80
+ def email=(new_email)
81
+ raise ArgumentError, "Invalid argument: email=#{new_email}" unless new_email.nil? || StudentBase.valid_email?(new_email)
82
+
83
+ @email = new_email
84
+ end
85
+
86
+ public
87
+
88
+ # Валидаторы объекта
89
+ def has_contacts?
90
+ !phone.nil? || !telegram.nil? || !email.nil?
91
+ end
92
+
93
+ def has_git?
94
+ !git.nil?
95
+ end
96
+
97
+ def valid?
98
+ has_contacts? && has_git?
99
+ end
100
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class StudentShort < StudentBase
4
+ # Делаем new предка публичным
5
+ public_class_method :new
6
+
7
+ # Стандартные геттеры и сеттеры
8
+
9
+ private
10
+
11
+ attr_writer :last_name_and_initials, :contact
12
+
13
+ public
14
+
15
+ attr_reader :last_name_and_initials, :contact
16
+
17
+ # Конструктор из Student
18
+ def self.from_student(student)
19
+ raise ArgumentError, 'Student ID is required' if student.id.nil?
20
+
21
+ StudentShort.new(student.id, student.short_info)
22
+ end
23
+
24
+ # Стандартный конструктор
25
+ def initialize(id, info_str)
26
+ params = JSON.parse(info_str, { symbolize_names: true })
27
+ raise ArgumentError, 'Fields required: last_name_and_initials' if !params.key?(:last_name_and_initials) || params[:last_name_and_initials].nil?
28
+
29
+ self.id = id
30
+ self.last_name_and_initials = params[:last_name_and_initials]
31
+ self.contact = params[:contact]
32
+ self.git = params[:git]
33
+
34
+ options = {}
35
+ options[:id] = id
36
+ options[:git] = git
37
+ options[contact[:type].to_sym] = contact[:value] if contact
38
+ super(**options)
39
+ end
40
+
41
+ # Методы приведения объекта к строке
42
+ def to_s
43
+ result = last_name_and_initials
44
+ %i[id contact git].each do |attr|
45
+ attr_val = send(attr)
46
+ result += ", #{attr}=#{attr_val}" unless attr_val.nil?
47
+ end
48
+ result
49
+ end
50
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'win32api'
4
+
5
+ class PublisherInputFormControllerCreate
6
+ def initialize(parent_controller)
7
+ @parent_controller = parent_controller
8
+ @publisher_rep = PublisherDBDataSource.new
9
+ end
10
+
11
+ def set_view(view)
12
+ @view = view
13
+ end
14
+
15
+ def on_view_created
16
+ # begin
17
+ # @student_rep = StudentRepository.new(DBSourceAdapter.new)
18
+ # rescue Mysql2::Error::ConnectionError
19
+ # on_db_conn_error
20
+ # end
21
+ end
22
+
23
+ def process_fields(fields)
24
+ begin
25
+ puts fields
26
+ item = Publisher.new(-1, *fields.values)
27
+ puts item
28
+ item = @publisher_rep.add(item)
29
+ @parent_controller.state_notifier.add(item)
30
+ @view.close
31
+ rescue ArgumentError => e
32
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
33
+ api.call(0, e.message, 'Error', 0)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def on_db_conn_error
40
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
41
+ api.call(0, "No connection to DB", "Error", 0)
42
+ @view.close
43
+ end
44
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'win32api'
4
+
5
+ class PublisherInputFormControllerEdit
6
+ def initialize(parent_controller, item)
7
+ @parent_controller = parent_controller
8
+ @item = item
9
+ @publisher_rep = PublisherDBDataSource.new
10
+ end
11
+
12
+ def set_view(view)
13
+ @view = view
14
+ end
15
+
16
+ def on_view_created
17
+ # begin
18
+ # @student_rep = StudentRepository.new(DBSourceAdapter.new)
19
+ # rescue Mysql2::Error::ConnectionError
20
+ # on_db_conn_error
21
+ # end
22
+
23
+ # @item = @author_rep.get(@item_id)
24
+ # @view.make_readonly(:git, :telegram, :email, :phone)
25
+ populate_fields(@item)
26
+ end
27
+
28
+ def populate_fields(item)
29
+ @view.set_value(:name, item.name)
30
+ @view.set_value(:email, item.email)
31
+ end
32
+
33
+ def process_fields(fields)
34
+ begin
35
+ item = Publisher.new(@item.publisher_id, *fields.values)
36
+ item = @publisher_rep.change(item)
37
+ @parent_controller.state_notifier.replace(@item, item)
38
+ @view.close
39
+ rescue ArgumentError => e
40
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
41
+ api.call(0, e.message, 'Error', 0)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def on_db_conn_error
48
+ api = Win32API.new('user32', 'MessageBox', ['L', 'P', 'P', 'L'], 'I')
49
+ api.call(0, "No connection to DB", "Error", 0)
50
+ @view.close
51
+ end
52
+ end