Skip to content
Browse files

Added highstock chart library

  • Loading branch information...
1 parent 14d4456 commit 7c62e9be0b17be7a07f89077bd193a54d7f4a316 @rahult committed Mar 30, 2012
View
5 app/assets/stylesheets/application.scss
@@ -8,3 +8,8 @@ body {
.sidebar-nav {
padding: 9px 0;
}
+
+#score-chart {
+ height: 500px;
+ min-width: 500px;
+}
View
13 app/controllers/clubs_controller.rb
@@ -1,6 +1,4 @@
class ClubsController < ApplicationController
- # GET /clubs
- # GET /clubs.json
def index
@clubs = Club.all
@@ -10,8 +8,6 @@ def index
end
end
- # GET /clubs/1
- # GET /clubs/1.json
def show
@club = Club.find(params[:id])
@@ -21,8 +17,6 @@ def show
end
end
- # GET /clubs/new
- # GET /clubs/new.json
def new
@club = Club.new
@@ -32,13 +26,10 @@ def new
end
end
- # GET /clubs/1/edit
def edit
@club = Club.find(params[:id])
end
- # POST /clubs
- # POST /clubs.json
def create
@club = Club.new(params[:club])
@@ -53,8 +44,6 @@ def create
end
end
- # PUT /clubs/1
- # PUT /clubs/1.json
def update
@club = Club.find(params[:id])
@@ -69,8 +58,6 @@ def update
end
end
- # DELETE /clubs/1
- # DELETE /clubs/1.json
def destroy
@club = Club.find(params[:id])
@club.destroy
View
4 app/controllers/users_controller.rb
@@ -1,4 +1,8 @@
class UsersController < ApplicationController
+ def index
+ @users = User.all
+ end
+
def show
@user = User.find(params[:id])
end
View
1 app/models/club.rb
@@ -1,5 +1,6 @@
class Club < ActiveRecord::Base
has_many :users
+ has_many :scores, through: :users
validates :name, presence: true
def to_s
View
7 app/models/user.rb
@@ -7,15 +7,16 @@ class User < ActiveRecord::Base
belongs_to :club
has_many :scores
- # Setup accessible (or protected) attributes for your model
attr_accessible :email, :password, :password_confirmation,
:remember_me, :first_name, :last_name, :club_id
- def to_s
+ def name
"#{first_name} #{last_name}".strip
end
+ alias :to_s :name
+
def data
- scores.map { |s| [s.date.to_i, s.score] }.inspect
+ scores.map { |s| [s.date.to_i * 1000, s.score] }.inspect
end
end
View
14 app/views/clubs/index.html.erb
@@ -1,21 +1,21 @@
<h1>Listing clubs</h1>
-<table>
+<table class="table table-striped table-bordered">
<tr>
<th>Name</th>
<th>Address</th>
- <th></th>
- <th></th>
- <th></th>
+ <th>Actions</th>
</tr>
<% @clubs.each do |club| %>
<tr>
<td><%= club.name %></td>
<td><%= club.address %></td>
- <td><%= link_to 'Show', club %></td>
- <td><%= link_to 'Edit', edit_club_path(club) %></td>
- <td><%= link_to 'Destroy', club, confirm: 'Are you sure?', method: :delete %></td>
+ <td>
+ <%= link_to 'Show', club, class: "btn" %>
+ <%= link_to 'Edit', edit_club_path(club), class: "btn" %>
+ <%= link_to 'Destroy', club, confirm: 'Are you sure?', method: :delete, class: "btn btn-danger" %>
+ </td>
</tr>
<% end %>
</table>
View
7 app/views/clubs/show.html.erb
@@ -10,6 +10,9 @@
<%= @club.address %>
</p>
+<%= render "users/chart", users: @club.users %>
+<%= render "scores/scores", scores: @club.scores %>
-<%= link_to 'Edit', edit_club_path(@club) %> |
-<%= link_to 'Back', clubs_path %>
+
+<%= link_to 'Edit', edit_club_path(@club), class: "btn" %>
+<%= link_to 'Back', clubs_path, class: "btn" %>
View
1 app/views/layouts/application.html.erb
@@ -26,6 +26,7 @@
<ul class="nav">
<%= content_tag :li, link_to("Home", root_path), class: "#{ "active" if current_page?(root_path) }" %>
<%= content_tag :li, link_to("Clubs", clubs_path), class: "#{ "active" if current_page?(clubs_path) }" %>
+ <%= content_tag :li, link_to("Users", users_path), class: "#{ "active" if current_page?(users_path) }" %>
<%= content_tag :li, link_to("Scores", scores_path), class: "#{ "active" if current_page?(scores_path) }" %>
</ul>
<p class="navbar-text pull-right">
View
4 app/views/scores/_scores.html.erb
@@ -1,4 +1,4 @@
-<table class="table-striped">
+<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Club</th>
@@ -9,8 +9,8 @@
</tr>
</thead>
-<% scores.each do |score| %>
<tbody>
+ <% scores.each do |score| %>
<tr>
<td><%= score.club %></td>
<td><%= score.user %></td>
View
36 app/views/users/_chart.html.erb
@@ -1,32 +1,32 @@
<% content_for :head do %>
<script type="text/javascript">
+ var data =
$(function() {
- var seriesOptions = [],
- yAxisOptions = [],
- colors = Highcharts.getOptions().colors;
+ var seriesOptions = [];
+ var yAxisOptions = [];
+ var colors = Highcharts.getOptions().colors;
- <% User.all.each_with_index do |user, index| %>
- seriesOptions[<%= index %>] = {
- name: "<%= user %>",
- data: <%= user.data %>,
- shadow : true,
- marker : {
- enabled : true,
- radius : 3
- }
- };
- <% end %>
-
- createChart();
+ <% users.each_with_index do |user, index| %>
+ seriesOptions[<%= index %>] = {
+ name: "<%= user %>",
+ data: <%= user.data %>,
+ shadow : true,
+ marker : {
+ enabled : true,
+ radius : 3
+ }
+ };
+ <% end %>
+ createChart();
// create the chart when all data is loaded
function createChart() {
chart = new Highcharts.StockChart({
chart: {
- renderTo: 'container'
+ renderTo: 'score-chart'
},
rangeSelector: {
@@ -45,4 +45,4 @@
</script>
<% end %>
-<div id="container" style="height: 500px; min-width: 500px"></div>
+<div id="score-chart"></div>
View
21 app/views/users/index.html.erb
@@ -0,0 +1,21 @@
+<h1>Users</h1>
+
+<%= render "chart", users: @users %>
+
+<table class="table table-striped table-bordered">
+ <tr>
+ <th>Name</th>
+ <th>Actions</th>
+ </tr>
+
+<% @users.each do |user| %>
+ <tr>
+ <td><%= user.name %></td>
+ <td>
+ <%= link_to 'Show', user, class: "btn" %>
+ </td>
+ </tr>
+<% end %>
+</table>
+
+<br />
View
4 app/views/users/show.html.erb
@@ -3,7 +3,7 @@
<%= @user %>
</p>
-<%= render "chart", scores: @user.scores %>
-<%#= render "scores/scores", scores: @user.scores %>
+<%= render "chart", users: [@user] %>
+<%= render "scores/scores", scores: @user.scores %>
<%= link_to 'Back', root_path %>

0 comments on commit 7c62e9b

Please sign in to comment.
Something went wrong with that request. Please try again.