From caba7630cf8b217a97b36681805e0b7fdc31fcf9 Mon Sep 17 00:00:00 2001 From: Torsten Date: Fri, 20 Jan 2023 14:59:34 +0200 Subject: [PATCH] clean up profile generation (wip) --- app/controllers/events_controller.rb | 2 +- app/controllers/profiles_controller.rb | 2 +- app/models/member.rb | 4 +- app/models/profile.rb | 4 +- app/views/members/_artist_profile.haml | 0 app/views/members/_member_profile.haml | 24 +++++++ app/views/members/_teacher_profile.haml | 10 +++ app/views/members/show.html.haml | 88 +++++++++++-------------- app/views/profiles/edit.html.haml | 2 +- 9 files changed, 78 insertions(+), 58 deletions(-) create mode 100644 app/views/members/_artist_profile.haml create mode 100644 app/views/members/_member_profile.haml create mode 100644 app/views/members/_teacher_profile.haml diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 56287e2..0a6e729 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -13,7 +13,7 @@ class EventsController < ApplicationController # GET /events/new def new kind = params[:profile] - kind = Profile.types.first unless Profile.types.include?(kind) + kind = Profile.kinds.first unless Profile.kinds.include?(kind) profile = current_member.profile(kind) if(profile) @event = Event.new profile: profile diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index bd39d82..23a25b6 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -13,7 +13,7 @@ class ProfilesController < ApplicationController # GET /profiles/new def new kind = params[:kind] - kind = Profile.types.first unless Profile.types.include?(kind) + kind = Profile.kinds.first unless Profile.kinds.include?(kind) @profile = Profile.new kind: kind end diff --git a/app/models/member.rb b/app/models/member.rb index 9c892f2..5ed99e7 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -9,8 +9,8 @@ class Member < ApplicationRecord has_many :entities has_many :profiles - Profile.types.each do |kind| - define_method :kind do + Profile.kinds.each do |kind| + define_method :"#{kind}_profile" do Profile.where( member_id: self.id).where(kind: kind).first end end diff --git a/app/models/profile.rb b/app/models/profile.rb index b457e83..0d44647 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -1,7 +1,7 @@ class Profile < ApplicationRecord belongs_to :member has_many :events - + validates :name , presence: true validates :kind , presence: true validates :bio , presence: true @@ -9,7 +9,7 @@ class Profile < ApplicationRecord mount_uploader :picture, PictureUploader - def self.types + def self.kinds ["member" , "artist" , "teacher"] end diff --git a/app/views/members/_artist_profile.haml b/app/views/members/_artist_profile.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/members/_member_profile.haml b/app/views/members/_member_profile.haml new file mode 100644 index 0000000..42bd21d --- /dev/null +++ b/app/views/members/_member_profile.haml @@ -0,0 +1,24 @@ +.flex.flex-col.justify-center + =link_to profile_path(profile) do + .px-4.py-4.text-center.bg-gray-200 + %h1.text-2xl.font-bold.tracking-tight.sm:text-4xl + Member Profile + .flex.mt-6.py-4.flex-col.max-w-screen-lg.overflow-hidden.bg-white.border.rounded.shadow-sm + .relative + -if profile.picture_url + = image_tag profile.picture_url, class: "object-cover w-full h-60" + -else + No picture + %h5.m-4.text-3xl.font-bold.text-center + = profile.name + .mb-8.text-gray-800.text-center + .prose= markdown(profile.bio) + + +.flex.justify-between + = 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 + = form_tag( profile_path(profile.id) , {method: :delete } ) do + %button.bg-red-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Delete Profile diff --git a/app/views/members/_teacher_profile.haml b/app/views/members/_teacher_profile.haml new file mode 100644 index 0000000..7dca767 --- /dev/null +++ b/app/views/members/_teacher_profile.haml @@ -0,0 +1,10 @@ + -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 + = 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 diff --git a/app/views/members/show.html.haml b/app/views/members/show.html.haml index 15b5239..17b293b 100644 --- a/app/views/members/show.html.haml +++ b/app/views/members/show.html.haml @@ -4,57 +4,43 @@ %h1.text-2xl.font-bold.tracking-tight.sm:text-4xl Settings and profiles %h4.text-xl.mt-4.md:text-2xl - Allowing you to create and edit various profiles - .mt-4.text-lg.pt-4 - You can have seperate profiles as teacher, artist, or coop member. - If you choose to create them they will be publicly listed. - Techers and Artists may then create events. + View and edit your profiles, and change settings -.grid.grid-cols-2.mx-20 - .first - - Profile.types.each do |kind| - .grid.grid-cols-4 - - if profile = @member.profile(kind) - %div - =profile.Kind - =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 - = 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 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 - = kind.capitalize - %div Create profile first - %div No events, create profile first +.grid.grid-cols-1.mx-8.gap-8.md:grid-cols-2.mx-12.gap-12.lg:grid-cols-3.mx-16.gap-16 + .flex.flex-col.justify-between + %h3.text-2xl.bg-gray-200.p-4.text-center Settings + .flex.justify-beteen.flex-wrap + = form_tag( destroy_member_session_path , {method: :delete } ) do + %button.m-4.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Sign out + = link_to edit_member_registration_path do + %button.m-4.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Change Password + = link_to members_edit_email_path do + %button.m-4.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} + Change Email + .grid.grid-cols-6.gap-4.mt-10.mx-10 + -@member.entities.each do |entity| + %div= entity.type + %div= entity.name + %div= entity.value + %div + If you are an artist click + =link_to "here" , new_profile_path(kind: :artist) , class: "underline" + %br + Or a teacher, click + =link_to "here" , new_profile_path(kind: :teacher) , class: "underline" -.grid.grid-cols-6.gap-4.mt-10.mx-10 - -@member.entities.each do |entity| - %div= entity.type - %div= entity.name - %div= entity.value + - unless @member.member_profile + %div + %h3.text-2xl.bg-gray-200.p-4.text-center No Profile + %h2 Create new + = link_to new_profile_path(kind: :member) do + %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 + Member profile + .prose + Member profiles are always public and contain an image and text. -.grid.grid-cols-1.md:grid-cols-2.lg:grid-cols-3 - .flex.justify-beteen - = form_tag( destroy_member_session_path , {method: :delete } ) do - %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} - Sign out - = link_to edit_member_registration_path do - %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} - Change Password - = link_to members_edit_email_path do - %button.mt-10.ml-10.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400{type: :submit} - Change Email + - Profile.kinds.each do |kind| + - if profile = @member.profile(kind) + %div= render "#{kind}_profile" , profile: profile diff --git a/app/views/profiles/edit.html.haml b/app/views/profiles/edit.html.haml index 152f6d0..7ca7c87 100644 --- a/app/views/profiles/edit.html.haml +++ b/app/views/profiles/edit.html.haml @@ -1,5 +1,5 @@ .flex.justify-center - .column + .column.max-w-lg .text-xl.m-4 Edit your =@profile.Kind