Compare commits
26 Commits
a136085d2b
...
4e43609619
Author | SHA1 | Date |
---|---|---|
|
4e43609619 | |
|
32246e534e | |
|
4b50c85fd6 | |
|
e5ecd0a2c0 | |
|
e06f924304 | |
|
6463997f8f | |
|
247a89ae77 | |
|
6c3c8b5703 | |
|
5fe1004871 | |
|
4f9bfa0f75 | |
|
a27e86ffcc | |
|
c8e268d91b | |
|
10b71f7a36 | |
|
144af1bf71 | |
|
17808c6eb1 | |
|
427f45373e | |
|
a1981c7dec | |
|
4497084ae6 | |
|
f2090aa9d0 | |
|
6b7de1446f | |
|
f8d2be9df5 | |
|
722237f486 | |
|
51af9d427e | |
|
b0fd584397 | |
|
aab004f1f1 | |
|
79d92a6567 |
|
@ -23,7 +23,7 @@ class GenerateAction
|
|||
public function asController(GenerateRequest $request): BaseCompiler|JsonResponse
|
||||
{
|
||||
app(ContributionFactory::class)->validateType($request);
|
||||
app(ContributionFactory::class)->validatePayload($request);
|
||||
$request->validateContribution();
|
||||
|
||||
return $request->input('validate')
|
||||
? response()->json([])
|
||||
|
|
|
@ -26,8 +26,5 @@ interface HasContributionData {
|
|||
|
||||
public function country(): ?Country;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function payload(): array;
|
||||
public function validateContribution(): void;
|
||||
}
|
||||
|
|
|
@ -29,13 +29,13 @@ class ContributionFactory
|
|||
];
|
||||
|
||||
/**
|
||||
* @return Collection<int, array{title: string, class: class-string<ContributionDocument>}>
|
||||
* @return Collection<int, array{name: string, id: class-string<ContributionDocument>}>
|
||||
*/
|
||||
public function compilerSelect(): Collection
|
||||
{
|
||||
return collect($this->documents)->map(fn ($document) => [
|
||||
'title' => $document::buttonName(),
|
||||
'class' => $document,
|
||||
'name' => $document::getName(),
|
||||
'id' => $document,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,5 @@ class ContributionFactory
|
|||
public function validateType(HasContributionData $request): void {
|
||||
Validator::make(['type' => $request->type()], $this->typeRule())->validate();
|
||||
}
|
||||
|
||||
public function validatePayload(HasContributionData $request): void {
|
||||
Validator::make($request->payload(), $this->rules($request->type()))->validate();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ class MemberData extends Data
|
|||
return collect($data)->map(fn ($member) => self::factory()->withoutMagicalCreation()->from([
|
||||
...$member,
|
||||
'birthday' => Carbon::parse($member['birthday'])->toAtomString(),
|
||||
'gender' => Gender::fromString($member['gender']),
|
||||
'gender' => $member['gender'] ? Gender::fromString($member['gender']) : null,
|
||||
'isLeader' => $member['is_leader'],
|
||||
]));
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Contribution\Contracts\HasContributionData;
|
|||
use App\Contribution\Data\MemberData;
|
||||
use App\Contribution\Traits\HasPdfBackground;
|
||||
use App\Country;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
|
@ -116,4 +117,15 @@ class BdkjHesse extends ContributionDocument
|
|||
'zipLocation' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public static function requiredFormSpecialTypes(): array {
|
||||
return [
|
||||
SpecialType::FIRSTNAME,
|
||||
SpecialType::LASTNAME,
|
||||
SpecialType::BIRTHDAY,
|
||||
SpecialType::ZIP,
|
||||
SpecialType::LOCATION,
|
||||
SpecialType::GENDER,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Contribution\Data\MemberData;
|
|||
use App\Contribution\Traits\FormatsDates;
|
||||
use App\Contribution\Traits\HasPdfBackground;
|
||||
use App\Country;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Invoice\InvoiceSettings;
|
||||
use Illuminate\Support\Collection;
|
||||
use Carbon\Carbon;
|
||||
|
@ -74,4 +75,15 @@ class CityFrankfurtMainDocument extends ContributionDocument
|
|||
'zipLocation' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public static function requiredFormSpecialTypes(): array {
|
||||
return [
|
||||
SpecialType::FIRSTNAME,
|
||||
SpecialType::LASTNAME,
|
||||
SpecialType::BIRTHDAY,
|
||||
SpecialType::ZIP,
|
||||
SpecialType::LOCATION,
|
||||
SpecialType::ADDRESS,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use App\Contribution\Contracts\HasContributionData;
|
|||
use App\Contribution\Traits\FormatsDates;
|
||||
use App\Contribution\Traits\HasPdfBackground;
|
||||
use App\Country;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Member\Member;
|
||||
use Illuminate\Support\Collection;
|
||||
use Carbon\Carbon;
|
||||
|
@ -65,4 +66,15 @@ class CityRemscheidDocument extends ContributionDocument
|
|||
'country' => 'required|integer|exists:countries,id',
|
||||
];
|
||||
}
|
||||
|
||||
public static function requiredFormSpecialTypes(): array {
|
||||
return [
|
||||
SpecialType::FIRSTNAME,
|
||||
SpecialType::LASTNAME,
|
||||
SpecialType::ADDRESS,
|
||||
SpecialType::BIRTHDAY,
|
||||
SpecialType::ZIP,
|
||||
SpecialType::LOCATION,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace App\Contribution\Documents;
|
|||
|
||||
use App\Contribution\Contracts\HasContributionData;
|
||||
use App\Contribution\Data\MemberData;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Invoice\InvoiceSettings;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
|
@ -94,4 +95,15 @@ class CitySolingenDocument extends ContributionDocument
|
|||
'zipLocation' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public static function requiredFormSpecialTypes(): array {
|
||||
return [
|
||||
SpecialType::FIRSTNAME,
|
||||
SpecialType::LASTNAME,
|
||||
SpecialType::BIRTHDAY,
|
||||
SpecialType::ZIP,
|
||||
SpecialType::LOCATION,
|
||||
SpecialType::ADDRESS,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace App\Contribution\Documents;
|
||||
|
||||
use App\Contribution\Contracts\HasContributionData;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use Zoomyboy\Tex\Document;
|
||||
use Zoomyboy\Tex\Template;
|
||||
|
||||
|
@ -14,6 +15,11 @@ abstract class ContributionDocument extends Document
|
|||
|
||||
abstract public static function fromPayload(HasContributionData $request): self;
|
||||
|
||||
/**
|
||||
* @return array<int, SpecialType>
|
||||
*/
|
||||
abstract public static function requiredFormSpecialTypes(): array;
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
|
@ -31,11 +37,6 @@ abstract class ContributionDocument extends Document
|
|||
];
|
||||
}
|
||||
|
||||
public static function buttonName(): string
|
||||
{
|
||||
return 'Für ' . static::getName() . ' erstellen';;
|
||||
}
|
||||
|
||||
public function setEventName(string $eventName): void
|
||||
{
|
||||
$this->eventName = $eventName;
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Contribution\Data\MemberData;
|
|||
use App\Contribution\Traits\FormatsDates;
|
||||
use App\Contribution\Traits\HasPdfBackground;
|
||||
use App\Country;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
@ -65,4 +66,15 @@ class RdpNrwDocument extends ContributionDocument
|
|||
'zipLocation' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public static function requiredFormSpecialTypes(): array {
|
||||
return [
|
||||
SpecialType::FIRSTNAME,
|
||||
SpecialType::LASTNAME,
|
||||
SpecialType::BIRTHDAY,
|
||||
SpecialType::ZIP,
|
||||
SpecialType::LOCATION,
|
||||
SpecialType::GENDER,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ use App\Contribution\Data\MemberData;
|
|||
use App\Contribution\Traits\FormatsDates;
|
||||
use App\Contribution\Traits\HasPdfBackground;
|
||||
use App\Country;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use Illuminate\Support\Collection;
|
||||
use Carbon\Carbon;
|
||||
|
||||
|
@ -60,4 +61,16 @@ class WuppertalDocument extends ContributionDocument
|
|||
'zipLocation' => 'required|string',
|
||||
];
|
||||
}
|
||||
|
||||
public static function requiredFormSpecialTypes(): array {
|
||||
return [
|
||||
SpecialType::FIRSTNAME,
|
||||
SpecialType::LASTNAME,
|
||||
SpecialType::ADDRESS,
|
||||
SpecialType::BIRTHDAY,
|
||||
SpecialType::ZIP,
|
||||
SpecialType::LOCATION,
|
||||
SpecialType::GENDER,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,256 @@
|
|||
<?php
|
||||
|
||||
namespace App\Contribution\Enums;
|
||||
|
||||
enum Country: string {
|
||||
case AD = 'Andorra';
|
||||
case AE = 'Vereinigte Arabische Emirate';
|
||||
case AF = 'Afghanistan';
|
||||
case AG = 'Antigua und Barbuda';
|
||||
case AI = 'Anguilla';
|
||||
case AL = 'Albanien';
|
||||
case AM = 'Armenien';
|
||||
case AN = 'Niederländische Antillen';
|
||||
case AO = 'Angola';
|
||||
case AQ = 'Antarktis';
|
||||
case AR = 'Argentinien';
|
||||
case AS = 'Amerikanisch-Samoa';
|
||||
case AT = 'Österreich (Austria)';
|
||||
case AU = 'Australien';
|
||||
case AW = 'Aruba';
|
||||
case AZ = 'Azerbaijan';
|
||||
case BA = 'Bosnien-Herzegovina';
|
||||
case BB = 'Barbados';
|
||||
case BD = 'Bangladesh';
|
||||
case BE = 'Belgien';
|
||||
case BF = 'Burkina Faso';
|
||||
case BG = 'Bulgarien';
|
||||
case BH = 'Bahrain';
|
||||
case BI = 'Burundi';
|
||||
case BJ = 'Benin';
|
||||
case BM = 'Bermudas';
|
||||
case BN = 'Brunei Darussalam';
|
||||
case BO = 'Bolivien';
|
||||
case BR = 'Brasilien';
|
||||
case BS = 'Bahamas';
|
||||
case BT = 'Bhutan';
|
||||
case BV = 'Bouvet Island';
|
||||
case BW = 'Botswana';
|
||||
case BY = 'Weißrußland (Belarus)';
|
||||
case BZ = 'Belize';
|
||||
case CA = 'Canada';
|
||||
case CC = 'Cocos (Keeling) Islands';
|
||||
case CD = 'Demokratische Republik Kongo';
|
||||
case CF = 'Zentralafrikanische Republik';
|
||||
case CG = 'Kongo';
|
||||
case CH = 'Schweiz';
|
||||
case CI = 'Elfenbeinküste (Cote D’Ivoire)';
|
||||
case CK = 'Cook Islands';
|
||||
case CL = 'Chile';
|
||||
case CM = 'Kamerun';
|
||||
case CN = 'China';
|
||||
case CO = 'Kolumbien';
|
||||
case CR = 'Costa Rica';
|
||||
case CS = 'Tschechoslowakei (ehemalige)';
|
||||
case CU = 'Kuba';
|
||||
case CV = 'Kap Verde';
|
||||
case CX = 'Christmas Island';
|
||||
case CY = 'Zypern';
|
||||
case CZ = 'Tschechische Republik';
|
||||
case DE = 'Deutschland';
|
||||
case DJ = 'Djibouti';
|
||||
case DK = 'Dänemark';
|
||||
case DM = 'Dominica';
|
||||
case DO = 'Dominikanische Republik';
|
||||
case DZ = 'Algerien';
|
||||
case EC = 'Ecuador';
|
||||
case EE = 'Estland';
|
||||
case EG = 'Ägypten';
|
||||
case EH = 'Westsahara';
|
||||
case ER = 'Eritrea';
|
||||
case ES = 'Spanien';
|
||||
case ET = 'Äthiopien';
|
||||
case FI = 'Finnland';
|
||||
case FJ = 'Fiji';
|
||||
case FK = 'Falkland-Inseln (Malvinas)';
|
||||
case FM = 'Micronesien';
|
||||
case FO = 'Faröer-Inseln';
|
||||
case FR = 'Frankreich';
|
||||
case FX = 'France, Metropolitan';
|
||||
case GA = 'Gabon';
|
||||
case GD = 'Grenada';
|
||||
case GE = 'Georgien';
|
||||
case GF = 'Französisch Guiana';
|
||||
case GH = 'Ghana';
|
||||
case GI = 'Gibraltar';
|
||||
case GL = 'Grönland';
|
||||
case GM = 'Gambia';
|
||||
case GN = 'Guinea';
|
||||
case GP = 'Guadeloupe';
|
||||
case GQ = 'Äquatorialguinea';
|
||||
case GR = 'Griechenland';
|
||||
case GS = 'Südgeorgien und Südliche Sandwich-Inseln';
|
||||
case GT = 'Guatemala';
|
||||
case GU = 'Guam';
|
||||
case GW = 'Guinea-Bissau';
|
||||
case GY = 'Guyana';
|
||||
case HK = 'Kong Hong';
|
||||
case HM = 'Heard und Mc Donald Islands';
|
||||
case HN = 'Honduras';
|
||||
case HT = 'Haiti';
|
||||
case HU = 'Ungarn';
|
||||
case ID = 'Indonesien';
|
||||
case IE = 'Irland';
|
||||
case IL = 'Israel';
|
||||
case IN = 'Indien';
|
||||
case IO = 'British Indian Ocean Territory';
|
||||
case IQ = 'Irak';
|
||||
case IR = 'Iran (Islamische Republik)';
|
||||
case IS = 'Island';
|
||||
case IT = 'Italien';
|
||||
case JM = 'Jamaica';
|
||||
case JO = 'Jordanien';
|
||||
case JP = 'Japan';
|
||||
case KE = 'Kenya';
|
||||
case KG = 'Kirgisien';
|
||||
case KH = 'Königreich Kambodscha';
|
||||
case KI = 'Kiribati';
|
||||
case KM = 'Komoren';
|
||||
case KN = 'Saint Kitts und Nevis';
|
||||
case KP = 'Korea, Volksrepublik';
|
||||
case KR = 'Korea';
|
||||
case KW = 'Kuwait';
|
||||
case KY = 'Kayman Islands';
|
||||
case KZ = 'Kasachstan';
|
||||
case LA = 'Laos';
|
||||
case LB = 'Libanon';
|
||||
case LC = 'Saint Lucia';
|
||||
case LI = 'Liechtenstein';
|
||||
case LK = 'Sri Lanka';
|
||||
case LR = 'Liberia';
|
||||
case LS = 'Lesotho';
|
||||
case LT = 'Littauen';
|
||||
case LU = 'Luxemburg';
|
||||
case LV = 'Lettland';
|
||||
case LY = 'Libyen';
|
||||
case MA = 'Marokko';
|
||||
case MC = 'Monaco';
|
||||
case MD = 'Moldavien';
|
||||
case MG = 'Madagaskar';
|
||||
case MH = 'Marshall-Inseln';
|
||||
case MK = 'Mazedonien, ehem. Jugoslawische Republik';
|
||||
case ML = 'Mali';
|
||||
case MM = 'Myanmar';
|
||||
case MN = 'Mongolei';
|
||||
case MO = 'Macao';
|
||||
case MP = 'Nördliche Marianneninseln';
|
||||
case MQ = 'Martinique';
|
||||
case MR = 'Mauretanien';
|
||||
case MS = 'Montserrat';
|
||||
case MT = 'Malta';
|
||||
case MU = 'Mauritius';
|
||||
case MV = 'Malediven';
|
||||
case MW = 'Malawi';
|
||||
case MX = 'Mexico';
|
||||
case MY = 'Malaysien';
|
||||
case MZ = 'Mozambique';
|
||||
case NA = 'Namibia';
|
||||
case NC = 'Neu Kaledonien';
|
||||
case NE = 'Niger';
|
||||
case NF = 'Norfolk Island';
|
||||
case NG = 'Nigeria';
|
||||
case NI = 'Nicaragua';
|
||||
case NL = 'Niederlande';
|
||||
case NO = 'Norwegen';
|
||||
case NP = 'Nepal';
|
||||
case NR = 'Nauru';
|
||||
case NU = 'Niue';
|
||||
case NZ = 'Neuseeland';
|
||||
case OM = 'Oman';
|
||||
case PA = 'Panama';
|
||||
case PE = 'Peru';
|
||||
case PF = 'Französisch Polynesien';
|
||||
case PG = 'Papua Neuguinea';
|
||||
case PH = 'Philippinen';
|
||||
case PK = 'Pakistan';
|
||||
case PL = 'Polen';
|
||||
case PM = 'St. Pierre und Miquelon';
|
||||
case PN = 'Pitcairn';
|
||||
case PR = 'Puerto Rico';
|
||||
case PT = 'Portugal';
|
||||
case PW = 'Palau';
|
||||
case PY = 'Paraguay';
|
||||
case QA = 'Katar';
|
||||
case RE = 'Reunion';
|
||||
case RO = 'Rumänien';
|
||||
case RU = 'Russische Föderation';
|
||||
case RW = 'Ruanda';
|
||||
case SA = 'Saudi Arabien';
|
||||
case SB = 'Salomonen';
|
||||
case SC = 'Seychellen';
|
||||
case SD = 'Sudan';
|
||||
case SE = 'Schweden';
|
||||
case SG = 'Singapur';
|
||||
case SH = 'St. Helena';
|
||||
case SI = 'Slovenien';
|
||||
case SJ = 'Svalbard und Jan Mayen Islands';
|
||||
case SK = 'Slowakei';
|
||||
case SL = 'Sierra Leone';
|
||||
case SM = 'San Marino';
|
||||
case SN = 'Senegal';
|
||||
case SO = 'Somalia';
|
||||
case SR = 'Surinam';
|
||||
case ST = 'Sao Tome und Principe';
|
||||
case SV = 'El Salvador';
|
||||
case SY = 'Syrien, Arabische Republik';
|
||||
case SZ = 'Swaziland';
|
||||
case TC = 'Turk und Caicos-Inseln';
|
||||
case TD = 'Tschad';
|
||||
case TF = 'Französisches Südl.Territorium';
|
||||
case TG = 'Togo';
|
||||
case TH = 'Thailand';
|
||||
case TJ = 'Tadschikistan';
|
||||
case TK = 'Tokelau';
|
||||
case TM = 'Turkmenistan';
|
||||
case TN = 'Tunesien';
|
||||
case TO = 'Tonga';
|
||||
case TP = 'Ost-Timor';
|
||||
case TR = 'Türkei';
|
||||
case TT = 'Trinidad und Tobago';
|
||||
case TV = 'Tuvalu';
|
||||
case TW = 'Taiwan';
|
||||
case TZ = 'Tansania, United Republic of';
|
||||
case UA = 'Ukraine';
|
||||
case UG = 'Uganda';
|
||||
case GB = 'Großbritannien';
|
||||
case US = 'Vereinigte Staaten';
|
||||
case UM = 'Vereinigte Staaten, Minor Outlying Islands';
|
||||
case UY = 'Uruguay';
|
||||
case UZ = 'Usbekistan';
|
||||
case VA = 'Vatikanstaat';
|
||||
case VC = 'Saint Vincent und Grenadines';
|
||||
case VE = 'Venezuela';
|
||||
case VG = 'Virgin Islands (Britisch)';
|
||||
case VI = 'Virgin Islands (U.S.)';
|
||||
case VN = 'Vietnam';
|
||||
case VU = 'Vanuatu';
|
||||
case WF = 'Wallis und Futuna Islands';
|
||||
case WS = 'Samoa';
|
||||
case YE = 'Jemen';
|
||||
case YT = 'Mayotte';
|
||||
case YU = 'Jugoslawien';
|
||||
case ZA = 'Südafrika';
|
||||
case ZM = 'Sambia';
|
||||
case ZW = 'Zimbabw';
|
||||
|
||||
/**
|
||||
* @return array<int, array{name: string, id: string}>
|
||||
*/
|
||||
public static function forSelect(): array
|
||||
{
|
||||
return collect(static::cases())
|
||||
->map(fn ($case) => ['id' => $case->value, 'name' => $case->value])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,17 +2,10 @@
|
|||
|
||||
namespace App\Contribution\Requests;
|
||||
|
||||
use App\Contribution\Contracts\HasContributionData;
|
||||
use App\Contribution\Data\MemberData;
|
||||
use App\Contribution\Documents\ContributionDocument;
|
||||
use App\Country;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use RuntimeException;
|
||||
|
||||
class GenerateApiRequest extends ActionRequest implements HasContributionData {
|
||||
class GenerateApiRequest extends GenerateRequest {
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
|
@ -21,47 +14,11 @@ class GenerateApiRequest extends ActionRequest implements HasContributionData {
|
|||
return $this->input();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array<array-key, mixed>
|
||||
*/
|
||||
public function value(string $key): string|array
|
||||
{
|
||||
if (!Arr::has($this->payload(), $key)) {
|
||||
throw new RuntimeException('Wert für '.$key.' nicht gefunden.');
|
||||
}
|
||||
return data_get($this->payload(), $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<ContributionDocument>
|
||||
*/
|
||||
public function type(): string
|
||||
{
|
||||
return $this->value('type');
|
||||
}
|
||||
|
||||
public function dateFrom(): Carbon {
|
||||
return Carbon::parse($this->value('dateFrom'));
|
||||
}
|
||||
|
||||
public function dateUntil(): Carbon {
|
||||
return Carbon::parse($this->value('dateUntil'));
|
||||
}
|
||||
|
||||
public function zipLocation(): string {
|
||||
return $this->value('zipLocation');
|
||||
}
|
||||
|
||||
public function eventName(): string {
|
||||
return $this->value('eventName');
|
||||
public function validateContribution(): void {
|
||||
}
|
||||
|
||||
public function members(): Collection {
|
||||
return MemberData::fromApi($this->value('member_data'));
|
||||
}
|
||||
|
||||
public function country(): ?Country {
|
||||
return Country::where('id', $this->value('country'))->first();
|
||||
return MemberData::fromApi($this->value('members'));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,22 +3,28 @@
|
|||
namespace App\Contribution\Requests;
|
||||
|
||||
use App\Contribution\Contracts\HasContributionData;
|
||||
use App\Contribution\ContributionFactory;
|
||||
use App\Contribution\Data\MemberData;
|
||||
use App\Contribution\Documents\ContributionDocument;
|
||||
use App\Country;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class GenerateRequest extends ActionRequest implements HasContributionData {
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function payload(): array
|
||||
protected function payload(): array
|
||||
{
|
||||
return json_decode(rawurldecode(base64_decode($this->input('payload', ''))), true);
|
||||
}
|
||||
|
||||
public function validateContribution(): void {
|
||||
Validator::make($this->payload(), app(ContributionFactory::class)->rules($this->type()))->validate();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|array<array-key, mixed>
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,10 @@ class FormStoreAction
|
|||
'needs_prevention' => 'present|boolean',
|
||||
'prevention_text' => 'array',
|
||||
'prevention_conditions' => 'array',
|
||||
'leader_conditions' => 'array',
|
||||
'zip' => 'present|nullable|string',
|
||||
'location' => 'present|nullable|string',
|
||||
'country' => 'nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Form\Actions;
|
||||
|
||||
use App\Form\Models\Form;
|
||||
use App\Lib\Editor\Condition;
|
||||
use App\Lib\Events\Succeeded;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
@ -36,6 +35,10 @@ class FormUpdateAction
|
|||
'needs_prevention' => 'present|boolean',
|
||||
'prevention_text' => 'array',
|
||||
'prevention_conditions' => 'array',
|
||||
'location' => 'present|nullable|string',
|
||||
'zip' => 'present|nullable|string',
|
||||
'country' => 'nullable|string|max:255',
|
||||
'leader_conditions' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Actions;
|
||||
|
||||
use App\Contribution\Contracts\HasContributionData;
|
||||
use App\Contribution\ContributionFactory;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Requests\FormCompileRequest;
|
||||
use App\Rules\JsonBase64Rule;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\ActionRequest;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
use Zoomyboy\Tex\BaseCompiler;
|
||||
use Zoomyboy\Tex\Tex;
|
||||
|
||||
class GenerateContributionAction
|
||||
{
|
||||
use AsAction;
|
||||
|
||||
public function handle(HasContributionData $request): BaseCompiler
|
||||
{
|
||||
return Tex::compile($request->type()::fromPayload($request));
|
||||
}
|
||||
|
||||
public function asController(ActionRequest $request, Form $form): BaseCompiler|JsonResponse
|
||||
{
|
||||
$r = FormCompileRequest::from(['form' => $form]);
|
||||
app(ContributionFactory::class)->validateType($r);
|
||||
$r->validateContribution();
|
||||
|
||||
return $request->input('validate')
|
||||
? response()->json([])
|
||||
: $this->handle($r);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'payload' => [new JsonBase64Rule()],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -114,7 +114,12 @@ class FieldCollection extends Collection
|
|||
return $this->map(fn ($field) => $field->presentRaw())->toArray();
|
||||
}
|
||||
|
||||
private function findBySpecialType(SpecialType $specialType): ?Field
|
||||
public function hasSpecialType(SpecialType $specialType): bool
|
||||
{
|
||||
return $this->findBySpecialType($specialType) !== null;
|
||||
}
|
||||
|
||||
public function findBySpecialType(SpecialType $specialType): ?Field
|
||||
{
|
||||
return $this->first(fn ($field) => $field->specialType === $specialType);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,11 @@ enum SpecialType: string
|
|||
case FIRSTNAME = 'Vorname';
|
||||
case LASTNAME = 'Nachname';
|
||||
case EMAIL = 'E-Mail-Adresse';
|
||||
case BIRTHDAY = 'Geburtsdatum';
|
||||
case ZIP = 'PLZ';
|
||||
case LOCATION = 'Ort';
|
||||
case ADDRESS = 'Adresse';
|
||||
case GENDER = 'Geschlecht';
|
||||
|
||||
/**
|
||||
* @return array<int, array{name: string, id: string}>
|
||||
|
|
|
@ -69,10 +69,8 @@ class ConfirmRegistrationMail extends Mailable
|
|||
*/
|
||||
public function attachments()
|
||||
{
|
||||
$conditionResolver = app(FormConditionResolver::class)->forParticipant($this->participant);
|
||||
|
||||
return $this->participant->form->getMedia('mailattachments')
|
||||
->filter(fn ($media) => $conditionResolver->filterCondition(Condition::fromMedia($media)))
|
||||
->filter(fn ($media) => $this->participant->matchesCondition(Condition::fromMedia($media)))
|
||||
->map(fn ($media) => Attachment::fromStorageDisk($media->disk, $media->getPathRelativeToRoot()))
|
||||
->all();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Models;
|
||||
|
||||
use App\Contribution\Enums\Country;
|
||||
use App\Form\Actions\UpdateParticipantSearchIndexAction;
|
||||
use App\Form\Data\ExportData;
|
||||
use App\Form\Data\FieldCollection;
|
||||
|
@ -18,7 +19,6 @@ use Laravel\Scout\Searchable;
|
|||
use Spatie\Image\Enums\Fit;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Zoomyboy\MedialibraryHelper\DefersUploads;
|
||||
|
||||
/** @todo replace editor content with EditorData cast */
|
||||
|
@ -49,6 +49,8 @@ class Form extends Model implements HasMedia
|
|||
'to' => 'datetime',
|
||||
'registration_from' => 'datetime',
|
||||
'registration_until' => 'datetime',
|
||||
'country' => Country::class,
|
||||
'leader_conditions' => Condition::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -69,25 +71,24 @@ class Form extends Model implements HasMedia
|
|||
return $this->hasMany(Participant::class);
|
||||
}
|
||||
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection('headerImage')
|
||||
->singleFile()
|
||||
->maxWidth(fn () => 500)
|
||||
->forceFileName(fn (Form $model, string $name) => $model->slug)
|
||||
->convert(fn () => 'jpg')
|
||||
->registerMediaConversions(function (Media $media) {
|
||||
->maxWidth(fn() => 500)
|
||||
->forceFileName(fn(Form $model) => $model->slug)
|
||||
->convert(fn() => 'jpg')
|
||||
->registerMediaConversions(function () {
|
||||
$this->addMediaConversion('square')->fit(Fit::Crop, 400, 400);
|
||||
});
|
||||
$this->addMediaCollection('mailattachments')
|
||||
->withDefaultProperties(fn () => [
|
||||
->withDefaultProperties(fn() => [
|
||||
'conditions' => [
|
||||
'mode' => 'all',
|
||||
'ifs' => []
|
||||
],
|
||||
])
|
||||
->withPropertyValidation(fn () => [
|
||||
->withPropertyValidation(fn() => [
|
||||
'conditions.mode' => 'required|string|in:all,any',
|
||||
'conditions.ifs' => 'array',
|
||||
'conditions.ifs.*.field' => 'required',
|
||||
|
@ -101,7 +102,7 @@ class Form extends Model implements HasMedia
|
|||
*/
|
||||
public function getRegistrationRules(): array
|
||||
{
|
||||
return $this->getFields()->reduce(fn ($carry, $field) => [
|
||||
return $this->getFields()->reduce(fn($carry, $field) => [
|
||||
...$carry,
|
||||
...$field->getRegistrationRules($this),
|
||||
], []);
|
||||
|
@ -112,7 +113,7 @@ class Form extends Model implements HasMedia
|
|||
*/
|
||||
public function getRegistrationMessages(): array
|
||||
{
|
||||
return $this->getFields()->reduce(fn ($carry, $field) => [
|
||||
return $this->getFields()->reduce(fn($carry, $field) => [
|
||||
...$carry,
|
||||
...$field->getRegistrationMessages($this),
|
||||
], []);
|
||||
|
@ -123,7 +124,7 @@ class Form extends Model implements HasMedia
|
|||
*/
|
||||
public function getRegistrationAttributes(): array
|
||||
{
|
||||
return $this->getFields()->reduce(fn ($carry, $field) => [
|
||||
return $this->getFields()->reduce(fn($carry, $field) => [
|
||||
...$carry,
|
||||
...$field->getRegistrationAttributes($this),
|
||||
], []);
|
||||
|
@ -189,8 +190,24 @@ class Form extends Model implements HasMedia
|
|||
return Sorting::from($this->meta['sorting']);
|
||||
}
|
||||
|
||||
public function isInDates(): bool {
|
||||
if ($this->registration_from && $this->registration_from->gt(now())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->registration_until && $this->registration_until->lt(now())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canRegister(): bool
|
||||
{
|
||||
if (!$this->is_active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->registration_from && $this->registration_from->gt(now())) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -4,12 +4,12 @@ namespace App\Form\Models;
|
|||
|
||||
use App\Form\Data\FieldCollection;
|
||||
use App\Form\Data\FormConfigData;
|
||||
use App\Form\Editor\FormConditionResolver;
|
||||
use App\Form\Mails\ConfirmRegistrationMail;
|
||||
use App\Form\Scopes\ParticipantFilterScope;
|
||||
use App\Lib\Editor\Condition;
|
||||
use App\Member\Member;
|
||||
use App\Prevention\Contracts\Preventable;
|
||||
use Database\Factories\Form\Models\ParticipantFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
@ -110,4 +110,8 @@ class Participant extends Model implements Preventable
|
|||
{
|
||||
return [...$this->data, 'parent-id' => $this->parent_id, 'created_at' => $this->created_at->timestamp];
|
||||
}
|
||||
|
||||
public function matchesCondition(Condition $condition): bool {
|
||||
return app(FormConditionResolver::class)->forParticipant($this)->filterCondition($condition);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
<?php
|
||||
|
||||
namespace App\Form\Requests;
|
||||
|
||||
use App\Contribution\Contracts\HasContributionData;
|
||||
use App\Contribution\Data\MemberData;
|
||||
use App\Contribution\Documents\ContributionDocument;
|
||||
use App\Country;
|
||||
use App\Form\Editor\FormConditionResolver;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Form\Models\Form;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class FormCompileRequest extends Data implements HasContributionData {
|
||||
|
||||
public function __construct(public Form $form) {}
|
||||
|
||||
/**
|
||||
* @return class-string<ContributionDocument>
|
||||
*/
|
||||
public function type(): string
|
||||
{
|
||||
$payload = json_decode(rawurldecode(base64_decode(request()->input('payload'))), true);
|
||||
|
||||
return $payload['type'];
|
||||
}
|
||||
|
||||
public function dateFrom(): Carbon
|
||||
{
|
||||
return $this->form->from;
|
||||
}
|
||||
|
||||
public function dateUntil(): Carbon
|
||||
{
|
||||
return $this->form->to;
|
||||
}
|
||||
|
||||
public function zipLocation(): string
|
||||
{
|
||||
return $this->form->zip.' '.$this->form->location;
|
||||
}
|
||||
|
||||
public function eventName(): string
|
||||
{
|
||||
return $this->form->name;
|
||||
}
|
||||
|
||||
public function members(): Collection
|
||||
{
|
||||
$members = [];
|
||||
$fields = [
|
||||
[SpecialType::FIRSTNAME, 'firstname'],
|
||||
[SpecialType::LASTNAME, 'lastname'],
|
||||
[SpecialType::BIRTHDAY, 'birthday'],
|
||||
[SpecialType::GENDER, 'gender'],
|
||||
[SpecialType::ADDRESS, 'address'],
|
||||
[SpecialType::ZIP, 'zip'],
|
||||
[SpecialType::LOCATION, 'location'],
|
||||
];
|
||||
|
||||
foreach ($this->form->participants as $participant) {
|
||||
$member = [];
|
||||
foreach ($fields as [$type, $name]) {
|
||||
$f = $this->form->getFields()->findBySpecialType($type);
|
||||
if (!$f) {
|
||||
continue;
|
||||
}
|
||||
$member[$name] = $participant->getFields()->find($f)->value;
|
||||
}
|
||||
|
||||
$members[] = [
|
||||
'is_leader' => $participant->matchesCondition($participant->form->leader_conditions),
|
||||
'gender' => 'weiblich',
|
||||
...$member,
|
||||
];
|
||||
}
|
||||
|
||||
return MemberData::fromApi($members);
|
||||
}
|
||||
|
||||
public function country(): ?Country
|
||||
{
|
||||
return Country::first();
|
||||
}
|
||||
|
||||
public function validateContribution(): void
|
||||
{
|
||||
Validator::make($this->form->toArray(), [
|
||||
'zip' => 'required',
|
||||
'location' => 'required'
|
||||
])
|
||||
->after(function($validator) {
|
||||
foreach ($this->type()::requiredFormSpecialTypes() as $type) {
|
||||
if (!$this->form->getFields()->hasSpecialType($type)) {
|
||||
$validator->errors()->add($type->name, 'Kein Feld für ' . $type->value . ' vorhanden.');
|
||||
}
|
||||
}
|
||||
if ($this->form->participants->count() === 0) {
|
||||
$validator->errors()->add('participants', 'Veranstaltung besitzt noch keine Teilnehmer*innen.');
|
||||
}
|
||||
})
|
||||
->validate();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Form\Resources;
|
||||
|
||||
use App\Contribution\Enums\Country;
|
||||
use App\Form\Data\ExportData;
|
||||
use App\Form\Enums\NamiType;
|
||||
use App\Form\Enums\SpecialType;
|
||||
|
@ -14,6 +15,7 @@ use App\Group;
|
|||
use App\Lib\Editor\EditorData;
|
||||
use App\Lib\HasMeta;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use App\Contribution\ContributionFactory;
|
||||
|
||||
/**
|
||||
* @mixin Form
|
||||
|
@ -44,6 +46,7 @@ class FormResource extends JsonResource
|
|||
'mail_bottom' => $this->mail_bottom,
|
||||
'registration_from' => $this->registration_from?->format('Y-m-d H:i:s'),
|
||||
'registration_until' => $this->registration_until?->format('Y-m-d H:i:s'),
|
||||
'is_in_dates' => $this->isInDates(),
|
||||
'config' => $this->config,
|
||||
'participants_count' => $this->participants_count,
|
||||
'is_active' => $this->is_active,
|
||||
|
@ -53,6 +56,10 @@ class FormResource extends JsonResource
|
|||
'needs_prevention' => $this->needs_prevention,
|
||||
'prevention_text' => $this->prevention_text,
|
||||
'prevention_conditions' => $this->prevention_conditions,
|
||||
'leader_conditions' => $this->leader_conditions,
|
||||
'zip' => $this->zip,
|
||||
'location' => $this->location,
|
||||
'country' => $this->country,
|
||||
'links' => [
|
||||
'participant_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => null]),
|
||||
'participant_root_index' => route('form.participant.index', ['form' => $this->getModel(), 'parent' => -1]),
|
||||
|
@ -62,6 +69,7 @@ class FormResource extends JsonResource
|
|||
'frontend' => str(app(FormSettings::class)->registerUrl)->replace('{slug}', $this->slug),
|
||||
'export' => route('form.export', $this->getModel()),
|
||||
'copy' => route('form.copy', $this->getModel()),
|
||||
'contribution' => route('form.contribution', $this->getModel()),
|
||||
]
|
||||
];
|
||||
}
|
||||
|
@ -83,6 +91,8 @@ class FormResource extends JsonResource
|
|||
'templates' => FormtemplateResource::collection(Formtemplate::get()),
|
||||
'namiTypes' => NamiType::forSelect(),
|
||||
'specialTypes' => SpecialType::forSelect(),
|
||||
'countries' => Country::forSelect(),
|
||||
'contribution_types' => app(ContributionFactory::class)->compilerSelect(),
|
||||
'default' => [
|
||||
'description' => [],
|
||||
'is_active' => true,
|
||||
|
@ -102,6 +112,9 @@ class FormResource extends JsonResource
|
|||
'id' => null,
|
||||
'export' => ExportData::from([]),
|
||||
'prevention_conditions' => ['mode' => 'all', 'ifs' => []],
|
||||
'zip' => '',
|
||||
'location' => '',
|
||||
'country' => null,
|
||||
],
|
||||
'section_default' => [
|
||||
'name' => '',
|
||||
|
|
|
@ -57,6 +57,8 @@ class FormFactory extends Factory
|
|||
'is_private' => false,
|
||||
'export' => ExportData::from([]),
|
||||
'prevention_conditions' => Condition::defaults(),
|
||||
'zip' => $this->faker->numberBetween(1100, 99999),
|
||||
'location' => $this->faker->city(),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->string('zip')->nullable()->after('name');
|
||||
$table->string('location')->nullable()->after('name');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->dropColumn('zip');
|
||||
$table->dropColumn('location');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->string('country')->nullable()->after('location');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->dropColumn('country');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->json('leader_conditions')->after('name')->default(json_encode(['mode' => 'all', 'ifs' => []]));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('forms', function (Blueprint $table) {
|
||||
$table->dropColumn('leader_conditions');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -1,3 +1,7 @@
|
|||
.v-popper__popper {
|
||||
@apply max-w-lg;
|
||||
}
|
||||
|
||||
.v-popper--theme-tooltip .v-popper__inner {
|
||||
@apply bg-primary-400 text-primary-800 px-3 py-1 text-sm;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
<template>
|
||||
<ui-popup v-for="(popup, index) in swal.popups" :key="index" :icon="popup.icon" :heading="popup.title" @close="popup.reject(popup.id)">
|
||||
<div class="text-center mt-4" v-text="popup.body" />
|
||||
<div class="mt-4">
|
||||
<div class="text-center" v-text="popup.body" />
|
||||
<div class="flex justify-center space-x-4 mt-8">
|
||||
<ui-button type="button" class="btn-primary" @click.prevent="popup.resolve(popup.id)">{{ popup.confirmButton }}</ui-button>
|
||||
<ui-button type="button" class="btn-default" @click.prevent="popup.reject(popup.id)">{{ popup.cancelButton }}</ui-button>
|
||||
</div>
|
||||
<template v-for="field in popup.fields">
|
||||
<f-text v-if="field.type === 'text'" :id="field.name" :key="field.name" v-model="popup.payload[field.name]" :name="field.name" :label="field.label" />
|
||||
<f-select v-if="field.type === 'select'" :id="field.name" :key="field.name" v-model="popup.payload[field.name]" :name="field.name" :label="field.label" :options="field.options" />
|
||||
</template>
|
||||
</div>
|
||||
<div class="flex justify-center space-x-4 mt-6">
|
||||
<ui-button type="button" class="btn-primary" @click.prevent="popup.resolve(popup.id)">{{ popup.confirmButton }}</ui-button>
|
||||
<ui-button type="button" class="btn-default" @click.prevent="popup.reject(popup.id)">{{ popup.cancelButton }}</ui-button>
|
||||
</div>
|
||||
</ui-popup>
|
||||
</template>
|
||||
|
|
|
@ -17,4 +17,4 @@ var options = {
|
|||
},
|
||||
};
|
||||
|
||||
export {Plugin, options};
|
||||
export { Plugin, options };
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { defineStore } from 'pinia';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
|
||||
type Payload = Record<string, string|null>;
|
||||
|
||||
interface Popup {
|
||||
id: string;
|
||||
|
@ -11,6 +12,16 @@ interface Popup {
|
|||
cancelButton: string;
|
||||
resolve: (id: string) => void;
|
||||
reject: (id: string) => void;
|
||||
fields: SwalField[];
|
||||
payload: Payload;
|
||||
}
|
||||
|
||||
interface SwalField {
|
||||
name: string;
|
||||
label: string;
|
||||
required: boolean;
|
||||
type: 'select' | 'text';
|
||||
options: [],
|
||||
}
|
||||
|
||||
export default defineStore('swal', {
|
||||
|
@ -30,6 +41,8 @@ export default defineStore('swal', {
|
|||
reject,
|
||||
id: uuidv4(),
|
||||
icon: 'warning-triangle-light',
|
||||
fields: [],
|
||||
payload: {},
|
||||
});
|
||||
}).then((id) => {
|
||||
this.remove(id);
|
||||
|
@ -41,8 +54,40 @@ export default defineStore('swal', {
|
|||
});
|
||||
},
|
||||
|
||||
ask(title: string, body: string, fields: SwalField[] = []): Promise<Payload> {
|
||||
return new Promise<Payload>((resolve, reject) => {
|
||||
new Promise<string>((resolve, reject) => {
|
||||
const payload: Payload = {};
|
||||
fields.forEach(f => payload[f.name] = null);
|
||||
this.popups.push({
|
||||
title,
|
||||
body,
|
||||
confirmButton: 'Okay',
|
||||
cancelButton: 'Abbrechen',
|
||||
resolve,
|
||||
reject,
|
||||
id: uuidv4(),
|
||||
icon: 'warning-triangle-light',
|
||||
fields: fields,
|
||||
payload: payload,
|
||||
});
|
||||
}).then((id) => {
|
||||
const p = this.find(id)?.payload;
|
||||
this.remove(id);
|
||||
resolve(p || {});
|
||||
}).catch((id) => {
|
||||
this.remove(id);
|
||||
reject();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
remove(id: string) {
|
||||
this.popups = this.popups.filter(p => p.id !== id);
|
||||
},
|
||||
|
||||
find(id: string): Popup|undefined {
|
||||
return this.popups.find(p => p.id === id);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<button v-for="(compiler, index) in compilers" :key="index" class="btn btn-primary mt-3 inline-block" @click.prevent="download('/contribution-generate', {...values, type: compiler.class})" v-text="compiler.title" />
|
||||
<button v-for="(compiler, index) in compilers" :key="index" class="btn btn-primary mt-3 inline-block" @click.prevent="download('/contribution-generate', {...values, type: compiler.id})" v-text="`Für ${compiler.name} erstellen`" />
|
||||
</form>
|
||||
</page-layout>
|
||||
</template>
|
||||
|
|
|
@ -20,14 +20,15 @@
|
|||
<ui-popup v-if="single !== null && single.config !== null" :heading="`Veranstaltung ${single.id ? 'bearbeiten' : 'erstellen'}`" full @close="cancel">
|
||||
<div class="flex flex-col mt-3">
|
||||
<ui-tabs v-model="active" :entries="tabs" />
|
||||
<div v-show="active === 0" class="grid grid-cols-2 gap-3">
|
||||
<div class="flex space-x-3">
|
||||
<div v-show="active === 0" class="grid grid-cols-4 gap-3">
|
||||
<div class="flex space-x-3 col-span-2">
|
||||
<f-text id="name" v-model="single.name" class="grow" label="Name" required />
|
||||
<f-switch id="is_active" v-model="single.is_active" name="is_active" label="Aktiv" />
|
||||
<f-switch id="is_private" v-model="single.is_private" name="is_private" label="Privat" />
|
||||
<f-switch id="is_active" v-model="single.is_active" name="is_active" label="Aktiv" hint="Inaktive Veranstaltungen werden außerhalb von Adrema wie nicht existierende Veranstaltungen betrachtet. Insbesondere ist eine Anmeldung dann nicht möglich und die Veranstaltung erscheint auch nicht in der Veranstaltungs-Übersicht." />
|
||||
<f-switch id="is_private" v-model="single.is_private" name="is_private" label="Privat" hint="Ist eine Veranstaltung privat, so wird diese nicht auf der Website angezeigt. Eine Anmeldung ist jedoch trotzdem möglich, wenn man über den Anmelde-Link verfügt." />
|
||||
</div>
|
||||
<f-singlefile id="header_image"
|
||||
v-model="single.header_image"
|
||||
class="col-span-2"
|
||||
label="Bild"
|
||||
name="header_image"
|
||||
parent-name="form"
|
||||
|
@ -37,13 +38,17 @@
|
|||
/>
|
||||
<f-text id="from" v-model="single.from" type="date" label="Von" required />
|
||||
<f-text id="to" v-model="single.to" type="date" label="Bis" required />
|
||||
<f-text id="registration_from" v-model="single.registration_from" type="datetime-local" label="Registrierung von" required />
|
||||
<f-text id="zip" v-model="single.zip" label="PLZ" />
|
||||
<f-text id="location" v-model="single.location" label="Ort" />
|
||||
<f-select id="country" v-model="single.country" class="col-span-2" name="country" label="Land" :options="meta.countries" />
|
||||
<f-text id="registration_from" v-model="single.registration_from" type="datetime-local" label="Registrierung von" hint="Ist eine Anmeldung laut dieser zwei Datumsangaben möglich, kann man sich anmelden. Andernfalls wird die Veranstaltung (mit Beschreibungstext) auf der Übersichtsseite angezeigt, man kommt allerdings nicht zum Anmeldeformular." required />
|
||||
<f-text id="registration_until" v-model="single.registration_until" type="datetime-local" label="Registrierung bis" required />
|
||||
<f-textarea id="excerpt"
|
||||
v-model="single.excerpt"
|
||||
hint="Gebe hier eine kurze Beschreibung für die Veranstaltungs-Übersicht ein (Maximal 130 Zeichen)."
|
||||
label="Auszug"
|
||||
:rows="5"
|
||||
class="col-span-full"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
@ -110,6 +115,11 @@
|
|||
<conditions id="prevention_conditions" v-model="single.prevention_conditions" :single="single" />
|
||||
</ui-box>
|
||||
</div>
|
||||
<div v-if="active === 6">
|
||||
<ui-box heading="Bedingung für Leiter*in">
|
||||
<conditions id="leader_conditions" v-model="single.leader_conditions" :single="single" />
|
||||
</ui-box>
|
||||
</div>
|
||||
</div>
|
||||
<template #actions>
|
||||
<a href="#" @click.prevent="submit">
|
||||
|
@ -136,6 +146,7 @@
|
|||
<th>Name</th>
|
||||
<th>Von</th>
|
||||
<th>Bis</th>
|
||||
<th>Tags</th>
|
||||
<th>Anzahl TN</th>
|
||||
<th />
|
||||
</tr>
|
||||
|
@ -152,6 +163,13 @@
|
|||
<td>
|
||||
<div v-text="form.to_human" />
|
||||
</td>
|
||||
<td>
|
||||
<div class="bool-row">
|
||||
<ui-bool true-comment="aktiv" false-comment="inaktiv" :value="form.is_active">A</ui-bool>
|
||||
<ui-bool true-comment="private Veranstaltung" false-comment="nicht private Veranstaltung" :value="form.is_private">P</ui-bool>
|
||||
<ui-bool true-comment="Anmeldung möglich (lt. 'Registrierung von / bis')" false-comment="Anmeldeschluss erreicht" :value="form.is_in_dates">D</ui-bool>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<div v-text="form.participants_count" />
|
||||
</td>
|
||||
|
@ -161,6 +179,7 @@
|
|||
<ui-action-button tooltip="Teilnehmende anzeigen" class="btn-info" icon="user" @click.prevent="showParticipants(form)" />
|
||||
<ui-action-button :href="form.links.frontend" target="_BLANK" tooltip="zur Anmeldeseite" class="btn-info" icon="eye" />
|
||||
<ui-action-button tooltip="Kopieren" class="btn-info" icon="copy" @click="onCopy(form)" />
|
||||
<ui-action-button tooltip="Zuschuss-Liste erstellen" class="btn-info" icon="contribution" @click="onGenerateContribution(form)" />
|
||||
<ui-action-button :href="form.links.export" target="_BLANK" tooltip="als Tabellendokument exportieren" class="btn-info" icon="document" />
|
||||
<ui-action-button tooltip="Löschen" class="btn-danger" icon="trash" @click.prevent="onDelete(form)" />
|
||||
</div>
|
||||
|
@ -183,18 +202,20 @@ import Conditions from './Conditions.vue';
|
|||
import ConditionsForm from './ConditionsForm.vue';
|
||||
import { useToast } from 'vue-toastification';
|
||||
import useSwal from '@/stores/swalStore.ts';
|
||||
import useDownloads from '@/composables/useDownloads.ts';
|
||||
|
||||
const props = defineProps(indexProps);
|
||||
const { meta, data, reloadPage, reload, create, single, edit, cancel, submit, remove, getFilter, setFilter } = useIndex(props.data, 'form');
|
||||
const axios = inject('axios');
|
||||
const toast = useToast();
|
||||
const {download} = useDownloads();
|
||||
|
||||
const showing = ref(null);
|
||||
const fileSettingPopup = ref(null);
|
||||
|
||||
const active = ref(0);
|
||||
const activeMailTab = ref(0);
|
||||
const tabs = [{ title: 'Allgemeines' }, { title: 'Beschreibung' }, { title: 'Formular' }, { title: 'Bestätigungs-E-Mail' }, { title: 'Export' }, { title: 'Prävention' }];
|
||||
const tabs = [{ title: 'Allgemeines' }, { title: 'Beschreibung' }, { title: 'Formular' }, { title: 'Bestätigungs-E-Mail' }, { title: 'Export' }, { title: 'Prävention' }, {title: 'Zuschüsse'}];
|
||||
const mailTabs = [{ title: 'vor Daten' }, { title: 'nach Daten' }];
|
||||
const swal = useSwal();
|
||||
|
||||
|
@ -219,6 +240,20 @@ async function onCopy(form) {
|
|||
reload(false);
|
||||
}
|
||||
|
||||
async function onGenerateContribution(form) {
|
||||
const response = await swal.ask('Zuschussliste erstellen', 'Hiermit erstellst du eine Zuschussliste mit allen angemeldeten Mitgliedern. Bite wähle aus, für welche Organisation du eine Liste erstellen willst.', [
|
||||
{
|
||||
name: 'type',
|
||||
label: 'Organisation',
|
||||
required: true,
|
||||
type: 'select',
|
||||
options: meta.value.contribution_types,
|
||||
}
|
||||
]);
|
||||
await download(form.links.contribution, {type: response.type, validate: '1'});
|
||||
await download(form.links.contribution, {type: response.type});
|
||||
}
|
||||
|
||||
async function onDelete(form) {
|
||||
await swal.confirm('Diese Veranstaltung löschen?', `Die Veranstaltung ${form.name} wird gelöscht werden.`);
|
||||
await remove(form);
|
||||
|
|
|
@ -34,6 +34,7 @@ use App\Form\Actions\FormtemplateStoreAction;
|
|||
use App\Form\Actions\FormtemplateUpdateAction;
|
||||
use App\Form\Actions\FormUpdateAction;
|
||||
use App\Form\Actions\FormUpdateMetaAction;
|
||||
use App\Form\Actions\GenerateContributionAction;
|
||||
use App\Form\Actions\IsDirtyAction;
|
||||
use App\Form\Actions\ParticipantAssignAction;
|
||||
use App\Form\Actions\ParticipantDestroyAction;
|
||||
|
@ -178,6 +179,7 @@ Route::group(['middleware' => 'auth:web'], function (): void {
|
|||
Route::patch('/participant/{participant}', ParticipantUpdateAction::class)->name('participant.update');
|
||||
Route::post('/form/{form}/participant', ParticipantStoreAction::class)->name('form.participant.store');
|
||||
Route::post('/form/{form}/copy', FormCopyAction::class)->name('form.copy');
|
||||
Route::get('/form/{form}/contribution', GenerateContributionAction::class)->name('form.contribution');
|
||||
|
||||
// ------------------------------------ fileshare -----------------------------------
|
||||
Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store');
|
||||
|
|
|
@ -100,3 +100,13 @@ dataset('contribution-assertions', fn () => [
|
|||
[BdkjHesse::class, ["Max", "Muster", "Jane"]],
|
||||
[WuppertalDocument::class, ["Max", "Muster", "Jane", "42777 SG", "15.06.1991", "16.06.1991"]],
|
||||
]);
|
||||
|
||||
dataset('contribution-documents', fn () => [
|
||||
CitySolingenDocument::class,
|
||||
RdpNrwDocument::class,
|
||||
CityRemscheidDocument::class,
|
||||
CityFrankfurtMainDocument::class,
|
||||
BdkjHesse::class,
|
||||
WuppertalDocument::class,
|
||||
]);
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Tests\EndToEnd\Form;
|
||||
|
||||
use App\Contribution\Documents\RdpNrwDocument;
|
||||
use App\Contribution\Enums\Country;
|
||||
use App\Fileshare\Data\FileshareResourceData;
|
||||
use App\Form\Data\ExportData;
|
||||
use App\Form\FormSettings;
|
||||
|
@ -11,186 +13,198 @@ use App\Form\Models\Participant;
|
|||
use Carbon\Carbon;
|
||||
use Tests\Feature\Form\FormtemplateSectionRequest;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\EndToEndTestCase;
|
||||
use Tests\RequestFactories\ConditionRequestFactory;
|
||||
|
||||
class FormIndexActionTest extends FormTestCase
|
||||
{
|
||||
uses(CreatesFormFields::class);
|
||||
uses(DatabaseTransactions::class);
|
||||
uses(EndToEndTestCase::class);
|
||||
|
||||
public function testItDisplaysForms(): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2023-03-03'));
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()
|
||||
->name('lala')
|
||||
->excerpt('fff')
|
||||
->description(EditorRequestFactory::new()->text(10, 'desc'))
|
||||
->from('2023-05-05')
|
||||
->to('2023-06-07')
|
||||
->mailTop(EditorRequestFactory::new()->text(10, 'Guten Tag'))
|
||||
->mailBottom(EditorRequestFactory::new()->text(10, 'Cheers'))
|
||||
->registrationFrom('2023-05-06 04:00:00')
|
||||
->registrationUntil('2023-04-01 05:00:00')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([$this->textField()])])
|
||||
->has(Participant::factory()->count(5))
|
||||
->create();
|
||||
it('testItDisplaysForms', function () {
|
||||
Carbon::setTestNow(Carbon::parse('2023-03-03'));
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$leaderConditions = ConditionRequestFactory::new()->whenField('f', 'v');
|
||||
$form = Form::factory()
|
||||
->name('lala')
|
||||
->excerpt('fff')
|
||||
->description(EditorRequestFactory::new()->text(10, 'desc'))
|
||||
->from('2023-05-05')
|
||||
->to('2023-06-07')
|
||||
->mailTop(EditorRequestFactory::new()->text(10, 'Guten Tag'))
|
||||
->mailBottom(EditorRequestFactory::new()->text(10, 'Cheers'))
|
||||
->registrationFrom('2023-05-06 04:00:00')
|
||||
->registrationUntil('2023-04-01 05:00:00')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([$this->textField()])])
|
||||
->has(Participant::factory()->count(5))
|
||||
->zip('12345')
|
||||
->location('SG')
|
||||
->country(Country::CH)
|
||||
->create(['leader_conditions' => $leaderConditions->toData()]);
|
||||
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
->assertOk()
|
||||
->assertInertiaPath('data.data.0.name', 'lala')
|
||||
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
|
||||
->assertInertiaPath('data.data.0.id', $form->id)
|
||||
->assertInertiaPath('data.data.0.excerpt', 'fff')
|
||||
->assertInertiaPath('data.data.0.description.blocks.0.data.text', 'desc')
|
||||
->assertInertiaPath('data.data.0.mail_top.blocks.0.data.text', 'Guten Tag')
|
||||
->assertInertiaPath('data.data.0.mail_bottom.blocks.0.data.text', 'Cheers')
|
||||
->assertInertiaPath('data.data.0.from_human', '05.05.2023')
|
||||
->assertInertiaPath('data.data.0.to_human', '07.06.2023')
|
||||
->assertInertiaPath('data.data.0.from', '2023-05-05')
|
||||
->assertInertiaPath('data.data.0.participants_count', 5)
|
||||
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
||||
->assertInertiaPath('data.data.0.is_active', true)
|
||||
->assertInertiaPath('data.data.0.is_private', false)
|
||||
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
|
||||
->assertInertiaPath('data.data.0.needs_prevention', false)
|
||||
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00')
|
||||
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form]))
|
||||
->assertInertiaPath('data.data.0.links.export', route('form.export', ['form' => $form]))
|
||||
->assertInertiaPath('data.meta.links.store', route('form.store'))
|
||||
->assertInertiaPath('data.meta.links.formtemplate_index', route('formtemplate.index'))
|
||||
->assertInertiaPath('data.meta.default.name', '')
|
||||
->assertInertiaPath('data.meta.default.prevention_conditions', ['mode' => 'all', 'ifs' => []])
|
||||
->assertInertiaPath('data.meta.default.prevention_text.version', '1.0')
|
||||
->assertInertiaPath('data.meta.default.description', [])
|
||||
->assertInertiaPath('data.meta.default.excerpt', '')
|
||||
->assertInertiaPath('data.meta.default.is_active', true)
|
||||
->assertInertiaPath('data.meta.default.is_private', false)
|
||||
->assertInertiaPath('data.meta.default.mailattachments', [])
|
||||
->assertInertiaPath('data.meta.default.export', ['root' => null, 'group_by' => null, 'to_group_field' => null])
|
||||
->assertInertiaPath('data.meta.default.config', null)
|
||||
->assertInertiaPath('data.meta.base_url', url(''))
|
||||
->assertInertiaPath('data.meta.namiTypes.0', ['id' => 'Vorname', 'name' => 'Vorname'])
|
||||
->assertInertiaPath('data.meta.specialTypes.0', ['id' => 'Vorname', 'name' => 'Vorname'])
|
||||
->assertInertiaPath('data.meta.section_default.name', '');
|
||||
}
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
->assertOk()
|
||||
->assertInertiaPath('data.data.0.name', 'lala')
|
||||
->assertInertiaPath('data.data.0.config.sections.0.name', 'sname')
|
||||
->assertInertiaPath('data.data.0.id', $form->id)
|
||||
->assertInertiaPath('data.data.0.excerpt', 'fff')
|
||||
->assertInertiaPath('data.data.0.description.blocks.0.data.text', 'desc')
|
||||
->assertInertiaPath('data.data.0.mail_top.blocks.0.data.text', 'Guten Tag')
|
||||
->assertInertiaPath('data.data.0.mail_bottom.blocks.0.data.text', 'Cheers')
|
||||
->assertInertiaPath('data.data.0.from_human', '05.05.2023')
|
||||
->assertInertiaPath('data.data.0.to_human', '07.06.2023')
|
||||
->assertInertiaPath('data.data.0.from', '2023-05-05')
|
||||
->assertInertiaPath('data.data.0.zip', '12345')
|
||||
->assertInertiaPath('data.data.0.location', 'SG')
|
||||
->assertInertiaPath('data.data.0.country', 'Schweiz')
|
||||
->assertInertiaPath('data.data.0.participants_count', 5)
|
||||
->assertInertiaPath('data.data.0.leader_conditions', $leaderConditions->create())
|
||||
->assertInertiaPath('data.data.0.to', '2023-06-07')
|
||||
->assertInertiaPath('data.data.0.is_active', true)
|
||||
->assertInertiaPath('data.data.0.is_private', false)
|
||||
->assertInertiaPath('data.data.0.registration_from', '2023-05-06 04:00:00')
|
||||
->assertInertiaPath('data.data.0.needs_prevention', false)
|
||||
->assertInertiaPath('data.data.0.registration_until', '2023-04-01 05:00:00')
|
||||
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form]))
|
||||
->assertInertiaPath('data.data.0.links.export', route('form.export', ['form' => $form]))
|
||||
->assertInertiaPath('data.data.0.links.contribution', route('form.contribution', ['form' => $form]))
|
||||
->assertInertiaPath('data.meta.links.store', route('form.store'))
|
||||
->assertInertiaPath('data.meta.links.formtemplate_index', route('formtemplate.index'))
|
||||
->assertInertiaPath('data.meta.default.name', '')
|
||||
->assertInertiaPath('data.meta.default.prevention_conditions', ['mode' => 'all', 'ifs' => []])
|
||||
->assertInertiaPath('data.meta.default.prevention_text.version', '1.0')
|
||||
->assertInertiaPath('data.meta.default.description', [])
|
||||
->assertInertiaPath('data.meta.default.excerpt', '')
|
||||
->assertInertiaPath('data.meta.default.zip', '')
|
||||
->assertInertiaPath('data.meta.default.location', '')
|
||||
->assertInertiaPath('data.meta.default.country', null)
|
||||
->assertInertiaPath('data.meta.default.is_active', true)
|
||||
->assertInertiaPath('data.meta.default.is_private', false)
|
||||
->assertInertiaPath('data.meta.default.mailattachments', [])
|
||||
->assertInertiaPath('data.meta.default.export', ['root' => null, 'group_by' => null, 'to_group_field' => null])
|
||||
->assertInertiaPath('data.meta.default.config', null)
|
||||
->assertInertiaPath('data.meta.countries.0.id', 'Andorra')
|
||||
->assertInertiaPath('data.meta.countries.0.name', 'Andorra')
|
||||
->assertInertiaPath('data.meta.base_url', url(''))
|
||||
->assertInertiaPath('data.meta.namiTypes.0', ['id' => 'Vorname', 'name' => 'Vorname'])
|
||||
->assertInertiaPath('data.meta.specialTypes.0', ['id' => 'Vorname', 'name' => 'Vorname'])
|
||||
->assertInertiaPath('data.meta.section_default.name', '')
|
||||
->assertInertiaPath('data.meta.contribution_types.0.id', RdpNrwDocument::class)
|
||||
->assertInertiaPath('data.meta.contribution_types.0.name', 'RdP NRW')
|
||||
->assertInertiaPath('data.meta.default.zip', '')
|
||||
->assertInertiaPath('data.meta.default.location', '');
|
||||
});
|
||||
|
||||
public function testFormtemplatesHaveData(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')->fields([
|
||||
$this->textField('vorname')
|
||||
])])
|
||||
->mailTop(EditorRequestFactory::new()->text(10, 'lala'))
|
||||
->mailBottom(EditorRequestFactory::new()->text(10, 'lalb'))
|
||||
->create();
|
||||
it('testFormtemplatesHaveData', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
Formtemplate::factory()->name('tname')->sections([FormtemplateSectionRequest::new()->name('sname')->fields([
|
||||
$this->textField('vorname')
|
||||
])])
|
||||
->mailTop(EditorRequestFactory::new()->text(10, 'lala'))
|
||||
->mailBottom(EditorRequestFactory::new()->text(10, 'lalb'))
|
||||
->create();
|
||||
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
->assertOk()
|
||||
->assertInertiaPath('data.meta.templates.0.name', 'tname')
|
||||
->assertInertiaPath('data.meta.templates.0.name', 'tname')
|
||||
->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname')
|
||||
->assertInertiaPath('data.meta.templates.0.config.sections.0.fields.0.key', 'vorname')
|
||||
->assertInertiaPath('data.meta.templates.0.mail_top.blocks.0.data.text', 'lala')
|
||||
->assertInertiaPath('data.meta.templates.0.mail_bottom.blocks.0.data.text', 'lalb');
|
||||
}
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
->assertOk()
|
||||
->assertInertiaPath('data.meta.templates.0.name', 'tname')
|
||||
->assertInertiaPath('data.meta.templates.0.name', 'tname')
|
||||
->assertInertiaPath('data.meta.templates.0.config.sections.0.name', 'sname')
|
||||
->assertInertiaPath('data.meta.templates.0.config.sections.0.fields.0.key', 'vorname')
|
||||
->assertInertiaPath('data.meta.templates.0.mail_top.blocks.0.data.text', 'lala')
|
||||
->assertInertiaPath('data.meta.templates.0.mail_bottom.blocks.0.data.text', 'lalb');
|
||||
});
|
||||
|
||||
public function testItDisplaysExport(): void
|
||||
{
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
Form::factory()
|
||||
->name('lala')
|
||||
->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => 2, 'resource' => '/dir']), 'group_by' => 'lala', 'to_group_field' => 'abc']))
|
||||
->create();
|
||||
it('testItDisplaysExport', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
Form::factory()
|
||||
->name('lala')
|
||||
->export(ExportData::from(['root' => FileshareResourceData::from(['connection_id' => 2, 'resource' => '/dir']), 'group_by' => 'lala', 'to_group_field' => 'abc']))
|
||||
->create();
|
||||
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
->assertInertiaPath('data.data.0.export.group_by', 'lala')
|
||||
->assertInertiaPath('data.data.0.export.root.connection_id', 2)
|
||||
->assertInertiaPath('data.data.0.export.root.resource', '/dir')
|
||||
->assertInertiaPath('data.data.0.export.to_group_field', 'abc');
|
||||
}
|
||||
sleep(1);
|
||||
$this->get(route('form.index'))
|
||||
->assertInertiaPath('data.data.0.export.group_by', 'lala')
|
||||
->assertInertiaPath('data.data.0.export.root.connection_id', 2)
|
||||
->assertInertiaPath('data.data.0.export.root.resource', '/dir')
|
||||
->assertInertiaPath('data.data.0.export.to_group_field', 'abc');
|
||||
});
|
||||
|
||||
public function testItHandlesFullTextSearch(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
|
||||
Form::factory()->to(now()->addYear())->name('Rover-Spek 2025')->create();
|
||||
it('testItHandlesFullTextSearch', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
|
||||
Form::factory()->to(now()->addYear())->name('Rover-Spek 2025')->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', ['search' => 'ZEM'])
|
||||
->assertInertiaCount('data.data', 1);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaCount('data.data', 2);
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', ['search' => 'ZEM'])
|
||||
->assertInertiaCount('data.data', 1);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaCount('data.data', 2);
|
||||
});
|
||||
|
||||
public function testItDisplaysParentLinkForFormWithNamiFields(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
||||
it('testItDisplaysParentLinkForFormWithNamiFields', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$form = Form::factory()->fields([$this->namiField('mitglieder')])->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaPath('data.data.0.has_nami_field', true)
|
||||
->assertInertiaPath('data.data.0.links.participant_root_index', route('form.participant.index', ['form' => $form, 'parent' => -1]))
|
||||
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form, 'parent' => null]));
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaPath('data.data.0.has_nami_field', true)
|
||||
->assertInertiaPath('data.data.0.links.participant_root_index', route('form.participant.index', ['form' => $form, 'parent' => -1]))
|
||||
->assertInertiaPath('data.data.0.links.participant_index', route('form.participant.index', ['form' => $form, 'parent' => null]));
|
||||
});
|
||||
|
||||
public function testItDisplaysRegisterUrl(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
FormSettings::fake(['registerUrl' => 'https://example.com/form/{slug}/register']);
|
||||
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
|
||||
it('testItDisplaysRegisterUrl', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
FormSettings::fake(['registerUrl' => 'https://example.com/form/{slug}/register']);
|
||||
Form::factory()->to(now()->addYear())->name('ZEM 2024')->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])->assertInertiaPath('data.data.0.links.frontend', 'https://example.com/form/zem-2024/register');
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])->assertInertiaPath('data.data.0.links.frontend', 'https://example.com/form/zem-2024/register');
|
||||
});
|
||||
|
||||
public function testItDisplaysCopyUrl(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$form = Form::factory()->create();
|
||||
it('testItDisplaysCopyUrl', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$form = Form::factory()->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])->assertInertiaPath('data.data.0.links.copy', route('form.copy', $form));
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])->assertInertiaPath('data.data.0.links.copy', route('form.copy', $form));
|
||||
});
|
||||
|
||||
public function testItDoesntReturnInactiveForms(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
Form::factory()->isActive(false)->count(1)->create();
|
||||
Form::factory()->isActive(true)->count(2)->create();
|
||||
it('testItDoesntReturnInactiveForms', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
Form::factory()->isActive(false)->count(1)->create();
|
||||
Form::factory()->isActive(true)->count(2)->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])->assertInertiaCount('data.data', 2);
|
||||
$this->callFilter('form.index', ['inactive' => true])->assertInertiaCount('data.data', 3);
|
||||
$this->callFilter('form.index', ['inactive' => false])->assertInertiaCount('data.data', 2);
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])->assertInertiaCount('data.data', 2);
|
||||
$this->callFilter('form.index', ['inactive' => true])->assertInertiaCount('data.data', 3);
|
||||
$this->callFilter('form.index', ['inactive' => false])->assertInertiaCount('data.data', 2);
|
||||
});
|
||||
|
||||
public function testItOrdersByStartDateDesc(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create();
|
||||
$form2 = Form::factory()->from(now()->addDays(3))->to(now()->addYear())->create();
|
||||
$form3 = Form::factory()->from(now()->addDays(2))->to(now()->addYear())->create();
|
||||
it('testItOrdersByStartDateDesc', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
$form1 = Form::factory()->from(now()->addDays(4))->to(now()->addYear())->create();
|
||||
$form2 = Form::factory()->from(now()->addDays(3))->to(now()->addYear())->create();
|
||||
$form3 = Form::factory()->from(now()->addDays(2))->to(now()->addYear())->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaPath('data.data.0.id', $form3->id)
|
||||
->assertInertiaPath('data.data.1.id', $form2->id)
|
||||
->assertInertiaPath('data.data.2.id', $form1->id);
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaPath('data.data.0.id', $form3->id)
|
||||
->assertInertiaPath('data.data.1.id', $form2->id)
|
||||
->assertInertiaPath('data.data.2.id', $form1->id);
|
||||
});
|
||||
|
||||
public function testItShowsPastEvents(): void
|
||||
{
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
Form::factory()->count(5)->to(now()->subDays(2))->create();
|
||||
Form::factory()->count(3)->to(now()->subDays(5))->create();
|
||||
Form::factory()->count(2)->to(now()->addDays(3))->create();
|
||||
it('testItShowsPastEvents', function () {
|
||||
$this->withoutExceptionHandling()->login()->loginNami();
|
||||
Form::factory()->count(5)->to(now()->subDays(2))->create();
|
||||
Form::factory()->count(3)->to(now()->subDays(5))->create();
|
||||
Form::factory()->count(2)->to(now()->addDays(3))->create();
|
||||
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', ['past' => true])
|
||||
->assertInertiaCount('data.data', 10);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaCount('data.data', 2);
|
||||
}
|
||||
}
|
||||
sleep(1);
|
||||
$this->callFilter('form.index', ['past' => true])
|
||||
->assertInertiaCount('data.data', 10);
|
||||
$this->callFilter('form.index', [])
|
||||
->assertInertiaCount('data.data', 2);
|
||||
});
|
||||
|
|
|
@ -22,8 +22,8 @@ class IndexTest extends TestCase
|
|||
$response = $this->get('/contribution');
|
||||
|
||||
$this->assertInertiaHas([
|
||||
'class' => RdpNrwDocument::class,
|
||||
'title' => 'Für RdP NRW erstellen',
|
||||
'id' => RdpNrwDocument::class,
|
||||
'name' => 'RdP NRW',
|
||||
], $response, 'compilers.0');
|
||||
$this->assertInertiaHas([
|
||||
'id' => $country->id,
|
||||
|
|
|
@ -89,7 +89,7 @@ it('testItCompilesContributionDocumentsViaApi', function (string $type, array $b
|
|||
'eventName' => 'Super tolles Lager',
|
||||
'type' => $type,
|
||||
'zipLocation' => '42777 SG',
|
||||
'member_data' => [
|
||||
'members' => [
|
||||
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Max', 'lastname' => 'Muster']),
|
||||
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster']),
|
||||
],
|
||||
|
@ -100,6 +100,28 @@ it('testItCompilesContributionDocumentsViaApi', function (string $type, array $b
|
|||
Tex::assertCompiled($type, fn ($document) => $document->hasAllContent($bodyChecks));
|
||||
})->with('contribution-assertions');
|
||||
|
||||
it('compiles when gender is null', function () {
|
||||
$this->withoutExceptionHandling();
|
||||
Tex::spy();
|
||||
Passport::actingAsClient(Client::factory()->create(), ['contribution-generate']);
|
||||
|
||||
$response = $this->postJson('/api/contribution-generate', [
|
||||
'country' => Country::factory()->create()->id,
|
||||
'dateFrom' => '1991-06-15',
|
||||
'dateUntil' => '1991-06-16',
|
||||
'eventName' => 'Super tolles Lager',
|
||||
'type' => CitySolingenDocument::class,
|
||||
'zipLocation' => '42777 SG',
|
||||
'members' => [
|
||||
ContributionMemberApiRequestFactory::new()->create(['address' => 'Maxstr 44', 'zip' => '42719', 'firstname' => 'Jane', 'lastname' => 'Muster', 'gender' => null]),
|
||||
],
|
||||
]);
|
||||
|
||||
$response->assertSessionDoesntHaveErrors();
|
||||
$response->assertOk();
|
||||
Tex::assertCompiled(CitySolingenDocument::class, fn () => true);
|
||||
});
|
||||
|
||||
it('testInputShouldBeBase64EncodedJson', function (string $payload) {
|
||||
$this->login()->loginNami();
|
||||
|
||||
|
|
|
@ -270,6 +270,14 @@ it('testItSavesParticipantAsModel', function () {
|
|||
$this->assertEquals('Abraham', $participants->first()->data['spitzname']);
|
||||
});
|
||||
|
||||
|
||||
it('cannot register when event is inactive', function () {
|
||||
$this->login()->loginNami();
|
||||
$form = Form::factory()->isActive(false)->create();
|
||||
|
||||
$this->register($form, [])->assertJsonValidationErrors(['event' => 'Anmeldung zzt nicht möglich.']);
|
||||
});
|
||||
|
||||
it('testItCannotRegisterWhenRegistrationFromReached', function () {
|
||||
$this->login()->loginNami();
|
||||
$form = Form::factory()->registrationFrom(now()->addDay())->create();
|
||||
|
|
|
@ -53,6 +53,8 @@ class FormRequest extends RequestFactory
|
|||
'export' => ExportData::from([])->toArray(),
|
||||
'needs_prevention' => $this->faker->boolean(),
|
||||
'prevention_text' => EditorRequestFactory::new()->create(),
|
||||
'zip' => (string) $this->faker->numberBetween(10, 6666),
|
||||
'location' => (string) $this->faker->city(),
|
||||
'prevention_conditions' => Condition::defaults()->toArray(),
|
||||
];
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Contribution\Enums\Country;
|
||||
use App\Fileshare\Data\FileshareResourceData;
|
||||
use App\Form\Data\ExportData;
|
||||
use App\Form\Enums\NamiType;
|
||||
|
@ -32,6 +33,9 @@ it('testItStoresForm', function () {
|
|||
->mailTop(EditorRequestFactory::new()->text(11, 'lala'))
|
||||
->mailBottom(EditorRequestFactory::new()->text(12, 'lalab'))
|
||||
->headerImage('htzz.jpg')
|
||||
->zip('12345')
|
||||
->location('Solingen')
|
||||
->country('Schweiz')
|
||||
->sections([FormtemplateSectionRequest::new()->name('sname')->fields([$this->textField()->namiType(NamiType::BIRTHDAY)->forMembers(false)->hint('hhh')])])
|
||||
->fake();
|
||||
|
||||
|
@ -55,6 +59,9 @@ it('testItStoresForm', function () {
|
|||
$this->assertFalse($form->config->sections->get(0)->fields->get(0)->forMembers);
|
||||
$this->assertCount(1, $form->getMedia('headerImage'));
|
||||
$this->assertEquals('formname.jpg', $form->getMedia('headerImage')->first()->file_name);
|
||||
$this->assertEquals('Solingen', $form->location);
|
||||
$this->assertEquals('12345', $form->zip);
|
||||
$this->assertEquals(Country::CH, $form->country);
|
||||
Event::assertDispatched(Succeeded::class, fn(Succeeded $event) => $event->message === 'Veranstaltung gespeichert.');
|
||||
$this->assertFrontendCacheCleared();
|
||||
});
|
||||
|
@ -71,14 +78,16 @@ it('testItStoresDefaultSorting', function () {
|
|||
$this->assertFalse(false, $form->meta['sorting']['direction']);
|
||||
});
|
||||
|
||||
it('testRegistrationDatesCanBeNull', function () {
|
||||
it('testValuesCanBeNull', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
|
||||
$this->postJson(route('form.store'), FormRequest::new()->registrationFrom(null)->registrationUntil(null)->create())->assertOk();
|
||||
$this->postJson(route('form.store'), FormRequest::new()->registrationFrom(null)->registrationUntil(null)->location(null)->zip(null)->create())->assertOk();
|
||||
|
||||
$this->assertDatabaseHas('forms', [
|
||||
'registration_until' => null,
|
||||
'registration_from' => null,
|
||||
'zip' => null,
|
||||
'location' => null,
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use App\Form\Models\Form;
|
|||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
use Tests\RequestFactories\ConditionRequestFactory;
|
||||
|
||||
uses(DatabaseTransactions::class);
|
||||
uses(CreatesFormFields::class);
|
||||
|
@ -118,6 +119,20 @@ it('testItUpdatesActiveState', function () {
|
|||
$this->assertTrue($form->fresh()->is_active);
|
||||
});
|
||||
|
||||
it('updates meta info', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$request = FormRequest::new()->zip('12345')->location('Musterstadt')->country('Schweiz')->create();
|
||||
|
||||
$this->patchJson(route('form.update', ['form' => $form]), $request)->assertOk();
|
||||
test()->assertDatabaseHas('forms', [
|
||||
'id' => $form->id,
|
||||
'zip' => '12345',
|
||||
'location' => 'Musterstadt',
|
||||
'country' => 'Schweiz',
|
||||
]);
|
||||
});
|
||||
|
||||
it('testItUpdatesPrivateState', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
|
@ -156,3 +171,16 @@ it('testItUpdatesPrevention', function () {
|
|||
$this->assertEquals('lorem ipsum', $form->fresh()->prevention_text->blocks[0]['data']['text']);
|
||||
$this->assertEquals(['mode' => 'all', 'ifs' => [['field' => 'vorname', 'value' => 'Max', 'comparator' => 'isEqual']]], $form->fresh()->prevention_conditions->toArray());
|
||||
});
|
||||
|
||||
it('updates leader conditions', function () {
|
||||
$this->login()->loginNami()->withoutExceptionHandling();
|
||||
$form = Form::factory()->create();
|
||||
$condition = ConditionRequestFactory::new()->whenField('A', 'TT')->create();
|
||||
$payload = FormRequest::new()
|
||||
->preventionText(EditorRequestFactory::new()->text(10, 'lorem ipsum'))
|
||||
->state(['leader_conditions' => ConditionRequestFactory::new()->whenField('A', 'TT')])
|
||||
->create();
|
||||
|
||||
$this->patchJson(route('form.update', ['form' => $form]), $payload);
|
||||
$this->assertEquals($condition, $form->fresh()->leader_conditions->toArray());
|
||||
});
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Form;
|
||||
|
||||
use App\Contribution\Documents\CitySolingenDocument;
|
||||
use App\Contribution\Documents\RdpNrwDocument;
|
||||
use App\Country;
|
||||
use App\Form\Enums\SpecialType;
|
||||
use App\Form\Models\Form;
|
||||
use App\Form\Models\Participant;
|
||||
use App\Form\Requests\FormCompileRequest;
|
||||
use App\Gender;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\Lib\CreatesFormFields;
|
||||
use Tests\RequestFactories\ConditionRequestFactory;
|
||||
use Zoomyboy\Tex\Tex;
|
||||
|
||||
uses(DatabaseTransactions::class);
|
||||
uses(CreatesFormFields::class);
|
||||
|
||||
mutates(FormCompileRequest::class);
|
||||
|
||||
beforeEach(function() {
|
||||
Country::factory()->create();
|
||||
Gender::factory()->male()->create();
|
||||
Gender::factory()->female()->create();
|
||||
Tex::spy();
|
||||
$this->login()->loginNami();
|
||||
});
|
||||
|
||||
it('doesnt create document when no special fields given', function (array $fields, string $field, string $message, string $type) {
|
||||
$form = Form::factory()
|
||||
->fields($fields)
|
||||
->has(Participant::factory())
|
||||
->create();
|
||||
|
||||
generate($type, $form, true)->assertJsonValidationErrors([$field => $message]);
|
||||
})
|
||||
->with([
|
||||
[fn() => [], 'FIRSTNAME', 'Kein Feld für Vorname vorhanden.'],
|
||||
[fn() => [test()->textField('f')->specialType(SpecialType::FIRSTNAME)], 'LASTNAME', 'Kein Feld für Nachname vorhanden.'],
|
||||
[fn() => [test()->textField('f')->specialType(SpecialType::FIRSTNAME), test()->textField('l')->specialType(SpecialType::LASTNAME)], 'BIRTHDAY', 'Kein Feld für Geburtsdatum vorhanden.'],
|
||||
[fn() => [test()->textField('f')->specialType(SpecialType::FIRSTNAME), test()->textField('l')->specialType(SpecialType::LASTNAME), test()->dateField('b')->specialType(SpecialType::BIRTHDAY)], 'ZIP', 'Kein Feld für PLZ vorhanden.'],
|
||||
[fn() => [test()->textField('f')->specialType(SpecialType::FIRSTNAME), test()->textField('l')->specialType(SpecialType::LASTNAME), test()->dateField('b')->specialType(SpecialType::BIRTHDAY), test()->dateField('p')->specialType(SpecialType::ZIP)], 'LOCATION', 'Kein Feld für Ort vorhanden.'],
|
||||
])->with('contribution-documents');
|
||||
|
||||
it('validates special types of each document', function (string $type, array $fields, string $field, string $message) {
|
||||
$form = Form::factory()->fields([
|
||||
test()->textField('f')->specialType(SpecialType::FIRSTNAME),
|
||||
test()->textField('l')->specialType(SpecialType::LASTNAME),
|
||||
test()->dateField('b')->specialType(SpecialType::BIRTHDAY),
|
||||
test()->dateField('p')->specialType(SpecialType::ZIP),
|
||||
test()->dateField('l')->specialType(SpecialType::LOCATION),
|
||||
...$fields,
|
||||
])
|
||||
->has(Participant::factory())
|
||||
->create();
|
||||
|
||||
generate($type, $form, true)->assertJsonValidationErrors([$field => $message]);
|
||||
})
|
||||
->with([
|
||||
[CitySolingenDocument::class, [], 'ADDRESS', 'Kein Feld für Adresse vorhanden.'],
|
||||
[RdpNrwDocument::class, [], 'GENDER', 'Kein Feld für Geschlecht vorhanden.'],
|
||||
]);
|
||||
|
||||
it('throws error when not validating but fields are not present', function () {
|
||||
$form = Form::factory()->fields([])
|
||||
->has(Participant::factory())
|
||||
->create();
|
||||
|
||||
generate(CitySolingenDocument::class, $form, false)->assertStatus(422);
|
||||
});
|
||||
|
||||
it('throws error when form doesnt have meta', function () {
|
||||
$form = Form::factory()->fields([])
|
||||
->has(Participant::factory())
|
||||
->zip('')
|
||||
->location('')
|
||||
->create();
|
||||
|
||||
generate(CitySolingenDocument::class, $form, false)->assertStatus(422)->assertJsonValidationErrors([
|
||||
'zip' => 'PLZ ist erforderlich.',
|
||||
'location' => 'Ort ist erforderlich.'
|
||||
]);
|
||||
});
|
||||
|
||||
it('throws error when form doesnt have participants', function () {
|
||||
$form = Form::factory()->fields([])->create();
|
||||
|
||||
generate(CitySolingenDocument::class, $form, true)->assertJsonValidationErrors(['participants' => 'Veranstaltung besitzt noch keine Teilnehmer*innen.']);
|
||||
});
|
||||
|
||||
dataset('default-form-contribution', fn () => [
|
||||
[
|
||||
['fn' => 'Baum', 'ln' => 'Muster', 'bd' => '1991-05-06', 'zip' => '33333', 'loc' => 'Musterstadt', 'add' => 'Laastr 4', 'gen' => 'weiblich'],
|
||||
fn () => [
|
||||
test()->textField('fn')->specialType(SpecialType::FIRSTNAME),
|
||||
test()->textField('ln')->specialType(SpecialType::LASTNAME),
|
||||
test()->dateField('bd')->specialType(SpecialType::BIRTHDAY),
|
||||
test()->dateField('zip')->specialType(SpecialType::ZIP),
|
||||
test()->dateField('loc')->specialType(SpecialType::LOCATION),
|
||||
test()->dateField('add')->specialType(SpecialType::ADDRESS),
|
||||
test()->dateField('gen')->specialType(SpecialType::GENDER),
|
||||
]
|
||||
]
|
||||
]);
|
||||
|
||||
dataset('form-contributions', fn () => [
|
||||
[
|
||||
[],
|
||||
[],
|
||||
CitySolingenDocument::class,
|
||||
['Baum', 'Muster', '1991', 'Musterstadt', 'Laastr 4', '33333'],
|
||||
],
|
||||
[
|
||||
['gen' => 'männlich'],
|
||||
[],
|
||||
RdpNrwDocument::class,
|
||||
['{m}'],
|
||||
],
|
||||
[
|
||||
['gen' => 'weiblich'],
|
||||
[],
|
||||
RdpNrwDocument::class,
|
||||
['{w}'],
|
||||
],
|
||||
]);
|
||||
|
||||
it('creates document with participant data', function (array $defaultData, array $defaultFields, array $newData, array $newFields, string $document, array $expected) {
|
||||
$form = Form::factory()->fields([
|
||||
...$defaultFields,
|
||||
...$newFields,
|
||||
])
|
||||
->has(Participant::factory()->data([...$defaultData, ...$newData]))
|
||||
->create();
|
||||
|
||||
generate($document, $form, false)->assertOk();
|
||||
Tex::assertCompiled($document, fn($document) => $document->hasAllContent($expected));
|
||||
})->with('default-form-contribution')->with('form-contributions');
|
||||
|
||||
it('creates document with is leader', function (array $defaultData, array $fields) {
|
||||
$form = Form::factory()->fields([
|
||||
...$fields,
|
||||
test()->dropdownField('leader')->options(['L', 'NL']),
|
||||
])
|
||||
->has(Participant::factory()->data([...$defaultData, 'leader' => 'L']))
|
||||
->leaderConditions(ConditionRequestFactory::new()->whenField('leader', 'L')->create())
|
||||
->create();
|
||||
|
||||
generate(RdpNrwDocument::class, $form, false)->assertOk();
|
||||
Tex::assertCompiled(RdpNrwDocument::class, fn($document) => $document->hasAllContent(['{L}']));
|
||||
})->with('default-form-contribution');
|
||||
|
||||
it('creates document with form meta', function () {
|
||||
$form = Form::factory()->fields([
|
||||
test()->textField('fn')->specialType(SpecialType::FIRSTNAME),
|
||||
test()->textField('ln')->specialType(SpecialType::LASTNAME),
|
||||
test()->dateField('bd')->specialType(SpecialType::BIRTHDAY),
|
||||
test()->dateField('zip')->specialType(SpecialType::ZIP),
|
||||
test()->dateField('loc')->specialType(SpecialType::LOCATION),
|
||||
test()->dateField('add')->specialType(SpecialType::ADDRESS),
|
||||
test()->dateField('gen')->specialType(SpecialType::GENDER),
|
||||
])
|
||||
->has(Participant::factory()->data(['fn' => 'Baum', 'ln' => 'Muster', 'bd' => '1991-05-06', 'zip' => '33333', 'loc' => 'Musterstadt', 'add' => 'Laastr 4', 'gen' => 'weiblich']))
|
||||
->name('Sommerlager')
|
||||
->from('2008-06-20')
|
||||
->to('2008-06-22')
|
||||
->zip('12345')
|
||||
->location('Frankfurt')
|
||||
->create();
|
||||
|
||||
generate(RdpNrwDocument::class, $form, false)->assertOk();
|
||||
Tex::assertCompiled(RdpNrwDocument::class, fn($document) => $document->hasAllContent(['20.06.2008', '22.06.2008', '12345 Frankfurt']));
|
||||
});
|
||||
|
||||
function generate(string $document, Form $form, bool $validate) {
|
||||
return test()->json('GET', route('form.contribution', [
|
||||
'payload' => test()->filterString(['type' => $document]),
|
||||
'form' => $form,
|
||||
'validate' => $validate ? '1' : '0'
|
||||
]));
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\RequestFactories;
|
||||
|
||||
use Worksome\RequestFactories\RequestFactory;
|
||||
use App\Lib\Editor\Condition;
|
||||
|
||||
class ConditionRequestFactory extends RequestFactory
|
||||
{
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'mode' => 'all',
|
||||
'ifs' => [],
|
||||
];
|
||||
}
|
||||
|
||||
public function whenField(string $field, string $value): self {
|
||||
return $this->state([
|
||||
'ifs' => [
|
||||
['field' => $field, 'value' => $value, 'comparator' => 'isEqual']
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function toData(): Condition {
|
||||
return Condition::from($this->create());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue