From c9bf64dc8c56f76a6f670621ebad27d87343b334 Mon Sep 17 00:00:00 2001 From: Wild Karl-Heinz Date: Sat, 22 Nov 2025 19:35:58 +0100 Subject: [PATCH] - added parties - changed layout for index and added svgs --- app/assets/tailwind/application.css | 4 +- app/controllers/parties_controller.rb | 16 +------ app/models/friend.rb | 5 ++ app/views/friends/_form.html.erb | 4 +- app/views/friends/_friend.html.erb | 22 --------- app/views/friends/edit.html.erb | 3 +- app/views/friends/index.html.erb | 65 ++++++++++++-------------- app/views/friends/new.html.erb | 3 +- app/views/friends/show.html.erb | 2 - app/views/layouts/application.html.erb | 4 ++ app/views/parties/_form.html.erb | 12 ++--- app/views/parties/_party.html.erb | 22 --------- app/views/parties/edit.html.erb | 5 +- app/views/parties/index.html.erb | 59 ++++++++++++++++------- app/views/parties/new.html.erb | 2 +- app/views/parties/show.html.erb | 2 - 16 files changed, 100 insertions(+), 130 deletions(-) delete mode 100644 app/views/friends/_friend.html.erb delete mode 100644 app/views/parties/_party.html.erb diff --git a/app/assets/tailwind/application.css b/app/assets/tailwind/application.css index da0fac2..e249e2c 100644 --- a/app/assets/tailwind/application.css +++ b/app/assets/tailwind/application.css @@ -13,7 +13,9 @@ li { @apply list-disc; } .notice p#notice { @apply py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-md inline-block; } form input[type="text"], -form input[type="number"] +form input[type="number"], +form input[type="date"], +form input[type="time"] { @apply block shadow-sm rounded-md border px-3 py-2 mt-2 w-full; } diff --git a/app/controllers/parties_controller.rb b/app/controllers/parties_controller.rb index fdfb152..d299b34 100644 --- a/app/controllers/parties_controller.rb +++ b/app/controllers/parties_controller.rb @@ -1,59 +1,47 @@ class PartiesController < ApplicationController before_action :set_party, only: %i[ show edit update destroy ] - # GET /parties or /parties.json def index @parties = Party.all end - # GET /parties/1 or /parties/1.json def show end - # GET /parties/new def new @party = Party.new end - # GET /parties/1/edit def edit end - # POST /parties or /parties.json def create @party = Party.new(party_params) respond_to do |format| if @party.save - format.html { redirect_to @party, notice: "Party was successfully created." } - format.json { render :show, status: :created, location: @party } + format.html { redirect_to parties_path, notice: "Party was successfully created." } else format.html { render :new, status: :unprocessable_entity } - format.json { render json: @party.errors, status: :unprocessable_entity } end end end - # PATCH/PUT /parties/1 or /parties/1.json def update respond_to do |format| if @party.update(party_params) - format.html { redirect_to @party, notice: "Party was successfully updated.", status: :see_other } - format.json { render :show, status: :ok, location: @party } + format.html { redirect_to parties_path, notice: "Party was successfully updated.", status: :see_other } else format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @party.errors, status: :unprocessable_entity } end end end - # DELETE /parties/1 or /parties/1.json def destroy @party.destroy! respond_to do |format| format.html { redirect_to parties_path, notice: "Party was successfully destroyed.", status: :see_other } - format.json { head :no_content } end end diff --git a/app/models/friend.rb b/app/models/friend.rb index 01ac1ea..f6d4a2c 100644 --- a/app/models/friend.rb +++ b/app/models/friend.rb @@ -1,3 +1,8 @@ class Friend < ApplicationRecord validates :firstname, :lastname, :email, :telefon, presence: true + + def fullname + [ firstname, lastname ].join(' ') + end + end diff --git a/app/views/friends/_form.html.erb b/app/views/friends/_form.html.erb index 2edfb0c..a8793d8 100644 --- a/app/views/friends/_form.html.erb +++ b/app/views/friends/_form.html.erb @@ -1,8 +1,6 @@ <%= form_with(model: friend, class: "contents") do |form| %> <% if friend.errors.any? %>
-

<%= pluralize(friend.errors.count, "error") %> prohibited this friend from being saved:

