diff --git a/app/assets/stylesheets/application.tailwind.css b/app/assets/stylesheets/application.tailwind.css index c746599e..e8503f23 100644 --- a/app/assets/stylesheets/application.tailwind.css +++ b/app/assets/stylesheets/application.tailwind.css @@ -6,6 +6,22 @@ :root { /* Override colors and other variables */ } + + h1 { + @apply text-2xl font-medium; + } + + h2 { + @apply text-xl; + } + + .arc_title { + @apply text-4xl font-bold text-red-600; + } + + .arc_subtitle { + @apply py-2 text-xl font-medium leading-normal; + } } @layer components { diff --git a/app/controllers/chapters_controller.rb b/app/controllers/chapters_controller.rb index bef984fb..69c847d5 100644 --- a/app/controllers/chapters_controller.rb +++ b/app/controllers/chapters_controller.rb @@ -2,7 +2,7 @@ class ChaptersController < ApplicationController include ActiveStorage::SetCurrent load_and_authorize_resource except: %i[ index show] # Load cancancan authorize for all actions - before_action :set_chapter, only: %i[ show edit update destroy ] + before_action :set_chapter, only: %i[ edit update destroy ] skip_before_action :authenticate_user!, only: %i[ index show] # GET /chapters or /chapters.json @@ -12,6 +12,7 @@ def index # GET /chapters/1 or /chapters/1.json def show + @chapter = Chapter.find_by_slug(params[:slug]) end # GET /chapters/new diff --git a/app/helpers/chapters_helper.rb b/app/helpers/chapters_helper.rb index 063540ba..41bbe8ac 100644 --- a/app/helpers/chapters_helper.rb +++ b/app/helpers/chapters_helper.rb @@ -1,2 +1,17 @@ module ChaptersHelper + def chapter_leader_card(chapter) + leader = UsersChapter.find_by(chapter_id: chapter.id, leader: true).user + image_tag = image_tag("https://github.com/#{leader.github_username}.png", size: "207x97") + name = UsersChapter.find_by_chapter(chapter.id) + + content_tag(:div, class: "bg-gray-100 rounded-md shadow-md overflow-hidden inline-block") do + content_tag(:div, class: "h-48") do + image_tag + end + + content_tag(:div, class: "bg-gray-200 px-4 py-2 my-4") do + content_tag(:p, name, class: "text-gray-800 font-bold") + + content_tag(:p, leader.github_username) + end + end + end end diff --git a/app/models/chapter.rb b/app/models/chapter.rb index cbb0a4cb..47208cda 100644 --- a/app/models/chapter.rb +++ b/app/models/chapter.rb @@ -1,6 +1,7 @@ class Chapter < ApplicationRecord # Attachments has_one_attached :image + has_one_attached :hero_image # Associations belongs_to :country @@ -16,6 +17,8 @@ class Chapter < ApplicationRecord locals: { country: self }, target: self } after_destroy_commit -> { broadcast_remove_to 'chapters', target: self } + before_validation :update_slug, on: [:create, :update] + # Validations validates :name, :location, :country_id, :description, presence: true validates :name, uniqueness: true @@ -27,4 +30,18 @@ class Chapter < ApplicationRecord # width: 400, height: 225, # message: 'is not given between dimension. It should be 400x225', # } + + def encoded_address + Addressable::URI.encode(self.location) + end + + private + + ## + # Update slug if the chapter name has changed + def update_slug + if name_changed? + self.slug = name.parameterize(separator: '-') + end + end end diff --git a/app/models/users_chapter.rb b/app/models/users_chapter.rb index 693e2f43..5a7ed6a7 100644 --- a/app/models/users_chapter.rb +++ b/app/models/users_chapter.rb @@ -2,4 +2,9 @@ class UsersChapter < ApplicationRecord # Associations belongs_to :chapter belongs_to :user + + def self.find_by_chapter(chapter_id) + users_chapter = find_by(chapter_id: chapter_id, leader: true) + users_chapter&.user&.name || 'No Leader yet' + end end diff --git a/app/views/chapters/_chapter_leader_card.html.erb b/app/views/chapters/_chapter_leader_card.html.erb new file mode 100644 index 00000000..d482ef20 --- /dev/null +++ b/app/views/chapters/_chapter_leader_card.html.erb @@ -0,0 +1,20 @@ +
+ <%= image_tag("https://github.com/#{user.github_username}.png", + alt: "#{user.name}'s Github photo", + class: 'h-[75] w-full rounded-t-lg bg-slate-200') %> + +
+

<%= user.name %>

+ + + +
+
\ No newline at end of file diff --git a/app/views/chapters/index.html.erb b/app/views/chapters/index.html.erb index de238046..df23352c 100644 --- a/app/views/chapters/index.html.erb +++ b/app/views/chapters/index.html.erb @@ -8,19 +8,16 @@ <% @chapters.each do |chapter| %>
- <%= image_tag chapter.image.attached? ? chapter.image.url : image_path('chapter.jpg'), - alt: 'Local meetups photo', - class: "rounded-lg rounded-tl-2xl" - %> + <%= link_to find_by_slug_chapters_path(chapter.slug) do %> + <%= image_tag chapter.image.attached? ? chapter.image.url : image_path('chapter.jpg'), + alt: 'Local meetups photo', + class: "rounded-lg rounded-tl-2xl" + %> + <% end %>
- <%= chapter.name %> - - <% if can? :manage, chapter %> - <%= link_to 'Edit', edit_chapter_path(chapter), class: 'btn btn-xs btn-info', - data: { turbo_frame: "edit_chapter_#{chapter.id}" } %> - <%= link_to 'Delete', chapter, class: 'btn btn-xs btn-error', - method: :delete %> + <%= link_to find_by_slug_chapters_path(chapter.slug) do %> + <%= chapter.name %> <% end %>
diff --git a/app/views/chapters/show.html.erb b/app/views/chapters/show.html.erb index cc5251ec..59198a28 100644 --- a/app/views/chapters/show.html.erb +++ b/app/views/chapters/show.html.erb @@ -1,10 +1,112 @@ -

<%= notice %>

+
+
+
+
+
+ <% if @chapter.hero_image.present? %> + <%= image_tag(@chapter.hero_image, class: 'Event_thumbnail h-[200] w-full rounded-s-lg bg-gray-200') %> + <% else %> +
+

+
+ <% end %> +
+
+
+
+
+
+
+

Upcoming event

+ + Click here for + upcoming events. -<%= render @chapter %> + +
-
- <%= link_to "Edit this chapter", edit_chapter_path(@chapter) %> | - <%= link_to "Back to chapters", chapters_path %> + +
+
+
+
- <%= button_to "Destroy this chapter", @chapter, method: :delete %> -
+
+

<%= @chapter.name %>

+ +
+
+
+

About Chapter

+

<%= sanitize(@chapter.description) %>

+
+
+

Chapter Leaders

+
+
+ <% if !UsersChapter.find_by(chapter_id: @chapter, leader: true).nil? %> + <% UsersChapter.where(chapter_id: @chapter, leader: true).each do |chapter_user| %> + <%= render 'chapter_leader_card', chapter: @chapter, user: chapter_user.user %> + <% end %> + <% else %> +

No Leaders yet

+ <% end %> +
+
+
+
+
+
+

Chapter Location

+
+
+ +
+ +
+ + +
+

<%= @chapter.location %>

+
+
+
+
+
+ +
+
+
+
+
+ \ No newline at end of file diff --git a/app/views/landing/learn.html.erb b/app/views/landing/learn.html.erb index 76c070ba..cd23d07c 100644 --- a/app/views/landing/learn.html.erb +++ b/app/views/landing/learn.html.erb @@ -6,7 +6,9 @@

Take a look at our list of resources that can help you get up to speed with the Ruby programming language from the basic building blocks upto to the various frameworks and tools in the Ruby - ecosystem. If you want to add your own resources, fork this repo and send in a pull request. + ecosystem. If you want to add your own resources, email us + at <%= link_to 'organisers@rubycommunity.africa', 'mailto:organisers@rubycommunity.africa', + class: 'text-red-500' %>.

diff --git a/config/motor.yml b/config/motor.yml index 53e043d0..ad0f9991 100644 --- a/config/motor.yml +++ b/config/motor.yml @@ -1,13 +1,15 @@ --- engine_version: 0.4.7 -file_version: 2023-03-09 16:16:17.698355000 Z +file_version: 2023-04-03 05:50:48.235103000 Z resources: - name: chapter preferences: columns: - column_type: richtext name: description - updated_at: 2023-03-05 09:31:13.962854000 +00:00 + - access_type: read_only + name: slug + updated_at: 2023-04-03 05:50:48.235103000 +00:00 - name: feature_flag preferences: columns: @@ -17,16 +19,9 @@ resources: configs: - key: header.links value: - - name: Reports - link_type: reports - - name: Forms - link_type: forms - - conditions: [] - type: header - name: Exit admin portal - path: "/" - link_type: header - updated_at: 2023-03-05 09:37:51.799389000 +00:00 + - name: "⭐ Star on GitHub" + path: https://github.com/motor-admin/motor-admin-rails + updated_at: 2023-03-30 00:41:34.130118000 +00:00 queries: [] dashboards: [] forms: [] @@ -36,5 +31,5 @@ api_configs: name: origin url: "/" preferences: {} - description: - updated_at: 2023-03-05 08:41:14.200426000 +00:00 + description: + updated_at: 2023-03-30 00:41:34.133532000 +00:00 diff --git a/config/routes.rb b/config/routes.rb index 672bb2af..c733fa65 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,10 @@ mount Motor::Admin => '/admin' end resources :projects - resources :chapters + resources :chapters, except: :show do + get ':slug', to: 'chapters#show', as: :find_by_slug, on: :collection + end + resources :countries devise_for :users, controllers: { registrations: 'users/registrations', # Override devise registration controller diff --git a/db/migrate/20230403051613_add_slug_to_chapters.rb b/db/migrate/20230403051613_add_slug_to_chapters.rb new file mode 100644 index 00000000..bbc04095 --- /dev/null +++ b/db/migrate/20230403051613_add_slug_to_chapters.rb @@ -0,0 +1,6 @@ +class AddSlugToChapters < ActiveRecord::Migration[7.0] + def change + add_column :chapters, :slug, :string, null: false + add_index :chapters, :slug, unique: true + end +end diff --git a/db/migrate/20230503174505_add_leader_to_users_chapter.rb b/db/migrate/20230503174505_add_leader_to_users_chapter.rb new file mode 100644 index 00000000..2d036805 --- /dev/null +++ b/db/migrate/20230503174505_add_leader_to_users_chapter.rb @@ -0,0 +1,5 @@ +class AddLeaderToUsersChapter < ActiveRecord::Migration[7.0] + def change + add_column :users_chapters, :leader, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 34156fca..485fc23f 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_03_13_002939) do +ActiveRecord::Schema[7.0].define(version: 2023_05_10_014204) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -49,7 +49,9 @@ t.bigint "country_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.string "slug", null: false t.index ["country_id"], name: "index_chapters_on_country_id" + t.index ["slug"], name: "index_chapters_on_slug", unique: true end create_table "countries", force: :cascade do |t| @@ -66,6 +68,25 @@ t.datetime "updated_at", null: false end + create_table "meetup_events", force: :cascade do |t| + t.string "title" + t.text "description" + t.string "rsvp_link" + t.string "image" + t.datetime "start_time" + t.datetime "end_time" + t.string "venue_name" + t.string "venue_address" + t.bigint "chapter_id" + t.jsonb "venue_coordinates", default: {}, null: false + t.jsonb "data", default: {}, null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "meetup_id" + t.index ["chapter_id"], name: "index_meetup_events_on_chapter_id" + t.index ["meetup_id"], name: "index_meetup_events_on_meetup_id", unique: true + end + create_table "motor_alert_locks", force: :cascade do |t| t.bigint "alert_id", null: false t.string "lock_timestamp", null: false @@ -305,6 +326,7 @@ t.boolean "main_chapter", default: false t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "leader", default: false t.index ["chapter_id"], name: "index_users_chapters_on_chapter_id" t.index ["user_id"], name: "index_users_chapters_on_user_id" end diff --git a/test/fixtures/chapters.yml b/test/fixtures/chapters.yml index b7344642..ac296d0f 100644 --- a/test/fixtures/chapters.yml +++ b/test/fixtures/chapters.yml @@ -4,8 +4,10 @@ one: name: MyString location: MyString description: MyText + slug: MyText two: name: MyString location: MyString description: MyText + slug: MyText2