Commit 587d930786e77f8e8f658cb905a5b769f573f329
Committed by
David Silva
1 parent
5e8e5a7e
Exists in
master
and in
79 other branches
Build DynamicTable into Operating Systems
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
6 changed files
with
71 additions
and
98 deletions
Show diff stats
lib/database_helper.rb
lib/dynamic_table_helper.rb
... | ... | @@ -2,6 +2,7 @@ class DynamicTableHelper |
2 | 2 | extend( |
3 | 3 | ActionView::Helpers::TagHelper, |
4 | 4 | ActionView::Helpers::FormTagHelper, |
5 | + ActionView::Helpers::FormOptionsHelper, | |
5 | 6 | ActionView::Helpers::UrlHelper, |
6 | 7 | ApplicationHelper |
7 | 8 | ) |
... | ... | @@ -21,11 +22,11 @@ class DynamicTableHelper |
21 | 22 | DATA = { |
22 | 23 | name: { |
23 | 24 | label: LABEL_TEXT[:name], |
24 | - name: COLLUMN_NAME[:name], | |
25 | + name: COLLUMN_NAME[:name] | |
25 | 26 | }, |
26 | 27 | version: { |
27 | 28 | label: LABEL_TEXT[:version], |
28 | - name: COLLUMN_NAME[:version], | |
29 | + name: COLLUMN_NAME[:version] | |
29 | 30 | } , |
30 | 31 | license: { |
31 | 32 | label: LABEL_TEXT[:license], |
... | ... | @@ -43,7 +44,7 @@ class DynamicTableHelper |
43 | 44 | end |
44 | 45 | |
45 | 46 | def self.generate_table_lines data={} |
46 | - @@model = data[:model_name].to_css_class | |
47 | + @@model = data[:model_name] | |
47 | 48 | @@field_name = data[:field_name] |
48 | 49 | @@hidden_label = data[:name][:value] |
49 | 50 | @@hidden_id = data[:name][:id] |
... | ... | @@ -66,7 +67,13 @@ class DynamicTableHelper |
66 | 67 | unless row_data.blank? |
67 | 68 | content_tag :tr, [ |
68 | 69 | self.label_collumn(row_data[:label]), |
69 | - self.value_collumn(row_data[:value], row_data[:name], row_data[:autocomplete]), | |
70 | + self.value_collumn( | |
71 | + row_data[:value], | |
72 | + row_data[:name], | |
73 | + row_data[:autocomplete], | |
74 | + row_data[:select_field], | |
75 | + row_data[:options] | |
76 | + ), | |
70 | 77 | self.hidden_collumn(row_data[:delete], row_data[:hidden]) |
71 | 78 | ].join() |
72 | 79 | end |
... | ... | @@ -76,7 +83,7 @@ class DynamicTableHelper |
76 | 83 | content_tag :td, label_tag(label) |
77 | 84 | end |
78 | 85 | |
79 | - def self.value_collumn value="", name="", autocomplete=false, disabled=false | |
86 | + def self.value_collumn value="", name="", autocomplete=false, select_field=false, options=[] | |
80 | 87 | html_options = |
81 | 88 | if autocomplete |
82 | 89 | { |
... | ... | @@ -88,11 +95,16 @@ class DynamicTableHelper |
88 | 95 | end |
89 | 96 | |
90 | 97 | html_options[:disabled] = @@disabled |
91 | - if autocomplete | |
92 | - content_tag :td, text_field_tag("#{@@model}_autocomplete", value, html_options) | |
98 | + | |
99 | + content = if select_field | |
100 | + select_tag("#{@@model}[][#{@@field_name}]", options, html_options) | |
101 | + elsif autocomplete | |
102 | + text_field_tag("#{@@model}_autocomplete", value, html_options) | |
93 | 103 | else |
94 | - content_tag :td, text_field_tag("#{@@model}[][#{name}]", value, html_options) | |
104 | + text_field_tag("#{@@model}[][#{name}]", value, html_options) | |
95 | 105 | end |
106 | + | |
107 | + content_tag :td, content | |
96 | 108 | end |
97 | 109 | |
98 | 110 | def self.hidden_collumn delete=false, hidden_data=false | ... | ... |
lib/library_helper.rb
lib/operating_system_helper.rb
1 | -module OperatingSystemHelper | |
1 | +class OperatingSystemHelper < DynamicTableHelper | |
2 | + MODEL_NAME = "operating_system" | |
3 | + FIELD_NAME = "operating_system_name_id" | |
4 | + | |
2 | 5 | def self.list_operating_system new_operating_systems |
3 | 6 | return [] if new_operating_systems.nil? or new_operating_systems.length == 0 |
4 | 7 | list_operating_system = [] |
... | ... | @@ -30,88 +33,39 @@ module OperatingSystemHelper |
30 | 33 | true |
31 | 34 | end |
32 | 35 | |
33 | - def self.operating_system_as_tables(list_operating_system, have_delete_button = true, show_information = false) | |
34 | - extend( | |
35 | - ActionView::Helpers::TagHelper, | |
36 | - ActionView::Helpers::FormTagHelper, | |
37 | - ActionView::Helpers::UrlHelper, | |
38 | - ActionView::Helpers::FormOptionsHelper, | |
39 | - ApplicationHelper | |
40 | - ) | |
41 | - | |
42 | - lambdas_list = [] | |
43 | - | |
44 | - if not show_information | |
45 | - return operating_system_html_structure( | |
46 | - {:operating_system_name_id => "", :version => ""}, | |
47 | - have_delete_button | |
48 | - ) if list_operating_system.nil? | |
49 | - | |
50 | - list_operating_system.each do |operating_system| | |
51 | - lambdas_list << operating_system_html_structure( | |
52 | - operating_system, | |
53 | - have_delete_button | |
54 | - ) | |
55 | - end | |
56 | - else | |
57 | - list_operating_system.each do |operating_system| | |
58 | - lambdas_list << operating_system_html_structure(operating_system) | |
59 | - end | |
60 | - end | |
36 | + def self.operating_system_as_tables(list_operating_system, disabled=false) | |
37 | + model_list = list_operating_system | |
38 | + model_list ||= [{:operating_system_name_id => "", :version => ""}] | |
61 | 39 | |
62 | - lambdas_list | |
40 | + models_as_tables model_list, "operating_system_html_structure", disabled | |
63 | 41 | end |
64 | 42 | |
65 | - def self.operating_system_html_structure (operating_system_data,have_delete_button = true) | |
66 | - Proc::new do | |
67 | - content_tag( | |
68 | - 'table', | |
69 | - content_tag( | |
70 | - 'tr', | |
71 | - content_tag('td', label_tag(_("Name")))+ | |
72 | - content_tag( | |
73 | - 'td', | |
74 | - select_tag( | |
75 | - "operating_system[][operating_system_name_id]", | |
76 | - SoftwareHelper.select_options( | |
77 | - OperatingSystemName.all, | |
78 | - operating_system_data[:operating_system_name_id] | |
79 | - ) | |
80 | - ) | |
81 | - )+ | |
82 | - content_tag('td') | |
83 | - )+ | |
43 | + def self.operating_system_html_structure (operating_system_data, disabled) | |
44 | + select_options = options_for_select( | |
45 | + OperatingSystemName.all.collect {|osn| [osn.name, osn.id]}, | |
46 | + operating_system_data[:operating_system_name_id] | |
47 | + ) | |
84 | 48 | |
85 | - content_tag( | |
86 | - 'tr', | |
87 | - content_tag('td', label_tag(_("Version")))+ | |
88 | - content_tag( | |
89 | - 'td', | |
90 | - text_field_tag( | |
91 | - "operating_system[][version]", | |
92 | - operating_system_data[:version] | |
93 | - ) | |
94 | - )+ | |
95 | - if have_delete_button | |
96 | - content_tag( | |
97 | - 'td', | |
98 | - button_without_text( | |
99 | - :delete, | |
100 | - _('Delete'), | |
101 | - "#" , | |
102 | - :class=>"delete-dynamic-table" | |
103 | - ), | |
104 | - :align => 'right' | |
105 | - ) | |
106 | - else | |
107 | - content_tag('td', "") | |
108 | - end | |
109 | - ),:class => 'dynamic-table library-table' | |
110 | - ) | |
111 | - end | |
49 | + data = { | |
50 | + model_name: MODEL_NAME, | |
51 | + field_name: FIELD_NAME, | |
52 | + name: { | |
53 | + hidden: false, | |
54 | + autocomplete: false, | |
55 | + select_field: true, | |
56 | + options: select_options | |
57 | + }, | |
58 | + version: { | |
59 | + value: operating_system_data[:version], | |
60 | + hidden: true, | |
61 | + delete: true | |
62 | + } | |
63 | + } | |
64 | + DATA[:license].delete(:value) | |
65 | + table_html_structure(data, disabled) | |
112 | 66 | end |
113 | 67 | |
114 | 68 | def self.add_dynamic_table |
115 | - operating_system_as_tables(nil).call | |
69 | + operating_system_as_tables(nil).first.call | |
116 | 70 | end |
117 | 71 | end | ... | ... |
lib/software_language_helper.rb
views/profile/_software_tab.html.erb
... | ... | @@ -112,9 +112,10 @@ |
112 | 112 | </td> |
113 | 113 | </tr> |
114 | 114 | |
115 | + | |
115 | 116 | <tr> |
116 | 117 | <td> |
117 | - <table class = "operating-system-info"> | |
118 | + <table class="operating-system-info"> | |
118 | 119 | <thead> |
119 | 120 | <tr> |
120 | 121 | <th colspan="2"><%= _("Operating System") %></th> |
... | ... | @@ -122,14 +123,17 @@ |
122 | 123 | </tr> |
123 | 124 | </thead> |
124 | 125 | |
125 | - <tbody> | |
126 | - <% profile.software_info.operating_systems.each do |operating_system| %> | |
127 | - <%= display_mpog_field(_('Name:'), operating_system.operating_system_name , :name, true) %> | |
128 | - <%= display_mpog_field(_('Version:'), operating_system, :version, true) %> | |
129 | - <% end %> | |
130 | - </tbody> | |
131 | - </table> | |
132 | - </td> | |
133 | - </tr> | |
126 | + <tbody> | |
127 | + <tr> <td> | |
128 | + <% operating_systems = profile.software_info.operating_systems %> | |
129 | + <% OperatingSystemHelper.operating_system_as_tables(operating_systems, true).each do |tab| %> | |
130 | + <%= tab.call %> | |
131 | + <%end%> | |
132 | + </td> </tr> | |
133 | + </tbody> | |
134 | + </table> | |
135 | + </td> | |
136 | + </tr> | |
137 | + | |
134 | 138 | </tr> |
135 | 139 | </table> |
136 | 140 | \ No newline at end of file | ... | ... |