-
- <%= form.submit %> + <%= form.submit 'Speichern' %>
<% end %> diff --git a/app/views/friends/_friend.html.erb b/app/views/friends/_friend.html.erb deleted file mode 100644 index 800de22..0000000 --- a/app/views/friends/_friend.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
-
- Firstname: - <%= friend.firstname %> -
-
- Lastname: - <%= friend.lastname %> -
-
- Email: - <%= friend.email %> -
-
- Telefon: - <%= friend.telefon %> -
-
- Level: - <%= friend.level %> -
-
diff --git a/app/views/friends/edit.html.erb b/app/views/friends/edit.html.erb index 3a77f61..f31e116 100644 --- a/app/views/friends/edit.html.erb +++ b/app/views/friends/edit.html.erb @@ -5,6 +5,5 @@ <%= render "form", friend: @friend %> - <%= link_to "Anzeigen", @friend, class: "btn-show" %> - <%= link_to "Liste", friends_path, class: "btn-show" %> + <%= link_to "Übersicht", friends_path, class: "btn-show" %> diff --git a/app/views/friends/index.html.erb b/app/views/friends/index.html.erb index 2cf4bf7..24825e4 100644 --- a/app/views/friends/index.html.erb +++ b/app/views/friends/index.html.erb @@ -7,43 +7,40 @@

Freunde

- <%= link_to "Neuer Freund", new_friend_path, class: "btn-new" %> + <%= link_to "+", new_friend_path, class: "rounded-md px-3 py-2 bg-slate-800 hover:bg-green-500 text-white block font-medium" %>
- - - - - - - - - - <% @friends.each do | friend | %> - - - - - - - <% end %> - -
NameE-MailTelefon
- -
- <% if @friends.any? %> - <% @friends.each do |friend| %> -
- <%= render friend %> -
- <%= link_to "Anzeigen", friend, class: "btn-show" %> - <%= link_to "Bearbeiten", edit_friend_path(friend), class: "btn-show" %> - <%= button_to "Löschen", friend, method: :delete, class: "btn-destroy", data: { turbo_confirm: "Sind Sie sich sicher?" } %> -
+
+ <% @friends.each do |friend| %> +
+
+

+ <%= friend.fullname %> + + 12 + +

+

+ <%= mail_to friend.email, "Mail: #{friend.email}" %>, + <%= phone_to friend.telefon, "Tel: #{friend.telefon}" %> +

- <% end %> - <% else %> -

Bisher kein Freund eingegeben.

+ +
+ <%= link_to edit_friend_path(friend), + class: "hover:bg-green-400 hover:text-white font-medium rounded border px-2 py-1" do %> + + <% end %> + + <%= button_to friend_path(friend), + method: :delete, + data: { confirm: "Löschen?" }, + class: "hover:bg-red-400 hover:text-white font-medium rounded border px-2 py-1" do %> + + <% end %> +
+
<% end %>
+
diff --git a/app/views/friends/new.html.erb b/app/views/friends/new.html.erb index acceb3b..b271e11 100644 --- a/app/views/friends/new.html.erb +++ b/app/views/friends/new.html.erb @@ -3,5 +3,6 @@

Neuer Freund

<%= render "form", friend: @friend %> - <%= link_to "Back to friends", friends_path, class: "btn-empty" %> + + <%= link_to "Übersicht", friends_path, class: "btn-empty" %>
diff --git a/app/views/friends/show.html.erb b/app/views/friends/show.html.erb index e86f93e..4676882 100644 --- a/app/views/friends/show.html.erb +++ b/app/views/friends/show.html.erb @@ -7,8 +7,6 @@

Freund anzeigen

