--wip-- [skip ci]

This commit is contained in:
philipp lang 2024-08-01 20:28:59 +02:00
parent 5f31489bab
commit 14925f6cb5
17 changed files with 70 additions and 152 deletions

View File

@ -1,21 +0,0 @@
<?php
namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare;
use App\Fileshare\Resources\FileshareResource;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\Concerns\AsAction;
class FileshareApiIndexAction
{
use AsAction;
public function handle(): AnonymousResourceCollection
{
session()->put('menu', 'setting');
session()->put('title', 'Datei-Verbindungen');
return FileshareResource::collection(Fileshare::paginate(15));
}
}

View File

@ -21,10 +21,8 @@ class FileshareSettings extends LocalSettings
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function viewData(): array public function data()
{ {
return [ return FileshareResource::collection(Fileshare::paginate(15));
'data' => FileshareResource::collection(Fileshare::paginate(15))
];
} }
} }

View File

@ -38,6 +38,10 @@ class UserResource extends JsonResource
public static function meta(): array public static function meta(): array
{ {
return [ return [
'default' => [
'firstname' => '',
'lastname' => '',
],
'links' => [] 'links' => []
]; ];
} }

View File

@ -18,14 +18,6 @@ class MailgatewaySettings extends LocalSettings
return 'E-Mail-Verbindungen'; return 'E-Mail-Verbindungen';
} }
/**
* @inheritdoc
*/
public function meta(): array
{
return MailgatewayResource::meta();
}
/** /**
* @inheritdoc * @inheritdoc
*/ */

View File

@ -41,11 +41,14 @@ class ModuleSettings extends LocalSettings implements Storeable
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function meta(): array public function data(): array
{ {
return [ return [
...parent::meta(), ...parent::data(),
'modules' => Module::forSelect() 'meta' => [
...parent::data()['meta'],
'modules' => Module::forSelect(),
]
]; ];
} }
} }

View File

@ -20,7 +20,6 @@ class ViewAction
return Inertia::render('setting/' . ucfirst($settingGroup::group()), [ return Inertia::render('setting/' . ucfirst($settingGroup::group()), [
'data' => $settingGroup->data(), 'data' => $settingGroup->data(),
'settingMenu' => app(SettingFactory::class)->getShare(), 'settingMenu' => app(SettingFactory::class)->getShare(),
'meta' => $settingGroup->meta(),
]); ]);
} }
} }

View File

@ -19,21 +19,19 @@ abstract class LocalSettings extends Settings
return $this->url(); return $this->url();
} }
public function meta(): array
{
return [
'links' => [
'store' => $this->storeUrl(),
]
];
}
/** /**
* @return mixed * @return mixed
*/ */
public function data() public function data()
{ {
return $this->toArray(); return [
'data' => $this->toArray(),
'meta' => [
'links' => [
'store' => $this->storeUrl(),
]
]
];
} }
public function beforeSave(ActionRequest $request): void public function beforeSave(ActionRequest $request): void

View File

@ -66,9 +66,12 @@ class NamiSettings extends LocalSettings implements Storeable
public function data(): array public function data(): array
{ {
return [ return [
'mglnr' => $this->mglnr, ...parent::data(),
'password' => '', 'data' => [
'default_group_id' => $this->default_group_id, 'mglnr' => $this->mglnr,
'password' => '',
'default_group_id' => $this->default_group_id,
],
]; ];
} }
} }

View File

@ -1,18 +0,0 @@
<?php
namespace App\User\Actions;
use App\Http\Resources\UserResource;
use App\User;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Lorisleiva\Actions\Concerns\AsAction;
class IndexAction
{
use AsAction;
public function handle(): AnonymousResourceCollection
{
return UserResource::collection(User::orderByRaw('lastname, firstname')->get());
}
}

View File

