Add generic api schema and scripts model
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
import Swal from 'sweetalert2';
|
||||
|
||||
window.Swal = Swal
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
<x-layouts.app :title="__('Dashboard')">
|
||||
<div class="flex h-full w-full flex-1 flex-col gap-4 rounded-xl">
|
||||
<div class="flex justify-end">
|
||||
<button class="bg-gray-600 p-2 text-white rounded-lg">
|
||||
<a href="{{ route('bots.create') }}">
|
||||
{{ __('Add Bot') }}
|
||||
</a>
|
||||
<button
|
||||
class="bg-gray-600 p-2 text-white rounded-lg cursor-pointer"
|
||||
wire:navigate
|
||||
href="{{ route('bots.create') }}"
|
||||
>
|
||||
{{ __('Add Bot') }}
|
||||
</button>
|
||||
</div>
|
||||
<div class="grid auto-rows-min gap-4 md:grid-cols-3">
|
||||
@@ -14,6 +16,11 @@
|
||||
<div class="p-4">
|
||||
<h2>Active Bots</h2>
|
||||
</div>
|
||||
@foreach ($bots->where('enabled', 1) as $bot)
|
||||
<div class="px-4 py-1">
|
||||
<p>{{ $bot->name }}</p>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
<div
|
||||
class="relative aspect-video overflow-hidden rounded-xl border border-neutral-200 dark:border-neutral-700"
|
||||
|
||||
@@ -3,35 +3,61 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="border px-4 py-2">Name</th>
|
||||
<th class="border px-4 py-2">Class</th>
|
||||
<th class="border px-4 py-2">Schema</th>
|
||||
<th class="border px-4 py-2">Schedule</th>
|
||||
<th class="border px-4 py-2">Next due</th>
|
||||
<th class="border px-4 py-2">Enabled</th>
|
||||
<th class="border px-4 py-2">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="text-center">
|
||||
@foreach ($bots as $bot)
|
||||
<tr>
|
||||
<td class="border px-4 py-2">
|
||||
<a href="{{ route('bots.edit', $bot) }}" class="text-blue-500">
|
||||
<td class="px-4 py-2">
|
||||
<a
|
||||
wire:navigate
|
||||
href="{{ route('bots.edit', $bot) }}"
|
||||
class="text-blue-500"
|
||||
>
|
||||
{{ $bot->name }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="border px-4 py-2">{{ $bot->class }}</td>
|
||||
<td class="border px-4 py-2">
|
||||
</td>
|
||||
<td class="px-4 py-2">{{ $bot->class_name }}</td>
|
||||
<td class="px-4 py-2">
|
||||
{{ $bot->schedule }}
|
||||
<span class="text-gray-300">
|
||||
({{ $bot->cron_to_human }})
|
||||
</span>
|
||||
</td>
|
||||
<td class="border px-4 py-2">{{ $bot->next_due }}</td>
|
||||
<td class="border px-4 py-2">
|
||||
<td class="px-4 py-2">{{ $bot->next_due }}</td>
|
||||
<td class="px-4 py-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
@checked($bot->enabled)
|
||||
wire:click="toggleBot({{ $bot->id }})"
|
||||
/>
|
||||
</td>
|
||||
<td>
|
||||
<button
|
||||
wire:click="runBot({{ $bot->id }})"
|
||||
class="ml-4 cursor-pointer"
|
||||
>
|
||||
<i class="fas fa-play"></i>
|
||||
</button>
|
||||
<button
|
||||
href="{{ route('bots.edit', $bot) }}"
|
||||
wire:navigate
|
||||
class="ml-4 cursor-pointer"
|
||||
>
|
||||
<i class="fas fa-edit"></i>
|
||||
</button>
|
||||
<button
|
||||
wire:click="deleteBot({{ $bot->id }})"
|
||||
class="ml-4 cursor-pointer"
|
||||
>
|
||||
<i class="fas fa-trash"></i>
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
@section('title', $routeName)
|
||||
<div>
|
||||
<div class="mb-4">
|
||||
<input
|
||||
@@ -14,13 +15,13 @@
|
||||
<div>
|
||||
<select wire:model.live="class" class="border p-2 rounded mb-2 w-full">
|
||||
<option hidden selected>Select Bot Schema</option>
|
||||
@foreach ($classList as $label => $class)
|
||||
<option class="text-black" value="{{ $label }}">
|
||||
@foreach ($classList as $class => $label)
|
||||
<option class="text-black" value="{{ $class }}">
|
||||
{{ $label }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@error('bot')
|
||||
@error('class')
|
||||
<span class="text-red-500">{{ $message }}</span>
|
||||
@enderror
|
||||
</div>
|
||||
@@ -41,20 +42,50 @@
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<h2>Config</h2>
|
||||
<div class="mb-4 text-xl">
|
||||
<h2>Config</h2>
|
||||
</div>
|
||||
@forelse ($configSchema as $field => $meta)
|
||||
<label>{{ $meta['label'] }}</label>
|
||||
<input
|
||||
class="border p-2 rounded mb-2 w-full"
|
||||
type="text"
|
||||
name="config[{{ $field }}]"
|
||||
value="{{ old("config.$field", $bot->config[$field] ?? '') }}"
|
||||
/>
|
||||
<div class="mb-4">
|
||||
<label>{{ $meta['label'] }}</label>
|
||||
|
||||
@if ($meta['type'] === 'json')
|
||||
<div x-data="jsonEditor(@entangle('config.' . $field))">
|
||||
<label
|
||||
for="config-body"
|
||||
class="block font-semibold mb-1"
|
||||
>
|
||||
Request Body (JSON)
|
||||
</label>
|
||||
<textarea
|
||||
id="config-body"
|
||||
x-model="value"
|
||||
wire:model.live="config.{{ $field }}"
|
||||
@keydown="handleKeydown($event)"
|
||||
class="w-full h-40 p-2 font-mono border rounded-md"
|
||||
></textarea>
|
||||
</div>
|
||||
<span
|
||||
class="text-blue-300 cursor-pointer"
|
||||
wire:click="prettify('{{ $field }}')"
|
||||
>
|
||||
Prettify
|
||||
</span>
|
||||
@else
|
||||
<input
|
||||
wire:model.live="config.{{ $field }}"
|
||||
class="border p-2 rounded mb-2 w-full"
|
||||
type="text"
|
||||
name="config[{{ $field }}]"
|
||||
value="{{ old("config.$field", $bot->config[$field] ?? '') }}"
|
||||
/>
|
||||
@endif
|
||||
</div>
|
||||
@error('config.' . $field)
|
||||
<span class="text-red-500">{{ $message }}</span>
|
||||
@enderror
|
||||
@empty
|
||||
Select a bot first
|
||||
<i class="text-gray-400">Select a bot first</i>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
@@ -68,9 +99,56 @@
|
||||
<div>
|
||||
<button
|
||||
wire:click="save"
|
||||
class="mt-6 bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600"
|
||||
class="mt-6 bg-blue-500 text-white px-4 py-2 rounded cursor-pointer"
|
||||
>
|
||||
{{ $routeName }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function jsonEditor(model) {
|
||||
return {
|
||||
value: model,
|
||||
handleKeydown(e) {
|
||||
const textarea = e.target;
|
||||
const val = textarea.value;
|
||||
const start = textarea.selectionStart;
|
||||
const end = textarea.selectionEnd;
|
||||
|
||||
// Map of pairs
|
||||
const pairs = {
|
||||
'{': '}',
|
||||
'[': ']',
|
||||
'"': '"',
|
||||
"'": "'",
|
||||
};
|
||||
|
||||
if (pairs[e.key]) {
|
||||
e.preventDefault();
|
||||
const open = e.key;
|
||||
const close = pairs[e.key];
|
||||
|
||||
textarea.setRangeText(open + close, start, end, 'end');
|
||||
textarea.selectionStart = textarea.selectionEnd = start + 1;
|
||||
this.value = textarea.value;
|
||||
}
|
||||
|
||||
// Auto-indent new line inside braces
|
||||
if (
|
||||
e.key === 'Enter' &&
|
||||
val[start - 1] === '{' &&
|
||||
val[end] === '}'
|
||||
) {
|
||||
e.preventDefault();
|
||||
const indent = ' ';
|
||||
const newText = `\n${indent}\n`;
|
||||
textarea.setRangeText(newText, start, end, 'end');
|
||||
textarea.selectionStart = textarea.selectionEnd =
|
||||
start + newText.length - 1;
|
||||
this.value = textarea.value;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
|
||||
<title>{{ $title ?? config('app.name') }}</title>
|
||||
<title>
|
||||
{{ config('app.name', 'VETiSearch') }} - @yield('title', $title ?? '')
|
||||
</title>
|
||||
|
||||
<link rel="icon" href="/favicon.ico" sizes="any">
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
|
||||
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
<link href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600" rel="stylesheet" />
|
||||
<link rel="icon" href="/favicon.ico" sizes="any" />
|
||||
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
|
||||
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
||||
|
||||
<link rel="preconnect" href="https://fonts.bunny.net" />
|
||||
<link
|
||||
href="https://fonts.bunny.net/css?family=instrument-sans:400,500,600"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.0/css/all.min.css" integrity="sha512-DxV+EoADOkOygM4IR9yXP8Sb2qwgidEmeqAEmDKIOfPRQZOWbXCzLC6vjbZyy0vPisbH2SyW27+ddLVCN+OMzQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
|
||||
@vite(['resources/css/app.css', 'resources/js/app.js'])
|
||||
@fluxAppearance
|
||||
|
||||
Reference in New Issue
Block a user