Class: Admin::MetricsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Admin::MetricsController
- Defined in:
- app/controllers/admin/metrics_controller.rb
Instance Method Summary collapse
- #calculate ⇒ Object
- #clone ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #evaluate ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #show ⇒ Object
-
#update ⇒ Object
PUT /admin/metrics/id —————————————————————————-.
Instance Method Details
#calculate ⇒ Object
64 65 66 67 68 |
# File 'app/controllers/admin/metrics_controller.rb', line 64 def calculate CalculateMetrics.calculate_metrics_for_id(params[:id]) flash[:notice] = "Completed calculating" redirect_to admin_metrics_url end |
#clone ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/controllers/admin/metrics_controller.rb', line 50 def clone @metric_to_clone = Metric.find(params[:id]) @metric = @metric_to_clone.clone @metric.title = "Copy of #{@metric.title}" @metric.sort = Metric.maximum(:sort, :conditions=>["resource_type_id = ?", @metric_to_clone.resource_type_id ]).to_i + 1 if @metric.save flash[:notice] = "#{@metric.title} has been cloned" redirect_to edit_admin_metric_url(@metric) else flash[:notice] = "There was an error" render :action => :new, :status => :unprocessable_entity end end |
#create ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/admin/metrics_controller.rb', line 39 def create @metric = Metric.new(params[:metric]) if @metric.save flash[:success] = "#{@metric.title} has been created" redirect_to admin_metrics_url else flash[:notice] = "There was an error" render :action => :new, :status => :unprocessable_entity end end |
#destroy ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/controllers/admin/metrics_controller.rb', line 27 def destroy if @metric = Metric.find(params[:id]) @metric.destroy flash[:success] = "Metric has been removed." redirect_to admin_metrics_url else flash[:alert] = "Metric has not been removed." redirect_to admin_metrics_url end end |
#edit ⇒ Object
15 16 17 18 19 |
# File 'app/controllers/admin/metrics_controller.rb', line 15 def edit @metric_categories = ResourceType.all @metric = Metric.find(params[:id]) @resource_type = ResourceType.find_by_id(@metric.resource_type_id) end |
#evaluate ⇒ Object
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 |
# File 'app/controllers/admin/metrics_controller.rb', line 70 def evaluate metric_logic = params["logic"].gsub(":staff", params[:logic_staff]) error = {} res = Thread.new{ require 'rubygems' require 'active_support' begin @has_error = false ActiveRecord::Base.establish_connection "needles_#{RAILS_ENV}" @result, @results = eval(metric_logic) ActiveRecord::Base.verify_active_connections! [@result,@results] rescue Exception => e logger.info "Error Message: #{e.message}" @has_error = true @errors = [e., e.backtrace.join("\r\n")].join("\r\n") end } @result, @results = res.value @results = @results.to_json respond_to do |format| format.js end end |
#index ⇒ Object
6 7 8 |
# File 'app/controllers/admin/metrics_controller.rb', line 6 def index @metric_categories = ResourceType.all end |
#new ⇒ Object
21 22 23 24 25 |
# File 'app/controllers/admin/metrics_controller.rb', line 21 def new @metric = Metric.new @metric.resource_type_id = params[:resource_type_id] @metric.resource_type = params[:resource_type] end |
#show ⇒ Object
10 11 12 13 |
# File 'app/controllers/admin/metrics_controller.rb', line 10 def show @metric = Metric.find(params[:id]) @metricnote = MetricNote.new end |
#update ⇒ Object
PUT /admin/metrics/id
102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/admin/metrics_controller.rb', line 102 def update @metric = Metric.find_by_id(params[:metric][:id]) if @metric.update_attributes(params[:metric]) flash[:notice] = "#{@metric.title} has been updated" # CalculateMetrics.calculate_metrics_for_id(@metric.id) redirect_to :action => :edit else render :action => :index, :status => :unprocessable_entity end end |