1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

optimise load plans json

This commit is contained in:
Peng DU 2016-06-21 14:49:39 +02:00
parent 8b699153cc
commit 4d0d3d6af0
6 changed files with 23 additions and 35 deletions

View File

@ -175,8 +175,8 @@ Application.Controllers.controller 'NewPlanController', ['$scope', '$uibModal',
##
# Controller used in the plan edition form
##
Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'plans', 'planPromise', 'machines', 'prices', 'partners', 'CSRF', '$state', '$stateParams', 'growl', '$filter', '_t', '$locale'
, ($scope, groups, plans, planPromise, machines, prices, partners, CSRF, $state, $stateParams, growl, $filter, _t, $locale) ->
Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'plans', 'planPromise', 'machines', 'prices', 'partners', 'CSRF', '$state', '$stateParams', 'growl', '$filter', '_t', '$locale', 'Plan'
, ($scope, groups, plans, planPromise, machines, prices, partners, CSRF, $state, $stateParams, growl, $filter, _t, $locale, Plan) ->
@ -207,12 +207,13 @@ Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'p
##
$scope.copyPricesFromPlan = ->
if $scope.plan.parent
parentPlan = $scope.getPlanFromId($scope.plan.parent)
for parentPrice in parentPlan.prices
for childKey, childPrice of $scope.plan.prices
if childPrice.priceable_type == parentPrice.priceable_type and childPrice.priceable_id == parentPrice.priceable_id
$scope.plan.prices[childKey].amount = parentPrice.amount
break
Plan.get {id: $scope.plan.parent}, (parentPlan) ->
for parentPrice in parentPlan.prices
for childKey, childPrice of $scope.plan.prices
if childPrice.priceable_type == parentPrice.priceable_type and childPrice.priceable_id == parentPrice.priceable_id
$scope.plan.prices[childKey].amount = parentPrice.amount
break
# if no plan were selected, unset every prices
else
for key, price of $scope.plan.prices
@ -257,4 +258,4 @@ Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'p
## !!! MUST BE CALLED AT THE END of the controller
initialize()
]
]

View File

@ -330,7 +330,7 @@ angular.module('application.router', ['ui.router']).
controller: 'ReserveMachineController'
resolve:
plansPromise: ['Plan', (Plan)->
Plan.query(attributes_requested: "['machines_credits']").$promise
Plan.query().$promise
]
groupsPromise: ['Group', (Group)->
Group.query().$promise
@ -375,7 +375,7 @@ angular.module('application.router', ['ui.router']).
Setting.get(name: 'training_explications_alert').$promise
]
plansPromise: ['Plan', (Plan)->
Plan.query(attributes_requested: "['trainings_credits']").$promise
Plan.query().$promise
]
groupsPromise: ['Group', (Group)->
Group.query().$promise
@ -423,7 +423,7 @@ angular.module('application.router', ['ui.router']).
Setting.get(name: 'subscription_explications_alert').$promise
]
plansPromise: ['Plan', (Plan)->
Plan.query(shallow: true).$promise
Plan.query().$promise
]
groupsPromise: ['Group', (Group)->
Group.query().$promise

View File

@ -2,14 +2,9 @@
before_action :authenticate_user!, except: [:index]
def index
@attributes_requested = params[:attributes_requested]
@plans = Plan.all
@plans = Plan.includes(:plan_file)
@plans = @plans.where(group_id: params[:group_id]) if params[:group_id]
if params[:shallow]
render :shallow_index
else
render :index
end
render :index
end
def show

View File

@ -6,23 +6,8 @@ json.plan_file_attributes do
json.attachment_identifier plan.plan_file.attachment_identifier
end if plan.plan_file
json.prices plan.prices do |price|
json.extract! price, :id, :group_id, :plan_id, :priceable_type, :priceable_id
json.amount price.amount / 100.0
json.priceable_name price.priceable.name
end
json.partners plan.partners do |partner|
json.first_name partner.first_name
json.last_name partner.last_name
json.email partner.email
end if plan.respond_to?(:partners)
json.training_credits plan.training_credits do |tc|
json.training_id tc.creditable_id
end if attribute_requested?(@attributes_requested, 'trainings_credits')
json.machine_credits plan.machine_credits do |mc|
json.machine_id mc.creditable_id
json.hours mc.hours
end if attribute_requested?(@attributes_requested, 'machines_credits')

View File

@ -1 +1,7 @@
json.partial! 'api/plans/plan', collection: @plans, as: :plan
json.cache! @plans do
json.array!(@plans) do |plan|
json.extract! plan, :id, :base_name, :name, :interval, :interval_count, :group_id, :training_credit_nb, :description, :type, :ui_weight
json.amount (plan.amount / 100.00)
json.plan_file_url plan.plan_file.attachment_url if plan.plan_file
end
end

View File

@ -1,2 +1,3 @@
json.extract! price, :id, :group_id, :plan_id, :priceable_type, :priceable_id
json.amount price.amount / 100.0
json.priceable_name price.priceable.name