Add preventAgainst to frontend
This commit is contained in:
parent
e97d39abd7
commit
5361c3930f
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Prevention\Actions;
|
||||
|
||||
use App\Prevention\Enums\Prevention;
|
||||
use App\Prevention\PreventionSettings;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Lorisleiva\Actions\Concerns\AsAction;
|
||||
|
@ -14,6 +15,9 @@ class SettingApiAction
|
|||
{
|
||||
return response()->json([
|
||||
'data' => app(PreventionSettings::class)->toFrontend(),
|
||||
'meta' => [
|
||||
'preventAgainsts' => Prevention::values(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ class SettingStoreAction
|
|||
$settings->freshRememberInterval = $request->freshRememberInterval;
|
||||
$settings->active = $request->active;
|
||||
$settings->yearlyMemberFilter = FilterScope::from($request->yearlyMemberFilter);
|
||||
$settings->preventAgainst = $request->preventAgainst;
|
||||
$settings->save();
|
||||
|
||||
Succeeded::message('Einstellungen gespeichert.')->dispatch();
|
||||
|
|
|
@ -49,4 +49,15 @@ enum Prevention
|
|||
'tooltip' => $case->tooltip($preventions->pluck('type')->doesntContain($case)),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function values(): array
|
||||
{
|
||||
return collect(static::cases())->map(fn($case) => [
|
||||
'id' => $case->name,
|
||||
'name' => $case->text(),
|
||||
])->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ class PreventionSettings extends LocalSettings
|
|||
public int $freshRememberInterval;
|
||||
public bool $active;
|
||||
public FilterScope $yearlyMemberFilter;
|
||||
public array $preventAgainst;
|
||||
|
||||
public static function group(): string
|
||||
{
|
||||
|
|
|
@ -12,5 +12,6 @@ return new class extends SettingsMigration
|
|||
$this->migrator->add('prevention.freshRememberInterval', 12);
|
||||
$this->migrator->add('prevention.active', false);
|
||||
$this->migrator->add('prevention.yearlyMemberFilter', FilterScope::from([])->toArray());
|
||||
$this->migrator->add('prevention.preventAgainst', []);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
</div>
|
||||
<f-editor v-if="active === 1" id="yearlymail" v-model="data.yearlymail" label="Jährliche Präventions-Erinnerung"></f-editor>
|
||||
<f-member-filter id="yearly_member_filter" v-model="data.yearlyMemberFilter" label="nur für folgende Mitglieder erlauben" />
|
||||
<f-multipleselect id="prevent_against" v-model="data.preventAgainst" :options="meta.preventAgainsts" label="An diese Dokumente erinnern" size="sm"></f-multipleselect>
|
||||
</div>
|
||||
</form>
|
||||
</setting-layout>
|
||||
|
@ -38,7 +39,7 @@ const tabs = [
|
|||
];
|
||||
const active = ref(0);
|
||||
|
||||
const { axios, data, reload } = useApiIndex('/api/prevention', 'prevention');
|
||||
const { axios, data, meta, reload } = useApiIndex('/api/prevention', 'prevention');
|
||||
const loaded = ref(false);
|
||||
|
||||
async function load() {
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Tests\Feature\Prevention;
|
||||
|
||||
use App\Member\FilterScope;
|
||||
use App\Prevention\Enums\Prevention;
|
||||
use App\Prevention\PreventionSettings;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use Tests\RequestFactories\EditorRequestFactory;
|
||||
|
@ -27,6 +28,7 @@ it('receives settings', function () {
|
|||
'weeks' => 9,
|
||||
'freshRememberInterval' => 11,
|
||||
'active' => true,
|
||||
'preventAgainst' => [Prevention::MOREPS->name],
|
||||
'yearlyMemberFilter' => FilterScope::from([
|
||||
'memberships' => [['group_ids' => [33]]],
|
||||
'search' => 'searchstring',
|
||||
|
@ -40,7 +42,10 @@ it('receives settings', function () {
|
|||
->assertJsonPath('data.active', true)
|
||||
->assertJsonPath('data.freshRememberInterval', '11')
|
||||
->assertJsonPath('data.yearlyMemberFilter.search', 'searchstring')
|
||||
->assertJsonPath('data.yearlyMemberFilter.memberships.0.group_ids.0', 33);
|
||||
->assertJsonPath('data.yearlyMemberFilter.memberships.0.group_ids.0', 33)
|
||||
->assertJsonPath('data.preventAgainst', ['MOREPS'])
|
||||
->assertJsonPath('meta.preventAgainsts.0.name', 'erweitertes Führungszeugnis')
|
||||
->assertJsonPath('meta.preventAgainsts.0.id', 'EFZ');
|
||||
});
|
||||
|
||||
it('testItStoresSettings', function () {
|
||||
|
@ -52,6 +57,7 @@ it('testItStoresSettings', function () {
|
|||
'weeks' => 9,
|
||||
'freshRememberInterval' => 11,
|
||||
'active' => true,
|
||||
'preventAgainst' => ['EFZ'],
|
||||
'yearlyMemberFilter' => [
|
||||
'memberships' => [['group_ids' => 33]],
|
||||
'search' => 'searchstring',
|
||||
|
@ -64,4 +70,5 @@ it('testItStoresSettings', function () {
|
|||
test()->assertTrue(app(PreventionSettings::class)->active);
|
||||
test()->assertEquals([['group_ids' => 33]], app(PreventionSettings::class)->yearlyMemberFilter->memberships);
|
||||
test()->assertEquals('searchstring', app(PreventionSettings::class)->yearlyMemberFilter->search);
|
||||
test()->assertEquals('EFZ', app(PreventionSettings::class)->preventAgainst[0]);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue