Class: Marty::ImportView

Inherits:
Form
  • Object
show all
Includes:
Extras::Layout
Defined in:
app/components/marty/import_view.rb

Constant Summary

Constants included from Extras::Layout

Extras::Layout::BOOL_MAP, Extras::Layout::MAP_BOOL

Constants included from Permissions

Permissions::ALL_ROLES, Permissions::REQ_ROLES

Instance Method Summary collapse

Methods included from Extras::Layout

#bool_getter, #bool_setter, #dispfield, #enum_array, #enum_column, #enum_setter, #fieldset, #get_sorter, #hbox, #hspacer, #jsonb_field, #nullable_bool_column, #range_column, #range_field, #range_getter, #range_setter, #textarea_field, #tooltip, #vbox, #vspacer

Methods included from Permissions

#can_perform_action?, #can_perform_actions, #current_user_roles, #has_any_perm?, #has_marty_permissions

Constructor Details

#initialize(args, kwargs) ⇒ ImportView

Returns a new instance of ImportView.



14
15
16
17
18
19
20
# File 'app/components/marty/import_view.rb', line 14

def initialize args, kwargs
  super(args, kwargs)
  @model_view   = model_view.camelize.constantize   if model_view
  @parent_model = parent_model.camelize.constantize if parent_model
  @import_model = import_model.camelize.constantize if import_model
  @record       = nil
end

Instance Method Details

#configure(c) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/components/marty/import_view.rb', line 98

def configure(c)
  super
  c.title = nil
  c.items =
    [
      textarea_field(:import_data,
                     height: 300,
                     hide_label: true,
                     min_width: 10000,
                    ),
      :result,
    ]
end

#format_message(k, v) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/components/marty/import_view.rb', line 50

def format_message k, v
  case k
  when :clean  then "#{v} record(s) cleaned."
  when :same   then "#{v} record(s) unchanged."
  when :create then "#{v} record(s) created."
  when :update then "#{v} record(s) updated."
  when :blank  then "#{v} empty lines."
  end
end

#import(data) ⇒ Object



45
46
47
48
# File 'app/components/marty/import_view.rb', line 45

def import data
  Marty::DataImporter.
    do_import_summary(@import_model, data, 'infinity', nil, nil)
end

#import_modelObject



11
# File 'app/components/marty/import_view.rb', line 11

def import_model; end

#model_viewObject



12
# File 'app/components/marty/import_view.rb', line 12

def model_view;   end

#parent_modelObject



10
# File 'app/components/marty/import_view.rb', line 10

def parent_model; end

#post_importObject



41
42
43
# File 'app/components/marty/import_view.rb', line 41

def post_import
  nil
end

#process_additional_fieldsObject



33
34
35
# File 'app/components/marty/import_view.rb', line 33

def process_additional_fields
  nil
end

#process_import_dataObject



37
38
39
# File 'app/components/marty/import_view.rb', line 37

def process_import_data
  CSV.new(@import_data, headers: true, col_sep: "\t")
end

#validateObject



28
29
30
31
# File 'app/components/marty/import_view.rb', line 28

def validate
  return client.netzke_notify("Must provide import data.") if
    @import_data.empty?
end