@ -18,19 +18,11 @@ class UserSettings extends LocalSettings
return 'Benutzer'; return 'Benutzer';
} }
/**
* @inheritdoc
*/
public function meta(): array
{
return UserResource::meta();
}
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function data() public function data()
{ {
return UserResource::collection(User::orderByRaw('lastname, firstname')->get())->toArray(request()); return UserResource::collection(User::orderByRaw('lastname, firstname')->get());
} }
} }

View File

@ -76,10 +76,12 @@
</template> </template>
<script lang="js" setup> <script lang="js" setup>
import { useApiIndex } from '../../composables/useApiIndex.js'; import { useIndex, indexProps } from '../../composables/useInertiaApiIndex.js';
import SettingLayout from '../setting/Layout.vue'; import SettingLayout from '../setting/Layout.vue';
const { meta, data, reload, create, edit, cancel, single, submit } = useApiIndex('/api/fileshare', 'fileshare'); const props = defineProps(indexProps);
const { meta, data, reload, create, edit, cancel, single, submit } = useIndex(props.data, 'fileshare');
function getType(type) { function getType(type) {
if (!type) { if (!type) {
@ -89,6 +91,4 @@ function getType(type) {
} }
return meta.value.types.find((t) => t.id === type); return meta.value.types.find((t) => t.id === type);
} }
reload();
</script> </script>

View File

@ -5,6 +5,10 @@
</template> </template>
<ui-popup v-if="single !== null" :heading="single.id ? 'Benutzer bearbeiten' : 'Neuer Benutzer'" @close="cancel"> <ui-popup v-if="single !== null" :heading="single.id ? 'Benutzer bearbeiten' : 'Neuer Benutzer'" @close="cancel">
<form @submit.prevent="submit"> <form @submit.prevent="submit">
<section class="grid grid-cols-2 gap-3 mt-6">
<f-text id="firstname" v-model="single.firstname" name="firstname" label="Vorname" required></f-text>
<f-text id="lastname" v-model="single.lastname" name="lastname" label="Nachname" required></f-text>
</section>
<section class="flex mt-4 space-x-2"> <section class="flex mt-4 space-x-2">
<ui-button type="submit" class="btn-danger">Speichern</ui-button> <ui-button type="submit" class="btn-danger">Speichern</ui-button>
<ui-button class="btn-primary" @click.prevent="single = null">Abbrechen</ui-button> <ui-button class="btn-primary" @click.prevent="single = null">Abbrechen</ui-button>
@ -41,21 +45,9 @@
<script lang="js" setup> <script lang="js" setup>
import SettingLayout from '../setting/Layout.vue'; import SettingLayout from '../setting/Layout.vue';
const props = defineProps({
data: {
type: Object,
required: true,
},
meta: {
type: Object,
required: false,
default: () => {
return {};
},
},
});
import {indexProps, useIndex} from '../../composables/useInertiaApiIndex.js'; import {indexProps, useIndex} from '../../composables/useInertiaApiIndex.js';
const {data, meta, single, create} = useIndex(props); const props = defineProps(indexProps);
const {data, cancel, meta, single, create, edit} = useIndex(props.data);
</script> </script>

View File

@ -2,7 +2,7 @@ import {useIndex} from '../../composables/useInertiaApiIndex.js';
import SettingLayout from './Layout.vue'; import SettingLayout from './Layout.vue';
export function useSettings(props) { export function useSettings(props) {
const {data, meta, router} = useIndex(props); const {data, meta, router} = useIndex(props.data);
function submit() { function submit() {
router.post(meta.value.links.store, {...data.value}); router.post(meta.value.links.store, {...data.value});
@ -19,19 +19,10 @@ export function useSettings(props) {
const props = { const props = {
data: { data: {
type: Object,
required: true,
},
settingMenu: {
type: Object,
required: true,
},
meta: {
type: Object,
required: false,
default: () => { default: () => {
return {}; return {data: [], meta: {}};
}, },
type: Object,
}, },
}; };

View File

@ -4,10 +4,8 @@ use App\Contribution\Actions\GenerateApiAction as ContributionGenerateApiAction;
use App\Form\Actions\FormApiListAction; use App\Form\Actions\FormApiListAction;
use App\Form\Actions\RegisterAction; use App\Form\Actions\RegisterAction;
use App\Group\Actions\GroupApiIndexAction; use App\Group\Actions\GroupApiIndexAction;
use App\User\Actions\IndexAction as UserIndexAction;
Route::post('/contribution-generate', ContributionGenerateApiAction::class)->name('api.contribution.generate')->middleware('client:contribution-generate'); Route::post('/contribution-generate', ContributionGenerateApiAction::class)->name('api.contribution.generate')->middleware('client:contribution-generate');
Route::post('/form/{form}/register', RegisterAction::class)->name('form.register'); Route::post('/form/{form}/register', RegisterAction::class)->name('form.register');
Route::get('/group/{group?}', GroupApiIndexAction::class)->name('api.group'); Route::get('/group/{group?}', GroupApiIndexAction::class)->name('api.group');
Route::get('/form', FormApiListAction::class)->name('api.form.index'); Route::get('/form', FormApiListAction::class)->name('api.form.index');
Route::get('/user', UserIndexAction::class)->name('api.user.index');

View File

@ -19,7 +19,6 @@ use App\Invoice\Actions\InvoiceStoreAction;
use App\Course\Actions\CourseUpdateAction; use App\Course\Actions\CourseUpdateAction;
use App\Dashboard\Actions\IndexAction as DashboardIndexAction; use App\Dashboard\Actions\IndexAction as DashboardIndexAction;
use App\Efz\ShowEfzDocumentAction; use App\Efz\ShowEfzDocumentAction;
use App\Fileshare\Actions\FileshareApiIndexAction;
use App\Fileshare\Actions\FileshareStoreAction; use App\Fileshare\Actions\FileshareStoreAction;
use App\Fileshare\Actions\FileshareUpdateAction; use App\Fileshare\Actions\FileshareUpdateAction;
use App\Fileshare\Actions\ListFilesAction; use App\Fileshare\Actions\ListFilesAction;
@ -182,6 +181,5 @@ Route::group(['middleware' => 'auth:web'], function (): void {
// ------------------------------------ fileshare ----------------------------------- // ------------------------------------ fileshare -----------------------------------
Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store'); Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store');
Route::patch('/fileshare/{fileshare}', FileshareUpdateAction::class)->name('fileshare.update'); Route::patch('/fileshare/{fileshare}', FileshareUpdateAction::class)->name('fileshare.update');
Route::get('/api/fileshare', FileshareApiIndexAction::class)->name('api.fileshare.index');
Route::post('/api/fileshare/{fileshare}/files', ListFilesAction::class)->name('api.fileshare.files'); Route::post('/api/fileshare/{fileshare}/files', ListFilesAction::class)->name('api.fileshare.files');
}); });

View File

@ -12,24 +12,19 @@ class UserIndexTest extends TestCase
use DatabaseTransactions; use DatabaseTransactions;
public function testItOpensSettingsPage(): void public function testItOpensSettingsPage(): void
{
$this->login()->loginNami();
$this->get(route('setting.view', ['settingGroup' => 'user']))
->assertOk()
->assertComponent('setting/User');
}
public function testItListsUsers(): void
{ {
$this->login()->loginNami(); $this->login()->loginNami();
auth()->user()->update(['firstname' => 'Jane', 'lastname' => 'Doe']); auth()->user()->update(['firstname' => 'Jane', 'lastname' => 'Doe']);
User::factory()->create(['firstname' => 'John', 'lastname' => 'Doe']); User::factory()->create(['firstname' => 'John', 'lastname' => 'Doe']);
$anna = User::factory()->create(['firstname' => 'Anna', 'lastname' => 'Doe']); $anna = User::factory()->create(['firstname' => 'Anna', 'lastname' => 'Doe']);
$this->get(route('api.user.index')) $this->get(route('setting.view', ['settingGroup' => 'user']))
->assertJsonPath('data.0.firstname', 'Anna') ->assertOk()
->assertJsonPath('data.0.lastname', 'Doe') ->assertComponent('setting/User')
->assertJsonPath('data.0.id', $anna->id) ->assertInertiaPath('data.data.0.firstname', 'Anna')
->assertJsonPath('data.1.firstname', 'Jane') ->assertInertiaPath('data.data.0.lastname', 'Doe')
->assertJsonPath('data.2.firstname', 'John'); ->assertInertiaPath('data.data.0.id', $anna->id)
->assertInertiaPath('data.data.1.firstname', 'Jane')
->assertInertiaPath('data.data.2.firstname', 'John')
->assertInertiaPath('data.meta.default.firstname', '');
} }
} }

View File

@ -17,31 +17,25 @@ class FileshareIndexActionTest extends FileshareTestCase
->name('lokaler Server') ->name('lokaler Server')
->create(); ->create();
$this->get('/api/fileshare') $this->get(route('setting.view', ['settingGroup' => 'fileshare']))
->assertJsonPath('data.0.name', 'lokaler Server') ->assertComponent('setting/Fileshare')
->assertJsonPath('data.0.type', OwncloudConnection::class) ->assertInertiaPath('data.data.0.name', 'lokaler Server')
->assertJsonPath('data.0.config.user', 'badenpowell') ->assertInertiaPath('data.data.0.type', OwncloudConnection::class)
->assertJsonPath('data.0.config.password', 'secret') ->assertInertiaPath('data.data.0.config.user', 'badenpowell')
->assertJsonPath('data.0.config.base_url', env('TEST_OWNCLOUD_DOMAIN')) ->assertInertiaPath('data.data.0.config.password', 'secret')
->assertJsonPath('data.0.id', $connection->id) ->assertInertiaPath('data.data.0.config.base_url', env('TEST_OWNCLOUD_DOMAIN'))
->assertJsonPath('data.0.is_active', true) ->assertInertiaPath('data.data.0.id', $connection->id)
->assertJsonPath('data.0.type_human', 'Owncloud') ->assertInertiaPath('data.data.0.is_active', true)
->assertJsonPath('data.0.links.update', route('fileshare.update', ['fileshare' => $connection])) ->assertInertiaPath('data.data.0.type_human', 'Owncloud')
->assertJsonPath('meta.default.name', '') ->assertInertiaPath('data.data.0.links.update', route('fileshare.update', ['fileshare' => $connection]))
->assertJsonPath('meta.links.store', route('fileshare.store')) ->assertInertiaPath('data.meta.default.name', '')
->assertJsonPath('meta.types.0.id', NextcloudConnection::class) ->assertInertiaPath('data.meta.links.store', route('fileshare.store'))
->assertJsonPath('meta.types.0.name', 'Nextcloud') ->assertInertiaPath('data.meta.types.0.id', NextcloudConnection::class)
->assertJsonPath('meta.types.0.defaults.base_url', '') ->assertInertiaPath('data.meta.types.0.name', 'Nextcloud')
->assertJsonPath('meta.types.1.id', OwncloudConnection::class) ->assertInertiaPath('data.meta.types.0.defaults.base_url', '')
->assertJsonPath('meta.types.1.name', 'Owncloud') ->assertInertiaPath('data.meta.types.1.id', OwncloudConnection::class)
->assertJsonPath('meta.types.1.defaults.base_url', '') ->assertInertiaPath('data.meta.types.1.name', 'Owncloud')
->assertJsonPath('meta.types.0.fields.1', ['label' => 'Benutzer', 'key' => 'user', 'type' => 'text']); ->assertInertiaPath('data.meta.types.1.defaults.base_url', '')
} ->assertInertiaPath('data.meta.types.0.fields.1', ['label' => 'Benutzer', 'key' => 'user', 'type' => 'text']);
public function testItRendersComponent(): void
{
$this->withoutExceptionHandling()->login()->loginNami();
$this->get('/setting/fileshare')->assertComponent('setting/Fileshare');
} }
} }