mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-17 06:52:27 +01:00
optimize usernames mapping in statistics
This commit is contained in:
parent
4639a15e2f
commit
24f963645b
@ -1,7 +1,7 @@
|
||||
'use strict'
|
||||
|
||||
Application.Controllers.controller "StatisticsController", ["$scope", "$state", "$rootScope", "Statistics", "es", "Member", '_t'
|
||||
, ($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, membersPromise, statisticsPromise) ->
|
||||
|
||||
|
||||
|
||||
@ -21,10 +21,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
||||
$scope.preventRefresh = false
|
||||
|
||||
## statistics structure in elasticSearch
|
||||
$scope.statistics = []
|
||||
$scope.statistics = statisticsPromise
|
||||
|
||||
## fablab users list
|
||||
$scope.members = []
|
||||
$scope.members = membersPromise
|
||||
|
||||
## statistics data recovered from elasticSearch
|
||||
$scope.data = null
|
||||
@ -241,13 +241,10 @@ Application.Controllers.controller "StatisticsController", ["$scope", "$state",
|
||||
# @param id {number} user ID
|
||||
##
|
||||
$scope.getUserNameFromId = (id) ->
|
||||
if $scope.members.length == 0
|
||||
return "ID "+id
|
||||
else
|
||||
for member in $scope.members
|
||||
if member.id == id
|
||||
return member.name
|
||||
return "ID "+id
|
||||
name = $scope.members[id]
|
||||
if name
|
||||
return name
|
||||
else "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
|
||||
##
|
||||
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
|
||||
# which will cause every tabs to reload, one by one, when the view is closed
|
||||
$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" %>'
|
||||
controller: 'StatisticsController'
|
||||
resolve:
|
||||
membersPromise: ['Member', (Member) ->
|
||||
Member.mapping().$promise
|
||||
]
|
||||
statisticsPromise: ['Statistics', (Statistics)->
|
||||
Statistics.query().$promise
|
||||
]
|
||||
translations: [ 'Translations', (Translations) ->
|
||||
Translations.query('app.admin.statistics').$promise
|
||||
]
|
||||
|
@ -22,4 +22,7 @@ Application.Services.factory 'Member', ["$resource", ($resource)->
|
||||
url: '/api/members/search/:query'
|
||||
params: {query: "@query"}
|
||||
isArray: true
|
||||
mapping:
|
||||
method: 'GET'
|
||||
url: '/api/members/mapping'
|
||||
]
|
||||
|
@ -204,6 +204,12 @@ class API::MembersController < API::ApiController
|
||||
@members
|
||||
end
|
||||
|
||||
def mapping
|
||||
authorize User
|
||||
|
||||
@members = User.includes(:profile)
|
||||
end
|
||||
|
||||
private
|
||||
def set_member
|
||||
@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)
|
||||
end
|
||||
|
||||
def create?
|
||||
user.is_admin?
|
||||
end
|
||||
|
||||
def update?
|
||||
user.is_admin? or (user.id == record.id)
|
||||
end
|
||||
@ -29,8 +25,9 @@ class UserPolicy < ApplicationPolicy
|
||||
user.id == record.id
|
||||
end
|
||||
|
||||
def list?
|
||||
user.is_admin?
|
||||
%w(list create mapping).each do |action|
|
||||
define_method "#{action}?" do
|
||||
user.is_admin?
|
||||
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
|
||||
post 'list', action: 'list', on: :collection
|
||||
get 'search/:query', action: 'search', on: :collection
|
||||
get 'mapping', action: 'mapping', on: :collection
|
||||
end
|
||||
resources :reservations, only: [:show, :create, :index, :update]
|
||||
resources :notifications, only: [:index, :show, :update] do
|
||||
|
Loading…
x
Reference in New Issue
Block a user