Class: DeploymentRecommendationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/deployment_recommendations_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_admin!, #authenticate_user!, #forbidden_response, #json_request?, #record_not_found, #unauthorized_response

Instance Method Details

#destroyObject


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/deployment_recommendations_controller.rb', line 20

def destroy
  recommendation = current_user.deployment_recommendations.find(params[:recommendation_id])
  if recommendation.present?
    recommendation.delete
    respond_to do |format|
      format.json {render json:  'Recommendation deleted successfully!', status: :ok}
    end
  else
    respond_to do |format|
      format.json {render json:  'Recommendation could not be found!', status: :not_found}
    end
  end
end

#destroy_allObject


34
35
36
37
38
39
40
41
42
# File 'app/controllers/deployment_recommendations_controller.rb', line 34

def destroy_all
  ingredient = current_user.ingredients.find(params[:ingredient_id])

  ingredient.deployment_recommendations.destroy_all
  respond_to do |format|
    format.html
    format.json {render json: {'message' => "Destroyed all recommendations for ingredient with id #{ingredient.id}!"}, status: :ok}
  end
end

#has_recommendationsObject


44
45
46
47
48
49
50
51
52
# File 'app/controllers/deployment_recommendations_controller.rb', line 44

def has_recommendations
  root_ingredient = current_user.ingredients.find(params[:ingredient_id]).application_root
  @has_recommendations = current_user.deployment_recommendations.where(ingredient_id: root_ingredient.id).any?

  respond_to do |format|
    format.html
    format.json { render json: @has_recommendations, status: :ok}
  end
end

#indexObject


11
12
13
14
15
16
17
18
# File 'app/controllers/deployment_recommendations_controller.rb', line 11

def index
  @recommendations = current_user.deployment_recommendations.where(ingredient_id: params[:ingredient_id])

  respond_to do |format|
    format.html
    format.json {render json: @recommendations, status: :ok}
  end
end

#showObject


2
3
4
5
6
7
8
9
# File 'app/controllers/deployment_recommendations_controller.rb', line 2

def show
  @recommendation = current_user.deployment_recommendations.find_by(ingredient_id: params[:ingredient_id])

  respond_to do |format|
    format.html
    format.json {render json: @recommendation, status: :ok}
  end
end

#trigger_rangeObject


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/deployment_recommendations_controller.rb', line 54

def trigger_range
  ingredient = current_user.ingredients.find(params[:ingredient_id])
  min = params[:min].to_i || 100
  max = params[:max].to_i || 500
  step = params[:step].to_i || 50
  range = (min..max).step(step).to_a
  job_id = ingredient.schedule_recommendation_jobs(range).job_id

  respond_to do |format|
    format.html { redirect_to :back, notice: 'Deployment recommendation range has been scheduled!' }
    format.json { render json: {job_id: job_id}, status: :ok}
  end
rescue => e
  respond_to do |format|
    format.html { redirect_to :back, notice: "Error while scheduling deployment recommendation range:\n#{e.message}" }
    format.json { render json: e.message, status: :internal_server_error}
  end
end