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
- #sort ⇒ Object
-
#update ⇒ Object
PUT /admin/metrics/id —————————————————————————-.
Instance Method Details
#calculate ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/admin/metrics_controller.rb', line 76 def calculate threads = [] flash[:notice] = "Started calculating..." threads << Thread.new do CalculateMetrics.calculate_metrics_for_id(params[:id]) end threads.each(&:join) flash[:notice] = "Completed calculating" redirect_to admin_metrics_url end |
#clone ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/admin/metrics_controller.rb', line 62 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
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/controllers/admin/metrics_controller.rb', line 41 def create @metric = Metric.new(params[:metric]) @metric.has_detail = 1 @metric.data_type = "integer" 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
29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/controllers/admin/metrics_controller.rb', line 29 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 20 21 |
# File 'app/controllers/admin/metrics_controller.rb', line 15 def edit @metric_categories = ResourceType.all @metric = Metric.find(params[:id]) @resources = Resource.all @resource_type = ResourceType.find_by_id(@metric.resource_type_id) 1.times { @metric.metric_summaries.build } end |
#evaluate ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'app/controllers/admin/metrics_controller.rb', line 87 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 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
23 24 25 26 27 |
# File 'app/controllers/admin/metrics_controller.rb', line 23 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 |
#sort ⇒ Object
54 55 56 57 58 59 60 |
# File 'app/controllers/admin/metrics_controller.rb', line 54 def sort params[:metric].each_with_index do |metric_id, i| @metric = Metric.find(metric_id) @metric.update_attribute(:sort, i) end render :text => "sorted" end |
#update ⇒ Object
PUT /admin/metrics/id
119 120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/admin/metrics_controller.rb', line 119 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 |