Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a team and show on the add teams #68

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion app/controllers/team_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,58 @@
class TeamController < ApplicationController
before_action :authenticate_user!, except: %i[index show]

def index; end
def index
@teams = Team.all
end

def show
@team = Team.find(params[:id])
end

def new
@team = Team.new
end

def create
@team = Team.new(news_params)
@team.user_id = current_user.id

respond_to do |format|
if @team.save
format.html { redirect_to team_url(@team), notice: 'Team was successfully created.' }
else
format.html { redirect_to team_url, notice: 'Failure' }
end
end
end

def destroy
@team = Team.find(params[:id])
@team.delete
respond_to do |format|
format.html { redirect_to team_index_path, notice: 'News was successfully deleted.' }
end
end

def edit
@team = Team.find(params[:id])
end

def update
@team = Team.find(params[:id])
respond_to do |format|
if @team.update(news_params)
format.html { redirect_to team_url(@team.id), notice: 'Team was successfully updated.' }
else
format.html { redirect_to team_index_url, notice: 'Failure' }
end
end
end

private

def news_params
params.require(:team).permit(:first_name, :second_name, :last_name, :position, :image, :jersey_number, :about,
:user_id)
end
end
4 changes: 4 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Team < ApplicationRecord
belongs_to :user
has_one_attached :image
end
6 changes: 4 additions & 2 deletions app/views/news/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
<div>
<%= render "news/image_show" %>
</div>
<h2 class="text-2xl font-bold mt-4 mr-3 m-4"><%= @news.type_of_news %></h2>
<% if @news.type_of_news === "Match" %>
<h2 class="text-2xl font-bold mt-4 mr-3 m-4"><%= @news.type_of_news %></h2>

<h3 class="text-xl font-semibold m-4"><%= @news.header_news %></h3>
<p class="text-lg mt-2 p-4"><%= raw @news.body %></p>
<p class="text-semibold text-white mt-2 bg-[#D9D9D9]"><%= @news.created_at.strftime("%d.%m.%Y") %></p>

<% end %>
</div>
</div>
19 changes: 19 additions & 0 deletions app/views/team/_coaches.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
<h1 class="text-4xl pb-4 md:pb-0 md:p-4 font-bold"></h1>
<div class="grid xl:grid-cols-4 lg:grid-cols-3 md:grid-cols-2 flex-col text-center p-2">

<% @teams.each do |team| %>
<% if team.position === "Coach" %>
<%= link_to team_path(team.id) do %>
<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<% if team.image.attached? %>
<%= image_tag(team.image) %>
<% end %>
<div class="flex justify-between">
<div class="flex flex-col">
<h1 class="self-start"><%= team.first_name %></h1>
<h1 class="font-semibold text-2xl"><%= team.last_name %></h1>
</div>
<h1 class="text-gray-400 text-5xl">0<%= team.jersey_number %></h1>
</div>
</div>
<% end %>
<% end %>
<% end %>

<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 transition ease-in-out duration-500">
<%= %>
<div class="flex justify-between">
Expand Down
19 changes: 19 additions & 0 deletions app/views/team/_defenders.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
<hr class="ml-4 w-[6%] bg-[#FAE115] h-[10px] mb-2">
<div class="grid xl:grid-cols-4 lg:grid-cols-3 md:grid-cols-2 flex-col text-center p-2">

<% @teams.each do |team| %>
<% if team.position === "Defender" %>
<%= link_to team_path(team.id) do %>
<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<% if team.image.attached? %>
<%= image_tag(team.image) %>
<% end %>
<div class="flex justify-between">
<div class="flex flex-col">
<h1 class="self-start"><%= team.first_name %></h1>
<h1 class="font-semibold text-2xl"><%= team.last_name %></h1>
</div>
<h1 class="text-gray-400 text-5xl">0<%= team.jersey_number %></h1>
</div>
</div>
<% end %>
<% end %>
<% end %>

