Commit d2f905f7d30020109a2ae559340a35d927e4fb84
Committed by
David Silva
1 parent
19330e12
Exists in
master
and in
79 other branches
Build DynamicTable into Library
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
9 changed files
with
114 additions
and
123 deletions
Show diff stats
lib/database_helper.rb
... | ... | @@ -43,11 +43,8 @@ class DatabaseHelper < DynamicTableHelper |
43 | 43 | end |
44 | 44 | |
45 | 45 | def self.database_as_tables(list_databases, disabled=false) |
46 | - model_list = if list_databases.blank? | |
47 | - [{:database_description_id => "", :version => ""}] | |
48 | - else | |
49 | - list_databases | |
50 | - end | |
46 | + model_list = list_databases | |
47 | + model_list ||= [{:database_description_id => "", :version => ""}] | |
51 | 48 | |
52 | 49 | models_as_tables model_list, "database_html_structure", disabled |
53 | 50 | end |
... | ... | @@ -69,12 +66,16 @@ class DatabaseHelper < DynamicTableHelper |
69 | 66 | name: { |
70 | 67 | value: database_name, |
71 | 68 | id: database_id, |
69 | + hidden: true, | |
70 | + autocomplete: true | |
72 | 71 | }, |
73 | 72 | version: { |
74 | - value: database_data[:version] | |
73 | + value: database_data[:version], | |
74 | + hidden: true, | |
75 | + delete: true | |
75 | 76 | } |
76 | 77 | } |
77 | - | |
78 | + DATA[:license].delete(:value) | |
78 | 79 | table_html_structure(data, disabled) |
79 | 80 | end |
80 | 81 | ... | ... |
lib/dynamic_table_helper.rb
... | ... | @@ -21,19 +21,16 @@ class DynamicTableHelper |
21 | 21 | DATA = { |
22 | 22 | name: { |
23 | 23 | label: LABEL_TEXT[:name], |
24 | - hidden: true, | |
25 | - autocomplete: true, | |
26 | 24 | name: COLLUMN_NAME[:name], |
27 | 25 | }, |
28 | 26 | version: { |
29 | 27 | label: LABEL_TEXT[:version], |
30 | 28 | name: COLLUMN_NAME[:version], |
31 | - hidden: true, | |
32 | - delete: true, | |
33 | 29 | } , |
34 | 30 | license: { |
35 | 31 | label: LABEL_TEXT[:license], |
36 | 32 | name: COLLUMN_NAME[:license], |
33 | + delete: true | |
37 | 34 | } |
38 | 35 | } |
39 | 36 | @@disabled = false |
... | ... | @@ -58,7 +55,7 @@ class DynamicTableHelper |
58 | 55 | self.table_line(row_data[:version]) |
59 | 56 | ] |
60 | 57 | |
61 | - if row_data[:license].has_key? :value | |
58 | + if row_data[:license].has_key?(:value) | |
62 | 59 | table_line_data << self.table_line(row_data[:license]) |
63 | 60 | end |
64 | 61 | ... | ... |
lib/library_helper.rb
1 | -module LibraryHelper | |
1 | +class LibraryHelper < DynamicTableHelper | |
2 | + MODEL_NAME ="library" | |
3 | + | |
2 | 4 | def self.list_libraries new_libraries |
3 | 5 | return [] if new_libraries.nil? or new_libraries.length == 0 |
4 | 6 | list_libraries = [] |
... | ... | @@ -26,79 +28,34 @@ module LibraryHelper |
26 | 28 | true |
27 | 29 | end |
28 | 30 | |
29 | - def self.library_as_tables list_libraries | |
30 | - extend( | |
31 | - ActionView::Helpers::TagHelper, | |
32 | - ActionView::Helpers::FormTagHelper, | |
33 | - ActionView::Helpers::UrlHelper, | |
34 | - ApplicationHelper | |
35 | - ) | |
36 | - | |
37 | - return library_html_structure( | |
38 | - { | |
39 | - :name=>"", | |
40 | - :version=>"", | |
41 | - :license=>"" | |
42 | - } | |
43 | - ) if list_libraries.nil? | |
44 | - | |
45 | - lambdas_list = [] | |
31 | + def self.libraries_as_tables list_libraries, disabled=false | |
32 | + model_list = list_libraries | |
33 | + model_list ||= [{:name=>"", :version=>"", :license=>""}] | |
46 | 34 | |
47 | - list_libraries.each do |library| | |
48 | - lambdas_list << library_html_structure(library) | |
49 | - end | |
50 | - | |
51 | - lambdas_list | |
35 | + models_as_tables model_list, "library_html_structure", disabled | |
52 | 36 | end |
53 | 37 | |
54 | - def self.library_html_structure library_data | |
55 | - Proc::new do | |
56 | - content_tag( | |
57 | - 'table', | |
58 | - content_tag( | |
59 | - 'tr', | |
60 | - content_tag('td', label_tag(_("Name")))+ | |
61 | - content_tag( | |
62 | - 'td', | |
63 | - text_field_tag("library[][name]", library_data[:name]) | |
64 | - )+ | |
65 | - content_tag('td') | |
66 | - )+ | |
67 | - | |
68 | - content_tag( | |
69 | - 'tr', | |
70 | - content_tag('td', label_tag(_("Version")))+ | |
71 | - content_tag( | |
72 | - 'td', | |
73 | - text_field_tag("library[][version]", library_data[:version]) | |
74 | - )+ | |
75 | - content_tag('td') | |
76 | - )+ | |
77 | - | |
78 | - content_tag( | |
79 | - 'tr', | |
80 | - content_tag('td', label_tag(_("License")))+ | |
81 | - content_tag( | |
82 | - 'td', | |
83 | - text_field_tag("library[][license]", library_data[:license])) + | |
84 | - content_tag( | |
85 | - 'td', | |
86 | - button_without_text( | |
87 | - :delete, | |
88 | - _('Delete'), | |
89 | - "#" , | |
90 | - :class=>"delete-dynamic-table" | |
91 | - ), | |
92 | - :align => 'right' | |
93 | - ) | |
94 | - ), | |
38 | + def self.library_html_structure library_data, disabled | |
39 | + data = { | |
40 | + model_name: MODEL_NAME, | |
41 | + name: { | |
42 | + value: library_data[:name], | |
43 | + hidden: false, | |
44 | + autocomplete: false | |
45 | + }, | |
46 | + version: { | |
47 | + value: library_data[:version], | |
48 | + delete: false | |
49 | + }, | |
50 | + license: { | |
51 | + value: library_data[:license] | |
52 | + } | |
53 | + } | |
95 | 54 | |
96 | - :class => 'dynamic-table library-table' | |
97 | - ) | |
98 | - end | |
55 | + table_html_structure(data, disabled) | |
99 | 56 | end |
100 | 57 | |
101 | 58 | def self.add_dynamic_table |
102 | - library_as_tables(nil).call | |
59 | + libraries_as_tables(nil).first.call | |
103 | 60 | end |
104 | 61 | end | ... | ... |
lib/mpog_software_plugin.rb
... | ... | @@ -5,7 +5,6 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
5 | 5 | include ActionView::Helpers::JavaScriptHelper |
6 | 6 | include ActionView::Helpers::AssetTagHelper |
7 | 7 | include FormsHelper |
8 | - include LibraryHelper | |
9 | 8 | include ActionView::Helpers |
10 | 9 | include ActionDispatch::Routing |
11 | 10 | include Rails.application.routes.url_helpers |
... | ... | @@ -73,8 +72,11 @@ class MpogSoftwarePlugin < Noosfero::Plugin |
73 | 72 | |
74 | 73 | def profile_tabs |
75 | 74 | if context.profile.community? |
76 | - profile_tabs_software if context.profile.software? | |
77 | - profile_tabs_institution | |
75 | + if context.profile.software? | |
76 | + profile_tabs_software | |
77 | + elsif context.profile.institution? | |
78 | + profile_tabs_institution | |
79 | + end | |
78 | 80 | end |
79 | 81 | end |
80 | 82 | ... | ... |
lib/software_language_helper.rb
... | ... | @@ -42,11 +42,8 @@ class SoftwareLanguageHelper < DynamicTableHelper |
42 | 42 | end |
43 | 43 | |
44 | 44 | def self.language_as_tables(list_languages, disabled=false) |
45 | - model_list = if list_languages.blank? | |
46 | - [{:programming_language_id => "", :version => ""}] | |
47 | - else | |
48 | - list_languages | |
49 | - end | |
45 | + model_list = list_languages | |
46 | + model_list ||= [{:programming_language_id => "", :version => ""}] | |
50 | 47 | |
51 | 48 | models_as_tables model_list, "language_html_structure", disabled |
52 | 49 | end |
... | ... | @@ -68,12 +65,16 @@ class SoftwareLanguageHelper < DynamicTableHelper |
68 | 65 | name: { |
69 | 66 | value: language_name, |
70 | 67 | id: language_id, |
68 | + hidden: true, | |
69 | + autocomplete: true | |
71 | 70 | }, |
72 | 71 | version: { |
73 | - value: language_data[:version] | |
72 | + value: language_data[:version], | |
73 | + hidden: true, | |
74 | + delete: true | |
74 | 75 | } |
75 | 76 | } |
76 | - | |
77 | + DATA[:license].delete(:value) | |
77 | 78 | table_html_structure(data, disabled) |
78 | 79 | end |
79 | 80 | ... | ... |
views/mpog_software_plugin_myprofile/_database_fields.html.erb
views/mpog_software_plugin_myprofile/_language_fields.html.erb
1 | 1 | <%= fields_for :software_language, @software_language do |lng| %> |
2 | 2 | |
3 | 3 | <div id='languages'> |
4 | - <% languages = [] if languages.nil? %> | |
4 | + <% languages = [] if languages.blank? %> | |
5 | 5 | <% SoftwareLanguageHelper.language_as_tables(languages).each do |tab| %> |
6 | 6 | <%= tab.call %> |
7 | 7 | <%end%> | ... | ... |
views/mpog_software_plugin_myprofile/_library_fields.html.erb
1 | 1 | <%= fields_for :library ,@library do |lib| %> |
2 | 2 | |
3 | 3 | <div id='libraries'> |
4 | - <% libraries = [] if libraries.nil? %> | |
5 | - <% LibraryHelper.library_as_tables(libraries).each do |tab| %> | |
4 | + <% libraries = [] if libraries.blank? %> | |
5 | + <% LibraryHelper.libraries_as_tables(libraries).each do |tab| %> | |
6 | 6 | <%= tab.call %> |
7 | 7 | <% end %> |
8 | 8 | </div> | ... | ... |
views/profile/_software_tab.html.erb
... | ... | @@ -30,13 +30,22 @@ |
30 | 30 | |
31 | 31 | <tr> |
32 | 32 | <td> |
33 | - <table class = "libraries-info dynamic-table"> | |
34 | - <%= content_tag('tr', content_tag('td', _("Libraries")) + content_tag('td', '')) %> | |
35 | - <% profile.software_info.libraries.each do |library| %> | |
36 | - <%= display_mpog_field(_('Name:'), library, :name, true) %> | |
37 | - <%= display_mpog_field(_('Version:'), library, :version, true) %> | |
38 | - <%= display_mpog_field(_('License:'), library, :license, true) %> | |
39 | - <% end %> | |
33 | + <table class = "libraries-info"> | |
34 | + <thead> | |
35 | + <tr> | |
36 | + <th colspan="2"><%= _("Libraries") %></th> | |
37 | + <th></th> | |
38 | + </tr> | |
39 | + </thead> | |
40 | + | |
41 | + <tbody> | |
42 | + <tr> <td> | |
43 | + <% libraries = profile.software_info.libraries %> | |
44 | + <% LibraryHelper.libraries_as_tables(libraries, true).each do |tab| %> | |
45 | + <%= tab.call %> | |
46 | + <%end%> | |
47 | + </td> </tr> | |
48 | + </tbody> | |
40 | 49 | </table> |
41 | 50 | </td> |
42 | 51 | </tr> |
... | ... | @@ -49,14 +58,22 @@ |
49 | 58 | |
50 | 59 | <tr> |
51 | 60 | <td> |
52 | - <table class = "database-info dynamic-table"> | |
53 | - <%= content_tag('tr', content_tag('td', _("Software Databases")) + content_tag('td', '')) %> | |
54 | - <tr> <td> | |
55 | - <% databases = profile.software_info.software_databases %> | |
56 | - <% DatabaseHelper.database_as_tables(databases, true).each do |tab| %> | |
57 | - <%= tab.call %> | |
58 | - <%end%> | |
59 | - </td> </tr> | |
61 | + <table class = "database-info"> | |
62 | + <thead> | |
63 | + <tr> | |
64 | + <th colspan="2"><%= _("Software Databases") %></th> | |
65 | + <th></th> | |
66 | + </tr> | |
67 | + </thead> | |
68 | + | |
69 | + <tbody> | |
70 | + <tr> <td> | |
71 | + <% databases = profile.software_info.software_databases %> | |
72 | + <% DatabaseHelper.database_as_tables(databases, true).each do |tab| %> | |
73 | + <%= tab.call %> | |
74 | + <%end%> | |
75 | + </td> </tr> | |
76 | + </tbody> | |
60 | 77 | </table> |
61 | 78 | </td> |
62 | 79 | </tr> |
... | ... | @@ -69,14 +86,22 @@ |
69 | 86 | |
70 | 87 | <tr> |
71 | 88 | <td> |
72 | - <table class = "language-info dynamic-table"> | |
73 | - <%= content_tag('tr', content_tag('td', _("Software Languages")) + content_tag('td', '')) %> | |
74 | - <tr> <td> | |
75 | - <% languages = profile.software_info.software_languages %> | |
76 | - <% SoftwareLanguageHelper.language_as_tables(languages, true).each do |tab| %> | |
77 | - <%= tab.call %> | |
78 | - <%end%> | |
79 | - </td> </tr> | |
89 | + <table class = "language-info"> | |
90 | + <thead> | |
91 | + <tr> | |
92 | + <th colspan="2"><%= _("Software Languages") %></th> | |
93 | + <th></th> | |
94 | + </tr> | |
95 | + </thead> | |
96 | + | |
97 | + <tbody> | |
98 | + <tr> <td> | |
99 | + <% languages = profile.software_info.software_languages %> | |
100 | + <% SoftwareLanguageHelper.language_as_tables(languages, true).each do |tab| %> | |
101 | + <%= tab.call %> | |
102 | + <%end%> | |
103 | + </td> </tr> | |
104 | + </tbody> | |
80 | 105 | </table> |
81 | 106 | </td> |
82 | 107 | </tr> |
... | ... | @@ -89,12 +114,20 @@ |
89 | 114 | |
90 | 115 | <tr> |
91 | 116 | <td> |
92 | - <table class = "operating-system-info dynamic-table"> | |
93 | - <%= content_tag('tr', content_tag('td', _("Operating System")) + content_tag('td', '')) %> | |
94 | - <% profile.software_info.operating_systems.each do |operating_system| %> | |
95 | - <%= display_mpog_field(_('Name:'), operating_system.operating_system_name , :name, true) %> | |
96 | - <%= display_mpog_field(_('Version:'), operating_system, :version, true) %> | |
97 | - <% end %> | |
117 | + <table class = "operating-system-info"> | |
118 | + <thead> | |
119 | + <tr> | |
120 | + <th colspan="2"><%= _("Operating System") %></th> | |
121 | + <th></th> | |
122 | + </tr> | |
123 | + </thead> | |
124 | + | |
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> | |
98 | 131 | </table> |
99 | 132 | </td> |
100 | 133 | </tr> | ... | ... |