Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Revert "use request.xhr? with newer Sinatra"
Browse files Browse the repository at this point in the history
This reverts commit cc6b4c0.
  • Loading branch information
obfuscurity committed Feb 7, 2014
1 parent cc6b4c0 commit a13dc9a
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion lib/descartes/routes/cats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/cats/:count/?' do
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
@cats = []
begin
Expand Down
2 changes: 1 addition & 1 deletion lib/descartes/routes/chartroulette.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/chartroulette/?' do
if request.xhr?
if request.accept.include?("application/json")
favorites = User.filter(:email => session['user']['email']).first.favorites
content_type 'application/json'
status 200
Expand Down
12 changes: 6 additions & 6 deletions lib/descartes/routes/dashboards.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/dashboards/?' do
if request.xhr?
if request.accept.include?('application/json')
@dashboards = []
if params[:search]
@dashboards = Dashboard.get_dashboards_with_graphs_by_search(params[:search])
Expand All @@ -19,7 +19,7 @@ class Web < Sinatra::Base
end

post '/dashboards/?' do
if request.xhr? && params[:uuids] && params[:name]
if request.accept.include?('application/json') && params[:uuids] && params[:name]
owner = api_token? ? 'api@localhost' : session['user']['uid']
@dashboard = Dashboard.new({ :owner => owner, :name => params[:name] })
@dashboard.save
Expand Down Expand Up @@ -93,7 +93,7 @@ class Web < Sinatra::Base
@graphs.sort_by! { |k| k[:created_at] }.reverse!
end
end
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
{ :dashboard => @dashboard, :graphs => @graphs }.to_json
else
Expand All @@ -118,7 +118,7 @@ class Web < Sinatra::Base
end

post '/dashboards/:id/favorite/?' do
if request.xhr?
if request.accept.include?('application/json')
if @dashboard = Dashboard.filter(:enabled => true, :uuid => params[:id]).first
User.filter(:uid => session['user']['uid']).first.add_favorite(@dashboard.uuid)
session['user']['preferences'] = User.filter(:uid => session['user']['uid']).first.preferences
Expand All @@ -132,7 +132,7 @@ class Web < Sinatra::Base
end

delete '/dashboards/:id/favorite/?' do
if request.xhr?
if request.accept.include?('application/json')
if @dashboard = Dashboard.filter(:enabled => true, :uuid => params[:id]).first
User.filter(:uid => session['user']['uid']).first.remove_favorite(@dashboard.uuid)
session['user']['preferences'] = User.filter(:uid => session['user']['uid']).first.preferences
Expand All @@ -146,7 +146,7 @@ class Web < Sinatra::Base
end

post '/dashboards/:id/graphs/?' do
if request.xhr? && params[:uuids]
if request.accept.include?('application/json') && params[:uuids]
@dashboard = Dashboard.filter(:enabled => true, :uuid => params[:id]).first
params[:uuids].split(',').each do |g_uuid|
@graph = Graph.filter(:enabled => true, :uuid => g_uuid).first
Expand Down
2 changes: 1 addition & 1 deletion lib/descartes/routes/favorites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/favorites/?' do
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
status 200
JSON.parse(User.filter(:uid => session['user']['uid']).first.preferences)['favorites'].to_json
Expand Down
12 changes: 6 additions & 6 deletions lib/descartes/routes/gists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/gists/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
status 200
Gist.all.to_json
Expand All @@ -12,7 +12,7 @@ class Web < Sinatra::Base
end

post '/gists/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
@gist = Gist.new(:owner => session['user']['uid'], :remote_image_url => params[:url])
@gist.save
Expand All @@ -24,7 +24,7 @@ class Web < Sinatra::Base
end

get '/gists/:uuid/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
status 200
Gist.filter(:uuid => params[:uuid]).first.to_json
Expand All @@ -34,7 +34,7 @@ class Web < Sinatra::Base
end

put '/gists/:uuid/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
@gist = Gist.filter(:uuid => params[:uuid]).first
params.delete('uuid')
Expand All @@ -50,7 +50,7 @@ class Web < Sinatra::Base
end

delete '/gists/:uuid/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
Gist.filter(:uuid => params[:uuid]).first.destroy
status 204
Expand All @@ -60,7 +60,7 @@ class Web < Sinatra::Base
end

post '/gists/:uuid/comments/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
@gist = Gist.filter(:uuid => params[:uuid]).first
@comment = Comment.new(:owner => session['user']['uid'], :g_uuid => params[:uuid], :body => params[:body])
Expand Down
14 changes: 7 additions & 7 deletions lib/descartes/routes/graphs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/graphs/?' do
if request.xhr?
if request.accept.include?('application/json')
@graphs = []
if params[:search]
matching_graphs = []
Expand Down Expand Up @@ -84,7 +84,7 @@ class Web < Sinatra::Base
end
end
end
if request.xhr?
if request.accept.include?('application/json')
status 200
# XXX - should return tags too
@graph.to_json
Expand All @@ -102,7 +102,7 @@ class Web < Sinatra::Base

get '/graphs/:uuid/?' do
@graph = Graph.filter(:uuid => params[:uuid]).first
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
status 200
@graph.to_json
Expand All @@ -115,7 +115,7 @@ class Web < Sinatra::Base
end

get '/graphs/:uuid/tags/?' do
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
@graph = Graph.filter(:uuid => params[:uuid]).first
@tags = Tag.select(:id, :name).filter(:graph_id => @graph.id).order(:id).all
Expand All @@ -127,7 +127,7 @@ class Web < Sinatra::Base
end

post '/graphs/:uuid/tags/?' do
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
if params[:name]
tags = []
Expand Down Expand Up @@ -183,7 +183,7 @@ class Web < Sinatra::Base
end

post '/graphs/:id/gists/?' do
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
@graph = Graph.filter(:uuid => params[:id]).first
@gist = Gist.new(:owner => session['user']['uid'], :url => params[:url], :name => @graph.name, :data => params[:data], :graph_id => @graph.id)
Expand All @@ -196,7 +196,7 @@ class Web < Sinatra::Base
end

post '/graphs/:id/comments/?' do
if request.xhr?
if request.accept.include?('application/json')
content_type 'application/json'
@graph = Graph.filter(:uuid => params[:uuid]).first
@comment = Comment.new(:owner => session['user']['uid'], :uuid => @graph.uuid)
Expand Down
4 changes: 2 additions & 2 deletions lib/descartes/routes/metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Descartes
class Web < Sinatra::Base

get '/metrics/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
status 200
Metric.all.to_json
Expand All @@ -12,7 +12,7 @@ class Web < Sinatra::Base
end

get '/metrics/search/?' do
if request.xhr?
if request.accept.include?("application/json")
content_type "application/json"
status 200
Metric.find(params[:pattern]).to_json
Expand Down
2 changes: 1 addition & 1 deletion lib/descartes/routes/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Web < Sinatra::Base

before do
if !(request.path_info =~ /\/auth/)
if !(api_token? && request.xhr?)
if !(api_token? && request.accept.include?("application/json"))
if !current_user
session.clear
session['redirect_to'] = request.path_info
Expand Down

0 comments on commit a13dc9a

Please sign in to comment.