mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
40 lines
1.1 KiB
Ruby
40 lines
1.1 KiB
Ruby
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)
|
|
@results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
|
render xlsx: 'export_#{path}.xlsx', filename: "#{path}.xlsx"
|
|
end
|
|
}
|
|
end
|
|
|
|
def export_global
|
|
# query all stats with range arguments
|
|
render xls: []
|
|
end
|
|
|
|
def scroll
|
|
authorize :statistic, :scroll?
|
|
|
|
results = Elasticsearch::Model.client.scroll scroll: params[:scroll], scroll_id: params[:scrollId]
|
|
render json: results
|
|
end
|
|
|
|
end
|