Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/preview screen for import #19

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge main
shubhrathasetty committed Feb 13, 2024
commit 744fe11c90d944f57cb2f28db99d1119f178dbfe
26 changes: 14 additions & 12 deletions app/controllers/importo/imports_controller.rb
Original file line number Diff line number Diff line change
@@ -28,21 +28,11 @@ def create
render :new
return
end
@import = Import.new(import_params.merge(locale: I18n.locale, importo_ownable: Importo.config.current_import_owner))
@import = Import.new(import_params.merge(locale: I18n.locale,
importo_ownable: Importo.config.current_import_owner.call))
if @import.valid?
@import.save!
redirect_to action: :preview, id: @import.id, kind: @import.kind
else
flash[:error] = t('.flash.error')
render :new
end
end

def upload
@import = Import.find(params[:id])
@import.confirm! if @import.can_confirm?
if @import.valid? && @import.schedule!
redirect_to action: :index
else
Signum.error(Current.user, text: t('.flash.error', error: @import.errors&.full_messages&.join('.')))
render :new
@@ -65,6 +55,18 @@ def undo
end
end

def upload
@import = Import.find(params[:id])
@import.confirm! if @import.can_confirm?
if @import.valid? && @import.schedule!
flash[:notice] = t('.flash.success', id: @import.id)
redirect_to action: :index
else
flash[:error] = t('.flash.error')
render :new
end
end

def destroy
@import = Import.where(importo_ownable: Importo.config.current_import_owner.call).find(params[:id])
redirect_to(action: :index, alert: 'Not allowed') && return unless Importo.config.admin_can_destroy.call(@import)
3 changes: 1 addition & 2 deletions app/models/importo/import.rb
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@ class Import < Importo::ApplicationRecord
belongs_to :importo_ownable, polymorphic: true

has_many :message_instances, as: :messagable
has_many :results, class_name: 'Importo::Result', dependent: :delete_all

validates :kind, presence: true
validates :original, presence: true
@@ -31,7 +30,7 @@ class Import < Importo::ApplicationRecord
state :reverted

after_transition any => any do |imprt, transition|
imprt.importer.state_changed(imprt, transition)
CallbackService.perform_later(import: imprt&.id, callback: transition.to_name)
end

after_transition any => :scheduled, do: :schedule_import
1 change: 1 addition & 0 deletions test/models/importo/import_test.rb
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ class ImportTest < ActiveSupport::TestCase
import.original.attach(io: simple_sheet([%w[id name description], %w[aid atest atest-description]]),
filename: 'simple_sheet.xlsx')
assert import.save, import.errors.messages

import.confirm
import.schedule
assert_equal 'scheduled', import.state
You are viewing a condensed version of this merge commit. You can view the full changes here.