Skip to content

Commit

Permalink
filtro utenti in fase di esportazione. closes #282
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed May 26, 2024
1 parent b252d0d commit 5a05c50
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
5 changes: 5 additions & 0 deletions code/app/Http/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function export(Request $request)
$headers = UserFormatter::getHeaders($fields);
$users = $this->service->list('', true);

if ($request->input('exportables') == 'selected') {
$selected = $request->input('users', []);
$users = $users->filter(fn($u) => in_array($u->id, $selected));
}

return output_csv(_i('utenti.csv'), $headers, $users, function($user) use ($fields) {
return UserFormatter::format($user, $fields);
});
Expand Down
2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/gasdotto.js": "/js/gasdotto.js?id=41cdd2ba6c344b1c60f8e34ed31144bf",
"/js/gasdotto.js": "/js/gasdotto.js?id=c80f8b235b90f882ed3a36b93ca9e3f3",
"/css/gasdotto.css": "/css/gasdotto.css?id=944fde138a68e0877df0d9da8e03d933"
}
27 changes: 21 additions & 6 deletions code/resources/assets/js/callables.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,33 @@ class Callables {
}
}

/*
Usata in diversi ambiti per ottenere l'elenco degli utenti attualmente
visualizzati e iniettarlo nel form in elaborazione, per fungere da
filtro
*/
static collectFilteredUsers(form) {
form.find('input:hidden[name^="users"]').remove();
let table = $('#user-list');

$('#credits_status_table tbody tr:visible').each(function() {
var user_id = $(this).find('input[name^=user_id]').val();
form.append('<input type="hidden" name="users[]" value="' + user_id + '">');
});
if (table.is('table')) {
$('tbody tr:visible', table).each(function() {
var user_id = $(this).find('input[name^=user_id]').val();
form.append('<input type="hidden" name="users[]" value="' + user_id + '">');
});
}
else {
$('.accordion-item:visible', table).each(function() {
var user_id = $(this).attr('data-element-id');
form.append('<input type="hidden" name="users[]" value="' + user_id + '">');
});
}
}

static formToDownload(form) {
var data = form.find('input, select').serializeArray();
var url = form.attr('action') + '&' + $.param(data);
let data = form.find('input, select').serializeArray();
let baseaction = form.attr('action');
let url = baseaction + (baseaction.match(/[\?]/g) ? '&' : '?') + $.param(data);
window.open(url, '_blank');
throw "Done!";
}
Expand Down
2 changes: 1 addition & 1 deletion code/resources/views/movement/credits.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<hr />

<div class="row">
<div class="col" id="credits_status_table">
<div class="col" id="user-list">
<div class="table-responsive">
<table class="table" id="creditsTable">
<?php $currencies = App\Currency::enabled() ?>
Expand Down
2 changes: 1 addition & 1 deletion code/resources/views/movement/suppliers.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<hr/>

<div class="row">
<div class="col" id="credits_status_table">
<div class="col" id="user-list">
<div class="table-responsive">
<table class="table" id="suppliersTable">
<?php $currencies = App\Currency::enabled() ?>
Expand Down
8 changes: 6 additions & 2 deletions code/resources/views/pages/users.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@

<x-larastrap::mbutton :label="_i('Esporta CSV')" triggers_modal="exportCSVusers" />
<x-larastrap::modal id="exportCSVusers" :title="_i('Esporta CSV')" classes="close-on-submit">
<x-larastrap::form method="GET" :action="url('users/export')" :buttons="[['label' => _i('Download'), 'type' => 'submit']]">
<x-larastrap::iform method="GET" :action="url('users/export')" :buttons="[['label' => _i('Download'), 'type' => 'submit']]">
<input type="hidden" name="pre-saved-function" value="collectFilteredUsers">
<input type="hidden" name="pre-saved-function" value="formToDownload">

<p>
{!! _i("Per la consultazione e l'elaborazione dei files in formato CSV (<i>Comma-Separated Values</i>) si consiglia l'uso di <a target=\"_blank\" href=\"http://it.libreoffice.org/\">LibreOffice</a>.") !!}
</p>

<hr/>

<x-larastrap::structchecks name="fields" :label="_i('Colonne')" :options="App\Formatters\User::formattableColumns('export')" />
</x-larastrap::form>
<x-larastrap::radios name="exportables" :label="_i('Esporta')" :options="['all' => _i('Tutti'), 'selected' => _i('Solo selezionati')]" value="all" />
</x-larastrap::iform>
</x-larastrap::modal>

@if(Gate::check('users.admin', $currentgas) || Gate::check('users.movements', $currentgas))
Expand Down

0 comments on commit 5a05c50

Please sign in to comment.