Compare commits
No commits in common. "d56cb253a96105b3db80d0d88cd161c63a1853f0" and "0d76b3cc5fda3bc6d98b61857bbc55b540901fad" have entirely different histories.
d56cb253a9
...
0d76b3cc5f
|
@ -1,68 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Form\Actions;
|
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
|
||||||
use App\Form\Models\Participant;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
|
||||||
use Zoomyboy\TableDocument\SheetData;
|
|
||||||
use Zoomyboy\TableDocument\TableDocumentData;
|
|
||||||
|
|
||||||
class CreateExcelDocumentAction
|
|
||||||
{
|
|
||||||
use AsAction;
|
|
||||||
|
|
||||||
public Form $form;
|
|
||||||
|
|
||||||
public function handle(Form $form, Collection $participants): string
|
|
||||||
{
|
|
||||||
$this->form = $form;
|
|
||||||
|
|
||||||
return file_get_contents($this->allSheet($participants)->compile($this->tempPath()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param Collection<int, Participant> $participants
|
|
||||||
*/
|
|
||||||
private function allSheet(Collection $participants): TableDocumentData
|
|
||||||
{
|
|
||||||
$document = TableDocumentData::from(['title' => 'Anmeldungen für ' . $this->form->name, 'sheets' => []]);
|
|
||||||
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->toArray();
|
|
||||||
|
|
||||||
$document->addSheet(SheetData::from([
|
|
||||||
'header' => $headers,
|
|
||||||
'data' => $participants
|
|
||||||
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
|
|
||||||
->toArray(),
|
|
||||||
'name' => 'Alle',
|
|
||||||
]));
|
|
||||||
|
|
||||||
if ($this->form->export->groupBy) {
|
|
||||||
$groups = $participants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
|
|
||||||
|
|
||||||
foreach ($groups as $name => $participants) {
|
|
||||||
$document->addSheet(SheetData::from([
|
|
||||||
'header' => $headers,
|
|
||||||
'data' => $participants
|
|
||||||
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
|
|
||||||
->toArray(),
|
|
||||||
'name' => $name,
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
$document->addSheet(SheetData::from([
|
|
||||||
'header' => ['Wert', 'Anzahl'],
|
|
||||||
'data' => $groups->map(fn ($participants, $name) => [$name, (string) count($participants)])->toArray(),
|
|
||||||
'name' => 'Statistik',
|
|
||||||
]));
|
|
||||||
}
|
|
||||||
|
|
||||||
return $document;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function tempPath(): string
|
|
||||||
{
|
|
||||||
return sys_get_temp_dir() . '/' . str()->uuid()->toString();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,14 +15,22 @@ class ExportAction
|
||||||
|
|
||||||
public function handle(Form $form): string
|
public function handle(Form $form): string
|
||||||
{
|
{
|
||||||
return CreateExcelDocumentAction::run($form, $form->participants);
|
$csv = Writer::createFromString();
|
||||||
|
|
||||||
|
$csv->insertOne($form->getFields()->names());
|
||||||
|
|
||||||
|
foreach ($form->participants as $participant) {
|
||||||
|
$csv->insertOne($participant->getFields()->presentValues());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $csv->toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function asController(Form $form, ActionRequest $request): StreamedResponse
|
public function asController(Form $form, ActionRequest $request): StreamedResponse
|
||||||
{
|
{
|
||||||
$contents = $this->handle($form);
|
$contents = $this->handle($form);
|
||||||
|
|
||||||
$filename = 'tn-' . $form->slug . '.xlsx';
|
$filename = 'tn-' . $form->slug . '.csv';
|
||||||
Storage::disk('temp')->put($filename, $contents);
|
Storage::disk('temp')->put($filename, $contents);
|
||||||
|
|
||||||
return Storage::disk('temp')->download($filename);
|
return Storage::disk('temp')->download($filename);
|
||||||
|
|
|
@ -3,8 +3,12 @@
|
||||||
namespace App\Form\Actions;
|
namespace App\Form\Actions;
|
||||||
|
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
|
use App\Form\Models\Participant;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use Lorisleiva\Actions\Concerns\AsAction;
|
use Lorisleiva\Actions\Concerns\AsAction;
|
||||||
|
use Zoomyboy\TableDocument\SheetData;
|
||||||
|
use Zoomyboy\TableDocument\TableDocumentData;
|
||||||
|
|
||||||
class ExportSyncAction
|
class ExportSyncAction
|
||||||
{
|
{
|
||||||
|
@ -14,13 +18,15 @@ class ExportSyncAction
|
||||||
|
|
||||||
public function handle(Form $form): void
|
public function handle(Form $form): void
|
||||||
{
|
{
|
||||||
|
$this->form = $form;
|
||||||
|
|
||||||
if (!$form->export->root) {
|
if (!$form->export->root) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$storage = $form->export->root->getStorage();
|
$storage = $form->export->root->getStorage();
|
||||||
|
|
||||||
$storage->put($form->export->root->resource . '/Anmeldungen ' . $form->name . '.xlsx', CreateExcelDocumentAction::run($form, $form->participants));
|
$storage->put($form->export->root->resource . '/Anmeldungen ' . $form->name . '.xlsx', file_get_contents($this->allSheet($this->form->participants)->compile($this->tempPath())));
|
||||||
|
|
||||||
if ($form->export->toGroupField) {
|
if ($form->export->toGroupField) {
|
||||||
foreach ($form->participants->groupBy(fn ($participant) => $participant->data[$form->export->toGroupField]) as $groupId => $participants) {
|
foreach ($form->participants->groupBy(fn ($participant) => $participant->data[$form->export->toGroupField]) as $groupId => $participants) {
|
||||||
|
@ -29,7 +35,7 @@ class ExportSyncAction
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$group->fileshare->getStorage()->put($group->fileshare->resource . '/Anmeldungen ' . $form->name . '.xlsx', CreateExcelDocumentAction::run($form, $participants));
|
$group->fileshare->getStorage()->put($group->fileshare->resource . '/Anmeldungen ' . $form->name . '.xlsx', file_get_contents($this->allSheet($participants)->compile($this->tempPath())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,4 +44,48 @@ class ExportSyncAction
|
||||||
{
|
{
|
||||||
$this->handle(Form::find($formId));
|
$this->handle(Form::find($formId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection<int, Participant> $participants
|
||||||
|
*/
|
||||||
|
private function allSheet(Collection $participants): TableDocumentData
|
||||||
|
{
|
||||||
|
$document = TableDocumentData::from(['title' => 'Anmeldungen für ' . $this->form->name, 'sheets' => []]);
|
||||||
|
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->toArray();
|
||||||
|
|
||||||
|
$document->addSheet(SheetData::from([
|
||||||
|
'header' => $headers,
|
||||||
|
'data' => $participants
|
||||||
|
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
|
||||||
|
->toArray(),
|
||||||
|
'name' => 'Alle',
|
||||||
|
]));
|
||||||
|
|
||||||
|
if ($this->form->export->groupBy) {
|
||||||
|
$groups = $participants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
|
||||||
|
|
||||||
|
foreach ($groups as $name => $participants) {
|
||||||
|
$document->addSheet(SheetData::from([
|
||||||
|
'header' => $headers,
|
||||||
|
'data' => $participants
|
||||||
|
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
|
||||||
|
->toArray(),
|
||||||
|
'name' => $name,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
$document->addSheet(SheetData::from([
|
||||||
|
'header' => ['Wert', 'Anzahl'],
|
||||||
|
'data' => $groups->map(fn ($participants, $name) => [$name, (string) count($participants)])->toArray(),
|
||||||
|
'name' => 'Statistik',
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $document;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function tempPath(): string
|
||||||
|
{
|
||||||
|
return sys_get_temp_dir() . '/' . str()->uuid()->toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ namespace App\Form\Resources;
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use App\Form\Scopes\ParticipantFilterScope;
|
use App\Form\Scopes\ParticipantFilterScope;
|
||||||
use App\Prevention\Enums\Prevention;
|
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
@ -29,7 +28,6 @@ class ParticipantResource extends JsonResource
|
||||||
'created_at_display' => $this->created_at->format('d.m.Y'),
|
'created_at_display' => $this->created_at->format('d.m.Y'),
|
||||||
'children_count' => $this->children_count,
|
'children_count' => $this->children_count,
|
||||||
'member_id' => $this->member_id,
|
'member_id' => $this->member_id,
|
||||||
'prevention_items' => $this->member ? Prevention::items($this->member->preventions()) : [],
|
|
||||||
'links' => [
|
'links' => [
|
||||||
'assign' => route('participant.assign', ['participant' => $this->getModel()]),
|
'assign' => route('participant.assign', ['participant' => $this->getModel()]),
|
||||||
'destroy' => route('participant.destroy', ['participant' => $this->getModel()]),
|
'destroy' => route('participant.destroy', ['participant' => $this->getModel()]),
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
|
|
||||||
namespace App\Prevention\Enums;
|
namespace App\Prevention\Enums;
|
||||||
|
|
||||||
use App\Member\Member;
|
|
||||||
use Carbon\Carbon;
|
|
||||||
|
|
||||||
enum Prevention
|
enum Prevention
|
||||||
{
|
{
|
||||||
case EFZ;
|
case EFZ;
|
||||||
|
@ -21,31 +18,4 @@ enum Prevention
|
||||||
static::VK => 'Verhaltenskodex',
|
static::VK => 'Verhaltenskodex',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tooltip(bool $value): string
|
|
||||||
{
|
|
||||||
return $this->text() . ' ' . ($value ? 'vorhanden' : 'nicht vorhanden');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function letter(): string
|
|
||||||
{
|
|
||||||
return match ($this) {
|
|
||||||
static::EFZ => 'F',
|
|
||||||
static::PS => 'P',
|
|
||||||
static::MOREPS => 'A',
|
|
||||||
static::VK => 'V',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param array<int, self> $preventions
|
|
||||||
*/
|
|
||||||
public static function items(array $preventions)
|
|
||||||
{
|
|
||||||
return collect(static::cases())->map(fn ($case) => [
|
|
||||||
'letter' => $case->letter(),
|
|
||||||
'value' => !in_array($case, $preventions),
|
|
||||||
'tooltip' => $case->tooltip(!in_array($case, $preventions)),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/bash
|
#/bin/bash
|
||||||
|
|
||||||
echo "drop database scoutrobot;" | sudo mysql
|
echo "drop database scoutrobot;" | sudo mysql
|
||||||
echo "create database scoutrobot;" | sudo mysql
|
echo "create database scoutrobot;" | sudo mysql
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 8aefd17b06ee3c26d00b472a154a48898b884d15
|
Subproject commit c1d0221dcd2b4200b3ff17747e31f451fcc749f0
|
|
@ -175,7 +175,7 @@
|
||||||
<ui-action-button tooltip="Bearbeiten" class="btn-warning" icon="pencil" @click.prevent="edit(form)"></ui-action-button>
|
<ui-action-button tooltip="Bearbeiten" class="btn-warning" icon="pencil" @click.prevent="edit(form)"></ui-action-button>
|
||||||
<ui-action-button tooltip="Teilnehmende anzeigen" class="btn-info" icon="user" @click.prevent="showParticipants(form)"></ui-action-button>
|
<ui-action-button tooltip="Teilnehmende anzeigen" class="btn-info" icon="user" @click.prevent="showParticipants(form)"></ui-action-button>
|
||||||
<ui-action-button :href="form.links.frontend" target="_BLANK" tooltip="zur Anmeldeseite" class="btn-info" icon="eye"></ui-action-button>
|
<ui-action-button :href="form.links.frontend" target="_BLANK" tooltip="zur Anmeldeseite" class="btn-info" icon="eye"></ui-action-button>
|
||||||
<ui-action-button :href="form.links.export" target="_BLANK" tooltip="als Tabellendokument exportieren" class="btn-info" icon="document"></ui-action-button>
|
<ui-action-button :href="form.links.export" target="_BLANK" tooltip="als CSV exportieren" class="btn-info" icon="document"></ui-action-button>
|
||||||
<ui-action-button tooltip="Löschen" class="btn-danger" icon="trash" @click.prevent="deleting = form"></ui-action-button>
|
<ui-action-button tooltip="Löschen" class="btn-danger" icon="trash" @click.prevent="deleting = form"></ui-action-button>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Form;
|
namespace Tests\Feature\Form;
|
||||||
|
|
||||||
|
use App\Form\Fields\TextField;
|
||||||
use App\Form\Models\Form;
|
use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
|
use App\Form\Scopes\ParticipantFilterScope;
|
||||||
|
use App\Group;
|
||||||
|
use Carbon\Carbon;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
@ -28,12 +32,12 @@ class ParticipantExportActionTest extends FormTestCase
|
||||||
->name('ZEM 2024')
|
->name('ZEM 2024')
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->get(route('form.export', ['form' => $form]))->assertDownload('tn-zem-2024.xlsx');
|
$this->get(route('form.export', ['form' => $form]))->assertDownload('tn-zem-2024.csv');
|
||||||
$contents = Storage::disk('temp')->get('tn-zem-2024.xlsx');
|
$contents = Storage::disk('temp')->get('tn-zem-2024.csv');
|
||||||
$this->assertExcelContent('Max', $contents);
|
$this->assertTrue(str_contains($contents, 'Max'));
|
||||||
$this->assertExcelContent('A, B', $contents);
|
$this->assertTrue(str_contains($contents, 'A, B'));
|
||||||
$this->assertExcelContent('Pfadfinder', $contents);
|
$this->assertTrue(str_contains($contents, 'Pfadfinder'));
|
||||||
$this->assertExcelContent('Stufe', $contents);
|
$this->assertTrue(str_contains($contents, 'Stufe'));
|
||||||
$this->assertExcelContent('Abcselect', $contents);
|
$this->assertTrue(str_contains($contents, 'Abcselect'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ use App\Form\Models\Form;
|
||||||
use App\Form\Models\Participant;
|
use App\Form\Models\Participant;
|
||||||
use App\Form\Scopes\ParticipantFilterScope;
|
use App\Form\Scopes\ParticipantFilterScope;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
use App\Member\Member;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
|
||||||
|
@ -208,18 +207,4 @@ class ParticipantIndexActionTest extends FormTestCase
|
||||||
->assertJsonPath('meta.current_page', 1);
|
->assertJsonPath('meta.current_page', 1);
|
||||||
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
$this->callFilter('form.participant.index', [], ['form' => $form, 'parent' => $participant->id])->assertJsonPath('data.0.children_count', 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItShowsPreventionState(): void
|
|
||||||
{
|
|
||||||
$this->login()->loginNami()->withoutExceptionHandling();
|
|
||||||
$participant = Participant::factory()->data(['vorname' => 'Max'])
|
|
||||||
->for(Member::factory()->defaults()->state(['efz' => null]))
|
|
||||||
->for(Form::factory())
|
|
||||||
->create();
|
|
||||||
|
|
||||||
$this->callFilter('form.participant.index', [], ['form' => $participant->form])
|
|
||||||
->assertJsonPath('data.0.prevention_items.0.letter', 'F')
|
|
||||||
->assertJsonPath('data.0.prevention_items.0.value', false)
|
|
||||||
->assertJsonPath('data.0.prevention_items.0.tooltip', 'erweitertes Führungszeugnis nicht vorhanden');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,12 @@ use PHPUnit\Framework\Assert;
|
||||||
use Tests\Lib\MakesHttpCalls;
|
use Tests\Lib\MakesHttpCalls;
|
||||||
use Tests\Lib\TestsInertia;
|
use Tests\Lib\TestsInertia;
|
||||||
use Zoomyboy\LaravelNami\Authentication\Auth;
|
use Zoomyboy\LaravelNami\Authentication\Auth;
|
||||||
use Zoomyboy\TableDocument\TestsExcelDocuments;
|
|
||||||
|
|
||||||
abstract class TestCase extends BaseTestCase
|
abstract class TestCase extends BaseTestCase
|
||||||
{
|
{
|
||||||
use CreatesApplication;
|
use CreatesApplication;
|
||||||
use TestsInertia;
|
use TestsInertia;
|
||||||
use MakesHttpCalls;
|
use MakesHttpCalls;
|
||||||
use TestsExcelDocuments;
|
|
||||||
|
|
||||||
protected User $me;
|
protected User $me;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue