1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-19 13:54:25 +01:00

interface to configure space price per plan + refactored plans interface code

This commit is contained in:
Sylvain 2017-02-14 17:06:42 +01:00
parent 42819b18cb
commit ec4a06a0e4
5 changed files with 80 additions and 49 deletions

View File

@ -6,7 +6,7 @@
class PlanController
constructor: ($scope, groups, plans, machines, prices, partners, CSRF) ->
constructor: ($scope, groups, prices, partners, CSRF) ->
# protection against request forgery
CSRF.setMetaTags()
@ -15,12 +15,6 @@ class PlanController
## groups list
$scope.groups = groups
## plans list
$scope.plans = plans
## machines list
$scope.machines = machines
## users with role 'partner', notifiables for a partner plan
$scope.partners = partners.users
@ -48,38 +42,11 @@ class PlanController
##
# Retrieve a plan from its numeric identifier
# @param id {number} plan ID
# @returns {Object} Plan, inherits from $resource
##
$scope.getPlanFromId = (id) ->
for plan in $scope.plans
if plan.id == id
return plan
##
# Retrieve the name of a machine from its ID
# @param machine_id {number} machine identifier
# @returns {string} Machine's name
##
$scope.getMachineName = (machine_id) ->
for machine in $scope.machines
if machine.id == machine_id
return machine.name
##
# Controller used in the plan creation form
##
Application.Controllers.controller 'NewPlanController', ['$scope', '$uibModal', 'groups', 'plans', 'machines', 'prices', 'partners', 'CSRF', '$state', 'growl', '_t'
, ($scope, $uibModal, groups, plans, machines, prices, partners, CSRF, $state, growl, _t) ->
Application.Controllers.controller 'NewPlanController', ['$scope', '$uibModal', 'groups', 'prices', 'partners', 'CSRF', '$state', 'growl', '_t'
, ($scope, $uibModal, groups, prices, partners, CSRF, $state, growl, _t) ->
@ -175,7 +142,7 @@ Application.Controllers.controller 'NewPlanController', ['$scope', '$uibModal',
new PlanController($scope, groups, plans, machines, prices, partners, CSRF)
new PlanController($scope, groups, prices, partners, CSRF)
]
@ -183,13 +150,25 @@ 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', 'Plan'
, ($scope, groups, plans, planPromise, machines, prices, partners, CSRF, $state, $stateParams, growl, $filter, _t, Plan) ->
Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'plans', 'planPromise', 'machines', 'spaces', 'prices', 'partners', 'CSRF', '$state', '$stateParams', 'growl', '$filter', '_t', 'Plan'
, ($scope, groups, plans, planPromise, machines, spaces, prices, partners, CSRF, $state, $stateParams, growl, $filter, _t, Plan) ->
### PUBLIC SCOPE ###
## List of spaces
$scope.spaces = spaces
## List of plans
$scope.plans = plans
## List of machines
$scope.machines = machines
## List of groups
$scope.groups = groups
## current form is used for edition mode
$scope.mode = 'edition'
@ -231,9 +210,9 @@ Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'p
##
$scope.afterSubmit = (content) ->
if !content.id? and !content.plan_ids?
growl.error(_t('confirm_changes.unable_to_save_subscription_changes_please_try_again'))
growl.error(_t('edit_plan.unable_to_save_subscription_changes_please_try_again'))
else
growl.success(_t('confirm_changes.subscription_successfully_changed'))
growl.success(_t('edit_plan.subscription_successfully_changed'))
$state.go('app.admin.pricing')
@ -251,6 +230,30 @@ Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'p
##
# Retrieve the name of a machine from its ID
# @param machine_id {number} machine identifier
# @returns {string} Machine's name
##
$scope.getMachineName = (machine_id) ->
for machine in $scope.machines
if machine.id == machine_id
return machine.name
##
# Retrieve the name of a space from its ID
# @param space_id {number} space identifier
# @returns {string} Space's name
##
$scope.getSpaceName = (space_id) ->
for space in $scope.spaces
if space.id == space_id
return space.name
### PRIVATE SCOPE ###
##
@ -258,7 +261,7 @@ Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'p
##
initialize = ->
# Using the PlansController
new PlanController($scope, groups, plans, machines, prices, partners, CSRF)
new PlanController($scope, groups, prices, partners, CSRF)
## !!! MUST BE CALLED AT THE END of the controller
initialize()

View File

@ -838,15 +838,9 @@ angular.module('application.router', ['ui.router']).
prices: ['Pricing', (Pricing) ->
Pricing.query().$promise
]
machines: ['Machine', (Machine) ->
Machine.query().$promise
]
groups: ['Group', (Group) ->
Group.query().$promise
]
plans: ['Plan', (Plan) ->
Plan.query().$promise
]
partners: ['User', (User) ->
User.query({role: 'partner'}).$promise
]
@ -867,6 +861,15 @@ angular.module('application.router', ['ui.router']).
templateUrl: '<%= asset_path "admin/plans/edit.html" %>'
controller: 'EditPlanController'
resolve:
spaces: ['Space', (Space) ->
Space.query().$promise
]
machines: ['Machine', (Machine) ->
Machine.query().$promise
]
plans: ['Plan', (Plan) ->
Plan.query().$promise
]
planPromise: ['Plan', '$stateParams', (Plan, $stateParams) ->
Plan.get({id: $stateParams.id}).$promise
]

View File

@ -46,7 +46,7 @@
</thead>
<tbody>
<tr ng-repeat="price in plan.prices">
<tr ng-repeat="price in plan.prices" ng-if="price.priceable_type === 'Machine'">
<td style="width: 60%;">{{ getMachineName(price.priceable_id) }} (id {{ price.priceable_id }}) *</td>
<td>
<div class="input-group" ng-class="{'has-error': planForm['plan[prices_attributes][][amount]'].$dirty && planForm['plan[prices_attributes][][amount]'].$invalid}">
@ -59,6 +59,27 @@
</tbody>
</table>
<h3 translate>{{ 'edit_plan.spaces' }}</h3>
<table class="table">
<thead>
<th translate>{{ 'edit_plan.space' }}</th>
<th translate>{{ 'edit_plan.hourly_rate' }}</th>
</thead>
<tbody>
<tr ng-repeat="price in plan.prices" ng-if="price.priceable_type === 'Space'">
<td style="width: 60%;">{{ getSpaceName(price.priceable_id) }} *</td>
<td>
<div class="input-group" ng-class="{'has-error': planForm['plan[prices_attributes][][amount]'].$dirty && planForm['plan[prices_attributes][][amount]'].$invalid}">
<span class="input-group-addon">{{currencySymbol}}</span>
<input type="number" class="form-control" name="plan[prices_attributes][][amount]" ng-value="price.amount" required="required"/>
<input type="hidden" class="form-control" name="plan[prices_attributes][][id]" ng-value="price.id"/>
</div>
</td>
</tr>
</tbody>
</table>
<div class="panel-footer no-padder">
<input type="submit" value="{{ 'confirm_changes' | translate }}" class="r-b btn-valid btn btn-warning btn-block p-lg btn-lg text-u-c" ng-disabled="planForm.$invalid"/>
</div>

View File

@ -228,6 +228,8 @@ en:
machines: "Machines"
machine: "Machine"
hourly_rate: "Hourly rate"
spaces: "Spaces"
space: "Space"
unable_to_save_subscription_changes_please_try_again: "Unable to save subscription changes. Please try again."
subscription_successfully_changed: "Subscription successfully changed."

View File

@ -228,6 +228,8 @@ fr:
machines: "Machines"
machine: "Machine"
hourly_rate: "Tarif horaire"
spaces: "Espaces"
space: "Espace"
unable_to_save_subscription_changes_please_try_again: "Les modifications de l'abonnement n'ont pas pu être enregistrées. Veuillez réessayer."
subscription_successfully_changed: "Modification de l'abonnement réussie."