1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-29 18:52:22 +01:00

hide disabled machine in admin pricing zone + prevent creating negative credits

This commit is contained in:
Sylvain 2017-10-11 14:48:03 +02:00
parent ad288628cc
commit 02baf9097e
9 changed files with 44 additions and 16 deletions

View File

@ -232,14 +232,14 @@ Application.Controllers.controller 'EditPlanController', ['$scope', 'groups', 'p
##
# Retrieve the name of a machine from its ID
# Retrieve the machine from its ID
# @param machine_id {number} machine identifier
# @returns {string} Machine's name
# @returns {object} Machine
##
$scope.getMachineName = (machine_id) ->
$scope.getMachine = (machine_id) ->
for machine in $scope.machines
if machine.id == machine_id
return machine.name
return machine

View File

@ -35,6 +35,7 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
## List of machines
$scope.machines = machinesPromise
$scope.enabledMachines = machinesPromise.filter (t) -> !t.disabled
## List of coupons
$scope.coupons = couponsPromise
@ -193,21 +194,37 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
##
# In the Credits tab, while editing a machine credit row, select the current machine from the
# drop-down list of machines as the current item.
# In the Credits tab, return the name of the machine/space associated with the given credit
# @param credit {Object} credit object, inherited from $resource
# @returns {String}
##
$scope.showCreditableName = (credit) ->
selected = _t('pricing.not_set')
if credit and credit.creditable_id
object = $scope.getCreditable(credit)
selected = object.name
if credit.creditable_type == 'Machine'
selected += ' ( id. ' + object.id + ' )'
return selected
##
# In the Credits tab, return the machine/space associated with the given credit
# @param credit {Object} credit object, inherited from $resource
# @returns {Object}
##
$scope.getCreditable = (credit) ->
selected = undefined
if credit and credit.creditable_id
if credit.creditable_type == 'Machine'
angular.forEach $scope.machines, (m)->
if m.id == credit.creditable_id
selected = m.name + ' ( id. ' + m.id + ' )'
selected = m
else if credit.creditable_type == 'Space'
angular.forEach $scope.spaces, (s)->
if s.id == credit.creditable_id
selected = s.name
selected = s
return selected
@ -236,6 +253,9 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
, (resp) ->
$scope.machineCredits[$scope.machineCredits.length-1].id = resp.id
growl.success(_t('pricing.credit_was_successfully_saved'))
, (err) ->
$scope.machineCredits.pop()
growl.error(_t('pricing.error_creating_credit'))
##
@ -299,10 +319,14 @@ Application.Controllers.controller "EditPricingController", ["$scope", "$state",
, (resp) ->
$scope.spaceCredits[$scope.spaceCredits.length - 1].id = resp.id
growl.success(_t('pricing.credit_was_successfully_saved'))
, (err) ->
$scope.spaceCredits.pop()
growl.error(_t('pricing.error_creating_credit'))
##
##
# Removes the newly inserted but not saved space credit / Cancel the current space credit modification
# @param rowform {Object} see http://vitalets.github.io/angular-xeditable/
# @param index {number} credit index in the $scope.spaceCredits array

View File

@ -62,8 +62,8 @@
</thead>
<tbody>
<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>
<tr ng-repeat="price in plan.prices" ng-if="price.priceable_type === 'Machine'" ng-hide="getMachine(price.priceable_id).disabled">
<td style="width: 60%;">{{ getMachine(price.priceable_id).name }} (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}">
<span class="input-group-addon">{{currencySymbol}}</span>

View File

@ -58,7 +58,7 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="mc in machineCredits" ng-init="plan = getPlanFromId(mc.plan_id)" ng-hide="plan.disabled">
<tr ng-repeat="mc in machineCredits" ng-hide="getPlanFromId(mc.plan_id).disabled || getCreditable(mc).disabled">
<td>
<span editable-select="mc.creditable_id" e-name="creditable_id" e-form="rowform" e-ng-options="m.id as m.name+' ( id. '+m.id+' )' for m in machines" e-required>
{{ showCreditableName(mc) }}
@ -71,7 +71,7 @@
</td>
<td>
<span editable-select="mc.plan_id" e-ng-options="p.id as humanReadablePlanName(p, groups, 'short') for p in enabledPlans" e-name="plan_id" e-form="rowform">
{{ plan | humanReadablePlanName: groups: 'short' }}
{{ getPlanFromId(mc.plan_id) | humanReadablePlanName: groups: 'short' }}
</span>
</td>
<td>
@ -110,7 +110,7 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="sc in spaceCredits" ng-init="plan = getPlanFromId(sc.plan_id)" ng-hide="plan.disabled">
<tr ng-repeat="sc in spaceCredits" ng-hide="getPlanFromId(sc.plan_id).disabled || getCreditable(sc).disabled">
<td>
<span editable-select="sc.creditable_id" e-name="creditable_id" e-form="rowform" e-ng-options="s.id as s.name for s in spaces" e-required>
{{ showCreditableName(sc) }}
@ -123,7 +123,7 @@
</td>
<td>
<span editable-select="sc.plan_id" e-ng-options="p.id as humanReadablePlanName(p, groups, 'short') for p in enabledPlans" e-name="plan_id" e-form="rowform">
{{ plan | humanReadablePlanName: groups: 'short' }}
{{ getPlanFromId(sc.plan_id) | humanReadablePlanName: groups: 'short' }}
</span>
</td>
<td>

View File

@ -11,7 +11,7 @@
</tr>
</thead>
<tbody>
<tr ng-repeat="machine in machines">
<tr ng-repeat="machine in enabledMachines">
<td>
{{ machine.name }}
</td>

View File

@ -4,4 +4,5 @@ class Credit < ActiveRecord::Base
has_many :users_credits, dependent: :destroy
validates :creditable_id, uniqueness: { scope: [:creditable_type, :plan_id] }
validates :hours, numericality: { greater_than_or_equal_to: 0 }
end

View File

@ -204,6 +204,7 @@ en:
error_a_credit_linking_this_machine_with_that_subscription_already_exists: "Error : a credit linking this machine with that subscription already exists."
changes_have_been_successfully_saved: "Changes have been successfully saved."
credit_was_successfully_saved: "Credit was successfully saved."
error_creating_credit: "Unable to create credit, an error occurred"
do_you_really_want_to_delete_this_subscription_plan: "Do you really want to delete this subscription plan?"
subscription_plan_was_successfully_deleted: "Subscription plan was successfully deleted."
unable_to_delete_the_specified_subscription_an_error_occurred: "Unable to delete the specified subscription, an error occurred."

View File

@ -204,6 +204,7 @@ fr:
error_a_credit_linking_this_machine_with_that_subscription_already_exists: "Erreur : un crédit associant cette machine et cet abonnement existe déjà."
changes_have_been_successfully_saved: "Les modifications ont bien été enregistrées."
credit_was_successfully_saved: "Le crédit a bien été enregistré."
error_creating_credit: "Impossible de créer le credit, une erreur est survenue"
do_you_really_want_to_delete_this_subscription_plan: "Êtes-vous sûr(e) de vouloir supprimer cette formule d'abonnement ?"
subscription_plan_was_successfully_deleted: "La formule d'abonnement a bien été supprimée."
unable_to_delete_the_specified_subscription_an_error_occurred: "Impossible de supprimer l'abonnement spécifié, une erreur s'est produite."

View File

@ -204,6 +204,7 @@ pt:
error_a_credit_linking_this_machine_with_that_subscription_already_exists: "Erro : um link de crédito entre esta máquina e esta assinatura já existe."
changes_have_been_successfully_saved: "As modificações foram salvas com sucesso."
credit_was_successfully_saved: "Crédito salvo com sucesso."
error_creating_credit: "Unable to create credit, an error occurred" # TODO
do_you_really_want_to_delete_this_subscription_plan: "Você realmente deletar esse plano de assinatura?"
subscription_plan_was_successfully_deleted: "Plano de assinatura foi deletado com sucesso."
unable_to_delete_the_specified_subscription_an_error_occurred: "Não é possível deletar a assinatura específicada, um erro ocorreu."