mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 11:18:08 +00:00
- Refactored the MissionsController to use local variable `missions` instead of instance variable `@missions` for better clarity and performance. - Introduced grouping of missions by collection for display, improving the organization of mission listings. - Updated the view to iterate over `@missions_by_collection`, enhancing the presentation of missions by their respective collections. - Added new CSS styles for collection headings to improve UI aesthetics. Additionally, removed invalid missions from the database and updated mission collections for better categorization. Files modified: - missions_controller.rb: Refactored mission retrieval logic. - index.html.erb: Updated mission display logic and added new styles. - migration file: Added cleanup for invalid missions. - Various mission JSON files: Updated collections for consistency.
45 lines
1.5 KiB
Ruby
45 lines
1.5 KiB
Ruby
module BreakEscape
|
|
class MissionsController < ApplicationController
|
|
def index
|
|
missions = if defined?(Pundit)
|
|
policy_scope(Mission)
|
|
else
|
|
Mission.published
|
|
end
|
|
|
|
# Filter by collection if specified
|
|
if params[:collection].present?
|
|
missions = missions.by_collection(params[:collection])
|
|
end
|
|
|
|
# Eager load CyBOK data for display
|
|
missions = missions.includes(:break_escape_cyboks)
|
|
|
|
# Group missions by collection for display
|
|
@missions_by_collection = missions.group_by { |m| m.collection || 'default' }
|
|
@missions_by_collection = @missions_by_collection.sort_by { |collection, _| collection }
|
|
end
|
|
|
|
def show
|
|
@mission = Mission.find(params[:id])
|
|
authorize @mission if defined?(Pundit)
|
|
|
|
if @mission.requires_vms?
|
|
# VM missions (Hacktivity or standalone) need explicit setup
|
|
# Redirect to games#new which shows appropriate UI:
|
|
# - Hacktivity mode: VM set selection
|
|
# - Standalone mode: Flag input form
|
|
redirect_to "/break_escape/games/new?mission_id=#{@mission.id}"
|
|
else
|
|
# Legacy behavior for non-VM missions - auto-create game
|
|
@game = Game.find_or_create_by!(
|
|
player: current_player,
|
|
mission: @mission
|
|
)
|
|
# Use explicit path instead of route helper to ensure it works in engine context
|
|
redirect_to "/break_escape/games/#{@game.id}"
|
|
end
|
|
end
|
|
end
|
|
end
|