cycle_analytics_controller.rb 862 Bytes
Newer Older
1
class Projects::CycleAnalyticsController < Projects::ApplicationController
2
  include ActionView::Helpers::DateHelper
3
  include ActionView::Helpers::TextHelper
4
  include CycleAnalyticsParams
5

6 7
  before_action :authorize_read_cycle_analytics!

8
  def show
9
    @cycle_analytics = ::CycleAnalytics.new(@project, options(cycle_analytics_params))
10 11

    @cycle_analytics_no_data = @cycle_analytics.no_stats?
12 13 14

    respond_to do |format|
      format.html
15
      format.json { render json: cycle_analytics_json }
16
    end
17 18 19 20 21 22 23
  end

  private

  def cycle_analytics_params
    return {} unless params[:cycle_analytics].present?

24
    params[:cycle_analytics].permit(:start_date)
25
  end
26

27 28 29
  def cycle_analytics_json
    {
      summary: @cycle_analytics.summary,
30 31
      stats: @cycle_analytics.stats,
      permissions: @cycle_analytics.permissions(user: current_user)
32
    }
33
  end
34
end