diff --git a/app/Fileshare/Actions/IndexAction.php b/app/Fileshare/Actions/FileshareConnectionIndexAction.php similarity index 83% rename from app/Fileshare/Actions/IndexAction.php rename to app/Fileshare/Actions/FileshareConnectionIndexAction.php index c37d01d2..a790f66b 100644 --- a/app/Fileshare/Actions/IndexAction.php +++ b/app/Fileshare/Actions/FileshareConnectionIndexAction.php @@ -8,7 +8,7 @@ use Inertia\Inertia; use Inertia\Response; use Lorisleiva\Actions\Concerns\AsAction; -class IndexAction +class FileshareConnectionIndexAction { use AsAction; @@ -17,7 +17,7 @@ class IndexAction session()->put('menu', 'setting'); session()->put('title', 'Datei-Verbindungen'); - return Inertia::render('fileshare/Index', [ + return Inertia::render('fileshareconnection/Index', [ 'data' => FileshareConnectionResource::collection(FileshareConnection::paginate(15)), ]); } diff --git a/app/Fileshare/Actions/FileshareStoreAction.php b/app/Fileshare/Actions/FileshareConnectionStoreAction.php similarity index 96% rename from app/Fileshare/Actions/FileshareStoreAction.php rename to app/Fileshare/Actions/FileshareConnectionStoreAction.php index c5f1dc57..d3b9b28b 100644 --- a/app/Fileshare/Actions/FileshareStoreAction.php +++ b/app/Fileshare/Actions/FileshareConnectionStoreAction.php @@ -7,7 +7,7 @@ use Illuminate\Validation\ValidationException; use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\Concerns\AsAction; -class FileshareStoreAction +class FileshareConnectionStoreAction { use AsAction; diff --git a/app/Fileshare/ConnectionTypes/ConnectionType.php b/app/Fileshare/ConnectionTypes/ConnectionType.php index 26f85af3..c4b1c35d 100644 --- a/app/Fileshare/ConnectionTypes/ConnectionType.php +++ b/app/Fileshare/ConnectionTypes/ConnectionType.php @@ -7,4 +7,29 @@ use Spatie\LaravelData\Data; abstract class ConnectionType extends Data { abstract public function check(): bool; + + /** + * @return array + */ + abstract public static function defaults(): array; + + abstract public static function title(): string; + + /** + * @return array + */ + abstract public static function fields(): array; + + /** + * @return array + */ + public static function forSelect(): array + { + return collect(glob(base_path('app/Fileshare/ConnectionTypes/*'))) + ->map(fn ($file) => 'App\\Fileshare\\ConnectionTypes\\' . pathinfo($file, PATHINFO_FILENAME)) + ->filter(fn ($file) => $file !== static::class) + ->values() + ->map(fn ($file) => ['id' => $file, 'name' => $file::title(), 'defaults' => $file::defaults(), 'fields' => $file::fields()]) + ->toArray(); + } } diff --git a/app/Fileshare/ConnectionTypes/OwncloudConnection.php b/app/Fileshare/ConnectionTypes/OwncloudConnection.php index 44f8a519..0b053f00 100644 --- a/app/Fileshare/ConnectionTypes/OwncloudConnection.php +++ b/app/Fileshare/ConnectionTypes/OwncloudConnection.php @@ -29,4 +29,33 @@ class OwncloudConnection extends ConnectionType return false; } } + + /** + * @inheritdoc + */ + public static function defaults(): array + { + return [ + 'user' => '', + 'password' => '', + 'base_url' => '', + ]; + } + + public static function title(): string + { + return 'Owncloud'; + } + + /** + * @inheritdoc + */ + public static function fields(): array + { + return [ + ['label' => 'URL', 'key' => 'base_url', 'type' => 'text'], + ['label' => 'Benutzer', 'key' => 'user', 'type' => 'text'], + ['label' => 'Passwort', 'key' => 'password', 'type' => 'password'], + ]; + } } diff --git a/app/Fileshare/FileshareSettings.php b/app/Fileshare/FileshareSettings.php index 9b094cbe..26f75e46 100644 --- a/app/Fileshare/FileshareSettings.php +++ b/app/Fileshare/FileshareSettings.php @@ -2,7 +2,7 @@ namespace App\Fileshare; -use App\Fileshare\Actions\IndexAction; +use App\Fileshare\Actions\FileshareConnectionIndexAction; use App\Setting\Contracts\Indexable; use App\Setting\LocalSettings; @@ -20,7 +20,7 @@ class FileshareSettings extends LocalSettings implements Indexable public static function indexAction(): string { - return IndexAction::class; + return FileshareConnectionIndexAction::class; } public static function title(): string diff --git a/app/Fileshare/Resources/FileshareConnectionResource.php b/app/Fileshare/Resources/FileshareConnectionResource.php index c714d757..20f117dc 100644 --- a/app/Fileshare/Resources/FileshareConnectionResource.php +++ b/app/Fileshare/Resources/FileshareConnectionResource.php @@ -2,7 +2,9 @@ namespace App\Fileshare\Resources; +use App\Fileshare\ConnectionTypes\ConnectionType; use App\Fileshare\Models\FileshareConnection; +use App\Lib\HasMeta; use Illuminate\Http\Resources\Json\JsonResource; /** @@ -10,6 +12,9 @@ use Illuminate\Http\Resources\Json\JsonResource; */ class FileshareConnectionResource extends JsonResource { + + use HasMeta; + /** * Transform the resource into an array. * @@ -24,6 +29,25 @@ class FileshareConnectionResource extends JsonResource 'type' => get_class($this->type), 'config' => $this->type->toArray(), 'id' => $this->id, + 'type_human' => $this->type::title(), + ]; + } + + /** + * @return array + */ + public static function meta(): array + { + return [ + 'default' => [ + 'name' => '', + 'type' => null, + 'config' => null, + ], + 'types' => ConnectionType::forSelect(), + 'links' => [ + 'store' => route('fileshare.store'), + ] ]; } } diff --git a/resources/js/views/fileshareconnection/Index.vue b/resources/js/views/fileshareconnection/Index.vue new file mode 100644 index 00000000..ffef24af --- /dev/null +++ b/resources/js/views/fileshareconnection/Index.vue @@ -0,0 +1,77 @@ + + + diff --git a/routes/web.php b/routes/web.php index 71b8b98e..baec75c4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -19,7 +19,7 @@ use App\Invoice\Actions\InvoiceStoreAction; use App\Course\Actions\CourseUpdateAction; use App\Dashboard\Actions\IndexAction as DashboardIndexAction; use App\Efz\ShowEfzDocumentAction; -use App\Fileshare\Actions\FileshareStoreAction; +use App\Fileshare\Actions\FileshareConnectionStoreAction; use App\Form\Actions\ExportAction as ActionsExportAction; use App\Form\Actions\FormDestroyAction; use App\Form\Actions\FormIndexAction; @@ -169,5 +169,5 @@ Route::group(['middleware' => 'auth:web'], function (): void { Route::delete('/participant/{participant}', ParticipantDestroyAction::class)->name('participant.destroy'); // ------------------------------------ fileshare ----------------------------------- - Route::post('/fileshare', FileshareStoreAction::class)->name('fileshare.store'); + Route::post('/fileshare', FileshareConnectionStoreAction::class)->name('fileshare.store'); }); diff --git a/tests/Fileshare/IndexActionTest.php b/tests/Fileshare/FileshareConnectionIndexActionTest.php similarity index 61% rename from tests/Fileshare/IndexActionTest.php rename to tests/Fileshare/FileshareConnectionIndexActionTest.php index 5ac1d6ac..70895c76 100644 --- a/tests/Fileshare/IndexActionTest.php +++ b/tests/Fileshare/FileshareConnectionIndexActionTest.php @@ -6,7 +6,7 @@ use App\Fileshare\ConnectionTypes\OwncloudConnection; use App\Fileshare\Models\FileshareConnection; use Tests\FileshareTestCase; -class IndexActionTest extends FileshareTestCase +class FileshareConnectionIndexActionTest extends FileshareTestCase { public function testItListsOwncloudConnectionsThatAreActive(): void { @@ -23,6 +23,13 @@ class IndexActionTest extends FileshareTestCase ->assertInertiaPath('data.data.0.config.password', 'secret') ->assertInertiaPath('data.data.0.config.base_url', env('TEST_OWNCLOUD_DOMAIN')) ->assertInertiaPath('data.data.0.id', $connection->id) - ->assertInertiaPath('data.data.0.is_active', true); + ->assertInertiaPath('data.data.0.is_active', true) + ->assertInertiaPath('data.data.0.type_human', 'Owncloud') + ->assertInertiaPath('data.meta.default.name', '') + ->assertInertiaPath('data.meta.links.store', route('fileshare.store')) + ->assertInertiaPath('data.meta.types.0.id', OwncloudConnection::class) + ->assertInertiaPath('data.meta.types.0.name', 'Owncloud') + ->assertInertiaPath('data.meta.types.0.defaults.base_url', '') + ->assertInertiaPath('data.meta.types.0.fields.1', ['label' => 'Benutzer', 'key' => 'user', 'type' => 'text']); } } diff --git a/tests/Fileshare/StoreActionTest.php b/tests/Fileshare/FileshareConnectionStoreActionTest.php similarity index 96% rename from tests/Fileshare/StoreActionTest.php rename to tests/Fileshare/FileshareConnectionStoreActionTest.php index bbf38809..22b4f9db 100644 --- a/tests/Fileshare/StoreActionTest.php +++ b/tests/Fileshare/FileshareConnectionStoreActionTest.php @@ -6,7 +6,7 @@ use App\Fileshare\ConnectionTypes\OwncloudConnection; use App\Fileshare\Models\FileshareConnection; use Tests\FileshareTestCase; -class StoreActionTest extends FileshareTestCase +class FileshareConnectionStoreActionTest extends FileshareTestCase { public function testItStoresAConnection(): void {