-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.rb
105 lines (83 loc) · 2.33 KB
/
app.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
require "rubygems"
require "bundler/setup"
require "sinatra"
set :protection, except: :ip_spoofing
require "sinatra/content_for"
require "haml"
require "json"
require "nokogiri"
require "httpclient"
require "configatron"
require_relative "model/retriever"
require_relative "model/profiles_repository"
require_relative "config/config"
before do
@profiles_repository = ProfilesRepository.new(File.dirname(__FILE__) + '/db/profiles.json')
end
# API METHODS - Supporting Application/json
get '/?' do
content_type :json
status 200
Retriever.new.get_data.to_json
end
get '/profiles/?' do
content_type :json
status 200
@profiles_repository.get_all.to_json
end
post '/profile/?' do
content_type :json
status 201
profile_hash = JSON.parse(request.body.read)
profile = Profile.profile_from_hash(profile_hash)
result = @profiles_repository.save(profile)
status 400 unless result
end
delete '/profile/:name/?' do
content_type :json
status 200
@profiles_repository.delete(params[:name])
end
# UI Methods
get '/admin/?' do
radiator = Retriever.new.get_data
pipeline_names = []
radiator.pipelines.each do |p|
pipeline_names << p.name
end
pipeline_names = pipeline_names.sort
profiles = @profiles_repository.get_all.profiles
haml :admin, :locals => {:pipeline_names => pipeline_names, :profiles => profiles}, :format => :html5
end
get '/radiator/?' do
profiles = @profiles_repository.get_all.profiles
haml :setup, :locals => {:profiles => profiles}, :format => :html5
end
get '/radiator/:profile/?' do
radiator = Retriever.new.get_data(@profiles_repository.get(params[:profile]).pipelines)
rows = []
radiator.pipelines.each_slice(3) do |x,y,z|
rows << [x,y,z]
end
haml :index, :locals => {:rows => rows}, :format => :html5
end
get '/all/?' do
radiator = Retriever.new.get_data
rows = []
success_rows = []
pipelines = radiator.pipelines.select { |hash|
hash.current_stage[0].status != 'success'
}
pipelines.sort_by! {|p| p.name}
pipelines.each_slice(3) do |x|
rows << x
end
success_pipelines = radiator.pipelines.select { |hash|
hash.current_stage[0].status == 'success'
}
success_pipelines.sort_by! {|p| p.name}
success_pipelines.each_slice(4) do |x|
success_rows << x
end
haml :index, :locals => {:rows => rows, :success_rows => success_rows}, :format => :html5
end