Add fileshare api

This commit is contained in:
philipp lang 2024-06-27 18:04:58 +02:00
parent 73633d7628
commit 94cc0147bc
7 changed files with 77 additions and 31 deletions

View File

@ -0,0 +1,21 @@
<?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

@ -17,7 +17,7 @@ class FileshareIndexAction
session()->put('menu', 'setting'); session()->put('menu', 'setting');
session()->put('title', 'Datei-Verbindungen'); session()->put('title', 'Datei-Verbindungen');
return Inertia::render('fileshareconnection/Index', [ return Inertia::render('fileshare/Index', [
'data' => FileshareResource::collection(Fileshare::paginate(15)), 'data' => FileshareResource::collection(Fileshare::paginate(15)),
]); ]);
} }

View File

@ -3,6 +3,7 @@
namespace App\Fileshare\Actions; namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare; use App\Fileshare\Models\Fileshare;
use App\Lib\Events\Succeeded;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction; use Lorisleiva\Actions\Concerns\AsAction;
@ -35,5 +36,7 @@ class FileshareStoreAction
...$request->validated(), ...$request->validated(),
'type' => $type, 'type' => $type,
]); ]);
Succeeded::message('Verbindung erstellt.')->dispatch();
} }
} }

View File

@ -3,6 +3,7 @@
namespace App\Fileshare\Actions; namespace App\Fileshare\Actions;
use App\Fileshare\Models\Fileshare; use App\Fileshare\Models\Fileshare;
use App\Lib\Events\Succeeded;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction; use Lorisleiva\Actions\Concerns\AsAction;
@ -35,5 +36,7 @@ class FileshareUpdateAction
...$request->validated(), ...$request->validated(),
'type' => $type, 'type' => $type,
]); ]);
Succeeded::message('Verbindung bearbeitet.')->dispatch();
} }
} }

View File

@ -7,18 +7,32 @@
<form @submit.prevent="submit"> <form @submit.prevent="submit">
<section class="grid grid-cols-2 gap-3 mt-6"> <section class="grid grid-cols-2 gap-3 mt-6">
<f-text id="name" v-model="single.name" name="name" label="Bezeichnung" required></f-text> <f-text id="name" v-model="single.name" name="name" label="Bezeichnung" required></f-text>
<f-select id="type" :model-value="single.type" label="Typ" name="type" :options="meta.types" required <f-select
id="type"
:model-value="single.type"
label="Typ"
name="type"
:options="meta.types"
required
@update:model-value=" @update:model-value="
single = { single = {
...single, ...single,
type: $event, type: $event,
config: { ...getType($event).defaults }, config: {...getType($event).defaults},
} }
"></f-select> "
></f-select>
<template v-for="(field, index) in getType(single.type).fields"> <template v-for="(field, index) in getType(single.type).fields">
<f-text v-if="field.type === 'text' || field.type === 'password' || field.type === 'email'" <f-text
:id="field.key" :key="index" v-model="single.config[field.key]" :label="field.label" v-if="field.type === 'text' || field.type === 'password' || field.type === 'email'"
:type="field.type" :name="field.key" required></f-text> :id="field.key"
:key="index"
v-model="single.config[field.key]"
:label="field.label"
:type="field.type"
:name="field.key"
required
></f-text>
</template> </template>
</section> </section>
<section class="flex mt-4 space-x-2"> <section class="flex mt-4 space-x-2">
@ -41,12 +55,14 @@
<td v-text="connection.name"></td> <td v-text="connection.name"></td>
<td v-text="connection.type_human"></td> <td v-text="connection.type_human"></td>
<td> <td>
<ui-boolean-display :value="connection.is_active" long-label="Verbindungsstatus" <ui-boolean-display
:label="connection.is_active ? 'Verbindung erfolgreich' : 'Verbindung fehlgeschlagen'"></ui-boolean-display> :value="connection.is_active"
long-label="Verbindungsstatus"
:label="connection.is_active ? 'Verbindung erfolgreich' : 'Verbindung fehlgeschlagen'"
></ui-boolean-display>
</td> </td>
<td> <td>
<a v-tooltip="`Bearbeiten`" href="#" class="inline-flex btn btn-warning btn-sm" <a v-tooltip="`Bearbeiten`" href="#" class="inline-flex btn btn-warning btn-sm" @click.prevent="edit(connection)"><ui-sprite src="pencil"></ui-sprite></a>
@click.prevent="edit(connection)"><ui-sprite src="pencil"></ui-sprite></a>
</td> </td>
</tr> </tr>
</table> </table>
@ -60,11 +76,10 @@
</template> </template>
<script setup> <script setup>
import { indexProps, useIndex } from '../../composables/useInertiaApiIndex.js'; import {useApiIndex} from '../../composables/useApiIndex.js';
import SettingLayout from '../setting/Layout.vue'; import SettingLayout from '../setting/Layout.vue';
const props = defineProps(indexProps); const {meta, data, reload, create, edit, cancel, single, submit} = useApiIndex('/api/fileshare', 'fileshare');
const { meta, data, create, edit, cancel, single, submit } = useIndex(props.data, 'mailgateway');
function getType(type) { function getType(type) {
if (!type) { if (!type) {
@ -74,4 +89,6 @@ 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

@ -19,6 +19,7 @@ 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\Form\Actions\ExportAction as ActionsExportAction; use App\Form\Actions\ExportAction as ActionsExportAction;
@ -172,4 +173,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');
}); });

View File

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