Commit 4b43c159536ce27b93d05a52e6e71c677a9ba375

Authored by Fabio Teixeira
Committed by David Silva
1 parent 3b4ec38f
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

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>
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
... ...
lib/dynamic_table_helper.rb 0 → 100644
... ... @@ -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
... ...