Files
Virtnet.bond/extensions/Others/UptimeLab/UptimeLab.php
2025-11-30 11:57:22 +01:00

101 lines
4.8 KiB
PHP

<?php
namespace Paymenter\Extensions\Others\UptimeLab;
use App\Classes\Extension\Extension;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\View;
use Illuminate\Support\HtmlString;
use Paymenter\Extensions\Others\UptimeLab\Admin\Resources\UptimeServerResource;
use Paymenter\Extensions\Others\UptimeLab\Models\UptimeServer;
use Illuminate\Support\Facades\Blade;
class UptimeLab extends Extension
{
/**
* Get all the configuration for the extension
*
* @param array $values
* @return array
*/
public function getConfig($values = [])
{
try {
return [
[
'name' => 'Uptime Monitoring',
'type' => 'placeholder',
'label' => new HtmlString('Uptime Lab extension is now active. You can manage servers in the <a class="text-primary-600" href="' . UptimeServerResource::getUrl() . '">Uptime Lab</a> admin section.'),
],
];
} catch (\Exception $e) {
return [
[
'name' => 'Uptime Monitoring',
'type' => 'placeholder',
'label' => new HtmlString('Uptime Lab extension is now active. You\'ll need to enable this extension above to get started.'),
],
];
}
}
/**
* Called when the extension is enabled
*/
public function enabled()
{
// Run migrations
Artisan::call('migrate', ['--path' => 'extensions/Others/UptimeLab/database/migrations/2025_01_01_000001_create_ext_uptime_servers_table.php', '--force' => true]);
// Run seeder to populate sample data
try {
Artisan::call('db:seed', ['--class' => 'Paymenter\\Extensions\\Others\\UptimeLab\\Database\\Seeders\\UptimeServerSeeder', '--force' => true]);
} catch (\Exception $e) {
// Seeder might fail if data already exists, which is fine
}
}
/**
* Called when the extension is booted
*/
public function boot()
{
// Register routes
require __DIR__ . '/routes/web.php';
View::addNamespace('uptime-lab', __DIR__ . '/resources/views');
// Register Livewire components
\Livewire\Livewire::component('uptime.index', \Paymenter\Extensions\Others\UptimeLab\Livewire\Uptime\Index::class);
// Add navigation menu item to dashboard - no icon to avoid errors
Event::listen('navigation.dashboard', function () {
return [
'name' => new HtmlString('
<span class="relative" style="left: -2px;"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 122.88 99.54" style="width:20px;height:20px;vertical-align:middle; " >
<style type="text/css"><![CDATA[
.st0{fill:currentcolor;}
.st1{fill-rule:evenodd;clip-rule:evenodd;fill:#6BBE66;}
]]></style>
<g>
<path class="st0" d="M73.12,0c6.73,0,13.16,1.34,19.03,3.77c6.09,2.52,11.57,6.22,16.16,10.81l0,0c4.58,4.58,8.28,10.06,10.8,16.17 c2.43,5.87,3.77,12.3,3.77,19.02c0,6.73-1.34,13.16-3.77,19.03c-2.52,6.09-6.22,11.57-10.81,16.16l0,0 c-4.58,4.58-10.06,8.28-16.17,10.8c-5.87,2.43-12.3,3.77-19.02,3.77c-6.73,0-13.16-1.34-19.03-3.77 c-6.09-2.52-11.57-6.22-16.15-10.8l-0.01-0.01c-4.59-4.59-8.28-10.07-10.8-16.15c-0.78-1.89-1.45-3.83-2-5.82 c1.04,0.1,2.1,0.15,3.17,0.15c2.03,0,4.01-0.18,5.94-0.53c0.32,0.96,0.67,1.91,1.05,2.84c2.07,5,5.11,9.5,8.89,13.28 c3.78,3.78,8.29,6.82,13.28,8.89c4.81,1.99,10.1,3.1,15.66,3.1s10.84-1.1,15.66-3.1c5-2.07,9.5-5.11,13.28-8.89 c3.78-3.78,6.82-8.29,8.89-13.28c1.99-4.81,3.1-10.1,3.1-15.66s-1.1-10.84-3.1-15.66c-2.07-5-5.11-9.5-8.89-13.28 s-8.29-6.82-13.28-8.89c-4.81-1.99-10.1-3.1-15.66-3.1s-10.84,1.1-15.66,3.1c-0.43,0.18-0.86,0.37-1.28,0.56 c-1.64-2.58-3.62-4.92-5.89-6.95c1.24-0.64,2.51-1.23,3.8-1.77C59.97,1.34,66.39,0,73.12,0L73.12,0L73.12,0z M67.41,26.11 c0-1.22,0.5-2.32,1.29-3.12c0.8-0.8,1.9-1.29,3.12-1.29c1.22,0,2.32,0.49,3.12,1.29c0.8,0.8,1.29,1.9,1.29,3.12v23.22l17.35,10.29 c1.04,0.62,1.74,1.61,2.02,2.7c0.28,1.09,0.15,2.29-0.47,3.33v0.01l0,0c-0.62,1.04-1.61,1.74-2.7,2.02s-2.29,0.15-3.33-0.47h-0.01 l0,0L69.68,55.7c-0.67-0.37-1.22-0.91-1.62-1.55c-0.41-0.67-0.65-1.46-0.65-2.3V26.11L67.41,26.11L67.41,26.11z"/>
</g>
</svg></span></span><span>
Uptime</span>
'),
'route' => 'uptime.index',
'priority' => 32,
'spa' => true,
'params' => [],
'active' => request()->routeIs('uptime.index'),
];
});
// Add admin navigation - no icon to avoid errors
Event::listen('admin.navigation', function () {
return [
'name' => 'Uptime Lab',
'group' => 'Extensions',
'priority' => 10,
];
});
}
}