You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@hertzbeat.apache.org by zh...@apache.org on 2024/09/04 09:31:59 UTC
(hertzbeat) 03/03: ```feat(script-plugin): add script editor and parameter definition UI
This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch script
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
commit f7de9c4b650fe8682fd7f2ef4a031c763fce692f
Author: zqr10159 <zq...@126.com>
AuthorDate: Wed Sep 4 17:31:30 2024 +0800
```feat(script-plugin): add script editor and parameter definition UI
Implement a script editor and update the plugin parameter definition UI to improve the
user experience when setting up script-based plugins. The changes include the addition of
a new script editor component, adjustments to the plugin configuration UI, and updates to
the backend services to support these new features.
```
---
.../manager/controller/PluginController.java | 2 +-
.../org.apache.hertzbeat.plugin.PostAlertPlugin | 2 +
plugin/src/main/resources/define/define.yml | 45 ++++++++++++++++++++++
.../routes/setting/plugins/plugin.component.html | 2 +-
.../app/routes/setting/plugins/plugin.component.ts | 2 +
.../form-field/form-field.component.html | 13 +++++++
.../form-field/form-field.component.less | 0
web-app/src/app/shared/shared.module.ts | 38 +++++++++---------
8 files changed, 84 insertions(+), 20 deletions(-)
diff --git a/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java b/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java
index fc7d1762c..a8df4724e 100644
--- a/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java
+++ b/manager/src/main/java/org/apache/hertzbeat/manager/controller/PluginController.java
@@ -96,7 +96,7 @@ public class PluginController {
}
@PostMapping("/params")
- @Operation(summary = "get param define", description = "get param define by jar path")
+ @Operation(summary = "save param define", description = "save param define")
public ResponseEntity<Message<Boolean>> saveParams(@RequestBody List<PluginParam> pluginParams) {
pluginService.savePluginParam(pluginParams);
return ResponseEntity.ok(Message.success(true));
diff --git a/plugin/src/main/resources/META-INF/services/org.apache.hertzbeat.plugin.PostAlertPlugin b/plugin/src/main/resources/META-INF/services/org.apache.hertzbeat.plugin.PostAlertPlugin
index b1312a090..73c9c47e5 100644
--- a/plugin/src/main/resources/META-INF/services/org.apache.hertzbeat.plugin.PostAlertPlugin
+++ b/plugin/src/main/resources/META-INF/services/org.apache.hertzbeat.plugin.PostAlertPlugin
@@ -14,3 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
+
+org.apache.hertzbeat.plugin.impl.ScriptPluginImpl
\ No newline at end of file
diff --git a/plugin/src/main/resources/define/define.yml b/plugin/src/main/resources/define/define.yml
index 25b47f6ad..7456a9cc4 100644
--- a/plugin/src/main/resources/define/define.yml
+++ b/plugin/src/main/resources/define/define.yml
@@ -12,3 +12,48 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+
+params:
+ - field: type
+ name:
+ zh-CN: 脚本类型
+ en-US: Script Type
+ type: radio
+ required: true
+ options:
+ - label: Groovy
+ value: Groovy
+ - label: Shell
+ value: Shell
+ - label: JavaScript
+ value: JavaScript
+ - label: Java
+ value: Java
+ - label: QLExpress
+ value: QLExpress
+ - label: Python
+ value: Python
+ - label: Lua
+ value: Lua
+ - label: Aviator
+ value: Aviator
+ - label: Kotlin
+ value: Kotlin
+ - field: script
+ name:
+ zh-CN: 脚本内容
+ en-US: Script Content
+ type: script
+ required: true
+ - field: collector-config
+ name:
+ zh-CN: 采集器
+ en-US: Collector
+ type: collectors-selection
+ required: true
+ - field: alert-rule
+ name:
+ zh-CN: 阈值规则ID
+ en-US: Alert Rule ID
+ type: text
+ required: true
\ No newline at end of file
diff --git a/web-app/src/app/routes/setting/plugins/plugin.component.html b/web-app/src/app/routes/setting/plugins/plugin.component.html
index 0a8d3238d..d601fe3e1 100644
--- a/web-app/src/app/routes/setting/plugins/plugin.component.html
+++ b/web-app/src/app/routes/setting/plugins/plugin.component.html
@@ -80,7 +80,7 @@
<tr *ngFor="let data of fixedTable.data">
<td nzAlign="center" nzLeft [nzChecked]="checkedTagIds.has(data.id)" (nzCheckedChange)="onItemChecked(data.id, $event)"></td>
<td nzAlign="center">{{ data.name }}</td>
- <td nzAlign="left">
+ <td nzAlign="center">
<nz-tag *ngFor="let item of data?.items; let i = index" style="margin-top: 2px" class="hoverClass">
{{ 'plugin.type.' + item.type | i18n }}
</nz-tag>
diff --git a/web-app/src/app/routes/setting/plugins/plugin.component.ts b/web-app/src/app/routes/setting/plugins/plugin.component.ts
index 142a7533f..dc21f7922 100644
--- a/web-app/src/app/routes/setting/plugins/plugin.component.ts
+++ b/web-app/src/app/routes/setting/plugins/plugin.component.ts
@@ -62,6 +62,7 @@ export class SettingPluginsComponent implements OnInit {
search: string | undefined;
fileList: NzUploadFile[] = [];
pluginForm: FormGroup;
+ value!: string;
ngOnInit(): void {
this.loadPluginsTable();
@@ -316,6 +317,7 @@ export class SettingPluginsComponent implements OnInit {
}
onEditPluginParamDefineModalOk() {
+ console.log(this.value);
const savePluginParamDefine$ = this.pluginService
.savePluginParamDefine(Object.values(this.params))
.pipe(
diff --git a/web-app/src/app/shared/components/form-field/form-field.component.html b/web-app/src/app/shared/components/form-field/form-field.component.html
index 8b61e8141..a9f26ce89 100644
--- a/web-app/src/app/shared/components/form-field/form-field.component.html
+++ b/web-app/src/app/shared/components/form-field/form-field.component.html
@@ -169,3 +169,16 @@
[placeholder]="item.placeholder ? item.placeholder : ''"
></textarea>
</nz-textarea-count>
+
+<nz-code-editor
+ *ngIf="item.type === 'script'"
+ [(ngModel)]="value"
+ (ngModelChange)="onChange($event)"
+ [nzEditorOption]="{
+ language: 'javascript',
+ theme: 'vs-dark',
+ folding: true,
+ automaticLayout: true
+ }"
+ style="width: 100%; height: 300px"
+></nz-code-editor>
diff --git a/web-app/src/app/shared/components/form-field/form-field.component.less b/web-app/src/app/shared/components/form-field/form-field.component.less
deleted file mode 100644
index e69de29bb..000000000
diff --git a/web-app/src/app/shared/shared.module.ts b/web-app/src/app/shared/shared.module.ts
index bea3cd89d..4054760cc 100644
--- a/web-app/src/app/shared/shared.module.ts
+++ b/web-app/src/app/shared/shared.module.ts
@@ -24,6 +24,7 @@ import { I18nElsePipe } from './pipe/i18n-else.pipe';
import { TimezonePipe } from './pipe/timezone.pipe';
import { SHARED_DELON_MODULES } from './shared-delon.module';
import { SHARED_ZORRO_MODULES } from './shared-zorro.module';
+import {NzCodeEditorComponent} from "ng-zorro-antd/code-editor";
const ThirdModules: Array<Type<void>> = [];
const COMPONENTS: Array<Type<void>> = [
@@ -39,24 +40,25 @@ const COMPONENTS: Array<Type<void>> = [
const DIRECTIVES: Array<Type<void>> = [TimezonePipe, I18nElsePipe, ElapsedTimePipe];
@NgModule({
- imports: [
- CommonModule,
- FormsModule,
- RouterModule,
- ReactiveFormsModule,
- AlainThemeModule.forChild(),
- DelonACLModule,
- DelonFormModule,
- ...SHARED_DELON_MODULES,
- ...SHARED_ZORRO_MODULES,
- ...ThirdModules,
- NzBreadCrumbModule,
- NzTagModule,
- NzDividerComponent,
- NzRadioGroupComponent,
- NzRadioComponent,
- NzSwitchComponent
- ],
+ imports: [
+ CommonModule,
+ FormsModule,
+ RouterModule,
+ ReactiveFormsModule,
+ AlainThemeModule.forChild(),
+ DelonACLModule,
+ DelonFormModule,
+ ...SHARED_DELON_MODULES,
+ ...SHARED_ZORRO_MODULES,
+ ...ThirdModules,
+ NzBreadCrumbModule,
+ NzTagModule,
+ NzDividerComponent,
+ NzRadioGroupComponent,
+ NzRadioComponent,
+ NzSwitchComponent,
+ NzCodeEditorComponent
+ ],
declarations: [...COMPONENTS, ...DIRECTIVES, HelpMessageShowComponent],
exports: [
CommonModule,
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@hertzbeat.apache.org
For additional commands, e-mail: notifications-help@hertzbeat.apache.org