mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
optimize trainings API
This commit is contained in:
parent
4bc57c43d2
commit
e503d6edd8
@ -5,6 +5,7 @@
|
|||||||
- User public profile: UI re-design with possible admin's customization
|
- User public profile: UI re-design with possible admin's customization
|
||||||
- Admin: Invoices list and users list are now loaded per 10 items to improve pages load time
|
- Admin: Invoices list and users list are now loaded per 10 items to improve pages load time
|
||||||
- Admin: select member (eg. to buy a subscription for a member) is now loading the user's list dynamically when you type
|
- Admin: select member (eg. to buy a subscription for a member) is now loading the user's list dynamically when you type
|
||||||
|
- API: GET /api/trainings do not send the associated availabilities until they are requested
|
||||||
- [TODO DEPLOY] Regenerate the theme stylesheet (easy way: Customization/General/Main colour -> "Save")
|
- [TODO DEPLOY] Regenerate the theme stylesheet (easy way: Customization/General/Main colour -> "Save")
|
||||||
- [TODO DEPLOY] `bundle install` and `rake db:migrate`
|
- [TODO DEPLOY] `bundle install` and `rake db:migrate`
|
||||||
|
|
||||||
|
@ -3,8 +3,8 @@
|
|||||||
##
|
##
|
||||||
# Controller used in the prices edition page
|
# Controller used in the prices edition page
|
||||||
##
|
##
|
||||||
Application.Controllers.controller "EditPricingController", ["$scope", "$state", '$uibModal', 'Training', 'TrainingsPricing', 'Machine', '$filter', 'Credit', 'Pricing', 'Plan', 'plans', 'groups', 'growl', 'machinesPricesPromise', 'Price', 'dialogs', 'trainingsPricingsPromise', '_t'
|
Application.Controllers.controller "EditPricingController", ["$scope", "$state", '$uibModal', 'TrainingsPricing', '$filter', 'Credit', 'Pricing', 'Plan', 'plans', 'groups', 'growl', 'machinesPricesPromise', 'Price', 'dialogs', 'trainingsPricingsPromise', 'trainingsPromise', 'machineCreditsPromise', 'machinesPromise', 'trainingCreditsPromise', '_t'
|
||||||
, ($scope, $state, $uibModal, Training, TrainingsPricing, Machine, $filter, Credit, Pricing, Plan, plans, groups, growl, machinesPricesPromise, Price, dialogs, trainingsPricingsPromise, _t) ->
|
, ($scope, $state, $uibModal, TrainingsPricing, $filter, Credit, Pricing, Plan, plans, groups, growl, machinesPricesPromise, Price, dialogs, trainingsPricingsPromise, trainingsPromise, machineCreditsPromise, machinesPromise, trainingCreditsPromise, _t) ->
|
||||||
|
|
||||||
### PUBLIC SCOPE ###
|
### PUBLIC SCOPE ###
|
||||||
## List of machines prices (not considering any plan)
|
## List of machines prices (not considering any plan)
|
||||||
@ -20,19 +20,19 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
|
|||||||
$scope.groups = groups
|
$scope.groups = groups
|
||||||
|
|
||||||
## Associate free machine hours with subscriptions
|
## Associate free machine hours with subscriptions
|
||||||
$scope.machineCredits = []
|
$scope.machineCredits = machineCreditsPromise
|
||||||
|
|
||||||
## Array of associations (plan <-> training)
|
## Array of associations (plan <-> training)
|
||||||
$scope.trainingCredits = []
|
$scope.trainingCredits = trainingCreditsPromise
|
||||||
|
|
||||||
## Associate a plan with all its trainings ids
|
## Associate a plan with all its trainings ids
|
||||||
$scope.trainingCreditsGroups = {}
|
$scope.trainingCreditsGroups = {}
|
||||||
|
|
||||||
## List of trainings
|
## List of trainings
|
||||||
$scope.trainings = []
|
$scope.trainings = trainingsPromise
|
||||||
|
|
||||||
## List of machines
|
## List of machines
|
||||||
$scope.machines = []
|
$scope.machines = machinesPromise
|
||||||
|
|
||||||
## The plans list ordering. Default: by group
|
## The plans list ordering. Default: by group
|
||||||
$scope.orderPlans = 'group_id'
|
$scope.orderPlans = 'group_id'
|
||||||
@ -320,23 +320,13 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
|
|||||||
##
|
##
|
||||||
initialize = ->
|
initialize = ->
|
||||||
|
|
||||||
Credit.query({creditable_type: 'Training'}).$promise.then (data)->
|
$scope.trainingCreditsGroups = groupCreditsByPlan($scope.trainingCredits)
|
||||||
$scope.trainingCredits = data
|
|
||||||
$scope.trainingCreditsGroups = groupCreditsByPlan(data)
|
|
||||||
|
|
||||||
## adds empty array for plan which hasn't any credits yet
|
## adds empty array for plan which hasn't any credits yet
|
||||||
for plan in $scope.plans
|
for plan in $scope.plans
|
||||||
unless $scope.trainingCreditsGroups[plan.id]?
|
unless $scope.trainingCreditsGroups[plan.id]?
|
||||||
$scope.trainingCreditsGroups[plan.id] = []
|
$scope.trainingCreditsGroups[plan.id] = []
|
||||||
|
|
||||||
Credit.query({creditable_type: 'Machine'}).$promise.then (data)->
|
|
||||||
$scope.machineCredits = data
|
|
||||||
|
|
||||||
Training.query().$promise.then (data)->
|
|
||||||
$scope.trainings = data
|
|
||||||
|
|
||||||
Machine.query().$promise.then (data)->
|
|
||||||
$scope.machines = data
|
|
||||||
|
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -515,7 +515,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
controller: 'TrainingsController'
|
controller: 'TrainingsController'
|
||||||
resolve:
|
resolve:
|
||||||
trainingsPromise: ['Training', (Training)->
|
trainingsPromise: ['Training', (Training)->
|
||||||
Training.query().$promise
|
Training.query({requested_attributes:'[availabilities]'}).$promise
|
||||||
]
|
]
|
||||||
machinesPromise: ['Machine', (Machine)->
|
machinesPromise: ['Machine', (Machine)->
|
||||||
Machine.query().$promise
|
Machine.query().$promise
|
||||||
@ -601,6 +601,18 @@ angular.module('application.router', ['ui.router']).
|
|||||||
translations: [ 'Translations', (Translations) ->
|
translations: [ 'Translations', (Translations) ->
|
||||||
Translations.query('app.admin.pricing').$promise
|
Translations.query('app.admin.pricing').$promise
|
||||||
]
|
]
|
||||||
|
trainingsPromise: ['Training', (Training) ->
|
||||||
|
Training.query().$promise
|
||||||
|
]
|
||||||
|
machineCreditsPromise: ['Credit', (Credit) ->
|
||||||
|
Credit.query({creditable_type: 'Machine'}).$promise
|
||||||
|
]
|
||||||
|
machinesPromise: ['Machine', (Machine) ->
|
||||||
|
Machine.query().$promise
|
||||||
|
]
|
||||||
|
trainingCreditsPromise: ['Credit', (Credit) ->
|
||||||
|
Credit.query({creditable_type: 'Training'}).$promise
|
||||||
|
]
|
||||||
|
|
||||||
# plans
|
# plans
|
||||||
.state 'app.admin.plans',
|
.state 'app.admin.plans',
|
||||||
|
@ -3,6 +3,7 @@ class API::TrainingsController < API::ApiController
|
|||||||
before_action :set_training, only: [:show, :update, :destroy]
|
before_action :set_training, only: [:show, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@requested_attributes = params[:requested_attributes]
|
||||||
@trainings = policy_scope(Training)
|
@trainings = policy_scope(Training)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ json.array!(@trainings) do |training|
|
|||||||
json.full_name slot.reservation.user.profile.full_name
|
json.full_name slot.reservation.user.profile.full_name
|
||||||
json.is_valid slot.reservation.user.trainings.include?(training)
|
json.is_valid slot.reservation.user.trainings.include?(training)
|
||||||
end
|
end
|
||||||
end
|
end if attribute_requested?(@requested_attributes, 'availabilities')
|
||||||
json.nb_total_places training.nb_total_places
|
json.nb_total_places training.nb_total_places
|
||||||
|
|
||||||
json.plan_ids training.plan_ids if current_user and current_user.is_admin?
|
json.plan_ids training.plan_ids if current_user and current_user.is_admin?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user