diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index c1952dd..fd45637 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -2,7 +2,7 @@ class EventsController < ApplicationController before_action :set_event, only: %i[ show edit update destroy ] def index - @events = Event.all + @events = Event.where("start_date > ? " , Date.today - 3.days) end def show @@ -55,6 +55,6 @@ class EventsController < ApplicationController # Only allow a list of trusted parameters through. def event_params params.require(:event).permit(:name, :text, :start_date, :end_date, - :profile_id, :picture, :picture_cache) + :profile_id, :picture, :picture_cache , :info) end end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 0d38ced..2efe0e6 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -1,8 +1,10 @@ class ProfilesController < ApplicationController before_action :set_profile, only: %i[ show edit update destroy ] - def index - @profiles = Profile.page params[:page] + def teachers + @profiles = Profile.where(kind: :teacher).page( 1 ).per(50) + @header = "Meet Hub Feenix teachers and organizers" + render :index end def show @@ -52,6 +54,7 @@ class ProfilesController < ApplicationController # Only allow a list of trusted parameters through. def profile_params - params.require(:profile).permit(:name, :bio, :picture,:picture_cache, :kind) + params.require(:profile).permit(:name, :bio, :picture,:picture_cache, + :kind , :info) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5e688fc..195fadf 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,6 +7,9 @@ module ApplicationHelper "#{text[0..to]} . . . ".html_safe end + def small_date(date) + date.strftime("%-d.%-m") + end def main_app Rails.application.routes.url_helpers diff --git a/app/models/member.rb b/app/models/member.rb index 5ed99e7..ce9c005 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -14,10 +14,21 @@ class Member < ApplicationRecord Profile.where( member_id: self.id).where(kind: kind).first end end + def profile( kind ) Profile.where( member_id: self.id).where(kind: kind).first end + def teacher + profile( :teacher ) + end + + def future_events + teacher = profile( :teacher ) + return [] unless teacher + teacher.future_events + end + def admin? email == "torsten@villataika.fi" end diff --git a/app/models/profile.rb b/app/models/profile.rb index 0d44647..82f8c53 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -16,4 +16,8 @@ class Profile < ApplicationRecord def Kind self.kind.capitalize end + + def future_events + self.events.where( "start_date > ?" , Date.today) + end end diff --git a/app/views/events/_event.haml b/app/views/events/_event.haml index bab0e3c..3822960 100644 --- a/app/views/events/_event.haml +++ b/app/views/events/_event.haml @@ -9,3 +9,7 @@ = event.start_date .mt-8{ prose_classes } = markdown(event.text) + - unless event.info.blank? + = link_to event.info , target: :blank do + .mt-5.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400.bg-cyan-100.hover:bg-blue-300 + More info diff --git a/app/views/events/_event_small.haml b/app/views/events/_event_small.haml new file mode 100644 index 0000000..c374844 --- /dev/null +++ b/app/views/events/_event_small.haml @@ -0,0 +1,12 @@ +.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") + %div + %h3.pt-5.text-2xl.bg-gray-100.text-black.font-bold.text-center + = event.name + .py-1.text-xl.bg-gray-100.text-black.font-bold.text-center + = small_date(event.start_date) + " - " + small_date(event.end_date) + %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/_form.html.haml b/app/views/events/_form.html.haml index 8c6c088..39984b5 100644 --- a/app/views/events/_form.html.haml +++ b/app/views/events/_form.html.haml @@ -2,6 +2,7 @@ = f.error_notification = f.input :name + = f.input :info , label: "Link to event" = render "merged/form/editor" , object: @event , field: :text, form: f .grid.grid-cols-2.gap-10 = f.input :start_date @@ -13,6 +14,7 @@ label: (@event.picture.blank? ? "Add picture" : "Change picture") = f.hidden_field :picture_cache + .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' diff --git a/app/views/events/index.html.haml b/app/views/events/index.html.haml index 65f5481..4781d13 100644 --- a/app/views/events/index.html.haml +++ b/app/views/events/index.html.haml @@ -1,12 +1,4 @@ .flex.justify-center - .grid.grid-cols-4 + .grid.grid-cols-1.md:grid-cols-2.lg:grid-cols-4 - @events.each do |event| - .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) + = render "event_small" , event: event diff --git a/app/views/layouts/_footer.haml b/app/views/layouts/_footer.haml index 2bb535d..70bdd55 100644 --- a/app/views/layouts/_footer.haml +++ b/app/views/layouts/_footer.haml @@ -51,6 +51,16 @@ %li.border-white.border-x.py-2.px-4.hover:bg-gray-50.hover:border-gray-700 %a.text-gray-700.transition.hover:opacity-75{:href => "/coworking"} Coworking + + %p.mt-5.font-medium.text-gray-900 Events + %nav.mt-2{"aria-label" => "Footer Navigation - Hub Feenix"} + %ul.space-y-2.text-sm + %li.border-white.border-x.py-2.px-4.hover:bg-gray-50.hover:border-gray-700 + %a.text-gray-700.transition.hover:opacity-75{:href => "/events"} + Upcoming events + %li.border-white.border-x.py-2.px-4.hover:bg-gray-50.hover:border-gray-700 + %a.text-gray-700.transition.hover:opacity-75{:href => "/teachers"} + Teachers .col-span-2.sm:col-span-1 %p.font-medium.text-gray-900 News %nav.mt-6{"aria-label" => "Footer Navigation - Downloads"} diff --git a/app/views/members/_teacher_profile.haml b/app/views/members/_teacher_profile.haml index 72dcfa5..b4e7d6b 100644 --- a/app/views/members/_teacher_profile.haml +++ b/app/views/members/_teacher_profile.haml @@ -9,21 +9,6 @@ %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 -.flex.flex-col.justify-center - =link_to profile_path(profile) do - .my-2.px-2.py-2.text-center.bg-gray-200 - %h1.text-xl.font-bold.tracking-tight.sm:text-4xl - Your Events - -if event = profile.events.length >0 - %div - Your last Event: - = profile.events.first.name - =link_to event_path(profile.events.first) do - %button.mr-3.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400 - View - = 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 = 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 Event diff --git a/app/views/members/index.html.haml b/app/views/members/index.html.haml index 62262a8..227a60b 100644 --- a/app/views/members/index.html.haml +++ b/app/views/members/index.html.haml @@ -1,7 +1,7 @@ = paginate @members .flex.justify-center - .grid.grid-cols-4 + .grid.grid-cols-1.md:grid-cols-2.lg:grid-cols-4 - @members.each do |member| .fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10 =link_to member do diff --git a/app/views/members/settings.haml b/app/views/members/settings.haml index bf90432..fab107a 100644 --- a/app/views/members/settings.haml +++ b/app/views/members/settings.haml @@ -5,10 +5,10 @@ Settings and profiles %h4.text-xl.mt-4.md:text-2xl View and edit your profiles, and change settings -.grid.grid-cols-1.mx-8.gap-8.md:grid-cols-2.mx-12.gap-12.lg:grid-cols-3.mx-16.gap-16 +.grid.grid-cols-1.mx-8.gap-8.md:grid-cols-2.mx-12.gap-12.lg:grid-cols-4.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 + .flex.justify-center.flex-col = 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 @@ -18,7 +18,7 @@ = 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 + .grid.grid-cols-3.gap-4.mt-10.mx-10 -@member.entities.each do |entity| %div= entity.type %div= entity.name @@ -44,3 +44,14 @@ - Profile.kinds.each do |kind| - if profile = @member.profile(kind) %div= render "#{kind}_profile" , profile: profile + + -if (events = @member.future_events).length > 0 + - events.each do |event| + %div + = render "events/event_small" , event: event + =link_to event_path(event) do + %button.ml-10.mr-5.inline-block.rounded-lg.px-4.py-2.text-md.font-medium.border.border-gray-400 + View + = link_to edit_event_path(event) do + %button.bg-cyan-200.mr-3.inline-block.rounded-lg.px-4.py-2.text-md.font-medium.border.border-gray-400 + Edit diff --git a/app/views/profiles/_form.html.haml b/app/views/profiles/_form.html.haml index bc86d26..7c990e7 100644 --- a/app/views/profiles/_form.html.haml +++ b/app/views/profiles/_form.html.haml @@ -2,6 +2,7 @@ = f.error_notification = f.input :name + = f.input :info , label: "Link to Homapage" = render "merged/form/editor" , object: @profile , field: :bio, form: f = f.input :kind, :as => :hidden .flex.h-16.mt-2 diff --git a/app/views/profiles/_profile.haml b/app/views/profiles/_profile.haml index 32d027e..f7ad497 100644 --- a/app/views/profiles/_profile.haml +++ b/app/views/profiles/_profile.haml @@ -12,3 +12,7 @@ = profile.name .mb-8.text-gray-800 .prose= markdown(profile.bio) + - unless profile.info.blank? + = link_to profile.info , target: :blank do + .mt-5.inline-block.rounded-lg.px-4.py-3.text-md.font-medium.border.border-gray-400.bg-cyan-100.hover:bg-blue-300 + Homepage diff --git a/app/views/profiles/index.html.haml b/app/views/profiles/index.html.haml index c33eb44..c149b9f 100644 --- a/app/views/profiles/index.html.haml +++ b/app/views/profiles/index.html.haml @@ -1,14 +1,14 @@ -= paginate @profiles -.flex.justify-center - .grid.grid-cols-4 - - @profiles.each do |profile| - .fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm.m-10 - =link_to profile do - = image_for( profile , class: "h-60 w-full object-cover") - %h3.py-5.text-2xl.bg-gray-100.text-black.font-bold.text-center - = profile.name - %div.h-full - .p-5.text-center - .m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes } - = shorten markdown(profile.bio) +.flex.justify-center + %h3.text-3xl.font-bold= @header +.grid.grid-cols-1.md:grid-cols-2.lg:grid-cols-4.gap-10.m-10 + - @profiles.each do |profile| + .fex.flex-col.overflow-hidden.rounded-lg.border.border-gray-100.shadow-sm + =link_to profile do + = image_for( profile , class: "h-60 w-full object-cover") + %h3.py-5.text-2xl.bg-gray-100.text-black.font-bold.text-center + = profile.name + %div.h-full + .p-5.text-center + .m-2.text-sm.leading-relaxed.line-clamp-3{ prose_classes } + = shorten markdown(profile.bio) diff --git a/config/routes.rb b/config/routes.rb index 1375d97..553c450 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,8 +1,9 @@ Rails.application.routes.draw do resources :events - resources :profiles + resources :profiles, except: :index resources :entities + get "/teachers" , to: "profiles#teachers" devise_for :members ,controllers: { registrations: 'registrations' } devise_scope :member do diff --git a/db/migrate/20230611105046_add_info_to_events.rb b/db/migrate/20230611105046_add_info_to_events.rb new file mode 100644 index 0000000..8c263c7 --- /dev/null +++ b/db/migrate/20230611105046_add_info_to_events.rb @@ -0,0 +1,6 @@ +class AddInfoToEvents < ActiveRecord::Migration[7.0] + def change + add_column :events, :info, :string + add_column :profiles, :info, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 1730331..833ea7f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_16_120518) do +ActiveRecord::Schema[7.0].define(version: 2023_06_11_105046) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -33,6 +33,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_120518) do t.string "picture", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "info" t.index ["profile_id"], name: "index_events_on_profile_id" end @@ -72,6 +73,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_16_120518) do t.bigint "member_id", null: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "info" t.index ["member_id"], name: "index_profiles_on_member_id" end