- <%= render @friend %> - <%= link_to "Bearbeiten", edit_friend_path(@friend), class: "btn-show" %> <%= link_to "Liste anzeigen", friends_path, class: "btn-show" %> <%= button_to "Löschen", @friend, method: :delete, form_class: "sm:inline-block mt-2 sm:mt-0 sm:ml-2", diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 885d96c..5d650b1 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -6,6 +6,10 @@ + + + + <%= csrf_meta_tags %> <%= csp_meta_tag %> diff --git a/app/views/parties/_form.html.erb b/app/views/parties/_form.html.erb index 85bd203..7afac51 100644 --- a/app/views/parties/_form.html.erb +++ b/app/views/parties/_form.html.erb @@ -13,30 +13,30 @@
<%= form.label :title %> - <%= form.text_field :title, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:title].none?, "border-red-400 focus:outline-red-600": party.errors[:title].any?}] %> + <%= form.text_field :title, class: [{"border-gray-400 focus:outline-blue-600": party.errors[:title].none?, "border-red-400 focus:outline-red-600": party.errors[:title].any?}] %>
<%= form.label :location %> - <%= form.text_field :location, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:location].none?, "border-red-400 focus:outline-red-600": party.errors[:location].any?}] %> + <%= form.text_field :location, class: [{"border-gray-400 focus:outline-blue-600": party.errors[:location].none?, "border-red-400 focus:outline-red-600": party.errors[:location].any?}] %>
<%= form.label :start_date %> - <%= form.date_field :start_date, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:start_date].none?, "border-red-400 focus:outline-red-600": party.errors[:start_date].any?}] %> + <%= form.date_field :start_date, class: [{"border-gray-400 focus:outline-blue-600": party.errors[:start_date].none?, "border-red-400 focus:outline-red-600": party.errors[:start_date].any?}] %>
<%= form.label :start_time %> - <%= form.time_field :start_time, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:start_time].none?, "border-red-400 focus:outline-red-600": party.errors[:start_time].any?}] %> + <%= form.time_field :start_time, class: [{"border-gray-400 focus:outline-blue-600": party.errors[:start_time].none?, "border-red-400 focus:outline-red-600": party.errors[:start_time].any?}] %>
<%= form.label :status %> - <%= form.text_field :status, class: ["block shadow-sm rounded-md border px-3 py-2 mt-2 w-full", {"border-gray-400 focus:outline-blue-600": party.errors[:status].none?, "border-red-400 focus:outline-red-600": party.errors[:status].any?}] %> + <%= form.text_field :status, class: [{"border-gray-400 focus:outline-blue-600": party.errors[:status].none?, "border-red-400 focus:outline-red-600": party.errors[:status].any?}] %>
- <%= form.submit class: "w-full sm:w-auto rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white inline-block font-medium cursor-pointer" %> + <%= form.submit "Speichern" %>
<% end %> diff --git a/app/views/parties/_party.html.erb b/app/views/parties/_party.html.erb deleted file mode 100644 index 946fc55..0000000 --- a/app/views/parties/_party.html.erb +++ /dev/null @@ -1,22 +0,0 @@ -
-
- Title: - <%= party.title %> -
-
- Location: - <%= party.location %> -
-
- Start date: - <%= party.start_date %> -
-
- Start time: - <%= party.start_time %> -
-
- Status: - <%= party.status %> -
-
diff --git a/app/views/parties/edit.html.erb b/app/views/parties/edit.html.erb index 840fd8d..739916a 100644 --- a/app/views/parties/edit.html.erb +++ b/app/views/parties/edit.html.erb @@ -1,10 +1,9 @@ <% content_for :title, "Editing party" %>
-

Editing party

+

Party bearbeiten

<%= render "form", party: @party %> - <%= link_to "Show this party", @party, 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" %> - <%= 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" %> + <%= link_to "Übersicht", parties_path, class: "btn-show" %>
diff --git a/app/views/parties/index.html.erb b/app/views/parties/index.html.erb index f1ffe33..0bf270b 100644 --- a/app/views/parties/index.html.erb +++ b/app/views/parties/index.html.erb @@ -7,23 +7,48 @@

Parties

- <%= link_to "New party", new_party_path, class: "rounded-md px-3.5 py-2.5 bg-blue-600 hover:bg-blue-500 text-white block font-medium" %> -
- -
- <% if @parties.any? %> - <% @parties.each do |party| %> -
- <%= render party %> -
- <%= link_to "Show", 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 "Edit", 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" %> - <%= button_to "Destroy", party, method: :delete, class: "w-full sm:w-auto 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?" } %> -
-
- <% end %> - <% else %> -

No parties found.

+ <%= link_to new_party_path, class: "rounded-md px-3 py-2 bg-slate-800 hover:bg-green-500 text-white block font-medium" do %> + <% end %>
+ +
+ <% @parties.each do |party| %> +
+
+

+ <%= party.title %> + + 12 + +

+

+ <%= truncate(party.location, length: 100) %>, + <%= party.start_date.strftime("%d.%m.%Y") %> + um <%= party.start_time.strftime("%H:%M") %> +

+
+ +
+ <%= link_to edit_party_path(party), + class: "hover:bg-green-400 hover:text-white font-medium rounded border px-2 py-1" do %> + + <% end %> + + <%= link_to edit_party_path(party), + class: "hover:bg-green-400 hover:text-white font-medium rounded border px-2 py-1" do %> + + <% end %> + + <%= button_to party_path(party), + method: :delete, + data: { confirm: "Löschen?" }, + class: "hover:bg-red-400 hover:text-white font-medium rounded border px-2 py-1" do %> + + <% end %> +
+
+ <% end %> + +
diff --git a/app/views/parties/new.html.erb b/app/views/parties/new.html.erb index 0408960..1872f2f 100644 --- a/app/views/parties/new.html.erb +++ b/app/views/parties/new.html.erb @@ -5,5 +5,5 @@ <%= render "form", party: @party %> - <%= 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" %> + <%= link_to "Übersicht", 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" %> diff --git a/app/views/parties/show.html.erb b/app/views/parties/show.html.erb index 9cb8304..f5c9cf7 100644 --- a/app/views/parties/show.html.erb +++ b/app/views/parties/show.html.erb @@ -7,8 +7,6 @@

Showing party

- <%= render @party %> - <%= 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?" } %>