mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-02 21:24:25 +00:00
Added tournament backups to the database and added pages to restore and create backups
This commit is contained in:
78
app/controllers/tournament_backups_controller.rb
Normal file
78
app/controllers/tournament_backups_controller.rb
Normal file
@@ -0,0 +1,78 @@
|
||||
class TournamentBackupsController < ApplicationController
|
||||
before_action :set_tournament
|
||||
before_action :set_tournament_backup, only: [:show, :destroy, :restore]
|
||||
before_action :check_access_manage
|
||||
|
||||
# GET /tournament/:tournament_id/tournament_backups
|
||||
def index
|
||||
@tournament_backups = @tournament.tournament_backups.order(created_at: :desc)
|
||||
end
|
||||
|
||||
# GET /tournament/:tournament_id/tournament_backups/:id
|
||||
def show
|
||||
end
|
||||
|
||||
# DELETE /tournament/:tournament_id/tournament_backups/:id
|
||||
def destroy
|
||||
if @tournament_backup.destroy
|
||||
redirect_to tournament_tournament_backups_path(@tournament), notice: 'Backup was successfully deleted.'
|
||||
else
|
||||
redirect_to tournament_tournament_backups_path(@tournament), alert: 'Failed to delete the backup.'
|
||||
end
|
||||
end
|
||||
|
||||
# POST /tournament/:tournament_id/tournament_backups/create
|
||||
def create
|
||||
TournamentBackupService.new(@tournament, 'Manual backup').create_backup
|
||||
redirect_to tournament_tournament_backups_path(@tournament), notice: 'Backup was successfully created. It will show up soon, check your background jobs for status.'
|
||||
end
|
||||
|
||||
# POST /tournament/:tournament_id/tournament_backups/:id/restore
|
||||
def restore
|
||||
WrestlingdevImporter.new(@tournament, @tournament_backup).import
|
||||
redirect_to tournament_path(@tournament), notice: 'Restore has successfully been submitted, please check your background jobs to see if it has finished.'
|
||||
end
|
||||
|
||||
# POST /tournament/:tournament_id/tournament_backups/import_manual
|
||||
def import_manual
|
||||
import_text = params[:tournament][:import_text]
|
||||
if import_text.blank?
|
||||
redirect_to tournament_tournament_backups_path(@tournament), alert: 'Import text cannot be blank.'
|
||||
return
|
||||
end
|
||||
|
||||
begin
|
||||
|
||||
# Create a temporary backup object
|
||||
backup = TournamentBackup.new(
|
||||
tournament: @tournament,
|
||||
backup_data: Base64.encode64(import_text),
|
||||
backup_reason: 'Manual Import'
|
||||
)
|
||||
|
||||
# Pass the backup object to the importer
|
||||
WrestlingdevImporter.new(@tournament, backup).import
|
||||
|
||||
redirect_to tournament_path(@tournament), notice: 'Restore has successfully been submitted, please check your background jobs to see if it has finished.'
|
||||
rescue JSON::ParserError => e
|
||||
redirect_to tournament_tournament_backups_path(@tournament), alert: "Failed to parse JSON: #{e.message}"
|
||||
rescue StandardError => e
|
||||
redirect_to tournament_tournament_backups_path(@tournament), alert: "An error occurred: #{e.message}"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_tournament
|
||||
@tournament = Tournament.find(params[:tournament_id])
|
||||
end
|
||||
|
||||
def set_tournament_backup
|
||||
@tournament_backup = @tournament.tournament_backups.find(params[:id])
|
||||
end
|
||||
|
||||
def check_access_manage
|
||||
authorize! :manage, @tournament
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class TournamentsController < ApplicationController
|
||||
before_action :set_tournament, only: [:reset_bout_board,:calculate_team_scores, :import,:export,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||
before_action :check_access_manage, only: [:reset_bout_board,:calculate_team_scores, :import,:export,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||
before_action :set_tournament, only: [:reset_bout_board,:calculate_team_scores,:bout_sheets,:swap,:weigh_in_sheet,:error,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:remove_delegate,:school_delegate,:delegate,:matches,:weigh_in,:weigh_in_weight,:create_custom_weights,:show,:edit,:update,:destroy,:up_matches,:no_matches,:team_scores,:brackets,:generate_matches,:bracket,:all_brackets]
|
||||
before_action :check_access_manage, only: [:reset_bout_board,:calculate_team_scores,:swap,:weigh_in_sheet,:teampointadjust,:remove_teampointadjust,:remove_school_delegate,:school_delegate,:weigh_in,:weigh_in_weight,:create_custom_weights,:update,:edit,:generate_matches,:matches]
|
||||
before_action :check_access_destroy, only: [:destroy,:delegate,:remove_delegate]
|
||||
before_action :check_tournament_errors, only: [:generate_matches]
|
||||
before_action :check_for_matches, only: [:up_matches,:bracket,:all_brackets]
|
||||
@@ -10,10 +10,6 @@ class TournamentsController < ApplicationController
|
||||
|
||||
end
|
||||
|
||||
def export
|
||||
|
||||
end
|
||||
|
||||
def calculate_team_scores
|
||||
respond_to do |format|
|
||||
if @tournament.calculate_all_team_scores
|
||||
@@ -23,16 +19,6 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def import
|
||||
import_text = params[:tournament][:import_text]
|
||||
respond_to do |format|
|
||||
if WrestlingdevImporter.new(@tournament,import_text).import
|
||||
format.html { redirect_to "/tournaments/#{@tournament.id}", notice: 'Import is on-going. This will take 1-5 minutes.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def swap
|
||||
@wrestler = Wrestler.find(params[:wrestler][:originalId])
|
||||
respond_to do |format|
|
||||
|
||||
Reference in New Issue
Block a user