1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00
fab-manager/app/controllers/api/statistics_controller.rb

63 lines
2.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
# API Controller for various statistical resources (gateway to elasticsearch DB)
2016-03-23 18:39:41 +01:00
class API::StatisticsController < API::ApiController
before_action :authenticate_user!
def index
authorize :statistic, :index?
@statistics = StatisticIndex.all
end
2022-10-11 17:23:45 +02:00
%w[account event machine project subscription training user space order].each do |path|
2016-03-23 18:39:41 +01:00
class_eval %{
def #{path} # def account
authorize :statistic, :#{path}? # authorize :statistic, :account
render json: Statistics::QueryService.query('#{path}', request) # render json: Statistics::QueryService.query('account', request)
end # end
def export_#{path} # def export_account
authorize :statistic, :export_#{path}? # authorize :statistic, :export_account?
2022-11-16 16:55:56 +01:00
@export = Statistics::QueryService.export('#{path}', params, # @export = Statistics::QueryService.export('account', params,
current_user)
if @export.is_a?(Export)
if @export.save
render json: { export_id: @export.id }, status: :ok
else
render json: @export.errors, status: :unprocessable_entity
end
else
send_file @export,
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
disposition: 'attachment'
2016-07-06 19:00:22 +02:00
end
end
2022-11-16 16:55:56 +01:00
}, __FILE__, __LINE__ - 23
2016-03-23 18:39:41 +01:00
end
2016-06-21 13:16:42 +02:00
def export_global
2016-07-12 12:03:38 +02:00
authorize :statistic, :export_global?
2022-11-16 16:55:56 +01:00
@export = Statistics::QueryService.export('global', params, current_user)
if @export.is_a?(Export)
if @export.save
render json: { export_id: @export.id }, status: :ok
else
render json: @export.errors, status: :unprocessable_entity
end
else
send_file @export,
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
disposition: 'attachment'
2016-07-12 12:03:38 +02:00
end
end
2016-06-21 13:16:42 +02:00
def scroll
authorize :statistic, :scroll?
results = Elasticsearch::Model.client.scroll scroll: params[:scroll], scroll_id: params[:scrollId]
2016-06-21 13:16:42 +02:00
render json: results
end
2016-03-23 18:39:41 +01:00
end