2024-05-17 09:09:32 -04:00
|
|
|
class ImportsController < ApplicationController
|
2025-03-04 13:10:01 -05:00
|
|
|
before_action :set_import, only: %i[show publish destroy revert apply_template]
|
2024-05-17 09:09:32 -04:00
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def publish
|
|
|
|
@import.publish_later
|
2024-05-17 09:09:32 -04:00
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
redirect_to import_path(@import), notice: "Your import has started in the background."
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def index
|
|
|
|
@imports = Current.family.imports
|
2024-07-16 15:23:45 +02:00
|
|
|
|
2025-02-21 11:57:59 -05:00
|
|
|
render layout: "settings"
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def new
|
|
|
|
@pending_import = Current.family.imports.ordered.pending.first
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def create
|
2025-03-03 12:47:30 -05:00
|
|
|
account = Current.family.accounts.find_by(id: params.dig(:import, :account_id))
|
2025-03-04 13:10:01 -05:00
|
|
|
import = Current.family.imports.create!(
|
|
|
|
type: import_params[:type],
|
|
|
|
account: account,
|
|
|
|
date_format: Current.family.date_format,
|
|
|
|
)
|
2024-05-17 09:09:32 -04:00
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
redirect_to import_upload_path(import)
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def show
|
2024-10-18 16:10:18 +03:00
|
|
|
if !@import.uploaded?
|
|
|
|
redirect_to import_upload_path(@import), alert: "Please finalize your file upload."
|
|
|
|
elsif !@import.publishable?
|
|
|
|
redirect_to import_confirm_path(@import), alert: "Please finalize your mappings before proceeding."
|
|
|
|
end
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
|
2025-02-07 15:36:05 -05:00
|
|
|
def revert
|
|
|
|
@import.revert_later
|
|
|
|
redirect_to imports_path, notice: "Import is reverting in the background."
|
|
|
|
end
|
|
|
|
|
2025-03-04 13:10:01 -05:00
|
|
|
def apply_template
|
|
|
|
if @import.suggested_template
|
|
|
|
@import.apply_template!(@import.suggested_template)
|
|
|
|
redirect_to import_configuration_path(@import), notice: "Template applied."
|
|
|
|
else
|
|
|
|
redirect_to import_configuration_path(@import), alert: "No template found, please manually configure your import."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def destroy
|
|
|
|
@import.destroy
|
2024-05-17 09:09:32 -04:00
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
redirect_to imports_path, notice: "Your import has been deleted."
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def set_import
|
|
|
|
@import = Current.family.imports.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2024-10-01 10:47:59 -04:00
|
|
|
def import_params
|
|
|
|
params.require(:import).permit(:type)
|
2024-05-17 09:09:32 -04:00
|
|
|
end
|
|
|
|
end
|