<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500 mb-6">
<%= image_tag "defender1.png" %>
<div class="flex justify-between">
Expand Down
19 changes: 19 additions & 0 deletions app/views/team/_forward.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
<hr class="ml-4 w-[6%] bg-[#FAE115] h-[10px] mb-2">
<div class="grid lg:grid-cols-3 xl:grid-cols-4 md:grid-cols-2 flex-col text-center p-2">

<% @teams.each do |team| %>
<% if team.position === "Striker" %>
<%= link_to team_path(team.id) do %>
<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<% if team.image.attached? %>
<%= image_tag(team.image) %>
<% end %>
<div class="flex justify-between">
<div class="flex flex-col">
<h1 class="self-start"><%= team.first_name %></h1>
<h1 class="font-semibold text-2xl"><%= team.last_name %></h1>
</div>
<h1 class="text-gray-400 text-5xl">0<%= team.jersey_number %></h1>
</div>
</div>
<% end %>
<% end %>
<% end %>

<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<%= image_tag "BrianJumaAT.png" %>
<div class="flex justify-between">
Expand Down
28 changes: 18 additions & 10 deletions app/views/team/_goalkeeper.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
<h1 class="text-4xl pb-4 md:pb-0 md:p-4 font-bold">Goalkeepers</h1>
<hr class="ml-4 sm:w-[6%] md:w-[12%] lg:w-[12%] xl:w-[8%] w-[18%] bg-[#FAE115] h-[10px] mb-2">
<div class="grid lg:grid-cols-3 xl:grid-cols-4 md:grid-cols-2 flex-col text-center p-2">
<% @teams.each do |team| %>
<% if team.position === "Goalkeeper" %>
<%= link_to team_path(team.id) do %>
<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<% if team.image.attached? %>
<%= image_tag(team.image) %>
<% end %>
<div class="flex justify-between">
<div class="flex flex-col">
<h1 class="self-start"><%= team.first_name %></h1>
<h1 class="font-semibold text-2xl"><%= team.last_name %></h1>
</div>
<h1 class="text-gray-400 text-5xl">0<%= team.jersey_number %></h1>
</div>
</div>
<% end %>
<% end %>
<% end %>

<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<%= image_tag "wilsongk.png" %>
<div class="flex justify-between">
<div class="flex flex-col">
<h1 class="self-start">Wilson</h1>
<h1 class="font-semibold text-2xl">Mwangi</h1>
</div>
<h1 class="text-gray-400 text-5xl">01</h1>
</div>
</div>

<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<%= image_tag "goalkeeper2.png" %>
Expand Down
19 changes: 19 additions & 0 deletions app/views/team/_midfielders.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
<hr class="ml-4 w-[6%] bg-[#FAE115] h-[10px] mb-2">
<div class="grid lg:grid-cols-3 xl:grid-cols-4 md:grid-cols-2 flex-col text-center p-2">

<% @teams.each do |team| %>
<% if team.position === "Midfielder" %>
<%= link_to team_path(team.id) do %>
<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500">
<% if team.image.attached? %>
<%= image_tag(team.image) %>
<% end %>
<div class="flex justify-between">
<div class="flex flex-col">
<h1 class="self-start"><%= team.first_name %></h1>
<h1 class="font-semibold text-2xl"><%= team.last_name %></h1>
</div>
<h1 class="text-gray-400 text-5xl">0<%= team.jersey_number %></h1>
</div>
</div>
<% end %>
<% end %>
<% end %>

<div class="w-[300px] flex-flex-col cursor-pointer hover:scale-105 hover:text-[#FAE115] transition ease-in-out duration-500 mb-6">
<%= image_tag "EricBalecho.png" %>
<div class="flex justify-between">
Expand Down
1 change: 1 addition & 0 deletions app/views/team/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
<%= render "team/defenders" %>
<%= render "team/midfielders" %>
<%= render "team/forward" %>
<%= render "team/coaches" %>
</div>
43 changes: 43 additions & 0 deletions app/views/team/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<%= form_with model: @team, url: team_index_path, method: :post, data: { turbo: false }, local: true do |f| %>


