1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-02-20 14:54:15 +01:00

associate plan w/ category

This commit is contained in:
Sylvain 2021-06-08 17:26:40 +02:00
parent ae039cdd0c
commit 4ca16c2688
9 changed files with 38 additions and 9 deletions

View File

@ -68,7 +68,7 @@ class API::PlansController < API::ApiController
@parameters = @parameters.require(:plan)
.permit(:base_name, :type, :group_id, :amount, :interval, :interval_count, :is_rolling,
:training_credit_nb, :ui_weight, :disabled, :monthly_payment, :description,
:training_credit_nb, :ui_weight, :disabled, :monthly_payment, :description, :plan_category_id,
plan_file_attributes: %i[id attachment _destroy],
prices_attributes: %i[id amount])
end

View File

@ -8,7 +8,7 @@ export const Loader: React.FC = ({children }) => {
<div className="fa-3x">
<i className="fas fa-circle-notch fa-spin" />
</div>
);
);// compile
return (
<Suspense fallback={loading}>
{children}

View File

@ -78,13 +78,16 @@ class PlanController {
/**
* Controller used in the plan creation form
*/
Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal', 'groups', 'prices', 'partners', 'CSRF', '$state', 'growl', '_t',
function ($scope, $uibModal, groups, prices, partners, CSRF, $state, growl, _t) {
Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal', 'groups', 'prices', 'partners', 'CSRF', '$state', 'growl', '_t', 'planCategories',
function ($scope, $uibModal, groups, prices, partners, CSRF, $state, growl, _t, planCategories) {
/* PUBLIC SCOPE */
// current form is used to create a new plan
$scope.mode = 'creation';
// list of all plan categories
$scope.planCategories = planCategories;
// prices bindings
$scope.prices = {
training: {},
@ -218,8 +221,8 @@ Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal',
/**
* Controller used in the plan edition form
*/
Application.Controllers.controller('EditPlanController', ['$scope', 'groups', 'plans', 'planPromise', 'machines', 'spaces', 'prices', 'partners', 'CSRF', '$state', '$stateParams', 'growl', '$filter', '_t', 'Plan',
function ($scope, groups, plans, planPromise, machines, spaces, 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', 'planCategories',
function ($scope, groups, plans, planPromise, machines, spaces, prices, partners, CSRF, $state, $stateParams, growl, $filter, _t, Plan, planCategories) {
/* PUBLIC SCOPE */
// List of spaces
@ -234,6 +237,9 @@ Application.Controllers.controller('EditPlanController', ['$scope', 'groups', 'p
// List of groups
$scope.allGroups = groups;
// list of all plan categories
$scope.planCategories = planCategories;
// current form is used for edition mode
$scope.mode = 'edition';

View File

@ -550,7 +550,7 @@ angular.module('application.router', ['ui.router'])
resolve: {
categoriesPromise: ['Category', function (Category) { return Category.query().$promise; }],
themesPromise: ['EventTheme', function (EventTheme) { return EventTheme.query().$promise; }],
ageRangesPromise: ['AgeRange', function (AgeRange) { return AgeRange.query().$promise; }],
ageRangesPromise: ['AgeRange', function (AgeRange) { return AgeRange.query().$promise; }]
}
})
.state('app.public.events_show', {
@ -801,6 +801,9 @@ angular.module('application.router', ['ui.router'])
templateUrl: '/admin/plans/new.html',
controller: 'NewPlanController'
}
},
resolve: {
planCategories: ['PlanCategory', function (PlanCategory) { return PlanCategory.query().$promise; }]
}
})
.state('app.admin.plans.edit', {
@ -815,7 +818,8 @@ angular.module('application.router', ['ui.router'])
spaces: ['Space', function (Space) { return Space.query().$promise; }],
machines: ['Machine', function (Machine) { return Machine.query().$promise; }],
plans: ['Plan', function (Plan) { return Plan.query().$promise; }],
planPromise: ['Plan', '$stateParams', function (Plan, $stateParams) { return Plan.get({ id: $stateParams.id }).$promise; }]
planPromise: ['Plan', '$stateParams', function (Plan, $stateParams) { return Plan.get({ id: $stateParams.id }).$promise; }],
planCategories: ['PlanCategory', function (PlanCategory) { return PlanCategory.query().$promise; }]
}
})
// plan categories

View File

@ -0,0 +1,5 @@
'use strict';
Application.Services.factory('PlanCategory', ['$resource', function ($resource) {
return $resource('/api/plan_categories');
}]);

View File

@ -48,6 +48,18 @@
<span class="help-block" ng-show="planForm['plan[group_id]'].$dirty && planForm['plan[group_id]'].$error.required" translate>{{ 'app.shared.plan.group_is_required' }}</span>
</div>
<div class="form-group" ng-class="{'has-error': planForm['plan[plan_category_id]'].$dirty && planForm['plan[group_id]'].$invalid}">
<label for="plan[plan_category_id]">{{ 'app.shared.plan.category' | translate }} *</label>
<select id="plan[plan_category_id]"
name="plan[plan_category_id]"
class="form-control"
ng-model="plan.plan_category_id"
ng-options="cat.id as cat.name for cat in planCategories track by cat.id">
</select>
<input type="hidden"
name="plan[plan_category_id]"
ng-value="plan.plan_category_id"/>
</div>
<div class="form-group" ng-class="{'has-error': planForm['plan[interval]'].$dirty && planForm['plan[interval]'].$invalid}">
<label for="plan[interval]">{{ 'app.shared.plan.period' | translate }} *</label>
<select id="plan[interval]"

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
json.extract! plan, :id, :base_name, :name, :interval, :interval_count, :group_id, :training_credit_nb, :is_rolling, :description, :type,
:ui_weight, :disabled, :monthly_payment
:ui_weight, :disabled, :monthly_payment, :plan_category_id
json.amount plan.amount / 100.00
json.prices plan.prices, partial: 'api/prices/price', as: :price
if plan.plan_file

View File

@ -174,6 +174,7 @@ en:
all: "All"
transversal_all_groups: "Transversal (all groups)"
group_is_required: "Group is required."
category: "Category"
number_of_periods: "Number of periods"
number_of_periods_is_required: "Number of periods is required."
period: "Period"

View File

@ -174,6 +174,7 @@ fr:
all: "Tous"
transversal_all_groups: "Transversal (tout les groupes)"
group_is_required: "Le groupe est requis."
category: "Catégorie"
number_of_periods: "Nombre de périodes"
number_of_periods_is_required: "Le nombre de périodes est requis."
period: "Période"