diff --git a/database/factories/PluginFactory.php b/database/factories/PluginFactory.php new file mode 100644 index 0000000..a4aa033 --- /dev/null +++ b/database/factories/PluginFactory.php @@ -0,0 +1,35 @@ + $this->faker->uuid(), + 'user_id' => '1', + 'name' => $this->faker->randomElement(['Weather', 'Clock', 'News', 'Stocks', 'Calendar']), + 'data_payload' => null, + 'data_stale_minutes' => $this->faker->numberBetween(5, 300), + 'data_strategy' => $this->faker->randomElement(['polling', 'webhook']), + 'polling_url' => $this->faker->url(), + 'polling_verb' => $this->faker->randomElement(['get', 'post']), + 'polling_header' => null, + 'render_markup' => null, + 'render_markup_view' => null, + 'detail_view_route' => null, + 'icon_url' => null, + 'flux_icon_name' => null, + 'author_name' => $this->faker->name(), + 'created_at' => Carbon::now(), + 'updated_at' => Carbon::now(), + ]; + } +} diff --git a/resources/views/livewire/plugins/index.blade.php b/resources/views/livewire/plugins/index.blade.php index 562ef30..88138fa 100644 --- a/resources/views/livewire/plugins/index.blade.php +++ b/resources/views/livewire/plugins/index.blade.php @@ -4,13 +4,61 @@ use Livewire\Volt\Component; new class extends Component { - public $plugins = [ + public string $name; + public int $data_stale_minutes = 60; + public string $data_strategy = "polling"; + public string $polling_url; + public string $polling_verb ="get"; + public $polling_header; + public array $plugins; + + public array $native_plugins = [ 'markup' => - ['name' => 'Markup', 'icon' => 'code-backet', 'route' => 'plugins.markup'], + ['name' => 'Markup', 'flux_icon_name' => 'code-bracket', 'detail_view_route' => 'plugins.markup'], 'api' => - ['name' => 'API', 'icon' => 'code-backet', 'route' => 'plugins.api'], + ['name' => 'API', 'flux_icon_name' => 'braces', 'detail_view_route' => 'plugins.api'], ]; + protected $rules = [ + 'name' => 'required|string|max:255', + 'data_stale_minutes' => 'required|integer|min:1', + 'data_strategy' => 'required|string|in:polling,webhook', + 'polling_url' => 'required|url', + 'polling_verb' => 'required|string|in:get,post', + 'polling_header' => 'nullable|string|max:255', + ]; + + public function addPlugin(): void + { + abort_unless(auth()->user() !== null, 403); + $this->validate(); + + \App\Models\Plugin::create([ + 'uuid' => \Illuminate\Support\Str::uuid(), + 'user_id' => auth()->id(), + 'name' => $this->name, + 'data_stale_minutes' => $this->data_stale_minutes, + 'data_strategy' => $this->data_strategy, + 'polling_url' => $this->polling_url, + 'polling_verb' => $this->polling_verb, + 'polling_header' => $this->polling_header, + ]); + + $this->reset(['name', 'data_stale_minutes', 'data_strategy', 'polling_url', 'polling_verb', 'polling_header']); + Flux::modal('add-plugin')->close(); + } + + + + public function mount(): void + { + $userPlugins =auth()->user()->plugins->map(function ($plugin) { + return $plugin->toArray(); + })->toArray(); + + $this->plugins = array_merge($this->native_plugins, $userPlugins); + } + }; ?> @@ -18,14 +66,67 @@ new class extends Component {