student_MyGem 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 326b40637c381f98e9b1d8a29cc26b33aec6d417ea6e3b790c4225d519dc3e8f
4
+ data.tar.gz: 338d6b18646690850174859bebf5f5c5a5b4dabac61b88927f632b42e56a6f56
5
+ SHA512:
6
+ metadata.gz: 81a48913cdb67ec34552eab970eb565baf27b5a0141ab896da45b4eb01d31046242e1ff92213b0f2fd68b6f5b6fc609cb703947d1a7dc210a625f56e219372d9
7
+ data.tar.gz: 46244ee4dad9416a5f5bb80c69e319264c3febf68c11702571e314b717169e8383f1500e7df262895fca5e244c140d1bfd93ce36d0b71ce1250b7aa39ecedf43
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'glimmer-dsl-libui', '~> 0.7.4'
4
+ gem 'mysql2'
5
+ gem 'rubocop', group: 'development'
6
+ gem 'win32api'
7
+ gem "minitest"
8
+ gem 'sinatra', '~> 3.0', '>= 3.0.6'
9
+ gem 'thin', '~> 1.8', '>= 1.8.2'
10
+ gem 'student_MyGem'
@@ -0,0 +1,21 @@
1
+ require_relative 'Data_list'
2
+
3
+ class Data_List_Student_Short<Data_list
4
+
5
+ attr_accessor :view
6
+
7
+ def notify
8
+ self.view.set_table_params(self.get_objects_attr_names.map{|x| x.to_s}, self.list.size)
9
+ self.view.set_table_data(self.get_data)
10
+ end
11
+
12
+ private
13
+ def get_objects_attr(obj)
14
+ return [obj.short_name, obj.Git, obj.contact]
15
+ end
16
+
17
+ def get_objects_attr_names
18
+ return ["short_name","git","contact"]
19
+ end
20
+
21
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'data_table'
2
+ class Data_list
3
+ private
4
+ attr_accessor :selected, :arary
5
+ public
6
+ attr_accessor :list
7
+
8
+ def initialize(list:)
9
+ self.list = list
10
+ self.arary = []
11
+ end
12
+
13
+ def unselect
14
+ self.arary = []
15
+ end
16
+
17
+ def select(number)
18
+ self.arary.append(self.list[number].ID)
19
+ end
20
+ def get_selected
21
+ self.arary
22
+ end
23
+ def get_names
24
+ return ["№", *get_objects_attr_names]
25
+ end
26
+ def get_data
27
+ table = []
28
+ counter = 0
29
+ list.each { |obj| table.append([counter, *get_objects_attr(obj)]); counter += 1}
30
+ return Data_table.new(table: table)
31
+ end
32
+
33
+ protected
34
+
35
+ def get_objects_attr(obj)
36
+ return []
37
+ end
38
+ def get_objects_attr_names()
39
+ return []
40
+ end
41
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'Basic_format'
2
+ class Student_list_DB < Basic_format
3
+
4
+ require 'mysql2'
5
+ require_relative 'DB_singleton'
6
+ require 'json'
7
+
8
+ private
9
+ def format_to_hash(str: )
10
+ return JSON.parse(str, {:symbolize_names => true})
11
+ end
12
+
13
+ def hash_to_format(hash: )
14
+ values = hash.map { |h|
15
+ h.values.join ","
16
+ }.map { |str|
17
+ "(#{str})"
18
+ }.join(",")
19
+ return values
20
+ end
21
+
22
+ def read_file(rfile:)
23
+ results = client.query("SELECT * FROM student", symbolize_keys: true).to_a
24
+ return JSON.pretty_generate(results)
25
+ end
26
+
27
+ def write_file(wfile:, data:)
28
+ insert_query = "insert into student values #{data}"
29
+ self.client.query insert_query
30
+ end
31
+
32
+ public
33
+ attr_accessor :client
34
+ def initialize
35
+ self.client = Mysql2::Client.new(
36
+ host: 'localhost',
37
+ username: 'root',
38
+ password: 'йцукен123456789',
39
+ database: 'students'
40
+ )
41
+ end
42
+
43
+ end
@@ -0,0 +1,65 @@
1
+ class Super_Student
2
+
3
+ attr_accessor :Name, :Surname, :Father_name, :ID, :Git
4
+
5
+ def initialize(name, surname, father_name, id, git)
6
+ self.Name = name
7
+ self.Surname = surname
8
+ self.Father_name = father_name
9
+ self.ID = id
10
+ self.Git = git
11
+ end
12
+
13
+ def self.id_valid?(id)
14
+ String(id).match(/^\d+$/)
15
+ end
16
+
17
+ def ID=(id)
18
+ @ID = id
19
+ end
20
+
21
+ def self.name_valid?(name)
22
+ name.match(/^[А-Я][^А-Я\d]+$/)
23
+ end
24
+
25
+ def Name=(name)
26
+ raise ArgumentError("Invalid value, Name is russian alphabet sequence") unless Super_Student.name_valid?(name)
27
+ @Name = name
28
+ end
29
+
30
+ def Surname=(surname)
31
+ raise ArgumentError("Invalid value, Surname is russian alphabet sequence") if !surname.nil? && !Super_Student.name_valid?(surname)
32
+ @Surname = surname
33
+ end
34
+
35
+ def Father_name=(father_name)
36
+ raise ArgumentError("Invalid value, Father name is russian alphabet sequence") if !father_name.nil? && !Super_Student.name_valid?(father_name)
37
+ @Father_name = father_name
38
+ end
39
+
40
+ def self.acc_valid?(account)
41
+ account.match(/^@[\w\d\-_]+$/)
42
+ end
43
+
44
+ def Git=(git)
45
+ raise ArgumentError, "Invalid value, Git's correct form is @X where X is english alphabet sequence" if !git.nil? && !Student.acc_valid?(git)
46
+ @Git = git
47
+ end
48
+
49
+ def short_name
50
+ "#{Surname} #{Name.upcase[0]}. #{Father_name.upcase[0]}"
51
+ end
52
+
53
+ def self.parse_str(str)
54
+ end
55
+
56
+ def getInfo
57
+ end
58
+
59
+ def contact
60
+ end
61
+
62
+ def to_s
63
+ end
64
+
65
+ end
@@ -0,0 +1,27 @@
1
+ class Data_table
2
+
3
+ private
4
+ attr_writer :table
5
+ public
6
+ attr_reader :table
7
+ def initialize(table:)
8
+ self.table = table
9
+ end
10
+ def get_element(row:, col:)
11
+ return self.table[row][col]
12
+ end
13
+ def get_rows_number
14
+ return self.table.size
15
+ end
16
+
17
+ def each(&block)
18
+ table.each do |row|
19
+ block.call(row)
20
+ end
21
+ end
22
+
23
+ def get_cols_number
24
+ return 0 if table.size == 0
25
+ return self.table[0].size
26
+ end
27
+ end
data/lib/files/main.rb ADDED
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'student'
4
+ require_relative 'student_short'
5
+ require_relative 'Super_Student'
6
+ require_relative 'Data_list'
7
+ require_relative 'data_table'
8
+ require_relative 'Data_List_Student_Short'
9
+ require 'mysql2'
10
+ require 'fox16'
11
+ require_relative 'window'
12
+ require_relative 'student_list_controller'
13
+ require_relative 'main_window'
14
+
15
+ str = 'name:Василий, surname:Васнецов, father_name:Анатольевич, id:11, git:@fdsa, tg:@qpfms'
16
+
17
+ # @db_host = "localhost"
18
+ # @db_user = "root"
19
+ # @db_pass = "йцукен123456789"
20
+ # @db_name = "students"
21
+
22
+ # client = Mysql2::Client.new(:host => @db_host, :username => @db_user, :password => @db_pass, :database => @db_name)
23
+
24
+ # results = client.query("SELECT * FROM student", symbolize_keys: true)
25
+
26
+ # results.each { |r|
27
+ # puts Student.new(**r)
28
+ # puts
29
+ # }
30
+
31
+ Student_List_View.new
32
+
@@ -0,0 +1,152 @@
1
+ require 'fox16'
2
+ include Fox
3
+
4
+ class MainWindow < FXMainWindow
5
+ attr_reader :add_button, :chg_button, :del_button, :upd_button
6
+ attr_reader :go_left_button, :go_right_button
7
+ attr_reader :page_count_label, :cur_page_label
8
+ attr_reader :table, :tabBook
9
+
10
+ def initialize(app)
11
+ super(app, "StudentListView" , :width => 800, :height => 500)
12
+
13
+ self.tabBook = FXTabBook.new(self)
14
+ tabFrame1 = FXTabItem.new(self.tabBook, "Вкладка 1", nil)
15
+ vFrame1 = FXVerticalFrame.new(self.tabBook)
16
+
17
+ tabFrame2 = FXTabItem.new(self.tabBook, "Вкладка 2", nil)
18
+ vFrame2 = FXVerticalFrame.new(self.tabBook)
19
+
20
+ tabFrame3 = FXTabItem.new(self.tabBook, "Вкладка 3", nil)
21
+ vFrame3 = FXVerticalFrame.new(self.tabBook)
22
+
23
+ # Фамилия Имя Отчество?
24
+ hFrame1 = FXHorizontalFrame.new(vFrame1)
25
+ self.add_name_field(hFrame1)
26
+
27
+ # Гит
28
+ self.add_git_field(hFrame1)
29
+
30
+ # Мейл
31
+ hFrame2 = FXHorizontalFrame.new(vFrame1)
32
+ self.add_email_field(hFrame2)
33
+
34
+ # Телефон
35
+ hFrame3 = FXHorizontalFrame.new(vFrame1)
36
+ self.add_phone_field(hFrame3)
37
+
38
+ # Телеграм
39
+ hFrame4 = FXHorizontalFrame.new(vFrame1)
40
+ self.add_tg_field(hFrame4)
41
+
42
+ # Табличка
43
+ hFrame5 = FXHorizontalFrame.new(vFrame1)
44
+ FXLabel.new(hFrame5, "Таблица")
45
+
46
+ hFrame6 = FXHorizontalFrame.new(vFrame1, opts: LAYOUT_FILL_X | LAYOUT_FIX_HEIGHT)
47
+ hFrame6.height = 230
48
+
49
+ self.add_table(hFrame6)
50
+
51
+ # Перелистываем страницы
52
+ hFrame7 = FXHorizontalFrame.new(vFrame1, opts: LAYOUT_FILL_X)
53
+ add_lcr_buttons(hFrame7)
54
+
55
+ # Кнопки
56
+ hFrame8 = FXHorizontalFrame.new(vFrame1, opts: LAYOUT_FILL_X)
57
+ add_crud_buttons(hFrame8)
58
+ end
59
+
60
+ def create
61
+ super
62
+ show(PLACEMENT_SCREEN)
63
+ end
64
+
65
+ def set_table_headers(arr)
66
+ self.table.setColumnText(0, "№")
67
+
68
+ arr.each_with_index { |value, index|
69
+ self.table.setColumnText(index+1, value)
70
+ }
71
+ end
72
+
73
+ private
74
+ attr_writer :add_button, :chg_button, :del_button, :upd_button
75
+ attr_writer :go_left_button, :go_right_button
76
+ attr_writer :page_count_label, :cur_page_label
77
+ attr_writer :table, :tabBook
78
+
79
+
80
+ def handle_list_box_command(index, listbox, field)
81
+ item_text = listbox.getItemText(index)
82
+
83
+ if(item_text == "Да")
84
+ field.enable
85
+ else
86
+ field.disable
87
+ end
88
+ end
89
+
90
+ def add_listboxed_field(frame, presence_of, field_name, field_width)
91
+ label = FXLabel.new(frame, presence_of)
92
+ list = FXListBox.new(frame, width: 20, opts: COMBOBOX_STATIC | COMBOBOX_NO_REPLACE)
93
+ list.appendItem("Да")
94
+ list.appendItem("Нет")
95
+ list.appendItem("Не важно")
96
+
97
+ field_label = FXLabel.new(frame, "Гит: ")
98
+ field = FXTextField.new(frame, field_width)
99
+
100
+ list.connect(SEL_COMMAND) do |_, _, index|
101
+ handle_list_box_command(index, list, field)
102
+ end
103
+ end
104
+
105
+ def add_name_field(frame)
106
+ name_label = FXLabel.new(frame, "Фамилия и инициалы: ")
107
+ name_field = FXTextField.new(frame, 10)
108
+ end
109
+
110
+ def add_git_field(frame)
111
+ add_listboxed_field(frame, "Наличие гита: ", "Гит: ", 10)
112
+ end
113
+
114
+ def add_email_field(frame)
115
+ add_listboxed_field(frame, "Наличие мейла: ", "Мейл: ", 30)
116
+ end
117
+
118
+ def add_phone_field(frame)
119
+ add_listboxed_field(frame, "Наличие телефона: ", "Телефон: ", 17)
120
+ end
121
+
122
+ def add_tg_field(frame)
123
+ add_listboxed_field(frame, "Наличие телеграма: ", "Телеграм: ", 10)
124
+ end
125
+
126
+ def add_table(frame)
127
+ self.table = FXTable.new(frame, :opts => LAYOUT_FILL)
128
+ self.table.editable = false
129
+ end
130
+
131
+ def add_crud_buttons(frame)
132
+ self.add_button = FXButton.new(frame, "Добавить")
133
+ self.chg_button = FXButton.new(frame, "Изменить")
134
+ self.del_button = FXButton.new(frame, "Удалить")
135
+ self.upd_button = FXButton.new(frame, "Обновить")
136
+
137
+ self.chg_button.disable
138
+ self.del_button.disable
139
+ end
140
+
141
+ def add_lcr_buttons(frame)
142
+ self.go_left_button = FXButton.new(frame, "<<")
143
+
144
+ self.cur_page_label = FXLabel.new(frame, "")
145
+
146
+ FXLabel.new(frame, "/")
147
+
148
+ self.page_count_label = FXLabel.new(frame, "")
149
+
150
+ self.go_right_button = FXButton.new(frame, ">>")
151
+ end
152
+ end
@@ -0,0 +1,129 @@
1
+ require_relative 'Super_Student'
2
+
3
+ class Student<Super_Student
4
+ attr_reader :Phone, :Tg, :Mail
5
+
6
+ def initialize(name:, surname:, father_name:, id:nil, git:nil, mail:nil, tg:nil, phone:nil)
7
+ super(name, surname, father_name, id, git)
8
+ set_contacts(mail:mail, tg:tg, phone:phone)
9
+ end
10
+
11
+ def self.phone_valid?(phone)
12
+ phone.match(/^\+?[7,8]{1}\-\d{3}\-\d{3}\-\d{2}\-\d{2}$/)
13
+ end
14
+
15
+ def Phone=(phone)
16
+ raise ArgumentError("Invalid value, phone number's correct form is \"+7(8)-XXX-XXX-XX-XX\"") if !phone.nil? && !Student.phone_valid?(phone)
17
+ @Phone = phone
18
+ end
19
+
20
+ def Tg=(tg)
21
+ raise ArgumentError, "Invalid value, Telegram account's correct form is @X where X is english alphabet sequence" if !tg.nil? && !Student.acc_valid?(tg)
22
+ @Tg = tg
23
+ end
24
+
25
+ def self.mail_valid?(mail)
26
+ mail.match(/^[\w\d]+@[\w]+\.[\w]+$/)
27
+ end
28
+
29
+
30
+ def Mail=(mail)
31
+ raise ArgumentError, "Invalid value, Mail's correct form is X@X.X where X is english alphabet sequence" if !mail.nil? && !Student.mail_valid?(mail)
32
+ @Mail = mail
33
+ end
34
+
35
+ def set_contacts(mail:, tg:, phone:)
36
+ self.Phone = phone unless phone.nil?
37
+ self.Mail = mail unless mail.nil?
38
+ self.Tg = tg unless tg.nil?
39
+ end
40
+
41
+ def to_s
42
+ info=@Name.to_s+" "+@Surname.to_s+" "+@Father_name.to_s+" "
43
+ info+=tg_to_s
44
+ info+=phone_to_s
45
+ info+=git_to_s
46
+ info
47
+ end
48
+
49
+ def self.parse_str(str)
50
+ str_student=str.split(', ').map{|x| x.split(':')}.to_h
51
+ raise ArgumentError,"Invalid name " unless str_student.key?("name") && Student.name_valid?(str_student["name"])
52
+ raise ArgumentError,"Invalid surname" unless str_student.key?("surname") && Student.name_valid?(str_student["surname"])
53
+ raise ArgumentError,"Invalid father's name" unless str_student.key?("father_name") && Student.name_valid?(str_student["father_name"])
54
+ if str_student.key?("tg")
55
+ raise ArgumentError, "Invalid telegram" unless Student.acc_valid?(str_student["tg"])
56
+ end
57
+ if str_student.key?("git")
58
+ raise ArgumentError, "Invalid git" unless Student.acc_valid?(str_student["git"])
59
+ end
60
+ if str_student.key?("mail")
61
+ raise ArgumentError, "Invalid mail addres" unless Student.mail_valid?(str_student["mail"])
62
+ end
63
+ if str_student.key?("id")
64
+ raise ArgumentError, "Invalid id" unless Student.id_valid?(str_student["id"])
65
+ end
66
+ if str_student.key?("phone")
67
+ raise ArgumentError, "Invalid phone number" unless Student.phone_valid?(str_student["phone"])
68
+ end
69
+ Student.new(name:str_student["name"],surname:str_student["surname"],father_name:str_student["father_name"],id:str_student["id"],git:str_student["git"],mail:str_student["mail"],phone: str_student["phone"], tg:str_student["tg"])
70
+ end
71
+
72
+ def getInfo
73
+ short=Student_short.from_student(self)
74
+ "#{short.short_name}, #{contact}, #{git_to_s}"
75
+ end
76
+
77
+ def get_short
78
+ short=Student_short.from_student(self)
79
+ return short.short_name
80
+ end
81
+
82
+ def contact
83
+ s=""
84
+ s+= self.phone_to_s
85
+ s+= self.tg_to_s
86
+ s+= self.mail_to_s
87
+ return s
88
+ end
89
+
90
+ def self.read_from_txt(path_name)
91
+ raise FileNotFoundError unless File.exist?(path_name)
92
+ File.read(path_name).split("\n").map{|line| Student.parse_str(line)}
93
+ end
94
+
95
+ def self.write_to_txt(path_name,student)
96
+ raise FileNotFoundError unless File.exist?(path_name)
97
+ File.open(path_name,'w') {|file| file.write(student.map{|stud|stud.getInfo}.join("\n"))}
98
+ end
99
+
100
+ def validate?
101
+ git? && self.contact!=""
102
+ end
103
+
104
+ def git?
105
+ !@Git.nil?
106
+ end
107
+
108
+ private
109
+
110
+ def mail_to_s
111
+ return "" if self.Mail.nil?
112
+ ", email: #{@Mail}"
113
+ end
114
+ def tg_to_s
115
+ return "" if self.Tg.nil?
116
+ ", telegram: #{@Tg}"
117
+ end
118
+
119
+ def phone_to_s
120
+ return "" if self.Phone.nil?
121
+ ", phone: #{@Phone}"
122
+ end
123
+
124
+ def git_to_s
125
+ return "" if self.Git.nil?
126
+ ", git: #{@Git}"
127
+ end
128
+
129
+ end
@@ -0,0 +1,97 @@
1
+ require_relative "window.rb"
2
+ require_relative 'Basic_list'
3
+ require_relative 'Student_list_DB'
4
+
5
+ class StudentListController
6
+ private
7
+ attr_accessor :view, :list, :data_list_student_short
8
+
9
+ public
10
+ def initialize(view)
11
+ self.view = view
12
+ self.list = Basic_list.new
13
+ self.list.format = Student_list_DB.new
14
+ self.load_list
15
+ self.data_list_student_short = self.list.get_k_n_student_short_list(k:0, n:self.table_row_count)
16
+ self.data_list_student_short.view = self.view
17
+ end
18
+
19
+ def cur_page
20
+ if @cur_page.nil? or @cur_page <= 1 or @cur_page > self.page_count then @cur_page = 1 end
21
+
22
+ @cur_page
23
+ end
24
+
25
+ def del_selected
26
+ id_array = self.data_list_student_short.get_selected
27
+ id_array.each do |id|
28
+ self.list.delete_byID(id: id)
29
+ end
30
+ end
31
+
32
+ def unselect
33
+ self.data_list_student_short.unselect
34
+ end
35
+
36
+ def select(id)
37
+ self.data_list_student_short.select(id)
38
+ end
39
+
40
+ def page_count
41
+ if !self.list.nil? then
42
+ (self.list.get_student_short_count.to_f / self.table_row_count).ceil
43
+ else
44
+ 1
45
+ end
46
+ end
47
+
48
+ def next_page
49
+ self.cur_page += 1
50
+ end
51
+
52
+ def prev_page
53
+ self.cur_page -= 1
54
+ end
55
+
56
+ def refresh_data(reload: false)
57
+ if (reload) then
58
+ self.load_list()
59
+ end
60
+
61
+ self.list.get_k_n_student_short_list(k:self.cur_page - 1, n:self.table_row_count, data_list: data_list_student_short)
62
+
63
+ self.data_list_student_short.notify
64
+ end
65
+
66
+ def sort
67
+ self.list.sort_si
68
+ end
69
+
70
+
71
+ private
72
+
73
+ def table_row_count; 10 end
74
+
75
+ def last_page?(page)
76
+ page >= self.page_count
77
+ end
78
+
79
+ def first_page?(page)
80
+ page <= 1
81
+ end
82
+
83
+ def cur_page=(value)
84
+ if last_page?(value) then
85
+ @cur_page = self.page_count
86
+ elsif first_page?(value) then
87
+ @cur_page = 1
88
+ else
89
+ @cur_page = value
90
+ end
91
+ end
92
+
93
+ def load_list
94
+ self.list.read_list
95
+ end
96
+
97
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'Super_Student'
2
+ require_relative 'student'
3
+
4
+ class Student_short<Super_Student
5
+ attr_reader :ID, :Surname, :Initials,:Git,:Contact
6
+ def initialize(id:, surname:, initials:, git:, contact:)
7
+ @ID = id
8
+ @Surname = surname
9
+ @Initials = initials
10
+ @Git = git
11
+ @Contact = contact
12
+ end
13
+
14
+ def self.from_student(student)
15
+ Student_short.new(id:student.ID, surname:student.Surname, initials:"#{student.Name[0]}. #{student.Father_name[0]}.", git:student.Git, contact:student.contact)
16
+ end
17
+
18
+ def self.parse_str(str)
19
+ Student_short.from_student(Student.parse_str(str))
20
+ end
21
+
22
+ def short_name
23
+ "#{@Surname} #{@Initials}"
24
+ end
25
+
26
+ def to_s
27
+ result = short_name
28
+ result += ", id=#{@ID} " unless @ID.nil?
29
+ result += ", git=#{@Git} " unless @Git.nil?
30
+ result += @Contact unless @Contact.nil?
31
+ result
32
+ end
33
+
34
+ def contact
35
+ @Contact
36
+ end
37
+
38
+ def getInfo
39
+ return self.short_name+@Git
40
+ end
41
+
42
+ def contact?
43
+ !@Contact.nil?
44
+ end
45
+ end
@@ -0,0 +1,139 @@
1
+ require_relative 'main_window'
2
+ require_relative 'student_list_controller'
3
+
4
+ class Student_List_View
5
+ def set_table_params(column_names, whole_entities_count)
6
+ self.window.table.setTableSize(whole_entities_count, 4)
7
+ self.window.set_table_headers(column_names)
8
+ end
9
+
10
+ def set_table_data(data_table)
11
+ table = self.window.table
12
+
13
+ self.erase_table
14
+
15
+ (0...data_table.get_rows_number).each do |x|
16
+ if data_table.get_element(row:x, col:0).nil? then break end
17
+
18
+ (0...data_table.get_cols_number).each do |y|
19
+ value = data_table.get_element(row:x, col:y)
20
+ puts value
21
+ table.setItemText(x, y, value.to_s)
22
+ end
23
+ end
24
+ end
25
+
26
+ def initialize
27
+
28
+ app = FXApp.new
29
+
30
+ self.window = MainWindow.new(app)
31
+
32
+ self.set_table_handlers
33
+ self.set_lcr_handlers
34
+ self.set_tab_book_handler
35
+
36
+ app.create
37
+
38
+ self.controller = StudentListController.new(self)
39
+
40
+ self.window.del_button.connect(SEL_COMMAND) do
41
+ self.controller.del_selected
42
+ self.refresh
43
+ end
44
+
45
+ self.refresh
46
+
47
+ app.run
48
+
49
+
50
+ end
51
+
52
+ def set_table_handlers
53
+ table = self.window.table
54
+ chg_button = self.window.chg_button
55
+ del_button = self.window.del_button
56
+
57
+ cells_selected_handler = Proc.new do
58
+ all_cols_selected = table.selEndColumn - table.selStartColumn + 1 == table.numColumns
59
+ num_selected_rows = table.selEndRow - table.selStartRow + 1
60
+
61
+ self.controller.unselect
62
+
63
+ (table.selStartRow..table.selEndRow).each do |row|
64
+ self.controller.select(row)
65
+ end
66
+
67
+ if num_selected_rows == 1 and all_cols_selected
68
+ chg_button.enable
69
+ del_button.enable
70
+ elsif num_selected_rows > 1 and all_cols_selected
71
+ chg_button.disable
72
+ del_button.enable
73
+ else
74
+ chg_button.disable
75
+ del_button.disable
76
+ end
77
+ end
78
+
79
+ table.connect(SEL_SELECTED, &cells_selected_handler)
80
+ table.connect(SEL_CHANGED, &cells_selected_handler)
81
+
82
+ table.columnHeader.connect(SEL_COMMAND) do |_, _, index|
83
+ if(index == 1)
84
+ puts("Сортировка")
85
+ self.sort
86
+ else
87
+ puts("Сортировочки пока нет...")
88
+ end
89
+ end
90
+ end
91
+
92
+ attr_accessor :window
93
+
94
+ private
95
+ attr_accessor :controller
96
+
97
+ def set_tab_book_handler
98
+ window.tabBook.connect(SEL_COMMAND) do |sender, selector, data|
99
+ if(sender.current == 0) then
100
+ self.refresh(reload: true)
101
+ end
102
+ end
103
+ end
104
+
105
+ def sort
106
+ self.controller.sort
107
+ self.refresh
108
+ end
109
+
110
+ def set_lcr_handlers
111
+ self.window.go_left_button.connect(SEL_COMMAND) do
112
+ self.controller.prev_page
113
+ self.refresh
114
+ end
115
+
116
+ self.window.go_right_button.connect(SEL_COMMAND) do
117
+ self.controller.next_page
118
+ self.refresh
119
+ end
120
+ end
121
+
122
+
123
+ def erase_table
124
+ for i in 0...self.window.table.numRows
125
+ for j in 0...self.window.table.numColumns
126
+ self.window.table.setItemText(i, j, "")
127
+ end
128
+ end
129
+ end
130
+
131
+ def refresh(reload: false)
132
+ self.controller.refresh_data(reload: reload)
133
+
134
+ self.window.page_count_label.text = self.controller.page_count.to_s
135
+ self.window.cur_page_label.text = self.controller.cur_page.to_s
136
+ end
137
+
138
+
139
+ end
@@ -0,0 +1,3 @@
1
+ module Student_MyGem
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require_relative 'student_MyGem/version'
2
+
3
+ module Student_MyGem
4
+ Dir[File.dirname(__FILE__) + '/files/**/*.rb'].each { |file|
5
+ puts file
6
+ require file
7
+ }
8
+ end
@@ -0,0 +1,15 @@
1
+ require_relative "lib/student_MyGem/version"
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "student_MyGem"
5
+ spec.version = Student_MyGem::VERSION
6
+ spec.authors = ["Valentin"]
7
+ spec.email = ["nenado@gmail.com"]
8
+ spec.summary = "Student App"
9
+ spec.description = "А gem that allows you to get pass for patterns"
10
+ spec.homepage = "https://github.com/Disskretkalove/Ruby"
11
+ spec.license = "MIT"
12
+ spec.required_ruby_version = ">= 3.2.0"
13
+ spec.add_dependency 'win32api'
14
+ spec.files = Dir.glob("**/*")
15
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: student_MyGem
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Valentin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: win32api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: А gem that allows you to get pass for patterns
28
+ email:
29
+ - nenado@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - lib/files/Data_List_Student_Short.rb
36
+ - lib/files/Data_list.rb
37
+ - lib/files/Student_list_DB.rb
38
+ - lib/files/Super_Student.rb
39
+ - lib/files/data_table.rb
40
+ - lib/files/main.rb
41
+ - lib/files/main_window.rb
42
+ - lib/files/student.rb
43
+ - lib/files/student_list_controller.rb
44
+ - lib/files/student_short.rb
45
+ - lib/files/window.rb
46
+ - lib/student_MyGem.rb
47
+ - lib/student_MyGem/version.rb
48
+ - student_MyGem.gemspec
49
+ homepage: https://github.com/Disskretkalove/Ruby
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.3.26
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Student App
72
+ test_files: []