Skip to content

Commit e9b53ef

Browse files
'#TDP - IW Realise table auto
Realise filter for auto
1 parent 3d60e30 commit e9b53ef

File tree

21 files changed

+429
-147
lines changed

21 files changed

+429
-147
lines changed

IndividualWork/Unit_tests/tests_db/test_auto.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_get_k_n
2222
model = table.get_element(0,1)
2323
highlander = table.get_element(1,1)
2424
surname = table.get_element(1,0)
25-
color = table.get_element(1,2)
25+
color = table.get_element(1,3)
2626
assert_equal("model", model)
2727
assert_equal("Яковлев", surname)
2828
assert_equal("Higlander", highlander)
@@ -40,7 +40,7 @@ def test_after_db_files_json
4040
table = data_list_auto.getDataFromTable()
4141
model = table.get_element(0,1)
4242
model_name = table.get_element(1,1)
43-
id_owner = table.get_element(1,4)
43+
id_owner = table.get_element(1,5)
4444
assert_equal("model", model)
4545
assert_equal("X6", model_name)
4646
assert_equal(1, id_owner)

IndividualWork/Unit_tests/tests_db/test_model.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def setup
1111

1212
def test_initialize
1313
elem = @model.get_element_by_id("X6")
14+
print elem,"\n"
1415
assert_equal("BMW", elem["mark"])
1516
assert_equal("X6", elem["model"])
1617
end

IndividualWork/Unit_tests/tests_entity/test_auto.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,26 @@ def setup
88
@auto1 = Auto.new(id:0,
99
id_owner:1,
1010
surname_owner:"Goblin",
11+
mark:"BMW",
1112
model:"Wolf",
1213
color:"black")
1314

14-
@auto2 = Auto.initialization("1,2,Kupit,Highlander,gray")
15+
@auto2 = Auto.initialization("1,2,Kupit,Highlander,Toyota,gray")
1516
end
1617

1718
def test_initialize_auto1
1819
assert_equal(1, @auto1.id_owner)
1920
assert_equal("Goblin", @auto1.surname_owner)
2021
assert_equal("Wolf", @auto1.model)
22+
assert_equal("BMW", @auto1.mark)
2123
assert_equal("black", @auto1.color)
2224
end
2325

2426
def test_initialize_auto2
2527
assert_equal(2, @auto2.id_owner)
2628
assert_equal("Kupit", @auto2.surname_owner)
2729
assert_equal("Highlander", @auto2.model)
30+
assert_equal("Toyota", @auto2.mark)
2831
assert_equal("gray", @auto2.color)
2932
end
3033

IndividualWork/Unit_tests/tests_files/test_auto_json.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_get_k_n
2424
table = data_list_auto.getDataFromTable()
2525
model = table.get_element(0,1)
2626
model_name = table.get_element(1,1)
27-
id_owner = table.get_element(1,4)
27+
id_owner = table.get_element(1,5)
2828
assert_equal("model", model)
2929
assert_equal("X6", model_name)
3030
assert_equal(1, id_owner)
@@ -42,24 +42,27 @@ def test_write_files
4242
id_owner:1,
4343
surname_owner:"Goblin",
4444
model:"X6",
45+
mark:"BMW",
4546
color:"black"),
4647
Auto.new(id:2,
4748
id_owner:2,
4849
surname_owner: "Kupit",
4950
model:"Highlander",
51+
mark:"Toyota",
5052
color:"gray"),
5153
Auto.new(id:3,
5254
id_owner:3,
5355
surname_owner: "Pisa",
54-
model:"Skoda",
56+
model:"Rapid",
57+
mark:"Skoda",
5558
color:"black")]
5659

5760
@auto_file.write_to_file("/../../testfile/testfile_auto/","test",elements)
5861

5962
data_list_auto = @auto_file.get_k_n_elements_list(1,3,data_list:nil)
6063
table = data_list_auto.getDataFromTable()
6164
assert_equal("Pisa", table.get_element(3,0))
62-
assert_equal("Skoda", table.get_element(3,1))
65+
assert_equal("Rapid", table.get_element(3,1))
6366

6467
end
6568

IndividualWork/controller/controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Controller
55
attr_writer :view
66
attr_reader :entity_list
77

8-
def initialize(owners_list,guard_list,auto_list,log_mode = :all)
8+
def initialize(owners_list,guard_list,auto_list,mark_list,model_list,log_mode = :all)
99
self.logger = Logger.new("log.txt")
1010
case log_mode
1111
when :errors
@@ -19,6 +19,8 @@ def initialize(owners_list,guard_list,auto_list,log_mode = :all)
1919
@owners_list = owners_list
2020
@guard_list = guard_list
2121
@auto_list = auto_list
22+
@mark_list = mark_list
23+
@model_list = model_list
2224
end
2325

