diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a23ad32..e8a79cf1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Fix a bug: wallet tab is not shown in members dashboard - Fix a bug: slots duration is not shown when looking at a new availability - Fix a bug: user's manual URL is not up-to-date +- Fix a bug: unable to create a subscription plan for only one group - Updated coveralls gem to a supported version ## v4.5.6 2020 September 1st diff --git a/app/assets/javascripts/controllers/admin/plans.js.erb b/app/assets/javascripts/controllers/admin/plans.js.erb index a86ab8da8..f7596be74 100644 --- a/app/assets/javascripts/controllers/admin/plans.js.erb +++ b/app/assets/javascripts/controllers/admin/plans.js.erb @@ -21,12 +21,20 @@ /* COMMON CODE */ class PlanController { - constructor ($scope, groups, prices, partners, CSRF) { + constructor ($scope, groups, prices, partners, CSRF, _t) { // protection against request forgery CSRF.setMetaTags(); // groups list - $scope.groups = groups.filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }); + $scope.groups = groups + .filter(function (g) { return (g.slug !== 'admins') && !g.disabled; }) + .map(e => Object.assign({}, e, { category: 'app.shared.plan.groups', id: `${e.id}` })) + $scope.groups.push({ id: 'all', name: 'app.shared.plan.transversal_all_groups', category: 'app.shared.plan.all' }); + + // dynamically translate a label if needed + $scope.translateLabel = function (group, prop) { + return group[prop] && group[prop].match(/^app\./) ? _t(group[prop]) : group[prop]; + } // users with role 'partner', notifiables for a partner plan $scope.partners = partners.users; @@ -156,7 +164,7 @@ Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal', } }; - return new PlanController($scope, groups, prices, partners, CSRF); + return new PlanController($scope, groups, prices, partners, CSRF, _t); } ]); @@ -177,13 +185,13 @@ Application.Controllers.controller('EditPlanController', ['$scope', 'groups', 'p $scope.machines = machines; // List of groups - $scope.groups = groups; + $scope.allGroups = groups; // current form is used for edition mode $scope.mode = 'edition'; // edited plan data - $scope.plan = planPromise; + $scope.plan = Object.assign({}, planPromise, { group_id: `${planPromise.group_id}` }); if ($scope.plan.type === null) { $scope.plan.type = 'Plan'; } if ($scope.plan.disabled) { $scope.plan.disabled = 'true'; } @@ -193,6 +201,11 @@ Application.Controllers.controller('EditPlanController', ['$scope', 'groups', 'p // HTTP method for the rest API $scope.method = 'PATCH'; + $scope.selectedGroup = function () { + const group = $scope.groups.filter(g => g.id === $scope.plan.group_id); + return $scope.translateLabel(group[0], 'name'); + } + /** * If a parent plan was set ($scope.plan.parent), the prices will be copied from this parent plan into * the current plan prices list. Otherwise, the current plan prices will be erased. @@ -281,6 +294,6 @@ Application.Controllers.controller('EditPlanController', ['$scope', 'groups', 'p }; // Using the PlansController - return new PlanController($scope, groups, prices, partners, CSRF); + return new PlanController($scope, groups, prices, partners, CSRF, _t); } ]); diff --git a/app/assets/javascripts/directives/convert_to_number.js b/app/assets/javascripts/directives/convert_to_number.js deleted file mode 100644 index e69de29bb..000000000 diff --git a/app/assets/templates/admin/plans/_form.html.erb b/app/assets/templates/admin/plans/_form.html.erb index c306fdee8..eeae32643 100644 --- a/app/assets/templates/admin/plans/_form.html.erb +++ b/app/assets/templates/admin/plans/_form.html.erb @@ -32,12 +32,19 @@ class="form-control" ng-model="plan.group_id" required="required" - ng-disabled="method == 'PATCH'"> - - - - + ng-if="method !== 'PATCH'" + ng-options="item.id as translateLabel(item, 'name') group by translateLabel(item, 'category') for item in groups track by item.id"> + + {{ 'app.shared.plan.group_is_required' }} diff --git a/app/assets/templates/admin/plans/edit.html.erb b/app/assets/templates/admin/plans/edit.html.erb index 324f892bf..030ec72e1 100644 --- a/app/assets/templates/admin/plans/edit.html.erb +++ b/app/assets/templates/admin/plans/edit.html.erb @@ -48,7 +48,7 @@
-
diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index c56464b19..a57521b74 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -162,6 +162,8 @@ en: standard: "Standard" type_is_required: "Type is required." group: "Group" + groups: "Groups" + all: "All" transversal_all_groups: "Transversal (all groups)" group_is_required: "Group is required." number_of_periods: "Number of periods"