mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
API accessing service & conforming server-side access points
This commit is contained in:
parent
38c00391fc
commit
b26bbd18ef
@ -2,8 +2,8 @@
|
||||
|
||||
|
||||
|
||||
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", '$uibModal', "Statistics", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
|
||||
, ($scope, $state, $rootScope, $uibModal, Statistics, es, Member, _t, membersPromise, statisticsPromise) ->
|
||||
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", '$uibModal', "Export", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
|
||||
, ($scope, $state, $rootScope, $uibModal, Export, es, Member, _t, membersPromise, statisticsPromise) ->
|
||||
|
||||
|
||||
|
||||
@ -288,9 +288,24 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
||||
|
||||
$uibModal.open options
|
||||
.result['finally'](null).then (info)->
|
||||
console.info(info)
|
||||
, (reason)->
|
||||
console.error(reason)
|
||||
# export requested
|
||||
if info.type == 'current'
|
||||
custom = buildCustomFilterQuery()
|
||||
Export.stats $scope.selectedIndex.es_type_key,
|
||||
buildElasticDataQuery($scope.type.active.key, custom, $scope.agePicker.start, $scope.agePicker.end, moment($scope.datePickerStart.selected), moment($scope.datePickerEnd.selected), $scope.sorting)
|
||||
else if info.type == 'global'
|
||||
Export.stats 'global',
|
||||
"query":
|
||||
"bool":
|
||||
"must": [
|
||||
{
|
||||
"range":
|
||||
"date":
|
||||
"gte": moment(info.dates.start).format()
|
||||
"lte": moment(info.dates.end).format()
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
|
||||
|
||||
@ -331,12 +346,7 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
||||
$scope.sumStat = 0
|
||||
$scope.totalHits = null
|
||||
$scope.searchDate = new Date()
|
||||
custom = null
|
||||
if $scope.customFilter.criterion and $scope.customFilter.criterion.key and $scope.customFilter.value
|
||||
custom = {}
|
||||
custom.key = $scope.customFilter.criterion.key
|
||||
custom.value = $scope.customFilter.value
|
||||
custom.exclude = $scope.customFilter.exclude
|
||||
custom = buildCustomFilterQuery()
|
||||
queryElasticStats $scope.selectedIndex.es_type_key, $scope.type.active.key, custom, (res, err)->
|
||||
if (err)
|
||||
console.error("[statisticsController::refreshStats] Unable to refresh due to "+err)
|
||||
@ -508,6 +518,20 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Build and return an object according to the custom filter set by the user, used to request elasticsearch
|
||||
# @return {Object|null}
|
||||
##
|
||||
buildCustomFilterQuery = ->
|
||||
custom = null
|
||||
if $scope.customFilter.criterion and $scope.customFilter.criterion.key and $scope.customFilter.value
|
||||
custom = {}
|
||||
custom.key = $scope.customFilter.criterion.key
|
||||
custom.value = $scope.customFilter.value
|
||||
custom.exclude = $scope.customFilter.exclude
|
||||
custom
|
||||
|
||||
|
||||
|
||||
# init the controller (call at the end !)
|
||||
initialize()
|
||||
@ -518,10 +542,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
||||
|
||||
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', ($scope, $uibModalInstance, dates) ->
|
||||
|
||||
# bindings for date range
|
||||
## Bindings for date range
|
||||
$scope.dates = dates
|
||||
|
||||
|
||||
## Binding of the export type (global / current)
|
||||
$scope.export =
|
||||
type: 'current'
|
||||
|
||||
@ -543,6 +567,8 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
|
||||
options:
|
||||
startingDay: Fablab.weekStartingDay
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Callback to open the datepicker (interval start)
|
||||
# @param $event {Object} jQuery event object
|
||||
@ -560,8 +586,24 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
|
||||
$scope.exportEnd.opened = !$scope.exportEnd.opened
|
||||
|
||||
|
||||
$scope.ok = (info) ->
|
||||
$uibModalInstance.close( info )
|
||||
|
||||
##
|
||||
# Callback to close the modal, telling the caller to start the export with the selected parameters
|
||||
##
|
||||
$scope.ok = ->
|
||||
info =
|
||||
type: $scope.export.type
|
||||
|
||||
if info.type == 'global'
|
||||
info.dates = $scope.dates
|
||||
|
||||
$uibModalInstance.close(info)
|
||||
|
||||
|
||||
|
||||
##
|
||||
# Callback to cancel the export and close the modal
|
||||
##
|
||||
$scope.cancel = ->
|
||||
$uibModalInstance.dismiss('cancel')
|
||||
]
|
11
app/assets/javascripts/services/export.coffee
Normal file
11
app/assets/javascripts/services/export.coffee
Normal file
@ -0,0 +1,11 @@
|
||||
'use strict'
|
||||
|
||||
Application.Services.factory 'Export', ["$http", ($http)->
|
||||
stats: (scope, query) ->
|
||||
$http.post('/stats/'+scope+'/export', query).then((res) ->
|
||||
console.log(res)
|
||||
, (err) ->
|
||||
console.error(err)
|
||||
)
|
||||
|
||||
]
|
@ -19,14 +19,16 @@ class API::StatisticsController < API::ApiController
|
||||
authorize :statistic, :#{path}?
|
||||
query = MultiJson.load(request.body.read)
|
||||
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xls
|
||||
end
|
||||
render xls: results
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
def export_global
|
||||
# query all stats with range arguments
|
||||
render xls: []
|
||||
end
|
||||
|
||||
def scroll
|
||||
authorize :statistic, :scroll?
|
||||
|
||||
|
@ -129,6 +129,7 @@ Rails.application.routes.draw do
|
||||
post "/stats/#{path}/_search", to: "api/statistics##{path}"
|
||||
post "/stats/#{path}/export", to: "api/statistics#export_#{path}"
|
||||
end
|
||||
post '/stats/global/export', to: "api/statistics#export_global"
|
||||
post '_search/scroll', to: "api/statistics#scroll"
|
||||
|
||||
match '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid', via: :get
|
||||
|
Loading…
Reference in New Issue
Block a user