Skip to content

Commit

Permalink
Add read-only index and show views for Chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
tjgrathwell committed Dec 8, 2015
1 parent 7b86e97 commit a2640e6
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/controllers/chapters_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class ChaptersController < ApplicationController
before_action :authenticate_user!, :except => [:show, :index]
before_action :assign_chapter, :only => [:show]

def index
@chapters = Chapter.all
end

def show
@chapter_events = (
@chapter.events + @chapter.external_events
).sort_by(&:ends_at)
end

private

def assign_chapter
@chapter = Chapter.find(params[:id])
end
end
25 changes: 25 additions & 0 deletions app/views/chapters/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= content_for(:header_text, 'Listing chapters') %>

<table class="table table-striped table-bordered table-condensed responsive-table datatable-sorted">
<thead>
<tr>
<th data-default-sort="asc">Name</th>
<th>Events</th>
</tr>
</thead>

<tbody>
<% @chapters.each do |chapter| %>
<tr>
<td><%= link_to chapter.name, chapter %></td>
<td data-label="Events:"><%= chapter.events_count + chapter.external_events_count %></td>
</tr>
<% end %>
</tbody>
</table>

<%= render 'shared/actions', links: [
['Regions', regions_path],
['Locations', locations_path],
['Events', events_path]
] %>
8 changes: 8 additions & 0 deletions app/views/chapters/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= content_for(:header_text, @chapter.name) %>

<h2>Events</h2>
<%= render 'shared/events_table', events: @chapter_events %>
<%= render 'shared/actions', links: [
['Back', chapters_path]
] %>
1 change: 1 addition & 0 deletions app/views/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<% links = [
['Organize Event', new_event_path],
['Manage Locations', locations_path],
['Manage Chapters', chapters_path],
['Manage Regions', regions_path]
] %>
<% if current_user.admin? %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
resources :meetup_users, only: [:show]

resources :locations
resources :chapters, only: [:index, :show]
resources :regions do
resources :region_leaderships, only: [:index, :create, :destroy]
end
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20151208074636_reset_chapter_counter_caches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ResetChapterCounterCaches < ActiveRecord::Migration
def change
Chapter.all.each do |chapter|
Chapter.reset_counters(chapter.id, :events, :external_events)
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20151207055515) do
ActiveRecord::Schema.define(version: 20151208074636) do

create_table "authentications", force: :cascade do |t|
t.integer "user_id"
Expand Down

0 comments on commit a2640e6

Please sign in to comment.