Skip to content

Commit

Permalink
lot of work, better UI
Browse files Browse the repository at this point in the history
  • Loading branch information
baldarn committed Aug 11, 2024
1 parent 36004e0 commit 0276194
Show file tree
Hide file tree
Showing 43 changed files with 419 additions and 80 deletions.
4 changes: 4 additions & 0 deletions app/assets/images/dashboard.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/module.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/tags.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/assets/images/trash.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions app/controllers/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# frozen_string_literal: true

class BaseController < ApplicationController
before_action :redirect_to_root, unless: :user_signed_in?
before_action :set_club

def redirect_to_root
redirect_to root_path
end

def set_club
@club = current_user.club
end
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/clubs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ def update

if @club.update(club_params)
respond_to do |format|
format.turbo_stream
format.html { redirect_to edit_club_url(@club), flash: { notice: I18n.t('club.updated') } }
format.turbo_stream { flash.now[:notice] = I18n.t('club.updated') }
end
else
render :new, status: :unprocessable_entity
respond_to do |format|
format.html { render :new, status: :unprocessable_entity }
format.turbo_stream
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def update

def destroy
@event = @club.events.find(params[:id])
@event.destroy

@event.discard
redirect_to club_events_url(@club), flash: { success: I18n.t('events.destroyed') }
end

private
Expand Down
15 changes: 13 additions & 2 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

class GroupsController < BaseController
def index
@groups = @club.groups
@groups = @club.groups.page(params[:page])
end

def new
@group = @club.groups.build
end

def edit
@group = @club.groups.find(params[:id])
end

def create
@group = @club.groups.build(group_params)

Expand All @@ -26,7 +30,7 @@ def create
end

def update
@group = @club.members.find(params[:id])
@group = @club.groups.find(params[:id])

if @group.update(group_params)
respond_to do |format|
Expand All @@ -41,6 +45,13 @@ def update
end
end

def destroy
@group = @club.groups.find(params[:id])
@group.destroy

redirect_to club_groups_url(@club), flash: { success: I18n.t('groups.destroyed') }
end

private

def group_params
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class MembersController < BaseController
def index
@members = @club.members.page(params[:page])
end

def dashboard
@group = params[:group_id] ? @club.groups.find(params[:group_id]) : @club.groups.first

if @group.blank?
Expand All @@ -15,6 +19,10 @@ def new
@member = @club.members.build
end

def edit
@member = @club.members.find(params[:id])
end

def create
@member = @club.members.build(member_params)

Expand Down Expand Up @@ -43,6 +51,13 @@ def update
end
end

def destroy
@member = @club.members.find(params[:id])
@member.discard

redirect_to club_members_url(@club), flash: { success: I18n.t('members.destroyed') }
end

private

def member_params
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ def update
end
end

def destroy
@tag = @club.tags.find(params[:id])
@tag.destroy

redirect_to club_tags_url(@club), flash: { success: I18n.t('tags.destroyed') }
end

private

def tag_params
Expand Down
62 changes: 62 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# frozen_string_literal: true

class UsersController < BaseController
def index
@users = @club.users.page(params[:page])
end

def new
@user = @club.users.build
end

def edit
@user = @club.users.find(params[:id])
end

def create
@user = @club.users.build(user_params)
@user.role = :collaborator
@user.password = 'password'

if @user.save
respond_to do |format|
format.html { redirect_to new_club_user_url(@club), flash: { notice: I18n.t('users.created') } }
format.turbo_stream { flash.now[:notice] = I18n.t('users.created') }
end
else
respond_to do |format|
format.html { render :new, status: :unprocessable_entity }
format.turbo_stream
end
end
end

def update
@user = @club.users.find(params[:id])

if @user.update(user_params)
respond_to do |format|
format.html { redirect_to club_users_url(@club), flash: { notice: I18n.t('users.updated') } }
format.turbo_stream { flash.now[:notice] = I18n.t('users.updated') }
end
else
respond_to do |format|
format.html { render :edit, status: :unprocessable_entity }
format.turbo_stream
end
end
end

def destroy
@user = @club.users.find(params[:id])
@user.destroy

redirect_to club_users_url(@club), flash: { success: I18n.t('users.destroyed') }
end

private

def user_params
params.require(:user).permit(:first_name, :last_name, :email, :picture)
end
end
6 changes: 4 additions & 2 deletions app/models/club.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ class Club < ApplicationRecord

has_one_attached :picture

belongs_to :user
has_many :users, dependent: :destroy

alias collaborators users

has_many :members, dependent: :destroy
has_many :groups, dependent: :destroy
has_many :tags, dependent: :destroy
has_many :events, dependent: :destroy
has_many :payments, through: :members

