1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-17 06:52:27 +01:00

allow filtering coupons list

This commit is contained in:
Sylvain 2019-04-04 18:00:19 +02:00
parent 9f8d24ec4f
commit 44479b5597
9 changed files with 57 additions and 6 deletions

View File

@ -4,6 +4,7 @@
- Improved end-user message when closing an accounting period
- Improved date checks before closing an accounting period
- Paginate list of coupons
- Allow filtering coupons list
- Fix a bug: when VAT has changed during fab-manager's lifecycle, this may not be reflected in archives
- Fix a bug: using a quote in event category's name results in angular $parse:syntax Error

View File

@ -53,7 +53,7 @@ Application.Controllers.controller('EditPricingController', ['$scope', '$state',
// List of coupons
$scope.coupons = couponsPromise;
$scope.couponsPage = 0;
$scope.couponsPage = 1;
// List of spaces
$scope.spaces = spacesPromise;
@ -82,6 +82,20 @@ Application.Controllers.controller('EditPricingController', ['$scope', '$state',
'all'
];
// Default: we do not filter coupons
$scope.filter = {
coupon: 'all',
};
// Available status for filtering coupons
$scope.couponStatus = [
'all',
'disabled',
'expired',
'sold_out',
'active'
];
$scope.findTrainingsPricing = function (trainingsPricings, trainingId, groupId) {
for (let trainingsPricing of Array.from(trainingsPricings)) {
if ((trainingsPricing.training_id === trainingId) && (trainingsPricing.group_id === groupId)) {
@ -566,13 +580,26 @@ Application.Controllers.controller('EditPricingController', ['$scope', '$state',
});
};
/**
* Load the next 10 coupons
*/
$scope.loadMore = function() {
$scope.couponsPage++;
Coupon.query({ page: $scope.couponsPage }, function (data) {
Coupon.query({ page: $scope.couponsPage, filter: $scope.filter.coupon }, function (data) {
$scope.coupons = $scope.coupons.concat(data);
});
};
/**
* Reset the list of coupons according to the newly selected filter
*/
$scope.updateCouponFilter = function() {
$scope.couponsPage = 1;
Coupon.query({ page: $scope.couponsPage, filter: $scope.filter.coupon }, function (data) {
$scope.coupons = data;
});
}
/* PRIVATE SCOPE */
/**

View File

@ -786,7 +786,7 @@ angular.module('application.router', ['ui.router'])
machineCreditsPromise: ['Credit', function (Credit) { return Credit.query({ creditable_type: 'Machine' }).$promise; }],
machinesPromise: ['Machine', function (Machine) { return Machine.query().$promise; }],
trainingCreditsPromise: ['Credit', function (Credit) { return Credit.query({ creditable_type: 'Training' }).$promise; }],
couponsPromise: ['Coupon', function (Coupon) { return Coupon.query({ page: 0 }).$promise; }],
couponsPromise: ['Coupon', function (Coupon) { return Coupon.query({ page: 1, filter: 'all' }).$promise; }],
spacesPromise: ['Space', function (Space) { return Space.query().$promise; }],
spacesPricesPromise: ['Price', function (Price) { return Price.query({ priceable_type: 'Space', plan_id: 'null' }).$promise; }],
spacesCreditsPromise: ['Credit', function (Credit) { return Credit.query({ creditable_type: 'Space' }).$promise; }]

View File

@ -1,6 +1,20 @@
<h2 translate>{{ 'pricing.list_of_the_coupons' }}</h2>
<button type="button" class="btn btn-warning m-t-lg m-b" ui-sref="app.admin.coupons_new" translate>{{ 'pricing.add_a_new_coupon' }}</button>
<div class="m-t-lg m-b">
<button type="button" class="btn btn-warning" ui-sref="app.admin.coupons_new">
<i class="fa fa-plus m-r"></i>
<span translate>{{ 'pricing.add_a_new_coupon' }}</span>
</button>
<div class="form-group pull-right">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-filter"></i></span>
<select ng-model="filter.coupon" class="form-control" ng-change="updateCouponFilter()">
<option ng-repeat="status in couponStatus" value="{{status}}" translate>{{ 'pricing.'+status }}</option>
</select>
</div>
</div>
</div>
<table class="table">
<thead>
<tr>

View File

@ -10,8 +10,13 @@ class API::CouponsController < API::ApiController
COUPONS_PER_PAGE = 10
def index
@coupons = Coupon.page(params[:page]).per(COUPONS_PER_PAGE).order('created_at DESC')
@total = Coupon.count
if params[:filter] == 'all'
@coupons = Coupon.page(params[:page]).per(COUPONS_PER_PAGE).order('created_at DESC')
@total = Coupon.count
else
@coupons = Coupon.order('created_at DESC').all.select { |c| c.status == params[:filter] }
@total = @coupons.count
end
end
def show; end

View File

@ -226,6 +226,7 @@ en:
expired: "Expired"
sold_out: "Sold out"
active: "Active"
all: "Display all"
confirmation_required: "Confirmation required"
do_you_really_want_to_delete_this_coupon: "Do you really want to delete this coupon?"
coupon_was_successfully_deleted: "Coupon was successfully deleted."

View File

@ -226,6 +226,7 @@ es:
expired: "Expirado"
sold_out: "Agotado"
active: "Activo"
all: "Display all" # translation_missing
confirmation_required: "Confirmación requerida"
do_you_really_want_to_delete_this_coupon: "¿Desea realmente eliminar este cupón?"
coupon_was_successfully_deleted: "El cupón se eliminó correctamente."

View File

@ -226,6 +226,7 @@ fr:
expired: "Expiré"
sold_out: "Épuisé"
active: "Actif"
all: "Afficher tous"
confirmation_required: "Confirmation requise"
do_you_really_want_to_delete_this_coupon: "Êtes-vous sûr(e) de vouloir supprimer ce code promotionnel ?"
coupon_was_successfully_deleted: "Le code promotionnel a bien été supprimé."

View File

@ -226,6 +226,7 @@ pt:
expired: "Expirado"
sold_out: "Esgotado"
active: "Ativo"
all: "Display all" # translation_missing
confirmation_required: "Confirmação obrigatória"
do_you_really_want_to_delete_this_coupon: "Você realmente deseja deletar este cupom?"
coupon_was_successfully_deleted: "O cupom foi deletado com sucesso."