From 37164b534dd259da7737db7a8c71bad41cd5a709 Mon Sep 17 00:00:00 2001 From: Torsten Date: Mon, 16 Jan 2023 18:59:07 +0200 Subject: [PATCH] improving event --- app/models/profile.rb | 3 ++- app/views/events/_event.haml | 11 +++++++++ app/views/events/_form.html.haml | 10 +++++--- app/views/events/index.html.haml | 41 +++++++++---------------------- app/views/events/show.html.haml | 25 ++----------------- app/views/members/show.html.haml | 21 ++++++++++------ app/views/profiles/_profile.haml | 14 +++++++++++ app/views/profiles/show.html.haml | 16 +----------- 8 files changed, 60 insertions(+), 81 deletions(-) create mode 100644 app/views/events/_event.haml create mode 100644 app/views/profiles/_profile.haml diff --git a/app/models/profile.rb b/app/models/profile.rb index 85ee47c..b457e83 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,6 +1,7 @@ class Profile < ApplicationRecord belongs_to :member - + has_many :events + validates :name , presence: true validates :kind , presence: true validates :bio , presence: true diff --git a/app/views/events/_event.haml b/app/views/events/_event.haml new file mode 100644 index 0000000..bab0e3c --- /dev/null +++ b/app/views/events/_event.haml @@ -0,0 +1,11 @@ +%section.overflow-hidden.grid.grid-cols-1.m-5.md:m-12.lg:m-20.md:grid-cols-2 + %div + = image_for( event , "h-56 w-full object-cover sm:h-full") + .p-8.md:p-12.lg:px-16.lg:py-24 + .mx-auto.max-w-xl.text-center + %h2.text-2xl.font-bold.md:text-4xl + = event.name + %h4.text-xl.mt-10.md:text-2xl + = event.start_date + .mt-8{ prose_classes } + = markdown(event.text) diff --git a/app/views/events/_form.html.haml b/app/views/events/_form.html.haml index fd757b2..3afd5fc 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -8,7 +8,9 @@ = f.input :end_date = f.input :profile_id , as: :hidden = f.input :picture , as: :file - %button.mt-6.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 - = f.submit 'Save' - %button.ml-20.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 - = link_to 'Back', @story + .flex.justify-between + %button.mt-6.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 + = f.submit 'Save' + = link_to member_path(current_member) do + .mt-6.ml-20.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 + Back diff --git a/app/views/events/index.html.haml b/app/views/events/index.html.haml index ae663e7..65f5481 100644 --- a/app/views/events/index.html.haml +++ b/app/views/events/index.html.haml @@ -1,31 +1,12 @@ -%h1 Listing events - -%table - %thead - %tr - %th Name - %th Text - %th Start date - %th End date - %th Profile - %th Picture - %th - %th - %th - - %tbody +.flex.justify-center + .grid.grid-cols-4 - @events.each do |event| - %tr - %td= event.name - %td= event.text - %td= event.start_date - %td= event.end_date - %td= event.profile - %td= event.picture - %td= link_to 'Show', event - %td= link_to 'Edit', edit_event_path(event) - %td= link_to 'Destroy', event, method: :delete, data: { confirm: 'Are you sure?' } - -%br - -= link_to 'New Event', new_event_path + .fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10 + =link_to event do + = image_for( event , class: "h-60 w-full object-cover") + %h3.py-5.text-2xl.bg-gray-100.text-black.font-bold.text-center + = event.name + %div.h-full + .p-5.text-center + .m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes } + = shorten markdown(event.text) diff --git a/app/views/events/show.html.haml b/app/views/events/show.html.haml index 1625ec4..80bbf8e 100644 --- a/app/views/events/show.html.haml +++ b/app/views/events/show.html.haml @@ -1,24 +1,3 @@ -%p#notice= notice += render "event" , event: @event -%p - %b Name: - = @event.name -%p - %b Text: - = @event.text -%p - %b Start date: - = @event.start_date -%p - %b End date: - = @event.end_date -%p - %b Profile: - = @event.profile -%p - %b Picture: - = @event.picture - -= link_to 'Edit', edit_event_path(@event) -\| -= link_to 'Back', events_path += render "profiles/profile" , profile: @event.profile , header: "About the teacher" diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 899cbbd..fed6c8f 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -13,28 +13,33 @@ .grid.grid-cols-2.mx-20 .first - Profile.types.each do |kind| - .grid.grid-cols-3 + .grid.grid-cols-4 - if profile = @member.profile(kind) %div =profile.Kind - exists with name =link_to profile.name , profile_path(profile) , class: "underline" + exists = link_to edit_profile_path(profile) do %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 Edit - =profile.Kind - = link_to new_event_path(profile: profile.kind) do %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 New #{profile.Kind} Event + -if event = profile.events.length >0 + %div + =link_to profile.events.first.name , event_path(profile.events.first) , class: "underline" + = link_to edit_event_path(profile.events.first) do + %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 + Edit + -else + No events -else - %div Create new #{kind.capitalize} profile as + %div Create new profile as = link_to new_profile_path(kind: kind) do %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 - New = kind.capitalize - %div Create profile first, then events - + %div Create profile first + %div No events, create profile first .grid.grid-cols-6.gap-4.mt-10.mx-10 -@member.entities.each do |entity| diff --git a/app/views/profiles/_profile.haml b/app/views/profiles/_profile.haml new file mode 100644 index 0000000..32d027e --- /dev/null +++ b/app/views/profiles/_profile.haml @@ -0,0 +1,14 @@ +.px-4.py-16.mx-auto.sm:max-w-xl.md:max-w-full.lg:max-w-screen-xl.md:px-24.lg:px-8.lg:py-20 + .flex.justify-center + .px-4.py-4.text-center + %h1.text-2xl.font-bold.tracking-tight.sm:text-4xl + = header + .flex.mt-6.py-4.flex-col.max-w-screen-lg.overflow-hidden.bg-white.border.rounded.shadow-sm.lg:flex-row.sm:mx-auto + .relative{:class => "lg:w-1/2"} + -if profile.picture_url + = image_tag profile.picture_url, class: "object-cover w-full lg:absolute h-80 lg:h-full" + .flex.flex-col.justify-center.p-8.lg:p-16.lg:pl-10{:class => "lg:w-1/2"} + %h5.mb-3.text-3xl.font-extrabold.leading-none.sm:text-4xl + = profile.name + .mb-8.text-gray-800 + .prose= markdown(profile.bio) diff --git a/app/views/profiles/show.html.haml b/app/views/profiles/show.html.haml index 9efa0bb..af96b88 100644 --- a/app/views/profiles/show.html.haml +++ b/app/views/profiles/show.html.haml @@ -1,15 +1 @@ -.px-4.py-16.mx-auto.sm:max-w-xl.md:max-w-full.lg:max-w-screen-xl.md:px-24.lg:px-8.lg:py-20 - .flex.justify-center - .px-4.py-4.text-center - %h1text-2xl.font-bold.tracking-tight.sm:text-4xl - = @profile.Kind - profile - .flex.py-4.flex-col.max-w-screen-lg.overflow-hidden.bg-white.border.rounded.shadow-sm.lg:flex-row.sm:mx-auto - .relative{:class => "lg:w-1/2"} - -if @profile.picture_url - = image_tag @profile.picture_url, class: "object-cover w-full lg:absolute h-80 lg:h-full" - .flex.flex-col.justify-center.p-8.lg:p-16.lg:pl-10{:class => "lg:w-1/2"} - %h5.mb-3.text-3xl.font-extrabold.leading-none.sm:text-4xl - = @profile.name - .mb-8.text-gray-800 - .prose= markdown(@profile.bio) += render "profile" , profile: @profile , header: "#{@profile.Kind} profile"