mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 22:34:47 +00:00
* Reshuffle/organize settings UI * Settings: AI prompt display/minor touch-ups * API key settings tests * Moved import/export together * Collapsible LLM prompt DIVs * Add export tests
76 lines
2.1 KiB
Ruby
76 lines
2.1 KiB
Ruby
class ImportsController < ApplicationController
|
|
include SettingsHelper
|
|
|
|
before_action :set_import, only: %i[show publish destroy revert apply_template]
|
|
|
|
def publish
|
|
@import.publish_later
|
|
|
|
redirect_to import_path(@import), notice: "Your import has started in the background."
|
|
rescue Import::MaxRowCountExceededError
|
|
redirect_back_or_to import_path(@import), alert: "Your import exceeds the maximum row count of #{@import.max_row_count}."
|
|
end
|
|
|
|
def index
|
|
@imports = Current.family.imports
|
|
@exports = Current.user.admin? ? Current.family.family_exports.ordered.limit(10) : nil
|
|
@breadcrumbs = [
|
|
[ "Home", root_path ],
|
|
[ "Import/Export", imports_path ]
|
|
]
|
|
render layout: "settings"
|
|
end
|
|
|
|
def new
|
|
@pending_import = Current.family.imports.ordered.pending.first
|
|
end
|
|
|
|
def create
|
|
account = Current.family.accounts.find_by(id: params.dig(:import, :account_id))
|
|
import = Current.family.imports.create!(
|
|
type: import_params[:type],
|
|
account: account,
|
|
date_format: Current.family.date_format,
|
|
)
|
|
|
|
redirect_to import_upload_path(import)
|
|
end
|
|
|
|
def show
|
|
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
|
|
end
|
|
|
|
def revert
|
|
@import.revert_later
|
|
redirect_to imports_path, notice: "Import is reverting in the background."
|
|
end
|
|
|
|
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
|
|
|
|
def destroy
|
|
@import.destroy
|
|
|
|
redirect_to imports_path, notice: "Your import has been deleted."
|
|
end
|
|
|
|
private
|
|
def set_import
|
|
@import = Current.family.imports.find(params[:id])
|
|
end
|
|
|
|
def import_params
|
|
params.require(:import).permit(:type)
|
|
end
|
|
end
|