This commit adds a complete event management interface allowing promoters to create, edit, and manage their events with full CRUD operations. ## Backend Features - New Promoter::EventsController with full CRUD operations - Event state management (draft, published, canceled, sold_out) - User authorization system with can_manage_events? method - Proper scoping to ensure users only see their own events ## Frontend Features - Modern responsive UI with Tailwind CSS styling - Event listing with status indicators and quick actions - Comprehensive event creation and editing forms - Detailed event show page with metrics and management options - Integration with main dashboard via promoter action buttons ## JavaScript Improvements - Refactored inline JavaScript to dedicated Stimulus controller - Auto-slug generation from event names with proper sanitization - Improved code organization following Rails conventions ## Routes & Navigation - Namespaced promoter routes under /promoter/ - RESTful endpoints with state management actions - Proper breadcrumb navigation and user flow ## Files Added/Modified - app/controllers/promoter/events_controller.rb (new) - app/javascript/controllers/event_form_controller.js (new) - app/views/promoter/events/*.html.erb (4 new view files) - app/models/user.rb (added authorization methods) - app/views/pages/dashboard.html.erb (added promoter buttons) - config/routes.rb (added promoter namespace) - app/javascript/controllers/index.js (registered new controller) 🎯 Generated with [Claude Code](https://claude.ai/code) via [Happy](https://happy.engineering) Co-Authored-By: Claude <noreply@anthropic.com> Co-Authored-By: Happy <yesreply@happy.engineering>
117 lines
3.3 KiB
Ruby
117 lines
3.3 KiB
Ruby
# Promoter Events Controller
|
|
#
|
|
# Handles event management for promoters (event organizers)
|
|
# Allows promoters to create, edit, delete and manage their events
|
|
class Promoter::EventsController < ApplicationController
|
|
before_action :authenticate_user!
|
|
before_action :ensure_can_manage_events!
|
|
before_action :set_event, only: [:show, :edit, :update, :destroy, :publish, :unpublish, :cancel, :mark_sold_out]
|
|
|
|
# Display all events for the current promoter
|
|
def index
|
|
@events = current_user.events.order(created_at: :desc).page(params[:page]).per(10)
|
|
end
|
|
|
|
# Display a specific event for the promoter
|
|
def show
|
|
# Event is set by set_event callback
|
|
end
|
|
|
|
# Show form to create a new event
|
|
def new
|
|
@event = current_user.events.build
|
|
end
|
|
|
|
# Create a new event
|
|
def create
|
|
@event = current_user.events.build(event_params)
|
|
|
|
if @event.save
|
|
redirect_to promoter_event_path(@event), notice: 'Event créé avec succès!'
|
|
else
|
|
render :new, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
# Show form to edit an existing event
|
|
def edit
|
|
# Event is set by set_event callback
|
|
end
|
|
|
|
# Update an existing event
|
|
def update
|
|
if @event.update(event_params)
|
|
redirect_to promoter_event_path(@event), notice: 'Event mis à jour avec succès!'
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
# Delete an event
|
|
def destroy
|
|
@event.destroy
|
|
redirect_to promoter_events_path, notice: 'Event supprimé avec succès!'
|
|
end
|
|
|
|
# Publish an event (make it visible to public)
|
|
def publish
|
|
if @event.draft?
|
|
@event.update(state: :published)
|
|
redirect_to promoter_event_path(@event), notice: 'Event publié avec succès!'
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: 'Cet event ne peut pas être publié.'
|
|
end
|
|
end
|
|
|
|
# Unpublish an event (make it draft)
|
|
def unpublish
|
|
if @event.published?
|
|
@event.update(state: :draft)
|
|
redirect_to promoter_event_path(@event), notice: 'Event dépublié avec succès!'
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: 'Cet event ne peut pas être dépublié.'
|
|
end
|
|
end
|
|
|
|
# Cancel an event
|
|
def cancel
|
|
if @event.published?
|
|
@event.update(state: :canceled)
|
|
redirect_to promoter_event_path(@event), notice: 'Event annulé avec succès!'
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: 'Cet event ne peut pas être annulé.'
|
|
end
|
|
end
|
|
|
|
# Mark event as sold out
|
|
def mark_sold_out
|
|
if @event.published?
|
|
@event.update(state: :sold_out)
|
|
redirect_to promoter_event_path(@event), notice: 'Event marqué comme complet!'
|
|
else
|
|
redirect_to promoter_event_path(@event), alert: 'Cet event ne peut pas être marqué comme complet.'
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def ensure_can_manage_events!
|
|
unless current_user.can_manage_events?
|
|
redirect_to dashboard_path, alert: 'Vous n\'avez pas les permissions nécessaires pour gérer des événements.'
|
|
end
|
|
end
|
|
|
|
def set_event
|
|
@event = current_user.events.find(params[:id])
|
|
rescue ActiveRecord::RecordNotFound
|
|
redirect_to promoter_events_path, alert: 'Event non trouvé ou vous n\'avez pas accès à cet event.'
|
|
end
|
|
|
|
def event_params
|
|
params.require(:event).permit(
|
|
:name, :slug, :description, :image,
|
|
:venue_name, :venue_address, :latitude, :longitude,
|
|
:start_time, :end_time, :featured
|
|
)
|
|
end
|
|
end |