mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
optimize usernames mapping in statistics
This commit is contained in:
parent
4639a15e2f
commit
24f963645b
@ -1,7 +1,7 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", "Statistics", "es", "Member", '_t'
|
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", "Statistics", "es", "Member", '_t', 'membersPromise', 'statisticsPromise'
|
||||||
, ($scope, $state, $rootScope, Statistics, es, Member, _t) ->
|
, ($scope, $state, $rootScope, Statistics, es, Member, _t, membersPromise, statisticsPromise) ->
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -21,10 +21,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
|||||||
$scope.preventRefresh = false
|
$scope.preventRefresh = false
|
||||||
|
|
||||||
## statistics structure in elasticSearch
|
## statistics structure in elasticSearch
|
||||||
$scope.statistics = []
|
$scope.statistics = statisticsPromise
|
||||||
|
|
||||||
## fablab users list
|
## fablab users list
|
||||||
$scope.members = []
|
$scope.members = membersPromise
|
||||||
|
|
||||||
## statistics data recovered from elasticSearch
|
## statistics data recovered from elasticSearch
|
||||||
$scope.data = null
|
$scope.data = null
|
||||||
@ -241,13 +241,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
|||||||
# @param id {number} user ID
|
# @param id {number} user ID
|
||||||
##
|
##
|
||||||
$scope.getUserNameFromId = (id) ->
|
$scope.getUserNameFromId = (id) ->
|
||||||
if $scope.members.length == 0
|
name = $scope.members[id]
|
||||||
return "ID "+id
|
if name
|
||||||
else
|
return name
|
||||||
for member in $scope.members
|
else "ID "+id
|
||||||
if member.id == id
|
|
||||||
return member.name
|
|
||||||
return "ID "+id
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -282,12 +279,6 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
|||||||
# Kind of constructor: these actions will be realized first when the controller is loaded
|
# Kind of constructor: these actions will be realized first when the controller is loaded
|
||||||
##
|
##
|
||||||
initialize = ->
|
initialize = ->
|
||||||
Statistics.query (stats) ->
|
|
||||||
$scope.statistics = stats
|
|
||||||
|
|
||||||
Member.query (members) ->
|
|
||||||
$scope.members = members
|
|
||||||
|
|
||||||
# workaround for angular-bootstrap::tabs behavior: on tab deletion, another tab will be selected
|
# workaround for angular-bootstrap::tabs behavior: on tab deletion, another tab will be selected
|
||||||
# which will cause every tabs to reload, one by one, when the view is closed
|
# which will cause every tabs to reload, one by one, when the view is closed
|
||||||
$rootScope.$on '$stateChangeStart', (event, toState, toParams, fromState, fromParams) ->
|
$rootScope.$on '$stateChangeStart', (event, toState, toParams, fromState, fromParams) ->
|
||||||
|
@ -808,6 +808,12 @@ angular.module('application.router', ['ui.router']).
|
|||||||
templateUrl: '<%= asset_path "admin/statistics/index.html" %>'
|
templateUrl: '<%= asset_path "admin/statistics/index.html" %>'
|
||||||
controller: 'StatisticsController'
|
controller: 'StatisticsController'
|
||||||
resolve:
|
resolve:
|
||||||
|
membersPromise: ['Member', (Member) ->
|
||||||
|
Member.mapping().$promise
|
||||||
|
]
|
||||||
|
statisticsPromise: ['Statistics', (Statistics)->
|
||||||
|
Statistics.query().$promise
|
||||||
|
]
|
||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query('app.admin.statistics').$promise
|
Translations.query('app.admin.statistics').$promise
|
||||||
]
|
]
|
||||||
|
@ -22,4 +22,7 @@ Application.Services.factory 'Member', ["$resource", ($resource)->
|
|||||||
url: '/api/members/search/:query'
|
url: '/api/members/search/:query'
|
||||||
params: {query: "@query"}
|
params: {query: "@query"}
|
||||||
isArray: true
|
isArray: true
|
||||||
|
mapping:
|
||||||
|
method: 'GET'
|
||||||
|
url: '/api/members/mapping'
|
||||||
]
|
]
|
||||||
|
@ -204,6 +204,12 @@ class API::MembersController < API::ApiController
|
|||||||
@members
|
@members
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mapping
|
||||||
|
authorize User
|
||||||
|
|
||||||
|
@members = User.includes(:profile)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def set_member
|
def set_member
|
||||||
@member = User.find(params[:id])
|
@member = User.find(params[:id])
|
||||||
|
@ -13,10 +13,6 @@ class UserPolicy < ApplicationPolicy
|
|||||||
user.is_admin? or (record.is_allow_contact and record.is_member?) or (user.id == record.id)
|
user.is_admin? or (record.is_allow_contact and record.is_member?) or (user.id == record.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create?
|
|
||||||
user.is_admin?
|
|
||||||
end
|
|
||||||
|
|
||||||
def update?
|
def update?
|
||||||
user.is_admin? or (user.id == record.id)
|
user.is_admin? or (user.id == record.id)
|
||||||
end
|
end
|
||||||
@ -29,8 +25,9 @@ class UserPolicy < ApplicationPolicy
|
|||||||
user.id == record.id
|
user.id == record.id
|
||||||
end
|
end
|
||||||
|
|
||||||
def list?
|
%w(list create mapping).each do |action|
|
||||||
user.is_admin?
|
define_method "#{action}?" do
|
||||||
|
user.is_admin?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
3
app/views/api/members/mapping.json.jbuilder
Normal file
3
app/views/api/members/mapping.json.jbuilder
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
@members.each do |member|
|
||||||
|
json.set! member.id, member.profile.full_name
|
||||||
|
end
|
@ -42,6 +42,7 @@ Rails.application.routes.draw do
|
|||||||
put ':id/merge', action: 'merge', on: :collection
|
put ':id/merge', action: 'merge', on: :collection
|
||||||
post 'list', action: 'list', on: :collection
|
post 'list', action: 'list', on: :collection
|
||||||
get 'search/:query', action: 'search', on: :collection
|
get 'search/:query', action: 'search', on: :collection
|
||||||
|
get 'mapping', action: 'mapping', on: :collection
|
||||||
end
|
end
|
||||||
resources :reservations, only: [:show, :create, :index, :update]
|
resources :reservations, only: [:show, :create, :index, :update]
|
||||||
resources :notifications, only: [:index, :show, :update] do
|
resources :notifications, only: [:index, :show, :update] do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user