-
Notifications
You must be signed in to change notification settings - Fork 0
/
radiator.rb
executable file
·109 lines (94 loc) · 2.71 KB
/
radiator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#/usr/bin/env ruby
require 'rubygems'
require 'bundler'
Bundler.require(:default,(ENV['RACK_ENV']||'development').to_sym)
# Base controllers for the radiator web UI
class Radiator < Sinatra::Base
helpers Sinatra::ContentFor
register Sinatra::StaticAssets
require './models.rb'
configure :test do
puts 'Test configuration in use'
DataMapper.setup(:default, "sqlite3::memory:")
DataMapper.auto_migrate!
enable :logging
end
configure :development do
puts 'Development configuration in use'
register Sinatra::Reloader
enable :logging
DataMapper.setup(:default, "sqlite3://#{Dir.pwd}/development.db")
DataMapper.auto_upgrade!
load './bootstrap.rb'
end
configure do
set :haml, {:format => :html5, :escape_html => false}
set :scss, {:style => :compact, :debug_info => false}
Compass.add_project_configuration(File.join(Dir.pwd, 'compass.rb'))
end
helpers do
def checkbox_helper(id,css,value,text)
haml_tag :input,
:type => 'checkbox',
:checked => value,
:class => css,
:name => %Q(#{css}[]),
:id => id,
:value => id
haml_tag :label, text, :for => id
end
# todo: Refactor helpers
def source_selection(values, selected)
values.collect do |value|
haml_tag :input,
:type => 'checkbox',
:checked => (selected.collect {|source| source.id}.include? value.id),
:class => 'source_list',
:name => "source[]",
:id => "source_#{value.id}",
:value => value.id
haml_tag :label, value.name, :for => "source_#{value.id}"
end
end
def status_image(color)
if color =~ /anime/
image_tag %Q(images/#{color}.gif)
else
image_tag %Q(images/#{color}.png)
end
end
end
get '/' do
@client = Client.find_or_create_by_ip(request.env['REMOTE_ADDR'])
@client.lookup_host(request.env['REMOTE_HOST']) if @client.host.nil?
@client.save
haml :index
end
get '/views' do
@client = Client.get(request.env['REMOTE_ADDR'])
haml :views, :layout => false
end
get '/configure' do
@client = Client.get(request.env['REMOTE_ADDR'])
@sources = Source.all
haml :configure, :layout => false
end
post '/configure' do
@client = Client.get(request.env['REMOTE_ADDR'])
@client.view.sources = []
params['source'].each do |sid|
@client.view.sources << Source.get(sid)
end
@client.view.reset_filters
params['filter'].each do |filter|
@client.view.send(%Q(#{filter}=).to_sym,true)
end
@client.view.save!
redirect '/',303
end
get '/admin' do
@clients = Client.all
@sources = Source.all
haml :admin
end
end