2426
def change_entity(num_tab)
@@ -27,6 +29,8 @@ def change_entity(num_tab)
2729
@entity_list = @owners_list
2830
when 1
2931
@entity_list = @guard_list
32+
when 2
33+
@entity_list = @auto_list
3034
else
3135
@entity_list = @owners_list
3236
end

IndividualWork/main.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
load './model_entity/entity_list/Parking_list.rb'
66
load './model_person/list_file/owner_list.rb'
77
load './model_person/list_file/guard_list.rb'
8-
load './model_auto/datatable/auto_list.rb'
9-
load './model_auto/datatable/mark_list.rb'
10-
load './model_auto/datatable/model_list.rb'
8+
load './model_auto/list_file/auto_list_json.rb'
9+
load './model_auto/list_file/mark/mark_list_json.rb'
10+
load './model_auto/list_file/model/model_list_json.rb'
1111
#--------------------Controller-----------
1212
load './controller/controller.rb'
1313
load './controller/controller_insert.rb'
1414
load './controller/controller_update.rb'
1515

16+
#--------------------View-----------
1617
load './views/view.rb'
1718
#------------------Owner---------------
1819
load './views/modal_window_owners/modal_window_create_owner.rb'
@@ -43,8 +44,8 @@ def self.actions(type_action,enitity,files:nil)
4344
end
4445
end
4546

46-
def self.build_main_controller(owner:nil,guard:nil,auto:nil)
47-
Controller.new(owner,guard,auto,:hybrid)
47+
def self.build_main_controller(owner:nil,guard:nil,auto:nil,mark:nil,model:nil)
48+
Controller.new(owner,guard,auto,mark,model,:hybrid)
4849
end
4950

