This is an automated email from the ASF dual-hosted git repository.
zhaoqingran pushed a commit to branch bulletin
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/bulletin by this push:
new 2a5d12c36 [feat(bulletin)] integrate monitor selection into bulletin
component
2a5d12c36 is described below
commit 2a5d12c36a972c3852dc09175bb6c6299c48a866
Author: zqr10159 <[email protected]>
AuthorDate: Thu Jul 11 15:02:36 2024 +0800
[feat(bulletin)] integrate monitor selection into bulletin component
Introduce a new monitor selection feature in the bulletin component using
a dropdown list. This allows users to select monitors by application,
enhancing the bulletin creation process with more specific monitoring
options. The `monitorIds` property is added to the `BulletinDefine` class
to accommodate this new feature.
BREAKING CHANGE: The addition of `monitorIds` property requires updates
to any consumers of the `BulletinDefine` class.
---
.../common/entity/manager/bulletin/Bulletin.java | 4 +-
.../entity/manager/bulletin/BulletinDto.java | 4 +-
.../manager/controller/BulletinController.java | 9 ++-
.../hertzbeat/manager/service/BulletinService.java | 6 ++
.../manager/service/impl/BulletinServiceImpl.java | 24 ++++++++
script/sureness.yml | 5 +-
web-app/src/app/pojo/BulletinDefine.ts | 4 +-
.../app/routes/bulletin/bulletin.component.html | 20 ++++++-
.../src/app/routes/bulletin/bulletin.component.ts | 64 ++++++++++------------
9 files changed, 93 insertions(+), 47 deletions(-)
diff --git
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
index 46726726d..d1e4c3283 100644
---
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
+++
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/Bulletin.java
@@ -23,6 +23,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
+import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
@@ -40,6 +41,7 @@ import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
+import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
* Bulletin
@@ -50,12 +52,12 @@ import org.springframework.data.annotation.LastModifiedDate;
@Builder
@AllArgsConstructor
@NoArgsConstructor
+@EntityListeners(AuditingEntityListener.class)
@Table(name = "hzb_bulletin")
public class Bulletin {
@Id
@Schema(description = "Bulletin ID", example = "1")
- @GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Schema(description = "Monitor ID", example = "1")
diff --git
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinDto.java
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinDto.java
index 707990ed4..fae1037bb 100644
---
a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinDto.java
+++
b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/bulletin/BulletinDto.java
@@ -40,8 +40,8 @@ public class BulletinDto {
private List<String> metrics;
/**
- * Monitor tags eg: host:name
+ * Monitor ids
*/
- private List<TagItem> tags;
+ private List<Long> monitorIds;
}
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
index 8de21422b..5660bfe32 100644
---
a/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
+++
b/manager/src/main/java/org/apache/hertzbeat/manager/controller/BulletinController.java
@@ -18,6 +18,7 @@
package org.apache.hertzbeat.manager.controller;
+import static org.apache.hertzbeat.common.constants.CommonConstants.FAIL_CODE;
import io.swagger.v3.oas.annotations.Parameter;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;
@@ -57,9 +58,11 @@ public class BulletinController {
*/
@PostMapping
public ResponseEntity<Message<Void>> addNewBulletin(@Valid @RequestBody
BulletinDto bulletinDto) {
-// bulletinService.validate(bulletinDto., false);
-// bulletinService.saveBulletin(bulletin);
- return ResponseEntity.ok(Message.success("Add success"));
+ if (bulletinService.addBulletin(bulletinDto)) {
+ return ResponseEntity.ok(Message.success("Add success"));
+ }else {
+ return ResponseEntity.ok(Message.fail(FAIL_CODE, "Add failed"));
+ }
}
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
b/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
index 3a5d57b7b..345247aa1 100644
---
a/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
+++
b/manager/src/main/java/org/apache/hertzbeat/manager/service/BulletinService.java
@@ -19,6 +19,7 @@ package org.apache.hertzbeat.manager.service;
import java.util.List;
import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
+import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
@@ -43,6 +44,11 @@ public interface BulletinService {
*/
void saveBulletin(Bulletin bulletin);
+ /**
+ * Add Bulletin
+ */
+ boolean addBulletin(BulletinDto bulletinDto);
+
/**
* Dynamic conditional query
* @param specification Query conditions
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
index 16392e014..b13cdf173 100644
---
a/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
+++
b/manager/src/main/java/org/apache/hertzbeat/manager/service/impl/BulletinServiceImpl.java
@@ -20,8 +20,11 @@
package org.apache.hertzbeat.manager.service.impl;
+import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
+import org.apache.hertzbeat.common.entity.manager.bulletin.BulletinDto;
+import org.apache.hertzbeat.common.util.SnowFlakeIdGenerator;
import org.apache.hertzbeat.manager.dao.BulletinDao;
import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
import org.apache.hertzbeat.manager.service.BulletinService;
@@ -74,6 +77,27 @@ public class BulletinServiceImpl implements BulletinService {
bulletinDao.save(bulletin);
}
+ /**
+ * Add Bulletin
+ */
+ @Override
+ public boolean addBulletin(BulletinDto bulletinDto) {
+ try {
+ List<Bulletin> bulletins = new ArrayList<>();
+ for (Long monitorId : bulletinDto.getMonitorIds()) {
+ Bulletin bulletin = new Bulletin();
+ bulletin.setId(SnowFlakeIdGenerator.generateId());
+ bulletin.setMetrics(bulletinDto.getMetrics());
+ bulletin.setMonitorId(monitorId);
+ bulletins.add(bulletin);
+ }
+ bulletinDao.saveAll(bulletins);
+ return true;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
/**
* Dynamic conditional query
*
diff --git a/script/sureness.yml b/script/sureness.yml
index c7253ff88..6ba3bf092 100644
--- a/script/sureness.yml
+++ b/script/sureness.yml
@@ -58,7 +58,10 @@ resourceRole:
- /api/status/page/**===post===[admin,user]
- /api/status/page/**===put===[admin,user]
- /api/status/page/**===delete===[admin]
-
+ - /api/bulletin/**===get===[admin,user,guest]
+ - /api/bulletin/**===post===[admin,user]
+ - /api/bulletin/**===put===[admin,user]
+ - /api/bulletin/**===delete===[admin]
# config the resource restful api that need bypass auth protection
# rule: api===method
# eg: /api/v1/source3===get means /api/v1/source3===get can be access by
anyone, no need auth.
diff --git a/web-app/src/app/pojo/BulletinDefine.ts
b/web-app/src/app/pojo/BulletinDefine.ts
index 22eed4608..400afd042 100644
--- a/web-app/src/app/pojo/BulletinDefine.ts
+++ b/web-app/src/app/pojo/BulletinDefine.ts
@@ -17,13 +17,11 @@
* under the License.
*/
-import {Monitor} from "./Monitor";
-import {TagItem} from "./NoticeRule";
export class BulletinDefine {
id!: number;
+ monitorIds!: number[];
app!: string;
- tags!: TagItem[];
metrics!: string[];
}
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.html
b/web-app/src/app/routes/bulletin/bulletin.component.html
index 70f7d451b..3fbd5b141 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.html
+++ b/web-app/src/app/routes/bulletin/bulletin.component.html
@@ -153,6 +153,23 @@
</nz-select>
</nz-form-control>
</nz-form-item>
+ <nz-form-item>
+ <nz-form-label [nzSpan]="7" nzFor="dropdown" nzRequired="true">{{
'dropdown.label' | i18n }}</nz-form-label>
+ <nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' |
i18n">
+ <nz-select
+ nzAllowClear
+ nzShowSearch
+ name="monitors"
+ [(ngModel)]="define.monitorIds"
+ (nzOnSearch)="onSearchMonitorsByApp(define.app)"
+ nzMode="multiple"
+ >
+ <ng-container *ngFor="let monitor of monitors">
+ <nz-option *ngIf="isMonitorListLoading" [nzValue]="monitor.id"
[nzLabel]="monitor.name"></nz-option>
+ </ng-container>
+ </nz-select>
+ </nz-form-control>
+ </nz-form-item>
<nz-form-item>
<nz-form-label [nzSpan]="7" nzFor="dropdown" nzRequired="true">{{
'dropdown.label' | i18n }}</nz-form-label>
<nz-form-control [nzSpan]="12" [nzErrorTip]="'validation.required' |
i18n">
@@ -160,7 +177,8 @@
[nzDataSource]="hierarchies"
[nzShowSelectAll]="false"
[nzRenderList]="[leftRenderList, null]"
- (nzChange)="transferChange($event)">
+ (nzChange)="transferChange($event)"
+ >
<ng-template #leftRenderList let-items
let-onItemSelect="onItemSelect">
<nz-tree
[nzData]="treeNodes"
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.ts
b/web-app/src/app/routes/bulletin/bulletin.component.ts
index cb46b4c13..b2343a016 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.ts
+++ b/web-app/src/app/routes/bulletin/bulletin.component.ts
@@ -67,11 +67,13 @@ export class BulletinComponent implements OnInit {
checkedDefineIds = new Set<number>();
isSwitchExportTypeModalVisible = false;
isAppListLoading = false;
+ isMonitorListLoading = false;
treeNodes!: NzTreeNodeOptions[];
hierarchies: NzTreeNodeOptions[] = [];
appMap = new Map<string, string>();
appEntries: Array<{ value: any; key: string }> = [];
checkedNodeList: NzTreeNode[] = [];
+ monitors: Monitor[] = [];
switchExportTypeModalFooter: ModalButtonOptions[] = [
{ label: this.i18nSvc.fanyi('common.button.cancel'), type: 'default',
onClick: () => (this.isSwitchExportTypeModalVisible = false) }
];
@@ -109,8 +111,8 @@ export class BulletinComponent implements OnInit {
onNewBulletinDefine() {
this.define = new BulletinDefine();
- this.define.tags = [];
this.define.metrics = [];
+ this.define.monitorIds = [];
this.isManageModalAdd = true;
this.isManageModalVisible = true;
this.isManageModalOkLoading = false;
@@ -182,8 +184,8 @@ export class BulletinComponent implements OnInit {
message => {
if (message.code === 0) {
this.define = message.data;
- if (this.define.tags == undefined) {
- this.define.tags = [];
+ if (this.define.monitorIds == undefined) {
+ this.define.monitorIds = [];
}
} else {
this.notifySvc.error(this.i18nSvc.fanyi('common.notify.monitor-fail'),
message.msg);
@@ -291,7 +293,6 @@ export class BulletinComponent implements OnInit {
isManageModalAdd = true;
define: BulletinDefine = new BulletinDefine();
-
onManageModalCancel() {
this.isManageModalVisible = false;
}
@@ -392,11 +393,6 @@ export class BulletinComponent implements OnInit {
}
onTagManageModalOk() {
this.isTagManageModalOkLoading = true;
- this.checkedTags.forEach(item => {
- if (this.define.tags.find(tag => tag.name == item.name && tag.value ==
item.tagValue) == undefined) {
- this.define.tags.push({ name: item.name, value: item.tagValue });
- }
- });
this.isTagManageModalOkLoading = false;
this.isTagManageModalVisible = false;
}
@@ -492,7 +488,6 @@ export class BulletinComponent implements OnInit {
}
);
}
- // 获取应用定义
onSearchAppDefines(): void {
this.appDefineSvc
.getAppDefines(this.i18nSvc.defaultLang)
@@ -515,7 +510,28 @@ export class BulletinComponent implements OnInit {
);
}
- // 应用改变事件
+ onSearchMonitorsByApp(app: string): void {
+ this.monitorSvc
+ .getMonitorsByApp(app)
+ .pipe()
+ .subscribe(
+ message => {
+ if (message.code === 0) {
+ this.monitors = message.data;
+ if (this.monitors != null) {
+ this.isMonitorListLoading = true;
+ }
+ console.log(this.monitors);
+ } else {
+ console.warn(message.msg);
+ }
+ },
+ error => {
+ console.warn(error.msg);
+ }
+ );
+ }
+
onAppChange(appKey: string): void {
if (appKey) {
this.onSearchTreeNodes(appKey);
@@ -525,8 +541,6 @@ export class BulletinComponent implements OnInit {
}
}
-
- // 获取树节点
onSearchTreeNodes(app: string): void {
this.appDefineSvc
.getAppHierarchyByName(this.i18nSvc.defaultLang, app)
@@ -535,7 +549,6 @@ export class BulletinComponent implements OnInit {
message => {
if (message.code === 0) {
this.hierarchies = this.transformToTransferItems(message.data);
- // this.treeNodes = this.transformToTreeData(message.data);
this.treeNodes = this.generateTree(this.hierarchies);
} else {
console.warn(message.msg);
@@ -547,7 +560,6 @@ export class BulletinComponent implements OnInit {
);
}
- // 转换为 TransferItem
transformToTransferItems(data: any[]): NzTreeNodeOptions[] {
const result: NzTreeNodeOptions[] = [];
let currentId = 1;
@@ -580,26 +592,8 @@ export class BulletinComponent implements OnInit {
return result;
}
-
-
- transformToTreeData(data: any[]): NzTreeNodeOptions[] {
- const transformNode = (node: any): NzTreeNodeOptions => {
- return {
- title: node.label,
- key: node.value,
- isLeaf: node.isLeaf,
- children: node.children ? node.children.map(transformNode) : []
- };
- };
-
- // 假设最外层节点只有一个
- const rootNode = data[0];
- return rootNode.children ? rootNode.children.map(transformNode) : [];
- }
-
private generateTree(arr: NzTreeNodeOptions[]): NzTreeNodeOptions[] {
const tree: NzTreeNodeOptions[] = [];
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
const mappedArr: any = {};
let arrElem: NzTreeNodeOptions;
let mappedElem: NzTreeNodeOptions;
@@ -623,8 +617,6 @@ export class BulletinComponent implements OnInit {
return tree;
}
-
-
treeCheckBoxChange(event: NzFormatEmitEvent, onItemSelect: (item:
NzTreeNodeOptions) => void): void {
this.checkBoxChange(event.node!, onItemSelect);
}
@@ -651,7 +643,7 @@ export class BulletinComponent implements OnInit {
this.checkedNodeList.forEach(node => {
node.isDisabled = isDisabled;
node.isChecked = isDisabled;
- this.define.metrics.push(node.key)
+ this.define.metrics.push(node.key);
});
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]