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

40 lines
1.1 KiB
Ruby
Raw Normal View History

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
%w(account event machine project subscription training user).each do |path|
class_eval %{
def #{path}
authorize :statistic, :#{path}?
query = MultiJson.load(request.body.read)
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
render json: results
end
def export_#{path}
authorize :statistic, :#{path}?
query = MultiJson.load(request.body.read)
2016-07-05 16:13:11 +02:00
@results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
render xlsx: 'export_#{path}.xlsx', filename: "#{path}.xlsx"
end
2016-03-23 18:39:41 +01:00
}
end
2016-06-21 13:16:42 +02:00
def export_global
# query all stats with range arguments
render xls: []
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