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
|
# File 'lib/coupler/extensions/scenarios.rb', line 4
def self.registered(app)
app.get '/projects/:project_id/scenarios' do
@scenarios = @project.scenarios
erb :'scenarios/index'
end
app.get '/projects/:project_id/scenarios/new' do
@scenario = Models::Scenario.new
erb 'scenarios/new'.to_sym
end
app.post "/projects/:project_id/scenarios" do
@scenario = Models::Scenario.new(params[:scenario])
@scenario.project = @project
if @scenario.save
flash[:newly_created] = true
redirect "/projects/#{@project.id}/scenarios/#{@scenario.id}"
else
erb 'scenarios/new'.to_sym
end
end
app.get '/projects/:project_id/scenarios/:id' do
@scenario = @project.scenarios_dataset[:id => params[:id]]
@resources = @scenario.resources
@matcher = @scenario.matcher
@results = @scenario.results
@running_jobs = @scenario.running_jobs
@scheduled_jobs = @scenario.scheduled_jobs
erb 'scenarios/show'.to_sym
end
app.get "/projects/:project_id/scenarios/:id/run" do
@scenario = @project.scenarios_dataset[:id => params[:id]]
Scheduler.instance.schedule_run_scenario_job(@scenario)
redirect "/projects/#{@project.id}/scenarios/#{@scenario.id}"
end
end
|