Permalink
Browse files

Namespace more controllers

  • Loading branch information...
1 parent 424abde commit f0501776dca4dc5842108e7c085ff7ac70313cd1 @iain committed Jan 19, 2012
@@ -0,0 +1,8 @@
+class Airbrake::ChartsController < ApplicationController
+
+ def show
+ project = Project.find(params[:project_id])
+ render :json => Airbrake::Chart[project]
+ end
+
+end
@@ -1,4 +1,4 @@
-class Airbrake::ErrorsController < ApplicationController
+class Airbrake::ErrorsController < InheritedResources::Base
skip_before_filter :verify_authenticity_token, :only => [:create]
@@ -7,4 +7,14 @@ def create
head :ok
end
+ belongs_to :project
+ defaults :resource_class => Airbrake::Error, :collection_name => 'airbrake_errors', :instance_name => 'airbrake_error'
+ has_scope :page, :default => 1
+
+ private
+
+
+ def collection
+ @airbrake_errors ||= end_of_association_chain.order("occurred_at DESC")
+ end
end
@@ -1,8 +0,0 @@
-class ChartsController < ApplicationController
-
- def show
- project = Project.find(params[:project_id])
- render :json => Charts::Errors[project]
- end
-
-end
@@ -1,14 +0,0 @@
-class ErrorsController < InheritedResources::Base
-
- belongs_to :project
- defaults :resource_class => Airbrake::Error, :collection_name => 'airbrake_errors', :instance_name => 'airbrake_error'
- has_scope :page, :default => 1
-
- private
-
-
- def collection
- @airbrake_errors ||= end_of_association_chain.order("occurred_at DESC")
- end
-
-end
@@ -0,0 +1,59 @@
+class Airbrake::Chart
+
+ def self.[](project)
+ query = project.airbrake_errors.by_date
+ series = { false => "Unresolved", true => "Resolved" }.map do |v, name|
+ data = query.resolved(v).map { |x| [ js_timestamp(Time.parse(x[:date])), x[:count] ] }
+ { :name => name, :data => data, :pointInterval => 24 * 3600 * 1000 }
+ end
+ {
+ :chart => {
+ :renderTo => 'chart',
+ :type => 'column',
+ :zoomType => 'x',
+ :plotBorderWidth => 1
+ },
+ :credits => {
+ :enabled => false
+ },
+ :plotOptions => {
+ :series => { :animation => { :duration => 100, :easing => :linear } },
+ :column => { :shadow => false, :groupPadding => 0, :pointPadding => 0, :borderWidth => 0, :stacking => "normal" }
+ },
+ :title => {
+ :text => "Errors"
+ },
+ :xAxis => {
+ :type => 'datetime',
+ :maxZoom => 24 * 3600000,
+ :tickWidth => 1,
+ :lineWitdh => 1,
+ :max => js_timestamp(1.day.from_now),
+ :minorTickInterval => 'auto',
+ :plotBands => plotbands(project)
+ },
+ :yAxis => {
+ :title => { :text => "Amount" },
+ :min => 0,
+ :tickWidth => 1,
+ :lineWitdh => 1
+ },
+ :series => series
+ }
+ end
+
+ def self.plotbands(project)
+ project.airbrake_deploys.map do |deploy|
+ {
+ :from => js_timestamp(deploy.deployed_at - 5.hours),
+ :to => js_timestamp(deploy.deployed_at + 5.hours),
+ :color => 'rgba(40, 210, 40, 0.5)'
+ }
+ end
+ end
+
+ def self.js_timestamp(time)
+ time.to_time.to_i * 1000
+ end
+
+end
@@ -14,4 +14,12 @@ def self.import(data)
end
end
+ def self.by_date
+ group("date").select("COUNT(airbrake_errors.id) AS count, DATE(airbrake_errors.occurred_at) AS date")
+ end
+
+ def self.resolved(resolved)
+ where(:resolved => resolved)
+ end
+
end
@@ -1,6 +1,6 @@
= render "projects/header", :project => @project, :tab => "errors"
-#foozing{data("chart", project_chart_path(@project, :errors))}
+#foobar{data(:chart, airbrake_project_chart_path(@project))}
%table.table.table-striped.errors
%thead
@@ -8,7 +8,9 @@
%ul.nav.tabs
%li{active_when(tab == "overview")}= link_to "Overview", project
- %li{active_when(tab == "errors")}= link_to "Errors", project_errors_path(project)
+ %li{active_when(tab == "errors")}= link_to "Errors", airbrake_project_errors_path(project)
+
- project.iframes.list.each do |iframe|
%li{active_when(tab == iframe.to_param)}= link_to iframe.name, [ project, iframe ]
+
%li{active_when(tab == "edit")}= link_to "Edit", edit_project_path(project)
@@ -1,3 +1,3 @@
= render "header", :project => @project, :tab => "overview"
-#foobar{data(:chart, project_chart_path(@project, :overview))}
+#foobar{data(:chart, airbrake_project_chart_path(@project))}
View
@@ -12,7 +12,8 @@
namespace :airbrake do
post "/errors" => "errors#create"
post "/projects" => "projects#create"
- get "/chart" => "charts#show"
+ get "/projects/:project_id/chart" => "charts#show", :as => :project_chart
+ get "/projects/:project_id/errors" => "errors#index", :as => :project_errors
end
namespace :pivotal_tracker do
@@ -1,6 +0,0 @@
-module Airbrake
- class Deploys
- def self.store(data)
- end
- end
-end
@@ -1,6 +0,0 @@
-module Airbrake
- class Errors
- def self.store(data)
- end
- end
-end
View
@@ -1,63 +0,0 @@
-module Charts
-
- class Errors
-
- def self.[](project)
- query = project.airbrake_errors.group("date").select("COUNT(airbrake_errors.id) AS count, DATE(airbrake_errors.occurred_at) AS date")
- series = { false => "Unresolved", true => "Resolved" }.map do |v, name|
- data = query.where(:resolved => v).map { |x| [ js_timestamp(Time.parse(x[:date])), x[:count] ] }
- { :name => name, :data => data, :pointInterval => 24 * 3600 * 1000 }
- end
- {
- :chart => {
- :renderTo => 'chart',
- :type => 'column',
- :zoomType => 'x',
- :plotBorderWidth => 1
- },
- :credits => {
- :enabled => false
- },
- :plotOptions => {
- :series => { :animation => { :duration => 100, :easing => :linear } },
- :column => { :shadow => false, :groupPadding => 0, :pointPadding => 0, :borderWidth => 0, :stacking => "normal" }
- },
- :title => {
- :text => "Errors"
- },
- :xAxis => {
- :type => 'datetime',
- :maxZoom => 24 * 3600000,
- :tickWidth => 1,
- :lineWitdh => 1,
- :max => js_timestamp(1.day.from_now),
- :minorTickInterval => 'auto',
- :plotBands => plotbands(project)
- },
- :yAxis => {
- :title => { :text => "Amount" },
- :min => 0,
- :tickWidth => 1,
- :lineWitdh => 1
- },
- :series => series
- }
- end
-
- def self.plotbands(project)
- project.airbrake_deploys.map do |deploy|
- {
- :from => js_timestamp(deploy.deployed_at - 5.hours),
- :to => js_timestamp(deploy.deployed_at + 5.hours),
- :color => 'rgba(40, 210, 40, 0.5)'
- }
- end
- end
-
- def self.js_timestamp(time)
- time.to_time.to_i * 1000
- end
-
- end
-
-end
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Airbrake::ChartsController do
+
+end
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe ChartsController do
-
-end
@@ -1,5 +0,0 @@
-require 'spec_helper'
-
-describe ErrorsController do
-
-end

0 comments on commit f050177

Please sign in to comment.