Class: DataMigration::MigrationPlansController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DataMigration::MigrationPlansController
- Includes:
- PunditAuthorization
- Defined in:
- app/controllers/data_migration/migration_plans_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #export_config ⇒ Object
- #import_config ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#create ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 22 def create @migration_plan = MigrationPlan.new(migration_plan_params) @migration_plan.user = current_user @migration_plan if @migration_plan.save redirect_to "/data_migration/migration_plans/#{@migration_plan.id}", notice: 'Migration plan was successfully created.' else render :new, status: :unprocessable_entity end end |
#destroy ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 50 def destroy @migration_plan if @migration_plan.destroy redirect_to '/data_migration/migration_plans', notice: 'Migration plan was successfully destroyed.' else redirect_to "/data_migration/migration_plans/#{@migration_plan.id}", alert: 'Cannot delete migration plan with existing executions.' end end |
#edit ⇒ Object
35 36 37 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 35 def edit @migration_plan end |
#export_config ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 61 def export_config @migration_plan service = MigrationPlans::ExportConfigService.new(@migration_plan) json_config = service.call send_data json_config, filename: "#{@migration_plan.name.parameterize}_config.json", type: 'application/json', disposition: 'attachment' end |
#import_config ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 73 def import_config MigrationPlan.new unless params[:config_file].present? redirect_to '/data_migration/migration_plans', alert: 'Please select a configuration file to import.' return end config_json = params[:config_file].read service = MigrationPlans::ImportConfigService.new(config_json, current_user) imported_plan = service.call if service.success? && imported_plan redirect_to "/data_migration/migration_plans/#{imported_plan.id}", notice: 'Migration plan configuration imported successfully!' else redirect_to '/data_migration/migration_plans', alert: "Import failed: #{service.errors.join(', ')}" end end |
#index ⇒ Object
9 10 11 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 9 def index @migration_plans = policy_scope(MigrationPlan).ordered_by_name end |
#new ⇒ Object
17 18 19 20 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 17 def new @migration_plan = MigrationPlan.new @migration_plan end |
#show ⇒ Object
13 14 15 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 13 def show @migration_plan end |
#update ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/data_migration/migration_plans_controller.rb', line 39 def update @migration_plan if @migration_plan.update(migration_plan_params) redirect_to "/data_migration/migration_plans/#{@migration_plan.id}", notice: 'Migration plan was successfully updated.' else render :edit, status: :unprocessable_entity end end |