Commit 4b43c159536ce27b93d05a52e6e71c677a9ba375
Committed by
David Silva
1 parent
3b4ec38f
Exists in
master
and in
79 other branches
Buid dynamic table into software database
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com> Signed-off-by: Parley Martins <parley@outlook.com>
Showing
2 changed files
with
100 additions
and
73 deletions
Show diff stats
lib/database_helper.rb
... | ... | @@ -64,84 +64,38 @@ module DatabaseHelper |
64 | 64 | end |
65 | 65 | |
66 | 66 | def self.database_html_structure(database_data) |
67 | - database_name = if database_data[:database_description_id].blank? | |
68 | - "" | |
67 | + database_name, database_id = if database_data[:database_description_id].blank? | |
68 | + ["", ""] | |
69 | 69 | else |
70 | - DatabaseDescription.find( | |
70 | + [DatabaseDescription.find( | |
71 | 71 | database_data[:database_description_id], |
72 | 72 | :select=>"name" |
73 | - ).name | |
73 | + ).name, database_data[:database_description_id]] | |
74 | 74 | end |
75 | 75 | |
76 | - Proc::new do | |
77 | - content_tag( | |
78 | - 'table', | |
79 | - content_tag( | |
80 | - 'tr', | |
81 | - content_tag('td', label_tag(_("database Name: ")))+ | |
82 | - content_tag( | |
83 | - 'td', | |
84 | - text_field_tag( | |
85 | - "database_autocomplete", | |
86 | - database_name, | |
87 | - :class=>"database_autocomplete", | |
88 | - :placeholder=>_("Autocomplete field, type something") | |
89 | - ) + | |
90 | - content_tag( | |
91 | - 'div', | |
92 | - _("Pick an item on the list"), | |
93 | - :class=>"autocomplete_validation_message hide-field" | |
94 | - ) | |
95 | - )+ | |
96 | - content_tag( | |
97 | - 'td', | |
98 | - hidden_field_tag( | |
99 | - "database[][database_description_id]", | |
100 | - database_data[:database_description_id], | |
101 | - :class => "database_description_id", | |
102 | - :data => {:label => database_name} | |
103 | - ) | |
104 | - ) | |
105 | - )+ | |
106 | - | |
107 | - content_tag( | |
108 | - 'tr', | |
109 | - content_tag('td', label_tag(_("Version")))+ | |
110 | - content_tag( | |
111 | - 'td', | |
112 | - text_field_tag( | |
113 | - "database[][version]", | |
114 | - database_data[:version], | |
115 | - :maxlength=>"20" | |
116 | - ) | |
117 | - )+ | |
118 | - content_tag('td') | |
119 | - )+ | |
120 | - | |
121 | - content_tag( | |
122 | - 'tr', | |
123 | - content_tag('td', label_tag(_("Operating System")))+ | |
124 | - content_tag( | |
125 | - 'td', | |
126 | - text_field_tag( | |
127 | - "database[][operating_system]", | |
128 | - database_data[:operating_system], | |
129 | - :maxlength=>"20" | |
130 | - ) | |
131 | - )+ | |
132 | - content_tag( | |
133 | - 'td', | |
134 | - button_without_text( | |
135 | - :delete, | |
136 | - _('Delete'), | |
137 | - "#" , | |
138 | - :class=>"delete-dynamic-table" | |
139 | - ), | |
140 | - :align => 'right' | |
141 | - ) | |
142 | - ), :class => 'dynamic-table database-table' | |
143 | - ) | |
144 | - end | |
76 | + data = { | |
77 | + model_name: "database", | |
78 | + field_name: "database_description_id", | |
79 | + name: { | |
80 | + label: _("Name"), | |
81 | + value: database_name, | |
82 | + hidden: true, | |
83 | + autocomplete: true, | |
84 | + id: database_id | |
85 | + }, | |
86 | + version: { | |
87 | + label: _("Version"), | |
88 | + value: database_data[:version], | |
89 | + hidden: true | |
90 | + }, | |
91 | + operating_system: { | |
92 | + label: _("Operating system"), | |
93 | + value: database_data[:operating_system], | |
94 | + delete: true | |
95 | + } | |
96 | + } | |
97 | + | |
98 | + DynamicTableHelper.table_html_structure(data) | |
145 | 99 | end |
146 | 100 | |
147 | 101 | def self.add_dynamic_table | ... | ... |
... | ... | @@ -0,0 +1,73 @@ |
1 | +module DynamicTableHelper | |
2 | + | |
3 | +extend( | |
4 | + ActionView::Helpers::TagHelper, | |
5 | + ActionView::Helpers::FormTagHelper, | |
6 | + ActionView::Helpers::UrlHelper, | |
7 | + ApplicationHelper | |
8 | + ) | |
9 | + | |
10 | + def self.table_html_structure data | |
11 | + Proc::new do | |
12 | + content_tag :table , DynamicTableHelper.generate_table_lines(data), :class => "dynamic-table" | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + def self.generate_table_lines data | |
17 | + @model = data[:model_name].to_css_class | |
18 | + @field_name = data[:field_name] | |
19 | + @value = data[:name][:value] | |
20 | + @hidden_id = data[:name][:id] | |
21 | + | |
22 | + [ | |
23 | + self.table_line(data[:name]), | |
24 | + self.table_line(data[:version]), | |
25 | + self.table_line(data[:operating_system]||data[:license]) | |
26 | + ].join() | |
27 | + end | |
28 | + | |
29 | + def self.table_line row_data | |
30 | + content_tag :tr, [ | |
31 | + self.label_collumn(row_data[:label]), | |
32 | + self.value_collumn(row_data[:value], row_data[:autocomplete]), | |
33 | + self.hidden_collumn(row_data[:delete], row_data[:hidden]) | |
34 | + ].join() | |
35 | + end | |
36 | + | |
37 | + def self.label_collumn label | |
38 | + content_tag :td, label_tag(label) | |
39 | + end | |
40 | + | |
41 | + def self.value_collumn value, autocomplete=false | |
42 | + html_options = | |
43 | + if autocomplete | |
44 | + { | |
45 | + :class => "#{@model}_autocomplete", | |
46 | + :placeholder => _("Autocomplete field, type something") | |
47 | + } | |
48 | + else | |
49 | + {} | |
50 | + end | |
51 | + | |
52 | + content_tag :td, text_field_tag("#{@model}", value, html_options) | |
53 | + end | |
54 | + | |
55 | + def self.hidden_collumn delete=false, hidden_data=false | |
56 | + value = | |
57 | + if delete | |
58 | + button_without_text( | |
59 | + :delete, _('Delete'), "#" , :class=>"delete-dynamic-table" | |
60 | + ) | |
61 | + elsif hidden_data | |
62 | + hidden_field_tag( | |
63 | + "#{@model}[][#{@field_name}]", | |
64 | + @hidden_id, | |
65 | + :class => "#{@field_name}", | |
66 | + :data => {:label => @value } #check how to get the name of an object of the current model | |
67 | + ) | |
68 | + else | |
69 | + nil | |
70 | + end | |
71 | + content_tag(:td, value, :align => 'right') | |
72 | + end | |
73 | +end | |
0 | 74 | \ No newline at end of file | ... | ... |