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'
|
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", '$uibModal', "Export", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
|
||||||
, ($scope, $state, $rootScope, $uibModal, Statistics, 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
|
$uibModal.open options
|
||||||
.result['finally'](null).then (info)->
|
.result['finally'](null).then (info)->
|
||||||
console.info(info)
|
# export requested
|
||||||
, (reason)->
|
if info.type == 'current'
|
||||||
console.error(reason)
|
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.sumStat = 0
|
||||||
$scope.totalHits = null
|
$scope.totalHits = null
|
||||||
$scope.searchDate = new Date()
|
$scope.searchDate = new Date()
|
||||||
custom = null
|
custom = buildCustomFilterQuery()
|
||||||
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
|
|
||||||
queryElasticStats $scope.selectedIndex.es_type_key, $scope.type.active.key, custom, (res, err)->
|
queryElasticStats $scope.selectedIndex.es_type_key, $scope.type.active.key, custom, (res, err)->
|
||||||
if (err)
|
if (err)
|
||||||
console.error("[statisticsController::refreshStats] Unable to refresh due to "+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 !)
|
# init the controller (call at the end !)
|
||||||
initialize()
|
initialize()
|
||||||
@ -518,10 +542,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
|||||||
|
|
||||||
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', ($scope, $uibModalInstance, dates) ->
|
Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$uibModalInstance', 'dates', ($scope, $uibModalInstance, dates) ->
|
||||||
|
|
||||||
# bindings for date range
|
## Bindings for date range
|
||||||
$scope.dates = dates
|
$scope.dates = dates
|
||||||
|
|
||||||
|
## Binding of the export type (global / current)
|
||||||
$scope.export =
|
$scope.export =
|
||||||
type: 'current'
|
type: 'current'
|
||||||
|
|
||||||
@ -543,6 +567,8 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
|
|||||||
options:
|
options:
|
||||||
startingDay: Fablab.weekStartingDay
|
startingDay: Fablab.weekStartingDay
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Callback to open the datepicker (interval start)
|
# Callback to open the datepicker (interval start)
|
||||||
# @param $event {Object} jQuery event object
|
# @param $event {Object} jQuery event object
|
||||||
@ -560,8 +586,24 @@ Application.Controllers.controller 'ExportStatisticsController', [ '$scope', '$u
|
|||||||
$scope.exportEnd.opened = !$scope.exportEnd.opened
|
$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 = ->
|
$scope.cancel = ->
|
||||||
$uibModalInstance.dismiss('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}?
|
authorize :statistic, :#{path}?
|
||||||
query = MultiJson.load(request.body.read)
|
query = MultiJson.load(request.body.read)
|
||||||
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
results = Stats::#{path.classify}.search(query, request.query_parameters.symbolize_keys).response
|
||||||
respond_to do |format|
|
render xls: results
|
||||||
format.html
|
|
||||||
format.xls
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def export_global
|
||||||
|
# query all stats with range arguments
|
||||||
|
render xls: []
|
||||||
|
end
|
||||||
|
|
||||||
def scroll
|
def scroll
|
||||||
authorize :statistic, :scroll?
|
authorize :statistic, :scroll?
|
||||||
|
|
||||||
|
@ -129,6 +129,7 @@ Rails.application.routes.draw do
|
|||||||
post "/stats/#{path}/_search", to: "api/statistics##{path}"
|
post "/stats/#{path}/_search", to: "api/statistics##{path}"
|
||||||
post "/stats/#{path}/export", to: "api/statistics#export_#{path}"
|
post "/stats/#{path}/export", to: "api/statistics#export_#{path}"
|
||||||
end
|
end
|
||||||
|
post '/stats/global/export', to: "api/statistics#export_global"
|
||||||
post '_search/scroll', to: "api/statistics#scroll"
|
post '_search/scroll', to: "api/statistics#scroll"
|
||||||
|
|
||||||
match '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid', via: :get
|
match '/project_collaborator/:valid_token', to: 'api/projects#collaborator_valid', via: :get
|
||||||
|
Loading…
Reference in New Issue
Block a user