validates :name, presence: true
validates :name, :email, presence: true
end
8 changes: 6 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ class User < ApplicationRecord
:recoverable, :rememberable, :validatable,
:confirmable, :lockable

enum role: { admin: 0, instructor: 1 }
has_one_attached :picture

has_one :club, dependent: :nullify
enum role: { admin: 0, collaborator: 1 }

belongs_to :club

validates :first_name, :last_name, :password, presence: true
end
42 changes: 21 additions & 21 deletions app/views/application/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,29 @@
<ul class="nav col-12 col-lg-auto my-2 justify-content-center my-md-0 text-small">
<li class="nav-item">
<% if user_signed_in? %>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<li class="nav-item">
<a href="<%= club_members_dashboard_path(@club) %>" class="nav-link text-secondary">
<%= image_tag "dashboard.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
Dashboard
</a>
</li>
<li class="nav-item">
<a href="<%= club_members_path(@club) %>" class="nav-link text-secondary">
<%= image_tag "person.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
Membri
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="<%= club_members_path(@club) %>">Lista</a></li>
<li><a class="dropdown-item" href="<%= new_club_member_path(@club) %>">Nuovo</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<%= image_tag "people.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
<li class="nav-item">
<a href="<%= club_tags_path(@club) %>" class="nav-link text-secondary">
<%= image_tag "tags.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
Attributi
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="<%= club_tags_path(@club) %>">Lista</a></li>
<li><a class="dropdown-item" href="<%= new_club_tag_path(@club) %>">Nuovo</a></li>
</ul>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<li class="nav-item">
<a href="<%= club_groups_path(@club) %>" class="nav-link text-secondary">
<%= image_tag "people.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
Gruppi
</a>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="<%= club_groups_path(@club) %>">Lista</a></li>
<li><a class="dropdown-item" href="<%= new_club_group_path(@club) %>">Nuovo</a></li>
</ul>
</li>
<li class="nav-item">
<a href="<%= edit_club_path(@club) %>" class="nav-link text-secondary">
Expand All @@ -57,9 +51,15 @@
</a>
</li>
<li class="nav-item">
<a href="<%= club_payments_url(@club) %>" class="nav-link text-secondary">
<a href="<%= club_users_url(@club) %>" class="nav-link text-secondary">
<%= image_tag "collaborator.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
Allenatori
Collaboratori
</a>
</li>
<li class="nav-item">
<a href="<%= root_path %>" class="nav-link text-secondary">
<%= image_tag "module.svg", aria: { hidden: true }, size: 24, class: "bi d-block mx-auto mb-1" %>
Moduli
</a>
</li>
<li class="nav-item">
Expand Down
21 changes: 11 additions & 10 deletions app/views/clubs/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<%= simple_form_for club, html: { class: 'row' } do |f| %>
<h3>
Club
</h3>
<%= f.input :name %>
<%= f.input :email %>
<%=
<%= turbo_frame_tag club do %>
<%= simple_form_for club, html: { class: 'row' } do |f| %>
<h3>
Club
</h3>
<%= f.input :name %>
<%= f.input :email %>
<%=
if club.picture.present?
image_tag club.picture, class: 'img-fluid img-thumbnail rounded mx-auto d-block', style: 'max-width: 200px'
end
%>
<%= f.submit 'Save', class: 'btn btn-primary' %>
</div>
<% end %>
<%= f.submit 'Save', class: 'btn btn-primary' %>
<% end %>
<% end %>
5 changes: 5 additions & 0 deletions app/views/clubs/update.turbo_stream.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_stream.prepend 'flash', partial: 'flash' %>

<%= turbo_stream.update @club do %>
<%= render 'form', club: @club %>
<% end %>
1 change: 1 addition & 0 deletions app/views/groups/edit.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render "form", group: @group %>
11 changes: 11 additions & 0 deletions app/views/groups/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
<%= link_to I18n.t('groups.new'), new_club_group_path(@club), class: 'btn btn-primary' %>

<%= paginate @groups %>
<table class="table">
<thead>
<tr>
<th scope="col">Nome</th>
<th scope="col"><%= I18n.t('actions') %></th>
</tr>
</thead>
<tbody>
<% @groups.each do |group| %>
<tr>
<td><%= group.name %></td>
<td>
<%= link_to edit_club_group_path(@club, group) do %>
<%= image_tag "edit.svg", aria: { hidden: true }, size: 24 %>
<% end %>
<%= link_to club_group_path(@club, group), data: { turbo_method: :delete, turbo_confirm: 'Are you sure?'} do %>
<%= image_tag "trash.svg", aria: { hidden: true }, size: 24 %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
Expand Down
3 changes: 3 additions & 0 deletions app/views/kaminari/_first_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_gap.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class='page-item disabled'>
<%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_last_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_next_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
</li>
Loading

0 comments on commit 0276194

Please sign in to comment.