<div class="md:p-0">
<div class="p-6 bg-[#FAE115] font-bold uppercase lg:text-5xl md:text-4xl text-3xl flex justify-between">
ADD NEWS TEAM MEMBERS
</div>
<div class="md:w-[800px] lg:w-[1024px] flex flex-col gap-4 md:my-24 md:mx-auto bg-[#F7F3ED] md:p-8">
<p class="text-xl font-light mt-5">
This is a platform where you can add news about your team members
</p>
<div>
<label htmlFor="header text">
Add Players
<span class="text-red-500">*</span>
</label>
</div>

<div class="flex justify-between pr-10">

<%= f.text_field :first_name, class: "h-[50px] w-[30%] p-2 border-b border-black bg-[#F7F3ED] focus:outline-none" ,placeholder: "first name", :required => :true %>
<%= f.text_field :second_name, class: "h-[50px] w-[30%] p-2 border-b border-black bg-[#F7F3ED] focus:outline-none" ,placeholder: "second name"%>
<%= f.text_field :last_name, class: "h-[50px] w-[30%] p-2 border-b border-black bg-[#F7F3ED] focus:outline-none" ,placeholder: "last name"%>

</div>
<div class="flex justify-between pr-10">

<%= f.select :position, %w[Striker Midfielder Defender Goalkeeper Coach], prompt: 'Role/Position', required: true, class: 'h-[50px] w-[45%] p-2 border-b border-black bg-[#F7F3ED] focus:outline-none' %>
<%= f.number_field :jersey_number, class: "h-[50px] w-[30%] p-2 border-b border-black bg-[#F7F3ED] focus:outline-none" ,placeholder: "Jersey Number"%>
<%= f.file_field :image, class: "h-[50px] w-[30%] p-2 border-b border-black bg-[#F7F3ED] focus:outline-none" ,placeholder: "Passport Photo of Player"%>

</div>

<%= f.text_area :about, class: "tinymce appearance-none border rounded w-full py-2 px-3 leading-tight focus:outline-none focus:shadow-outline" %>
<%= tinymce %>

<%= f.submit "Submit", class: "w-[300px] mt-10 mb-10 md:mb-10 md:mt-16 mx-auto p-4 bg-[#F4E721] text-3xl text-black uppercase" %>
</div>

</div>


<% end %>
14 changes: 14 additions & 0 deletions app/views/team/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="shadow-md">
<div class="p-6 bg-[#FAE115] font-bold uppercase lg:text-3xl md:text-3xl text-2xl flex justify-between truncate ...">
<p>Muranga Seal | <%= @team.first_name %></p>
</div>

<%= @team.first_name %>
<%= @team.second_name %>
<%= @team.last_name %>
<%= @team.position %>
<%= @team.jersey_number%>
<%= @team.image %>
<%= image_tag(@team.image, class: "w-[50%]") %>
<%= raw @team.about%>
</div>
16 changes: 16 additions & 0 deletions db/migrate/20231010130431_create_teams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateTeams < ActiveRecord::Migration[7.0]
def change
create_table :teams, id: :uuid do |t|
t.string :first_name
t.string :second_name
t.string :last_name
t.string :position
t.string :image
t.integer :jersey_number
t.string :about
t.references :user, null: false, foreign_key: true, type: :uuid

t.timestamps
end
end
end
17 changes: 16 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions test/fixtures/teams.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

one:
first_name: MyString
second_name: MyString
last_name: MyString
position: MyString
image: MyString
jersey_number: 1
about: MyString
user: one

two:
first_name: MyString
second_name: MyString
last_name: MyString
position: MyString
image: MyString
jersey_number: 1
about: MyString
user: two
7 changes: 7 additions & 0 deletions test/models/team_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class TeamTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
Loading