From 84e0393ebc3238e45351988b5f7c7fa3292bf31e Mon Sep 17 00:00:00 2001
From: makotocc0107 <1424018999@qq.com>
Date: Tue, 27 Aug 2024 11:01:22 +0800
Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E6=B7=BB]=E6=B7=BB=E5=8A=A0=E4=BA=86?=
=?UTF-8?q?MetricResource=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BA=93=E4=BB=A5?=
=?UTF-8?q?=E5=8F=8A=E9=A1=B5=E9=9D=A2=E5=85=83=E7=B4=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/workspace.xml | 20 ++-
.../app/Filament/Resources/MetricResource.php | 128 ++++++++++++++++++
.../MetricResource/Pages/CreateMetric.php | 12 ++
.../MetricResource/Pages/EditMetric.php | 19 +++
.../MetricResource/Pages/ListMetrics.php | 19 +++
management-panel/app/Models/Metric.php | 24 ++++
...2024_08_27_025841_create_metrics_table.php | 51 +++++++
7 files changed, 269 insertions(+), 4 deletions(-)
create mode 100644 management-panel/app/Filament/Resources/MetricResource.php
create mode 100644 management-panel/app/Filament/Resources/MetricResource/Pages/CreateMetric.php
create mode 100644 management-panel/app/Filament/Resources/MetricResource/Pages/EditMetric.php
create mode 100644 management-panel/app/Filament/Resources/MetricResource/Pages/ListMetrics.php
create mode 100644 management-panel/app/Models/Metric.php
create mode 100644 management-panel/database/migrations/2024_08_27_025841_create_metrics_table.php
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 5edb009..77bbbe2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,7 @@
-
+
@@ -26,6 +26,9 @@
+
+
+
@@ -351,7 +354,7 @@
-
+
@@ -393,7 +396,15 @@
1724726078488
-
+
+
+ 1724726680511
+
+
+
+ 1724726680511
+
+
@@ -414,6 +425,7 @@
-
+
+
\ No newline at end of file
diff --git a/management-panel/app/Filament/Resources/MetricResource.php b/management-panel/app/Filament/Resources/MetricResource.php
new file mode 100644
index 0000000..f983beb
--- /dev/null
+++ b/management-panel/app/Filament/Resources/MetricResource.php
@@ -0,0 +1,128 @@
+schema([
+ TextInput::make('name')
+ ->required()
+ ->maxLength(255),
+ TextInput::make('help')
+ ->maxLength(255),
+
+ Section::make('Node ID')
+ ->description('节点设置必须唯一')
+ ->columns([
+ 'default' => 3
+ ])
+ ->schema([
+ // 1 = Numeric, 2 = String, 3 = GUID
+ Select::make('identifier_type')
+ ->options([
+ 1 => 'Numeric',
+ 2 => 'String',
+ 3 => 'GUID',
+ ])
+ ->default(1)
+ ->label('Identifier Type')
+ ->required()
+ ->reactive(), // 确保当选择的值变化时触发其他字段的重新渲染
+
+ TextInput::make('namespace_index')
+ ->label('Namespace')
+ ->required(),
+
+ // 数值型标识符字段
+ TextInput::make('numeric_id')
+ ->label('Numeric ID')
+ ->required()
+ ->visible(fn($get) => $get('identifier_type') == Metric::TYPE_NUMERIC),
+
+ // 字符串型标识符字段
+ TextInput::make('string_id')
+ ->label('String ID')
+ ->required()
+ ->visible(fn($get) => $get('identifier_type') == Metric::TYPE_STRING),
+
+ // GUID 型标识符字段
+ TextInput::make('guid_id')
+ ->label('GUID ID')
+ ->required()
+ ->visible(fn($get) => $get('identifier_type') == Metric::TYPE_GUID),
+ ]),
+ ]);
+ }
+
+ public static function table(Table $table): Table
+ {
+ return $table
+ ->columns([
+ TextColumn::make('name'),
+ TextColumn::make('nodeid')
+ ->label('Node ID')
+ ->state(function ($record) {
+ switch ($record->identifier_type) {
+ case 1: // Numeric
+ return 'ns=' . $record->namespace_index . ';i=' . $record->numeric_id;
+ case 2: // String
+ return 'ns=' . $record->namespace_index . ';s=' . $record->string_id;
+ case 3: // GUID
+ return 'ns=' . $record->namespace_index . ';g=' . $record->guid_id;
+ default:
+ return 'Unknown Type';
+ }
+ }),
+ TextColumn::make('help')
+ ])
+ ->filters([
+ //
+ ])
+ ->actions([
+ Tables\Actions\EditAction::make(),
+ ])
+ ->bulkActions([
+ Tables\Actions\BulkActionGroup::make([
+ Tables\Actions\DeleteBulkAction::make(),
+ ]),
+ ]);
+ }
+
+ public static function getRelations(): array
+ {
+ return [
+ //
+ ];
+ }
+
+ public static function getPages(): array
+ {
+ return [
+ 'index' => Pages\ListMetrics::route('/'),
+ 'create' => Pages\CreateMetric::route('/create'),
+ 'edit' => Pages\EditMetric::route('/{record}/edit'),
+ ];
+ }
+}
diff --git a/management-panel/app/Filament/Resources/MetricResource/Pages/CreateMetric.php b/management-panel/app/Filament/Resources/MetricResource/Pages/CreateMetric.php
new file mode 100644
index 0000000..89c6dd7
--- /dev/null
+++ b/management-panel/app/Filament/Resources/MetricResource/Pages/CreateMetric.php
@@ -0,0 +1,12 @@
+id();
+ $table->string('name');
+
+ // 命名空间索引
+ $table->integer('namespace_index');
+
+ // 标识符类型,存储为整数
+ // 1 = Numeric, 2 = String, 3 = GUID
+ $table->Integer('identifier_type');
+
+ // 数值型标识符
+ $table->integer('numeric_id')->nullable();
+
+ // 字符串型标识符
+ $table->string('string_id')->nullable();
+
+ // GUID 型标识符
+ $table->char('guid_id', 36)->nullable();
+
+ $table->string('help')->nullable();
+ $table->timestamps();
+
+ // 在同一命名空间中,确保唯一标识符唯一
+ $table->unique(['namespace_index', 'numeric_id']);
+ $table->unique(['namespace_index', 'string_id']);
+ $table->unique(['namespace_index', 'guid_id']);
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::dropIfExists('metrics');
+ }
+};