-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcttsearch.rb
77 lines (64 loc) · 1.96 KB
/
cttsearch.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
$:. << File.join(File.dirname(__FILE__), 'lib')
require 'sinatra'
require 'sinatra/base'
require 'sinatra/content_for'
require 'frontend'
class CTTSearch < Sinatra::Base
helpers Sinatra::ContentFor
set :root, File.dirname(__FILE__)
get '/' do
@categories = Search.cats
erb :index
end
get '/cats/:id' do
@categories = Search.cats
@category = Search.cat(params[:id])
erb :category_explore
end
get '/search/?' do
@query = params[:q]
@tags = (params[:tags] || "").split(",")
hits = Search.party(@query, @tags)
@results = SearchResultsOrganiser.new.sort hits
erb :results
end
get '/process' do
builder = SearchUriBuilder.new(params[:query],[ params[:org_size], params[:user_prof]])
p "Redirecting to Search?: #{builder.uri}"
redirect builder.uri
end
get '/admin' do
if params.has_key?('success') and params['success']=='true'
@success = true
else
@success = false
end
@results = Search.party(' ', []) ## get a list of all entries
erb :admin_index
end
get '/admin/edit' do
if params.has_key?('success') and params['success']=='true'
@success = true
else
@success = false
end
@resourcetypes = ['ExternalLink', 'YouTubeVideo', 'InternalLink', 'PDF']
@resource = Resource.get(params['id']) ## get a list of all entries
erb :admin_edit
end
get '/admin/new' do
if params.has_key?('success') and params['success']=='true'
redirect '/admin?success=true'
else
@success = false
end
@resourcetypes = ['ExternalLink', 'YouTubeVideo', 'InternalLink', 'PDF']
@resource = {'id' => 0, 'title' => '', 'uri' => '', 'tags' => '', 'shortDescription' => '', 'longDescription' => '', 'resourceType' => ''}
erb :admin_edit
end
get '/admin/tags' do
@tags = (params[:tags] || "").split(",")
@results = Search.party(' ', @tags) ## get a list of all entries with given tags
erb :admin_index
end
end