Skip to content

Commit

Permalink
Improving select
Browse files Browse the repository at this point in the history
  • Loading branch information
ruby232 committed Dec 28, 2020
1 parent 0e4e738 commit 974cb3a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
16 changes: 15 additions & 1 deletion app/controllers/importers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,22 @@ def form_map_columns
@importer = Importer.find(params[:id])
columns = FatFreeCRM::ImportHandle.get_columns(@importer.attachment.path)

attributes = []

object = @importer.entity_class
_attrs = object.attribute_names - ['id']

_attrs.each do |attr|
attributes.push(
{
name: attr,
required: object.validators_on(attr).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
}
)
end

respond_to do |format|
format.html { render "form_map_columns", :locals => {columns: columns} }
format.html { render "form_map_columns", :locals => {columns: columns, attributes: attributes} }
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/polymorphic/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,9 @@ def get_messages()
JSON.parse(messages)
end

def entity_class
self.entity_type.capitalize.constantize
end

ActiveSupport.run_load_hooks(:fat_free_crm_importer, self)
end
15 changes: 12 additions & 3 deletions app/views/importers/form_map_columns.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@

%div
%table
- @importer.entity_attrs.each do |attr|
- attributes.each do |attr|
%tr
%td
.label #{ attr }
.label
#{ attr[:name] }
- if attr[:required]
%span.warn *
%td
= select_tag "map[#{ attr }]", options_for_select(columns), class: 'select2', :include_blank => true, id: "map_#{ attr }"
= select_tag "map[#{ attr[:name] }]",
options_for_select(columns),
class: 'select2',
include_blank: true,
data: {placeholder: t(:select_blank)},
required: attr[:required],
id: "map_#{ attr[:name] }"

.buttonbar
= f.submit t(:save)
2 changes: 1 addition & 1 deletion config/locales/fat_free_crm.en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -948,5 +948,5 @@ en-US:
upload_file: Upload file
save: Save
importer_description: Upload excel file to import its content to the databases. Only valid excel files are allowed.
map_columns_description: Link the excel column that corresponds to each attribute or leave it blank.
map_columns_description: Link the excel column that corresponds to each attribute or leave it blank. The elements with * must have a value in the column that is selected.
importer_status_label: Status
2 changes: 1 addition & 1 deletion config/locales/fat_free_crm.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -926,5 +926,5 @@ es:
upload_file: Subir fichero
save: Guardar
importer_description: Subir fichero excel para importar su contenido a las base de datos. Solo se admiten fichero excel validos.
map_columns_description: Enlazar la columna del excel que le corresponde a cada atributo o dejar en blanco.
map_columns_description: Enlazar la columna del excel que le corresponde a cada atributo o dejar en blanco. Los elementos con * tienen que tener valor en la columna que se seleccione.
importer_status_label: Estado

0 comments on commit 974cb3a

Please sign in to comment.