mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-02 13:24:20 +01:00
optimise load plans json
This commit is contained in:
parent
8b699153cc
commit
4d0d3d6af0
@ -175,8 +175,8 @@ Application.Controllers.controller 'NewPlanController', ['$scope', '$uibModal',
|
|||||||
##
|
##
|
||||||
# Controller used in the plan edition form
|
# 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'
|
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) ->
|
, ($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 = ->
|
$scope.copyPricesFromPlan = ->
|
||||||
if $scope.plan.parent
|
if $scope.plan.parent
|
||||||
parentPlan = $scope.getPlanFromId($scope.plan.parent)
|
Plan.get {id: $scope.plan.parent}, (parentPlan) ->
|
||||||
for parentPrice in parentPlan.prices
|
for parentPrice in parentPlan.prices
|
||||||
for childKey, childPrice of $scope.plan.prices
|
for childKey, childPrice of $scope.plan.prices
|
||||||
if childPrice.priceable_type == parentPrice.priceable_type and childPrice.priceable_id == parentPrice.priceable_id
|
if childPrice.priceable_type == parentPrice.priceable_type and childPrice.priceable_id == parentPrice.priceable_id
|
||||||
$scope.plan.prices[childKey].amount = parentPrice.amount
|
$scope.plan.prices[childKey].amount = parentPrice.amount
|
||||||
break
|
break
|
||||||
|
|
||||||
# if no plan were selected, unset every prices
|
# if no plan were selected, unset every prices
|
||||||
else
|
else
|
||||||
for key, price of $scope.plan.prices
|
for key, price of $scope.plan.prices
|
||||||
|
@ -330,7 +330,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
controller: 'ReserveMachineController'
|
controller: 'ReserveMachineController'
|
||||||
resolve:
|
resolve:
|
||||||
plansPromise: ['Plan', (Plan)->
|
plansPromise: ['Plan', (Plan)->
|
||||||
Plan.query(attributes_requested: "['machines_credits']").$promise
|
Plan.query().$promise
|
||||||
]
|
]
|
||||||
groupsPromise: ['Group', (Group)->
|
groupsPromise: ['Group', (Group)->
|
||||||
Group.query().$promise
|
Group.query().$promise
|
||||||
@ -375,7 +375,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
Setting.get(name: 'training_explications_alert').$promise
|
Setting.get(name: 'training_explications_alert').$promise
|
||||||
]
|
]
|
||||||
plansPromise: ['Plan', (Plan)->
|
plansPromise: ['Plan', (Plan)->
|
||||||
Plan.query(attributes_requested: "['trainings_credits']").$promise
|
Plan.query().$promise
|
||||||
]
|
]
|
||||||
groupsPromise: ['Group', (Group)->
|
groupsPromise: ['Group', (Group)->
|
||||||
Group.query().$promise
|
Group.query().$promise
|
||||||
@ -423,7 +423,7 @@ angular.module('application.router', ['ui.router']).
|
|||||||
Setting.get(name: 'subscription_explications_alert').$promise
|
Setting.get(name: 'subscription_explications_alert').$promise
|
||||||
]
|
]
|
||||||
plansPromise: ['Plan', (Plan)->
|
plansPromise: ['Plan', (Plan)->
|
||||||
Plan.query(shallow: true).$promise
|
Plan.query().$promise
|
||||||
]
|
]
|
||||||
groupsPromise: ['Group', (Group)->
|
groupsPromise: ['Group', (Group)->
|
||||||
Group.query().$promise
|
Group.query().$promise
|
||||||
|
@ -2,15 +2,10 @@
|
|||||||
before_action :authenticate_user!, except: [:index]
|
before_action :authenticate_user!, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@attributes_requested = params[:attributes_requested]
|
@plans = Plan.includes(:plan_file)
|
||||||
@plans = Plan.all
|
|
||||||
@plans = @plans.where(group_id: params[:group_id]) if params[:group_id]
|
@plans = @plans.where(group_id: params[:group_id]) if params[:group_id]
|
||||||
if params[:shallow]
|
|
||||||
render :shallow_index
|
|
||||||
else
|
|
||||||
render :index
|
render :index
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@plan = Plan.find(params[:id])
|
@plan = Plan.find(params[:id])
|
||||||
|
@ -6,23 +6,8 @@ json.plan_file_attributes do
|
|||||||
json.attachment_identifier plan.plan_file.attachment_identifier
|
json.attachment_identifier plan.plan_file.attachment_identifier
|
||||||
end if plan.plan_file
|
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.partners plan.partners do |partner|
|
||||||
json.first_name partner.first_name
|
json.first_name partner.first_name
|
||||||
json.last_name partner.last_name
|
json.last_name partner.last_name
|
||||||
json.email partner.email
|
json.email partner.email
|
||||||
end if plan.respond_to?(:partners)
|
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')
|
|
||||||
|
@ -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
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
json.extract! price, :id, :group_id, :plan_id, :priceable_type, :priceable_id
|
json.extract! price, :id, :group_id, :plan_id, :priceable_type, :priceable_id
|
||||||
json.amount price.amount / 100.0
|
json.amount price.amount / 100.0
|
||||||
|
json.priceable_name price.priceable.name
|
||||||
|
Loading…
Reference in New Issue
Block a user