Class: Formily::SubmitDataController
- Inherits:
-
FormilyController
- Object
- ActionController::Base
- FormilyController
- Formily::SubmitDataController
- Defined in:
- app/controllers/formily/submit_data_controller.rb
Instance Method Summary collapse
- #data_table ⇒ Object
- #destroy_response ⇒ Object
-
#submit ⇒ Object
On formily form submit.
- #submitted_data ⇒ Object
- #upload_file ⇒ Object
Instance Method Details
#data_table ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/formily/submit_data_controller.rb', line 122 def data_table if params[:model_name] && params[:model_id] model = params[:model_name].safe_constantize model = model.find(params[:model_id]) @res = model end @form = Formily::Form.find(params[:form_id]) @not_manage = true @page_name = @form.title @data_table = Formily::SubmittedDataTable.new(@form, @res) respond_to do |format| format.html { render formily_partial_path('data/submit_data_table') } format.csv { send_data @data_table.to_csv, filename: "#{@form.id}_#{@form.title.parameterize.underscore}.csv" } end end |
#destroy_response ⇒ Object
140 141 142 143 144 145 |
# File 'app/controllers/formily/submit_data_controller.rb', line 140 def destroy_response submit = Formily::Submit.find(params[:id]) submit.destroy render json: {}, status: :ok end |
#submit ⇒ Object
On formily form submit
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/formily/submit_data_controller.rb', line 10 def submit submit = Formily::Submit.find_by(id: params[:submit_id]) inputs_ids = [] @form_id = params[:form_id] @resource_id = params[:resource_id] @resource_type = params[:resource_type] @save_and_close = params[:save_and_close].present? if params[:formily_inputs].present? params[:formily_inputs].each do |key, value| if value.is_a?(Hash) value.each do |k, v| inputs_ids << k iv = submit.input_values.find_or_create_by(input_id: k) if v.is_a?(Array) v.each do |av| f = iv.attach.build(input_value_id: iv.id) f.file = av f.save iv.input_value = f.file.original_filename end elsif v.respond_to?('original_filename')# Detect file f = iv.attach.build(input_value_id: iv.id) f.file = v f.save iv.input_value = f.file.original_filename else iv.input_value = v end if @save_and_close iv.save else if iv.input_value.blank? iv.destroy else iv.save end end end else inputs_ids << key iv = submit.input_values.find_or_create_by(input_id: key) if value.is_a?(Array) value.each do |av| f = iv.attach.build(input_value_id: iv.id) f.file = av f.save iv.input_value = f.file.original_filename end elsif value.respond_to?('original_filename')# Detect file f = iv.attach.build(input_value_id: iv.id) f.file = value f.save iv.input_value = f.file.original_filename else iv.input_value = value end if @save_and_close iv.save else if iv.input_value.blank? iv.destroy else iv.save end end end end end submit.input_values.where.not(input_id: inputs_ids).each do |iv| iv.destroy if iv.attach.count == 0 # don't remove files end if @save_and_close submit.update_column(:state, 1) else submit.update_column(:state, 2) end end |
#submitted_data ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/controllers/formily/submit_data_controller.rb', line 110 def submitted_data model = params[:model_name].safe_constantize model = model.find(params[:model_id]) ids = model.formily_forms.pluck(:form_id) @forms = Formily::Form.where(id: ids) @model_name = params[:model_name] @model_id = params[:model_id] render partial: formily_partial_path('data/forms_table') end |
#upload_file ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'app/controllers/formily/submit_data_controller.rb', line 100 def upload_file submit = Formily::Submit.find(params[:submit_id]) iv = submit.input_values.find_or_create_by(input_id: params[:input_id], input_value: 'file') f = iv.attach.build(input_value_id: iv.id) f.file = params[:file] f.save render json: {file_id: f.id}, status: :ok end |