Class: Skadi::DashboardController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Skadi::DashboardController
- Defined in:
- app/controllers/skadi/dashboard_controller.rb
Instance Method Summary collapse
Instance Method Details
#data ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/skadi/dashboard_controller.rb', line 21 def data return head :forbidden unless can_view query_filters = params.permit(:date_from, :date_to, :page) if can_edit && params[:configuration].present? return custom_chart_data(query_filters) end unless params[:chart_id].present? return render json: { error: "The chart_id parameter must be specified" }, status: :unprocessable_content end return render json: @dashboard.chart_data(params[:chart_id], query_filters.to_h) rescue ActiveRecord::StatementInvalid => e = can_dangerously_use_sql ? e. : "Something went wrong fetching the data. Please contact a site admin." render json: { error: }, status: :unprocessable_content rescue Skadi::Dashboard::Error => e render json: { error: e. }, status: :unprocessable_content end |
#show ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/skadi/dashboard_controller.rb', line 10 def show return head :forbidden unless can_view render :show, locals: { dashboard_configuration: @dashboard.configuration, dataset_schema: Skadi::Schema.frontend_schema, can_edit: can_edit, can_dangerously_use_sql: can_dangerously_use_sql, } end |
#update ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/skadi/dashboard_controller.rb', line 42 def update return head :forbidden unless can_view && can_edit # The dashboard validator will strongly check the structure of :configuration @dashboard.configuration = params.to_unsafe_h[:configuration] if @dashboard.save head :ok else render json: { error: "Dashboard validation failed. #{@dashboard.errors..join("\n")}" }, status: :unprocessable_content end end |