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 5e709237b feat(bulletin): implement batch delete and update component
structure
5e709237b is described below
commit 5e709237b1b5d411a00f9c56f9d6fb5aa4fb4a8e
Author: zqr10159 <[email protected]>
AuthorDate: Fri Jul 26 00:13:45 2024 +0800
feat(bulletin): implement batch delete and update component structure
- Add functionality to allow users to delete multiple bulletin items at
once.
- Refactor the bulletin component to use a new data structure for tab
definitions.
- Replace Set with an array for managing selected define IDs to simplify
data handling.
- Modify the service and controller to support batch delete operations.
- Update the UI to improve user interaction with the bulletin selection
process.
BREAKING CHANGE: The change from using a Set to an array for
checkedDefineIds might affect consumers of this data structure who expect Set
behaviors.
---
.../manager/controller/BulletinController.java | 12 +-
.../apache/hertzbeat/manager/dao/BulletinDao.java | 5 +
.../hertzbeat/manager/service/BulletinService.java | 2 +-
.../manager/service/impl/BulletinServiceImpl.java | 10 +-
.../app/routes/bulletin/bulletin.component.html | 16 +--
.../src/app/routes/bulletin/bulletin.component.ts | 134 +++++++++------------
web-app/src/app/service/bulletin-define.service.ts | 12 +-
7 files changed, 89 insertions(+), 102 deletions(-)
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 a60c01bbd..52a0ea6f5 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
@@ -137,14 +137,14 @@ public class BulletinController {
}
/**
- * delete bulletin by id
+ * delete bulletin by name
*/
- @Operation(summary = "Delete Bulletin by ID", description = "Delete
Bulletin by ID")
+ @Operation(summary = "Delete Bulletin by Name", description = "Delete
Bulletin by Name")
@DeleteMapping
public ResponseEntity<Message<Void>> deleteBulletin(
- @Parameter(description = "Bulletin ID", example =
"402372614668544")
- @RequestParam List<Long> ids) {
- if (bulletinService.deleteBulletinById(ids)) {
+ @Parameter(description = "Bulletin Name", example =
"402372614668544")
+ @RequestParam List<String> names) {
+ if (bulletinService.deleteBulletinByName(names)) {
return ResponseEntity.ok(Message.success("Delete success"));
} else {
return ResponseEntity.ok(Message.fail(FAIL_CODE, "Delete failed"));
@@ -226,6 +226,7 @@ public class BulletinController {
for (String metric : bulletin.getMetrics().stream().map(metric ->
metric.split("-")[0]).distinct().toList()){
metricBuilder.name(metric);
CollectRep.MetricsData currentMetricsData =
realTimeDataReader.getCurrentMetricsData(bulletin.getMonitorId(), metric);
+
List<List<BulletinMetricsData.Field>> fieldsList = new
ArrayList<>();
List<CollectRep.ValueRow> valuesList =
currentMetricsData.getValuesList();
for (CollectRep.ValueRow valueRow : valuesList) {
@@ -242,6 +243,7 @@ public class BulletinController {
metricBuilder.fields(fieldsList);
metrics.add(metricBuilder.build());
}
+
contentBuilder.metrics(metrics);
dataBuilder.content(contentBuilder.build());
dataList.add(dataBuilder.build());
diff --git
a/manager/src/main/java/org/apache/hertzbeat/manager/dao/BulletinDao.java
b/manager/src/main/java/org/apache/hertzbeat/manager/dao/BulletinDao.java
index bdca1b8bf..52733783a 100644
--- a/manager/src/main/java/org/apache/hertzbeat/manager/dao/BulletinDao.java
+++ b/manager/src/main/java/org/apache/hertzbeat/manager/dao/BulletinDao.java
@@ -21,10 +21,15 @@
package org.apache.hertzbeat.manager.dao;
+import java.util.List;
import org.apache.hertzbeat.common.entity.manager.bulletin.Bulletin;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface BulletinDao extends JpaRepository<Bulletin, Long>,
JpaSpecificationExecutor<Bulletin> {
+ /**
+ * Delete Bulletin by name
+ */
+ void deleteByNameIn(List<String> names);
}
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 2c3feaaa7..e6bd45592 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
@@ -49,7 +49,7 @@ public interface BulletinService {
/**
* delete Bulletin by id
*/
- boolean deleteBulletinById(List<Long> ids);
+ boolean deleteBulletinByName(List<String> names);
/**
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 54ceac52c..84316e485 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
@@ -40,6 +40,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
/**
* Bulletin Service Implementation
@@ -140,7 +141,6 @@ public class BulletinServiceImpl implements BulletinService
{
/**
* Get Bulletin by id
*
- * @param id
*/
@Override
public Optional<Bulletin> getBulletinById(Long id) {
@@ -148,14 +148,14 @@ public class BulletinServiceImpl implements
BulletinService {
}
/**
- * delete Bulletin by ids
+ * delete Bulletin by names
*
- * @param ids
*/
@Override
- public boolean deleteBulletinById(List<Long> ids) {
+ @Transactional(rollbackFor = Exception.class)
+ public boolean deleteBulletinByName(List<String> names) {
try {
- ids.forEach(id -> bulletinDao.deleteById(id));
+ bulletinDao.deleteByNameIn(names);
return true;
} catch (Exception e) {
throw new RuntimeException(e);
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.html
b/web-app/src/app/routes/bulletin/bulletin.component.html
index 97438c8d6..8de4ee818 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.html
+++ b/web-app/src/app/routes/bulletin/bulletin.component.html
@@ -47,16 +47,11 @@
<nz-table
*ngIf="bulletinTab.data.length"
#fixedTable
- [nzData]="bulletinTab.data.slice((bulletinTab.pageIndex - 1) *
bulletinTab.pageSize, bulletinTab.pageIndex * bulletinTab.pageSize)"
- [nzPageIndex]="bulletinTab.pageIndex"
- [nzPageSize]="bulletinTab.pageSize"
- [nzTotal]="bulletinTab.total"
+ [nzData]="bulletinTab.data"
nzFrontPagination="false"
[nzLoading]="tableLoading"
nzShowSizeChanger
[nzShowTotal]="rangeTemplate"
- [nzPageSizeOptions]="[10, 20, 50, 100]"
- (nzQueryParams)="onTablePageChange($event)"
nzShowPagination="true"
[nzScroll]="{ x: 'auto' }"
nzBordered
@@ -88,14 +83,13 @@
</ng-container>
<ng-container *ngFor="let metricName of
getMetricNames(bulletinTab)">
<ng-container *ngFor="let field of
bulletinTab.bulletinColumn[metricName]">
- <td *ngIf="data[field].length > rowIndex"
- >{{ data[field][rowIndex].split('$$$')[0] }}
+ <td *ngIf= "data[field] !== null">
+ {{ data[field][rowIndex].split('$$$')[0] }}
<nz-tag *ngIf="data[field][rowIndex] == null"
nzColor="warning">{{ 'monitors.detail.value.null' | i18n }}</nz-tag>
<nz-tag *ngIf="data[field][rowIndex].split('$$$')[1]"
nzColor="success">{{
data[field][rowIndex].split('$$$')[1]
}}</nz-tag>
</td>
- <td *ngIf="data[field].length <= rowIndex"></td>
</ng-container>
</ng-container>
</tr>
@@ -217,11 +211,11 @@
<nz-select
nzMode="multiple"
nzPlaceHolder="Please select"
- [(ngModel)]="this.checkedDefineIds"
+ [(ngModel)]="this.bulletinNames"
[nzShowSearch]="true"
name="delete"
>
- <nz-option *ngFor="let bulletinTab of tabDefines"
[nzLabel]="bulletinTab.name" [nzValue]="bulletinTab.id"></nz-option>
+ <nz-option *ngFor="let bulletinTab of tabDefines"
[nzLabel]="bulletinTab.name" [nzValue]="bulletinTab.name"></nz-option>
</nz-select>
</nz-form-control>
</nz-form-item>
diff --git a/web-app/src/app/routes/bulletin/bulletin.component.ts
b/web-app/src/app/routes/bulletin/bulletin.component.ts
index 21a367774..d2dccb4e3 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.ts
+++ b/web-app/src/app/routes/bulletin/bulletin.component.ts
@@ -47,12 +47,9 @@ export class BulletinComponent implements OnInit {
@Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService
) {}
search!: string;
- pageIndex: number = 1;
- pageSize: number = 8;
- total: number = 0;
tabDefines!: any[];
tableLoading: boolean = true;
- checkedDefineIds: number[] = [];
+ bulletinNames: string[] = [];
isAppListLoading = false;
isMonitorListLoading = false;
treeNodes!: NzTreeNodeOptions[];
@@ -81,20 +78,17 @@ export class BulletinComponent implements OnInit {
}
-
-
- deleteBulletinDefines(defineIds: number[]) {
- if (defineIds == null || defineIds.length == 0) {
+ deleteBulletinDefines(defineNames: string[]) {
+ if (defineNames == null || defineNames.length == 0) {
this.notifySvc.warning(this.i18nSvc.fanyi('common.notify.no-select-delete'),
'');
return;
}
this.tableLoading = true;
- const deleteDefines$ =
this.bulletinDefineSvc.deleteBulletinDefines(defineIds).subscribe(
+ const deleteDefines$ =
this.bulletinDefineSvc.deleteBulletinDefines(defineNames).subscribe(
message => {
deleteDefines$.unsubscribe();
if (message.code === 0) {
this.notifySvc.success(this.i18nSvc.fanyi('common.notify.delete-success'), '');
- this.updatePageIndex(defineIds.length);
this.loadData();
} else {
this.tableLoading = false;
@@ -109,17 +103,6 @@ export class BulletinComponent implements OnInit {
);
}
- updatePageIndex(delSize: number) {
- const lastPage = Math.max(1, Math.ceil((this.total - delSize) /
this.pageSize));
- this.pageIndex = this.pageIndex > lastPage ? lastPage : this.pageIndex;
- }
-
-
- onTablePageChange(params: NzTableQueryParams) {
- const { pageSize, pageIndex, sort, filter } = params;
- this.pageIndex = pageIndex;
- this.pageSize = pageSize;
- }
isManageModalVisible = false;
isManageModalOkLoading = false;
@@ -354,56 +337,7 @@ export class BulletinComponent implements OnInit {
if (message.code === 0 && message.data) {
this.tableLoading = false;
this.rawData = message.data;
- const groupedData: any = {};
-
- this.rawData.forEach(item => {
- const name = item.name;
- if (!groupedData[name]) {
- groupedData[name] = {
- id: item.id,
- bulletinColumn: {},
- data: []
- };
- }
-
- let transformedItem: any = {
- app: item.app,
- monitorId: item.content.monitorId,
- host: item.content.host
- };
-
- item.content.metrics.forEach((metric: { name: string | number;
fields: any }) => {
- if (!groupedData[name].bulletinColumn[metric.name]) {
- groupedData[name].bulletinColumn[metric.name] = new
Set<string>();
- }
- metric.fields.forEach((field: any[]) => {
- field.forEach((fieldItem: any) => {
- const key = `${metric.name}$$$${fieldItem.key}`;
- const value = fieldItem.value;
- const unit = fieldItem.unit;
-
- if (!transformedItem[key]) {
- transformedItem[key] = [];
- }
- transformedItem[key].push(`${value}$$$${unit}`);
-
- groupedData[name].bulletinColumn[metric.name].add(key);
- });
- });
- });
- groupedData[name].data.push(transformedItem);
- });
-
- this.tabDefines = Object.keys(groupedData).map(name => ({
- name,
- id: groupedData[name].id,
- bulletinColumn: groupedData[name].bulletinColumn,
- data: groupedData[name].data,
- pageIndex: 1,
- pageSize: 10,
- total: groupedData[name].data.length
- }));
- console.log(this.tabDefines)
+ this.updateTabDefines();
} else if (message.code !== 0) {
this.notifySvc.warning(`${message.msg}`, '');
console.info(`${message.msg}`);
@@ -416,6 +350,55 @@ export class BulletinComponent implements OnInit {
);
}
+ updateTabDefines() {
+ const groupedData: any = {};
+
+ this.rawData.forEach(item => {
+ const name = item.name;
+ if (!groupedData[name]) {
+ groupedData[name] = {
+ id: item.id,
+ bulletinColumn: {},
+ data: []
+ };
+ }
+
+ let transformedItem: any = {
+ app: item.app,
+ monitorId: item.content.monitorId,
+ host: item.content.host
+ };
+
+ item.content.metrics.forEach((metric: { name: string | number; fields:
any }) => {
+ if (!groupedData[name].bulletinColumn[metric.name]) {
+ groupedData[name].bulletinColumn[metric.name] = new Set<string>();
+ }
+ metric.fields.forEach((field: any[]) => {
+ field.forEach((fieldItem: any) => {
+ const key = `${metric.name}$$$${fieldItem.key}`;
+ const value = fieldItem.value;
+ const unit = fieldItem.unit;
+
+ if (!transformedItem[key]) {
+ transformedItem[key] = [];
+ }
+ transformedItem[key].push(`${value}$$$${unit}`);
+
+ groupedData[name].bulletinColumn[metric.name].add(key);
+ });
+ });
+ });
+ groupedData[name].data.push(transformedItem);
+ });
+
+ this.tabDefines = Object.keys(groupedData).map(name => ({
+ name,
+ id: groupedData[name].id,
+ bulletinColumn: groupedData[name].bulletinColumn,
+ data: groupedData[name].data,
+ }));
+ }
+
getMetricNames(bulletinTab: any): string[] {
return Object.keys(bulletinTab.bulletinColumn);
}
@@ -424,7 +407,9 @@ export class BulletinComponent implements OnInit {
let maxRowSpan = 1;
for (let metricName of this.getMetricNames(bulletinTab)) {
for (let field of bulletinTab.bulletinColumn[metricName]) {
- maxRowSpan = Math.max(maxRowSpan, data[field].length);
+ if (Array.isArray(data[field])) {
+ maxRowSpan = Math.max(maxRowSpan, data[field].length);
+ }
}
}
return maxRowSpan;
@@ -446,10 +431,11 @@ export class BulletinComponent implements OnInit {
}
onDeleteModalOk() {
- console.log(this.checkedDefineIds)
- this.deleteBulletinDefines(this.checkedDefineIds);
+ this.deleteBulletinDefines(this.bulletinNames);
this.isDeleteModalOkLoading = false;
this.isDeleteModalVisible = false;
}
+
+ protected readonly Array = Array;
}
diff --git a/web-app/src/app/service/bulletin-define.service.ts
b/web-app/src/app/service/bulletin-define.service.ts
index 337bd70b5..03164df77 100644
--- a/web-app/src/app/service/bulletin-define.service.ts
+++ b/web-app/src/app/service/bulletin-define.service.ts
@@ -40,13 +40,13 @@ export class BulletinDefineService {
return this.http.put<Message<any>>(bulletin_define_uri, body);
}
- public deleteBulletinDefines(bulletinDefineIds: number[]):
Observable<Message<any>> {
- let httpParams = new HttpParams();
- bulletinDefineIds.forEach(bulletinDefineId => {
- httpParams = httpParams.append('ids', bulletinDefineId);
+ public deleteBulletinDefines(names: string[]): Observable<Message<any>> {
+ let params = new HttpParams();
+ names.forEach(name => {
+ params = params.append('names', name);
});
- const options = { params: httpParams };
- return this.http.delete<Message<any>>(bulletin_define_uri, options);
+
+ return this.http.delete<Message<any>>(bulletin_define_uri, { params });
}
public getAllMonitorMetricsData(): Observable<Message<any>> {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]