clean up profile generation (wip)

This commit is contained in:
Torsten 2023-01-20 14:59:34 +02:00
parent 82358d8642
commit caba7630cf
9 changed files with 78 additions and 58 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -1,5 +1,5 @@
.flex.justify-center
.column
.column.max-w-lg
.text-xl.m-4
Edit your
=@profile.Kind