5051
def self.build_main_window(application,
@@ -97,11 +98,14 @@ def self.connection_window_controller(controller,window)
9798
mysql_owner = Factory.actions(:mysql,:owner)
9899
mysql_guard = Factory.actions(:mysql,:guard)
99100
mysql_auto = Factory.actions(:mysql,:auto)
101+
mysql_model = Factory.actions(:mysql,:model)
102+
mysql_mark = Factory.actions(:mysql,:mark)
100103
json_owner = Factory.actions(:json,:owner,files:Persons_list_json.new(person:Owner_list.new(:json)))
101104
json_guard = Factory.actions(:json,:guard,files:Persons_list_json.new(person:Guard_list.new(:json)))
105+
json_auto= Factory.actions(:json,:auto,files:Auto_list_json.new())
102106

103107

104-
controller = Factory.build_main_controller(owner:mysql_owner,guard:mysql_guard,auto:mysql_auto)
108+
controller = Factory.build_main_controller(owner:mysql_owner,guard:mysql_guard,auto:mysql_auto,mark:mysql_mark,model:mysql_model)
105109
contoller_modal_create = Factory.build_controllers(:insert,controller)
106110
controller_modal_change = Factory.build_controllers(:update,controller)
107111
application = FXApp.new

IndividualWork/model_auto/auto.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class Auto
2-
attr_reader :id_owner,:model, :color,:surname_owner
2+
attr_reader :id_owner,:model, :color,:surname_owner,:mark
33
attr_accessor :id
44

55
define_singleton_method :check_word do |word|
@@ -14,25 +14,26 @@ class Auto
1414
/^[\-A-z0-9]+$/.match(word)
1515
end
1616

17-
def initialize(id:,id_owner:,surname_owner:,model:,color:)
18-
set_baseInfo(id_owner:id_owner,surname_owner:surname_owner,model:model,color:color)
17+
def initialize(id:,id_owner:,surname_owner:,model:,color:,mark:)
18+
set_baseInfo(id_owner:id_owner,surname_owner:surname_owner,model:model,color:color,mark:mark)
1919
self.id = id
2020
end
2121

2222
def self.initialization(information)
23-
raise "Not enough data or exists unnecessary data!(split [,])" if(information.count(",") > 5 || information.count(",") == 0)
23+
raise "Not enough data or exists unnecessary data!(split [,])" if(information.count(",") > 6 || information.count(",") == 0)
2424
hash_data = Auto.string_to_hash(information.delete(' ').split(","))
25-
Auto.new(id:hash_data["id"],id_owner:Integer(hash_data["id_owner"]),surname_owner:hash_data["surname_owner"],model:hash_data["model"],color:hash_data["color"])
25+
Auto.new(id:hash_data["id"],id_owner:Integer(hash_data["id_owner"]),surname_owner:hash_data["surname_owner"],model:hash_data["model"],color:hash_data["color"],mark:hash_data["mark"])
2626
end
2727

2828
def to_s()
2929
"#{self.model} #{self.color}"
3030
end
31-
def set_baseInfo(id_owner:nil,surname_owner:nil,model:nil,color:nil)
32-
valid_baseField_onCorrect(id_owner:id_owner,surname_owner:surname_owner,model:model,color:color)
31+
def set_baseInfo(id_owner:nil,surname_owner:nil,model:nil,color:nil,mark:nil)
32+
valid_baseField_onCorrect(id_owner:id_owner,surname_owner:surname_owner,model:model,color:color,mark:mark)
3333
self.id_owner = id_owner if(id_owner!=nil)
3434
self.surname_owner = surname_owner if(surname_owner != nil)
3535
self.model = model if (model!=nil)
36+
self.mark = mark if (mark!=nil)
3637
self.color = color if(color !=nil)
3738
end
3839

@@ -42,19 +43,20 @@ def get_info()
4243

4344

4445
private
45-
attr_writer :id_owner,:model, :color,:surname_owner
46+
attr_writer :id_owner,:model, :color,:surname_owner,:mark
4647

4748
def self.string_to_hash(data)
4849
hash_data = Hash.new
4950
hash_data["id"] = data[0]
5051
hash_data["id_owner"] = data[1]
5152
hash_data["surname_owner"] = data[2]
52-
hash_data["model"] = data[3]
53-
hash_data["color"] = data[4]
53+
hash_data["model"] = data[3]
54+
hash_data["mark"] = data[4]
55+
hash_data["color"] = data[5]
5456
hash_data
5557
end
5658

57-
def valid_baseField_onCorrect(id_owner:,model:,color:,surname_owner:)
59+
def valid_baseField_onCorrect(id_owner:,model:,color:,surname_owner:,mark:)
5860
if(color!=nil) then
5961
raise "Not valid color [A-Z][a-z]+ #{color}" if(Auto.check_word(color) == nil || color.length > 50)
6062
end
@@ -67,6 +69,9 @@ def valid_baseField_onCorrect(id_owner:,model:,color:,surname_owner:)
6769
if(model!=nil) then
6870
raise "Not valid model #{model}" if(Auto.check_no_special_symbol(model) == nil)
6971
end
72+
if(mark!=nil) then
73+
raise "Not valid mark #{mark}" if(Auto.check_no_special_symbol(mark) == nil)
74+
end
7075
end
7176

7277

IndividualWork/model_auto/auto_DB/auto_list_DB.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ def get_k_n_elements_list(k,n,data_list:nil,filter_initials:nil,filter_phone:nil
2020
list_auto = []
2121
@dbcon.crud_by_db("Select * FROM Auto LIMIT #{limit} OFFSET #{offset};").to_a.each do |elem|
2222
surname_owner = @dbcon.crud_by_db("Select surname FROM Owner WHERE id = #{elem["owner_id"]};").to_a
23+
mark = @dbcon.crud_by_db("Select mark FROM Model WHERE model = '#{elem["model"]}';").to_a
2324
auto = Auto.new(
2425
id:elem["id"],
2526
id_owner:Integer(elem["owner_id"]),
2627
surname_owner: surname_owner[0]["surname"],
2728
model:elem["model"],
29+
mark:mark[0]["mark"],
2830
color:elem["color"])
2931
list_auto.push(auto)
3032
end
@@ -62,7 +64,9 @@ def get_elements_count()
6264
def create_auto(element:,id:nil)
6365
Auto.new(id:id,
6466
id_owner:Integer(element["owner_id"]),
67+
surname_owner:element["surname_owner"],
6568
model:element["model"],
69+
mark:element["mark"],
6670
color:element["color"])
6771
end
6872

IndividualWork/model_auto/datatable/auto_list.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def create_auto(element:,id:nil)
5454
id_owner:element["id_owner"],
5555
surname_owner: element["surname_owner"],
5656
model:element["model"],
57+
mark:element["mark"],
5758
color:element["color"])
5859
end
5960

IndividualWork/model_auto/datatable/data_list_auto.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ def notify(whole_entities_count)
1111

1212
private
1313
def get_names()
14-
arr_attr= ["surname_owner","model","color"]
14+
arr_attr= ["num","surname_owner","model","mark","color"]
1515
end
1616

1717
def get_data()
1818
matrix = []
19+
count = 1
1920
@list_entities.each do |elem|
20-
matrix.push([elem.surname_owner,elem.model,elem.color,elem.id,elem.id_owner])
21+
matrix.push([count,elem.surname_owner,elem.model,elem.mark,elem.color,elem.id,elem.id_owner])
22+
count +=1
2123
end
2224
matrix
2325
end

0 commit comments

Comments
 (0)