diff --git a/Gemfile b/Gemfile index f5f28d0..fc200ba 100644 --- a/Gemfile +++ b/Gemfile @@ -48,9 +48,6 @@ gem "chart-js-rails", "~> 0.0.6" # JQueryUI gem 'jquery-ui-rails', '~> 4.1.0' -# Enables cache to actions -gem 'actionpack-action_caching', "~> 1.1.1" - group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 966fa43..d663e09 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,8 +10,6 @@ GEM erubis (~> 2.7.0) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionpack-action_caching (1.1.1) - actionpack (>= 4.0.0, < 5.0) activemodel (4.0.2) activesupport (= 4.0.2) builder (~> 3.1.0) @@ -268,7 +266,6 @@ PLATFORMS ruby DEPENDENCIES - actionpack-action_caching (~> 1.1.1) better_errors binding_of_caller capistrano (~> 3.0.1) diff --git a/app/controllers/modules_controller.rb b/app/controllers/modules_controller.rb index 399ffb9..12fbcb9 100644 --- a/app/controllers/modules_controller.rb +++ b/app/controllers/modules_controller.rb @@ -1,11 +1,9 @@ class ModulesController < ApplicationController - #caches_action :metric_history, cache_path: Proc.new{"#{params[:id]}_#{params[:metric_name]}"}, expires_in: 1.day, layout: false - # POST /modules/1/metric_history def metric_history - module_result = ModuleResult.find(params[:id].to_i) + @module_result = ModuleResult.find(params[:id].to_i) @container = params[:container] - @metric_history = module_result.metric_history(params[:metric_name]) # pending: sort this hash. + @metric_name = params[:metric_name] end # POST /modules/1/tree diff --git a/app/views/modules/metric_history.js.erb b/app/views/modules/metric_history.js.erb index 933a6cd..c0d9b61 100644 --- a/app/views/modules/metric_history.js.erb +++ b/app/views/modules/metric_history.js.erb @@ -1,16 +1,20 @@ -var dates = []; -var values = []; +<% cache("#{@module_result.id}_#{@metric_name}") do %> + <% metric_history = @module_result.metric_history(@metric_name) %> -<% @metric_history.keys.each do |date| %> - dates.push("<%= date %>"); - values.push(<%= @metric_history[date] %>); -<% end %> + var dates = []; + var values = []; -$("#loader_<%= @container %>").hide() -if (dates.length > 1) { - $("canvas#<%= @container %>").show() - Module.Graphic.display(dates, values, '<%= @container %>'); -} -else { - $('span#<%= @container %>').show() -} \ No newline at end of file + <% metric_history.keys.each do |date| %> + dates.push("<%= date %>"); + values.push(<%= metric_history[date] %>); + <% end %> + + $("#loader_<%= @container %>").hide(); + if (dates.length > 1) { + $("canvas#<%= @container %>").show(); + Module.Graphic.display(dates, values, '<%= @container %>'); + } + else { + $('span#<%= @container %>').show(); + } +<% end %> \ No newline at end of file diff --git a/spec/controllers/modules_controller_spec.rb b/spec/controllers/modules_controller_spec.rb index dd44547..97987c6 100644 --- a/spec/controllers/modules_controller_spec.rb +++ b/spec/controllers/modules_controller_spec.rb @@ -22,7 +22,6 @@ describe ModulesController do before :each do ModuleResult.expects(:find).at_least_once.with(module_result.id).returns(module_result) - module_result.expects(:metric_history).with(metric_name).returns({date => metric_result.value}) subject.expire_fragment("#{module_result.id}_#{metric_name}") request.env["HTTP_ACCEPT"] = 'application/javascript' # FIXME: there should be a better way to force JS -- libgit2 0.21.2