forked from railsbridge/bridge_troll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add read-only index and show views for Chapters
- Loading branch information
1 parent
7b86e97
commit a2640e6
Showing
7 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
] %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters