[增添]在初始仪表盘添加了用于导出etcd配置的widget
This commit is contained in:
19
.idea/workspace.xml
generated
19
.idea/workspace.xml
generated
@@ -4,9 +4,9 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[增添]添加了MetricResource的数据库以及页面元素">
|
<list default="true" id="596fb1a0-d6fb-4db8-a922-13b01593ce79" name="更改" comment="[增添]添加了etcd服务与对应页面">
|
||||||
<change afterPath="$PROJECT_DIR$/management-panel/app/Services/EtcdService.php" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/management-panel/app/Providers/Filament/AdminPanelProvider.php" beforeDir="false" afterPath="$PROJECT_DIR$/management-panel/app/Providers/Filament/AdminPanelProvider.php" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -356,7 +356,7 @@
|
|||||||
<workItem from="1724721535300" duration="1534000" />
|
<workItem from="1724721535300" duration="1534000" />
|
||||||
<workItem from="1724723119931" duration="37000" />
|
<workItem from="1724723119931" duration="37000" />
|
||||||
<workItem from="1724723165774" duration="1511000" />
|
<workItem from="1724723165774" duration="1511000" />
|
||||||
<workItem from="1724724784154" duration="5935000" />
|
<workItem from="1724724784154" duration="6338000" />
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00001" summary="[增添]添加注册">
|
<task id="LOCAL-00001" summary="[增添]添加注册">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
@@ -414,7 +414,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1724727682739</updated>
|
<updated>1724727682739</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="8" />
|
<task id="LOCAL-00008" summary="[增添]添加了etcd服务与对应页面">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1724736926763</created>
|
||||||
|
<option name="number" value="00008" />
|
||||||
|
<option name="presentableId" value="LOCAL-00008" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1724736926763</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="9" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -438,6 +446,7 @@
|
|||||||
<MESSAGE value="[增添]添加了Manage Exposer的默认数据库值以及Page页面" />
|
<MESSAGE value="[增添]添加了Manage Exposer的默认数据库值以及Page页面" />
|
||||||
<MESSAGE value="[增添]添加了MetricResource的数据库以及页面元素" />
|
<MESSAGE value="[增添]添加了MetricResource的数据库以及页面元素" />
|
||||||
<MESSAGE value="[增添]添加了MetricResource的数据库以及页面元素" />
|
<MESSAGE value="[增添]添加了MetricResource的数据库以及页面元素" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="[增添]添加了MetricResource的数据库以及页面元素" />
|
<MESSAGE value="[增添]添加了etcd服务与对应页面" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="[增添]添加了etcd服务与对应页面" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
75
management-panel/app/Filament/Widgets/UpdateConfigWidget.php
Normal file
75
management-panel/app/Filament/Widgets/UpdateConfigWidget.php
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Widgets;
|
||||||
|
|
||||||
|
use App\Services\EtcdService;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Widgets\Widget;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class UpdateConfigWidget extends Widget
|
||||||
|
{
|
||||||
|
protected static string $view = 'filament.widgets.update-config-widget';
|
||||||
|
|
||||||
|
public function updateSettingsToEtcd()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$etcd = new EtcdService();
|
||||||
|
// $etcd->deleteByPrefix("datasource");
|
||||||
|
|
||||||
|
$settings = DB::table('settings')
|
||||||
|
->where('group', 'datasource')
|
||||||
|
->get(); // 获取 group 为 datasource 的所有记录
|
||||||
|
|
||||||
|
foreach ($settings as $setting) {
|
||||||
|
$key = '/' . $setting->group . '/' . $setting->name;
|
||||||
|
$etcd->put($key, $setting->payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
$metrics = DB::table('metrics')->get(); // 获取所有 metrics 数据
|
||||||
|
|
||||||
|
foreach ($metrics as $index => $metric) {
|
||||||
|
$baseKey = '/metrics/' . $index;
|
||||||
|
|
||||||
|
// 存储 name 到 etcd
|
||||||
|
$etcd->put($baseKey . '/name', $metric->name);
|
||||||
|
|
||||||
|
// 存储 identifier_type 到 etcd
|
||||||
|
$etcd->put($baseKey . '/identifier_type', $metric->identifier_type);
|
||||||
|
|
||||||
|
// 根据 identifier_type 生成 nodeid 并存储到 etcd
|
||||||
|
switch ($metric->identifier_type) {
|
||||||
|
case 1: // Numeric
|
||||||
|
$nodeId = 'ns=' . $metric->namespace_index . ';i=' . $metric->numeric_id;
|
||||||
|
break;
|
||||||
|
case 2: // String
|
||||||
|
$nodeId = 'ns=' . $metric->namespace_index . ';s=' . $metric->string_id;
|
||||||
|
break;
|
||||||
|
case 3: // GUID
|
||||||
|
$nodeId = 'ns=' . $metric->namespace_index . ';g=' . $metric->guid_id;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$nodeId = ''; // 若 identifier_type 不符合预期,则 nodeId 为空
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$etcd->put($baseKey . '/nodeid', $nodeId);
|
||||||
|
|
||||||
|
// 存储 help 到 etcd
|
||||||
|
$etcd->put($baseKey . '/help', $metric->help ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title('配置更新成功!')
|
||||||
|
->success() // 设置为成功类型
|
||||||
|
->send(); // 发送通知
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
// 失败通知
|
||||||
|
Notification::make()
|
||||||
|
->title('配置更新失败!')
|
||||||
|
->danger() // 设置为错误类型
|
||||||
|
->body($e->getMessage()) // 显示异常信息
|
||||||
|
->send(); // 发送通知
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers\Filament;
|
namespace App\Providers\Filament;
|
||||||
|
|
||||||
|
use App\Filament\Widgets\UpdateConfigWidget;
|
||||||
use Filament\Http\Middleware\Authenticate;
|
use Filament\Http\Middleware\Authenticate;
|
||||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||||
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
||||||
@@ -40,6 +41,7 @@ class AdminPanelProvider extends PanelProvider
|
|||||||
->widgets([
|
->widgets([
|
||||||
Widgets\AccountWidget::class,
|
Widgets\AccountWidget::class,
|
||||||
Widgets\FilamentInfoWidget::class,
|
Widgets\FilamentInfoWidget::class,
|
||||||
|
UpdateConfigWidget::class,
|
||||||
])
|
])
|
||||||
->middleware([
|
->middleware([
|
||||||
EncryptCookies::class,
|
EncryptCookies::class,
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<x-filament-widgets::widget>
|
||||||
|
<x-filament::section>
|
||||||
|
<div class="flex flex-wrap items-center gap-4 justify-between">
|
||||||
|
<!-- 添加放大的圆形图形和标题 -->
|
||||||
|
<div class="flex items-center">
|
||||||
|
<div class="w-14 h-14 bg-blue-600 text-white flex items-center justify-center rounded-full">
|
||||||
|
<span class="text-2xl">⚙️</span> <!-- 增大符号 -->
|
||||||
|
</div>
|
||||||
|
<h2 class="ml-4 text-xl font-bold text-blue-600">配置导出</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- 按钮居右 -->
|
||||||
|
<x-filament::button
|
||||||
|
wire:click="updateSettingsToEtcd"
|
||||||
|
type="button"
|
||||||
|
class="bg-blue-600 text-white hover:bg-blue-700 font-semibold py-2 px-6 rounded-lg shadow-md transition ease-in-out duration-200"
|
||||||
|
>
|
||||||
|
导出配置到ETCD
|
||||||
|
</x-filament::button>
|
||||||
|
</div>
|
||||||
|
</x-filament::section>
|
||||||
|
</x-filament-widgets::widget>
|
||||||
Reference in New Issue
Block a user