mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-14 07:27:47 +00:00
add features
* feat: autojoin toggle * feat: auto add devices * feat: proxy feature * feat: support puppeteer in docker * feat: toggle to activate cloud proxy * feat: relay device information * feat: relay logs to cloud * feat: migrate on start * feat: calculate battery state, wifi signal * feat: eye candy for configure view * feat: update via api
This commit is contained in:
parent
d4eb832186
commit
715e6a2562
53 changed files with 1459 additions and 460 deletions
56
resources/views/livewire/plugins/api.blade.php
Normal file
56
resources/views/livewire/plugins/api.blade.php
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
public $token;
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$token = Auth::user()?->tokens()?->first();
|
||||
if ($token === null) {
|
||||
$token = Auth::user()->createToken('api-token', ['update-screen']);
|
||||
}
|
||||
$this->token = $token->plainTextToken;
|
||||
}
|
||||
|
||||
public function regenerateToken()
|
||||
{
|
||||
Auth::user()->tokens()?->first()?->delete();
|
||||
$token = Auth::user()->createToken('api-token', ['update-screen']);
|
||||
$this->token = $token->plainTextToken;
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h2 class="text-2xl font-semibold dark:text-gray-100">API</h2>
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<flux:badge>POST</flux:badge>
|
||||
<span class="ml-2 font-mono">{{route('display.update')}}</span>
|
||||
</p>
|
||||
<div class="mt-4">
|
||||
<h3 class="text-lg">Headers</h3>
|
||||
<div>Authorization <span class="ml-2 font-mono">Bearer {{$token ?? '**********'}}</span>
|
||||
<flux:button variant="subtle" size="xs" class="mt-2" wire:click="regenerateToken()">
|
||||
Regenerate Token
|
||||
</flux:button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<h3 class="text-lg">Body</h3>
|
||||
<div class="font-mono">
|
||||
<pre>
|
||||
{"markup":"<h1>Hello World</h1>"}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
36
resources/views/livewire/plugins/index.blade.php
Normal file
36
resources/views/livewire/plugins/index.blade.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
||||
public $plugins = [
|
||||
'markup' =>
|
||||
['name' => 'Markup', 'icon' => 'code-backet', 'route' => 'plugins.markup'],
|
||||
'api' =>
|
||||
['name' => 'API', 'icon' => 'code-backet', 'route' => 'plugins.api'],
|
||||
];
|
||||
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<div class="flex justify-between items-center mb-6">
|
||||
<h2 class="text-2xl font-semibold dark:text-gray-100">Plugins</h2>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
|
||||
@foreach($plugins as $plugin)
|
||||
<div
|
||||
class="rounded-xl border bg-white dark:bg-stone-950 dark:border-stone-800 text-stone-800 shadow-xs">
|
||||
<a href="{{ route($plugin['route']) }}" class="block">
|
||||
<div class="flex items-center space-x-4 px-10 py-8">
|
||||
<flux:icon name="code-bracket" class="text-4xl text-accent"/>
|
||||
<h3 class="text-xl font-medium dark:text-zinc-200">{{$plugin['name']}}</h3>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
171
resources/views/livewire/plugins/markup.blade.php
Normal file
171
resources/views/livewire/plugins/markup.blade.php
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\GenerateScreenJob;
|
||||
use Livewire\Volt\Component;
|
||||
|
||||
new class extends Component {
|
||||
|
||||
public string $blade_code = '';
|
||||
public bool $isLoading = false;
|
||||
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->isLoading = true;
|
||||
|
||||
$this->validate([
|
||||
'blade_code' => 'required|string'
|
||||
]);
|
||||
|
||||
try {
|
||||
$rendered = Blade::render($this->blade_code);
|
||||
|
||||
// if (config('app.puppeteer_docker')) {
|
||||
// GenerateScreenJob::dispatch(auth()->user()->devices()->first()->id, $rendered);
|
||||
// } else {
|
||||
GenerateScreenJob::dispatchSync(auth()->user()->devices()->first()->id, $rendered);
|
||||
// }
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('error', $e->getMessage());
|
||||
}
|
||||
|
||||
$this->isLoading = false;
|
||||
}
|
||||
|
||||
public function renderExample(string $example)
|
||||
{
|
||||
switch ($example) {
|
||||
case 'quote':
|
||||
$markup = $this->renderQuote();
|
||||
break;
|
||||
case 'trainMonitor':
|
||||
$markup = $this->renderTrainMonitor();
|
||||
break;
|
||||
case 'homeAssistant':
|
||||
$markup = $this->renderHomeAssistant();
|
||||
break;
|
||||
default:
|
||||
$markup = '<h1>Hello World!</h1>';
|
||||
break;
|
||||
}
|
||||
$this->blade_code = $markup;
|
||||
}
|
||||
|
||||
public function renderQuote(): string
|
||||
{
|
||||
return <<<HTML
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout>
|
||||
<x-trmnl::markdown gapSize="large">
|
||||
<x-trmnl::title>Motivational Quote</x-trmnl::title>
|
||||
<x-trmnl::content>“I love inside jokes. I hope to be a part of one someday.”</x-trmnl::content>
|
||||
<x-trmnl::label variant="underline">Michael Scott</x-trmnl::label>
|
||||
</x-trmnl::markdown>
|
||||
</x-trmnl::layout>
|
||||
<x-trmnl::title-bar/>
|
||||
</x-trmnl::view>
|
||||
HTML;
|
||||
}
|
||||
|
||||
public function renderTrainMonitor()
|
||||
{
|
||||
return <<<HTML
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout>
|
||||
<x-trmnl::table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><x-trmnl::title>Abfahrt</x-trmnl::title></th>
|
||||
<th><x-trmnl::title>Aktuell</x-trmnl::title></th>
|
||||
<th><x-trmnl::title>Zug</x-trmnl::title></th>
|
||||
<th><x-trmnl::title>Ziel</x-trmnl::title></th>
|
||||
<th><x-trmnl::title>Steig</x-trmnl::title></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><x-trmnl::label>08:51</x-trmnl::label></td>
|
||||
<td><x-trmnl::label>08:52</x-trmnl::label></td>
|
||||
<td><x-trmnl::label>REX 1</x-trmnl::label></td>
|
||||
<td><x-trmnl::label>Vienna Main Station</x-trmnl::label></td>
|
||||
<td><x-trmnl::label>3</x-trmnl::label></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</x-trmnl::table>
|
||||
</x-trmnl::layout>
|
||||
<x-trmnl::title-bar title="Train Monitor"/>
|
||||
</x-trmnl::view>
|
||||
HTML;
|
||||
|
||||
}
|
||||
|
||||
public function renderHomeAssistant()
|
||||
{
|
||||
return <<<HTML
|
||||
<x-trmnl::view>
|
||||
<x-trmnl::layout class="layout--col gap--space-between">
|
||||
<x-trmnl::grid cols="4">
|
||||
<x-trmnl::col position="center">
|
||||
<x-trmnl::item>
|
||||
<x-trmnl::meta/>
|
||||
<x-trmnl::content>
|
||||
<x-trmnl::value size="large">23.3°</x-trmnl::value>
|
||||
<x-trmnl::label class="w--full flex">
|
||||
<flux:icon icon="droplet"/>
|
||||
47.52 %
|
||||
</x-trmnl::label>
|
||||
<x-trmnl::label class="w--full flex">Sensor 1</x-trmnl::label>
|
||||
</x-trmnl::content>
|
||||
</x-trmnl::item>
|
||||
</x-trmnl::col>
|
||||
</x-trmnl::grid>
|
||||
</x-trmnl::layout>
|
||||
<x-trmnl::title-bar title="Home Assistant"/>
|
||||
</x-trmnl::view>
|
||||
HTML;
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="py-12">
|
||||
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8">
|
||||
<h2 class="text-2xl font-semibold dark:text-gray-100">Markup</h2>
|
||||
|
||||
{{-- <div class="flex justify-between items-center mb-6">--}}
|
||||
|
||||
<div class="mt-5 mb-5 ">
|
||||
<span>Examples</span>
|
||||
<div class="text-accent">
|
||||
<a href="#" wire:click="renderExample('quote')" class="text-xl">Quote</a> |
|
||||
<a href="#" wire:click="renderExample('trainMonitor')" class="text-xl">Train Monitor</a> |
|
||||
<a href="#" wire:click="renderExample('homeAssistant')" class="text-xl">Temperature Sensors</a>
|
||||
</div>
|
||||
</div>
|
||||
<form wire:submit="submit">
|
||||
<div class="mb-4">
|
||||
<flux:textarea
|
||||
label="Blade Code"
|
||||
class="font-mono"
|
||||
wire:model="blade_code"
|
||||
id="blade_code"
|
||||
name="blade_code"
|
||||
rows="15"
|
||||
placeholder="Enter your blade code here..."
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="flex">
|
||||
<flux:spacer/>
|
||||
<flux:button type="submit" variant="primary">
|
||||
Generate Screen
|
||||
</flux:button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{{-- </div>--}}
|
||||
</div>
|
||||
</div>
|
||||
Loading…
Add table
Add a link
Reference in a new issue