- working party
- working friend - working attendent
This commit is contained in:
@ -6,6 +6,7 @@ class PartiesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
@friends = Friend.order(:lastname, :firstname)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@ -45,6 +46,33 @@ class PartiesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def toggle_attendent
|
||||||
|
member = false
|
||||||
|
party = Party.find_by(id: params[:party_id])
|
||||||
|
friend = Friend.find_by(id: params[:friend_id])
|
||||||
|
|
||||||
|
if party.attendents.exists?( friend_id: friend.id )
|
||||||
|
puts "gefunden"
|
||||||
|
party.attendents.where(friend_id: friend.id).delete_all
|
||||||
|
else
|
||||||
|
puts "nicht gefunden"
|
||||||
|
party.attendents.create(friend_id: friend.id)
|
||||||
|
member = true
|
||||||
|
end
|
||||||
|
|
||||||
|
render turbo_stream:
|
||||||
|
turbo_stream.replace(
|
||||||
|
"party-#{party.id}-#{friend.id}",
|
||||||
|
partial: 'parties/attendent',
|
||||||
|
locals: {
|
||||||
|
friend: friend,
|
||||||
|
party: party,
|
||||||
|
member: member
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_party
|
def set_party
|
||||||
|
|||||||
@ -1,7 +0,0 @@
|
|||||||
class WalkReminderJob < ApplicationJob
|
|
||||||
queue_as :default
|
|
||||||
|
|
||||||
def perform(*args)
|
|
||||||
puts "Go with the dog!"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,4 +1,4 @@
|
|||||||
class Attendent < ApplicationRecord
|
class Attendent < ApplicationRecord
|
||||||
belongs_to :parties
|
belongs_to :party
|
||||||
belongs_to :friends
|
belongs_to :friend
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
class Friend < ApplicationRecord
|
class Friend < ApplicationRecord
|
||||||
|
has_many :attendents
|
||||||
|
has_many :parties, through: :attendents
|
||||||
|
|
||||||
validates :firstname, :lastname, :email, :telefon, presence: true
|
validates :firstname, :lastname, :email, :telefon, presence: true
|
||||||
|
|
||||||
def fullname
|
def fullname
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
class Party < ApplicationRecord
|
class Party < ApplicationRecord
|
||||||
|
has_many :attendents
|
||||||
|
has_many :friends, through: :attendents
|
||||||
|
|
||||||
validates :title, :location, :start_date, :start_time, :status, presence: true
|
validates :title, :location, :start_date, :start_time, :status, presence: true
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,8 +16,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<p class="text-lg font-semibold relative">
|
<p class="text-lg font-semibold relative">
|
||||||
<%= friend.fullname %>
|
<%= friend.fullname %>
|
||||||
<span class="m-2 -top-2 absolute text-[10px] bg-green-400 text-white rounded-full p-0.5">
|
<span class="m-2 -top-2 absolute text-[10px] bg-green-600 text-white rounded-full py-0.5 px-2">
|
||||||
12
|
<%= friend.parties.count %>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="text-gray-600 text-sm">
|
<p class="text-gray-600 text-sm">
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title><%= content_for(:title) || "Blog" %></title>
|
<title><%= content_for(:title) || "Meine Website" %></title>
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||||
<meta name="mobile-web-app-capable" content="yes">
|
<meta name="mobile-web-app-capable" content="yes">
|
||||||
|
|||||||
6
app/views/parties/_attendent.erb
Normal file
6
app/views/parties/_attendent.erb
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<div id="<%= "party-#{party.id}-#{friend.id}" %>"
|
||||||
|
class="flex justify-between w-full border rounded mb-2 p-2 <%= 'bg-green-400 text-white' if member %>">
|
||||||
|
<%= link_to party_toggle_attendent_path(party.id, friend.id) do %>
|
||||||
|
<span class="p-2"><%= friend.fullname %></span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
@ -18,8 +18,8 @@
|
|||||||
<div>
|
<div>
|
||||||
<p class="text-lg font-semibold relative">
|
<p class="text-lg font-semibold relative">
|
||||||
<%= party.title %>
|
<%= party.title %>
|
||||||
<span class="m-2 -top-2 absolute text-[10px] bg-green-400 text-white rounded-full p-0.5">
|
<span class="m-2 -top-2 absolute text-[10px] bg-green-600 text-white rounded-full py-0.5 px-2">
|
||||||
12
|
<%= party.attendents.count %>
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
<p class="text-gray-600 text-sm">
|
<p class="text-gray-600 text-sm">
|
||||||
@ -30,7 +30,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex space-x-3">
|
<div class="flex space-x-3">
|
||||||
<%= link_to edit_party_path(party),
|
<%= link_to party_path(party),
|
||||||
class: "hover:bg-green-400 hover:text-white font-medium rounded border px-2 py-1" do %>
|
class: "hover:bg-green-400 hover:text-white font-medium rounded border px-2 py-1" do %>
|
||||||
<svg class="h-6 w-6 " fill="currentColor" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10.644 17.08c2.866-.662 4.539-1.241 3.246-3.682-3.932-7.427-1.042-11.398 3.111-11.398 4.235 0 7.054 4.124 3.11 11.398-1.332 2.455.437 3.034 3.242 3.682 2.483.574 2.647 1.787 2.647 3.889v1.031h-18c0-2.745-.22-4.258 2.644-4.92zm-12.644 4.92h7.809c-.035-8.177 3.436-5.313 3.436-11.127 0-2.511-1.639-3.873-3.748-3.873-3.115 0-5.282 2.979-2.333 8.549.969 1.83-1.031 2.265-3.181 2.761-1.862.43-1.983 1.34-1.983 2.917v.773z"/></svg>
|
<svg class="h-6 w-6 " fill="currentColor" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M10.644 17.08c2.866-.662 4.539-1.241 3.246-3.682-3.932-7.427-1.042-11.398 3.111-11.398 4.235 0 7.054 4.124 3.11 11.398-1.332 2.455.437 3.034 3.242 3.682 2.483.574 2.647 1.787 2.647 3.889v1.031h-18c0-2.745-.22-4.258 2.644-4.92zm-12.644 4.92h7.809c-.035-8.177 3.436-5.313 3.436-11.127 0-2.511-1.639-3.873-3.748-3.873-3.115 0-5.282 2.979-2.333 8.549.969 1.83-1.031 2.265-3.181 2.761-1.862.43-1.983 1.34-1.983 2.917v.773z"/></svg>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@ -5,9 +5,18 @@
|
|||||||
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%= notice %></p>
|
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block" id="notice"><%= notice %></p>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<h1 class="font-bold text-4xl">Showing party</h1>
|
<h1 class="font-bold text-4xl">Party People</h1>
|
||||||
|
|
||||||
|
<div class="mt-6 mb-6 flex w-full gap-4">
|
||||||
|
<div class="mt-4 w-1/2">
|
||||||
|
<% @friends.each do |friend| %>
|
||||||
|
<%= render 'parties/attendent',
|
||||||
|
party: @party, friend: friend,
|
||||||
|
member: @party.attendents.exists?( friend_id: friend.id ) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<%= link_to "Übersicht", parties_path, class: 'btn-show' %>
|
||||||
|
|
||||||
<%= link_to "Edit this party", edit_party_path(@party), class: "w-full sm:w-auto text-center rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
|
||||||
<%= link_to "Back to parties", parties_path, class: "w-full sm:w-auto text-center mt-2 sm:mt-0 sm:ml-2 rounded-md px-3.5 py-2.5 bg-gray-100 hover:bg-gray-50 inline-block font-medium" %>
|
|
||||||
<%= button_to "Destroy this party", @party, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", class: "w-full rounded-md px-3.5 py-2.5 text-white bg-red-600 hover:bg-red-500 font-medium cursor-pointer", data: { turbo_confirm: "Are you sure?" } %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -5,7 +5,9 @@ Rails.application.routes.draw do
|
|||||||
# get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
|
# get "manifest" => "rails/pwa#manifest", as: :pwa_manifest
|
||||||
# get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
|
# get "service-worker" => "rails/pwa#service_worker", as: :pwa_service_worker
|
||||||
|
|
||||||
resources :parties
|
resources :parties do
|
||||||
|
get 'toggle-attendent/:friend_id' => 'parties#toggle_attendent', as: :toggle_attendent
|
||||||
|
end
|
||||||
resources :friends
|
resources :friends
|
||||||
|
|
||||||
get "pages/:page" => "welcome#pages", as: :pages
|
get "pages/:page" => "welcome#pages", as: :pages
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
class CreateAttendents < ActiveRecord::Migration[8.0]
|
class CreateAttendents < ActiveRecord::Migration[8.0]
|
||||||
def change
|
def change
|
||||||
create_table :attendents do |t|
|
create_table :attendents do |t|
|
||||||
t.references :parties, null: false, foreign_key: true
|
t.references :party, null: false, foreign_key: true
|
||||||
t.references :friends, null: false, foreign_key: true
|
t.references :friend, null: false, foreign_key: true
|
||||||
t.string :status, default: 'offen'
|
t.string :status, default: 'offen'
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user