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 e1a261d1e feat(bulletin): implement batch delete and update component 
structure
e1a261d1e is described below

commit e1a261d1eaceacb833496d444d566edc4bd06ba1
Author: zqr10159 <[email protected]>
AuthorDate: Tue Jul 23 23:21:53 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     |  4 +--
 .../hertzbeat/manager/service/BulletinService.java |  2 +-
 .../manager/service/impl/BulletinServiceImpl.java  |  8 ++---
 .../app/routes/bulletin/bulletin.component.html    |  5 +--
 .../src/app/routes/bulletin/bulletin.component.ts  | 35 ++++++++-------------
 web-app/src/app/service/bulletin-define.service.ts | 36 +---------------------
 6 files changed, 23 insertions(+), 67 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 6d3df1819..a60c01bbd 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
@@ -143,8 +143,8 @@ public class BulletinController {
     @DeleteMapping
     public ResponseEntity<Message<Void>> deleteBulletin(
             @Parameter(description = "Bulletin ID", example = 
"402372614668544")
-            @RequestParam Long id) {
-        if (bulletinService.deleteBulletinById(id)) {
+            @RequestParam List<Long> ids) {
+        if (bulletinService.deleteBulletinById(ids)) {
             return ResponseEntity.ok(Message.success("Delete success"));
         } else {
             return ResponseEntity.ok(Message.fail(FAIL_CODE, "Delete 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 7825f8718..2c3feaaa7 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(Long id);
+    boolean deleteBulletinById(List<Long> ids);
 
 
     /**
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 0ff652895..54ceac52c 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
@@ -148,14 +148,14 @@ public class BulletinServiceImpl implements 
BulletinService {
     }
 
     /**
-     * delete Bulletin by id
+     * delete Bulletin by ids
      *
-     * @param id
+     * @param ids
      */
     @Override
-    public boolean deleteBulletinById(Long id) {
+    public boolean deleteBulletinById(List<Long> ids) {
         try {
-            bulletinDao.deleteById(id);
+            ids.forEach(id -> bulletinDao.deleteById(id));
             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 7b2be91ea..97438c8d6 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.html
+++ b/web-app/src/app/routes/bulletin/bulletin.component.html
@@ -217,10 +217,11 @@
           <nz-select
             nzMode="multiple"
             nzPlaceHolder="Please select"
-            [(ngModel)]="this.tabDefines"
+            [(ngModel)]="this.checkedDefineIds"
             [nzShowSearch]="true"
+            name="delete"
           >
-            <nz-option *ngFor="let bulletinTab of tabDefines" 
[nzLabel]="bulletinTab.name" [nzValue]="bulletinTab.name"></nz-option>
+            <nz-option *ngFor="let bulletinTab of tabDefines" 
[nzLabel]="bulletinTab.name" [nzValue]="bulletinTab.id"></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 11c23b298..21a367774 100644
--- a/web-app/src/app/routes/bulletin/bulletin.component.ts
+++ b/web-app/src/app/routes/bulletin/bulletin.component.ts
@@ -26,14 +26,11 @@ import { NzTableQueryParams } from 'ng-zorro-antd/table';
 import { TransferChange } from 'ng-zorro-antd/transfer';
 import { NzFormatEmitEvent, NzTreeNode, NzTreeNodeOptions } from 
'ng-zorro-antd/tree';
 import { finalize } from 'rxjs/operators';
-
 import { BulletinDefine } from '../../pojo/BulletinDefine';
 import { Monitor } from '../../pojo/Monitor';
-import { AlertDefineService } from '../../service/alert-define.service';
 import { AppDefineService } from '../../service/app-define.service';
 import { BulletinDefineService } from '../../service/bulletin-define.service';
 import { MonitorService } from '../../service/monitor.service';
-import { TagService } from '../../service/tag.service';
 
 @Component({
   selector: 'app-bulletin',
@@ -53,10 +50,9 @@ export class BulletinComponent implements OnInit {
   pageIndex: number = 1;
   pageSize: number = 8;
   total: number = 0;
-  defines!: BulletinDefine[];
   tabDefines!: any[];
   tableLoading: boolean = true;
-  checkedDefineIds = new Set<number>();
+  checkedDefineIds: number[] = [];
   isAppListLoading = false;
   isMonitorListLoading = false;
   treeNodes!: NzTreeNodeOptions[];
@@ -85,22 +81,10 @@ export class BulletinComponent implements OnInit {
   }
 
 
-  onDeleteOneBulletinDefine(bulletinDefineId: number) {
-    let defineIds = new Set<number>();
-    defineIds.add(bulletinDefineId);
-    this.modal.confirm({
-      nzTitle: this.i18nSvc.fanyi('common.confirm.delete'),
-      nzOkText: this.i18nSvc.fanyi('common.button.ok'),
-      nzCancelText: this.i18nSvc.fanyi('common.button.cancel'),
-      nzOkDanger: true,
-      nzOkType: 'primary',
-      nzClosable: false,
-      nzOnOk: () => this.deleteBulletinDefines(defineIds)
-    });
-  }
 
-  deleteBulletinDefines(defineIds: Set<number>) {
-    if (defineIds == null || defineIds.size == 0) {
+
+  deleteBulletinDefines(defineIds: number[]) {
+    if (defineIds == null || defineIds.length == 0) {
       
this.notifySvc.warning(this.i18nSvc.fanyi('common.notify.no-select-delete'), 
'');
       return;
     }
@@ -110,7 +94,7 @@ export class BulletinComponent implements OnInit {
         deleteDefines$.unsubscribe();
         if (message.code === 0) {
           
this.notifySvc.success(this.i18nSvc.fanyi('common.notify.delete-success'), '');
-          this.updatePageIndex(defineIds.size);
+          this.updatePageIndex(defineIds.length);
           this.loadData();
         } else {
           this.tableLoading = false;
@@ -376,13 +360,13 @@ export class BulletinComponent implements OnInit {
             const name = item.name;
             if (!groupedData[name]) {
               groupedData[name] = {
+                id: item.id,
                 bulletinColumn: {},
                 data: []
               };
             }
 
             let transformedItem: any = {
-              id: item.id,
               app: item.app,
               monitorId: item.content.monitorId,
               host: item.content.host
@@ -395,7 +379,6 @@ export class BulletinComponent implements OnInit {
               metric.fields.forEach((field: any[]) => {
                 field.forEach((fieldItem: any) => {
                   const key = `${metric.name}$$$${fieldItem.key}`;
-                  console.log(key);
                   const value = fieldItem.value;
                   const unit = fieldItem.unit;
 
@@ -413,12 +396,14 @@ export class BulletinComponent implements OnInit {
 
           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)
         } else if (message.code !== 0) {
           this.notifySvc.warning(`${message.msg}`, '');
           console.info(`${message.msg}`);
@@ -461,6 +446,10 @@ export class BulletinComponent implements OnInit {
   }
 
   onDeleteModalOk() {
+    console.log(this.checkedDefineIds)
+    this.deleteBulletinDefines(this.checkedDefineIds);
+    this.isDeleteModalOkLoading = false;
+    this.isDeleteModalVisible = false;
 
   }
 }
diff --git a/web-app/src/app/service/bulletin-define.service.ts 
b/web-app/src/app/service/bulletin-define.service.ts
index 019144de8..337bd70b5 100644
--- a/web-app/src/app/service/bulletin-define.service.ts
+++ b/web-app/src/app/service/bulletin-define.service.ts
@@ -21,8 +21,6 @@ import {Injectable} from "@angular/core";
 import {HttpClient, HttpParams} from "@angular/common/http";
 import {Observable} from "rxjs";
 import {Message} from "../pojo/Message";
-import {Page} from "../pojo/Page";
-import {AlertDefine} from "../pojo/AlertDefine";
 import {BulletinDefine} from "../pojo/BulletinDefine";
 
 const bulletin_define_uri = '/bulletin';
@@ -42,47 +40,15 @@ export class BulletinDefineService {
     return this.http.put<Message<any>>(bulletin_define_uri, body);
   }
 
-  public getBulletinDefine(bulletinDefineId: number): 
Observable<Message<BulletinDefine>> {
-    return 
this.http.get<Message<BulletinDefine>>(`${bulletin_define_uri}/${bulletinDefineId}`);
-  }
-
-  public deleteBulletinDefines(bulletinDefineIds: Set<number>): 
Observable<Message<any>> {
+  public deleteBulletinDefines(bulletinDefineIds: number[]): 
Observable<Message<any>> {
     let httpParams = new HttpParams();
     bulletinDefineIds.forEach(bulletinDefineId => {
-      // 注意HttpParams是不可变对象 需要保存append后返回的对象为最新对象
-      // append方法可以叠加同一key, set方法会把key之前的值覆盖只留一个key-value
       httpParams = httpParams.append('ids', bulletinDefineId);
     });
     const options = { params: httpParams };
     return this.http.delete<Message<any>>(bulletin_define_uri, options);
   }
 
-  public getBulletinDefines(search: string | undefined, pageIndex: number, 
pageSize: number): Observable<Message<Page<BulletinDefine>>> {
-    pageIndex = pageIndex ? pageIndex : 0;
-    pageSize = pageSize ? pageSize : 8;
-    // 注意HttpParams是不可变对象 需要保存set后返回的对象为最新对象
-    let httpParams = new HttpParams();
-    httpParams = httpParams.appendAll({
-      sort: 'id',
-      order: 'desc',
-      pageIndex: pageIndex,
-      pageSize: pageSize
-    });
-    if (search != undefined && search.trim() != '') {
-      httpParams = httpParams.append('search', search.trim());
-    }
-    const options = { params: httpParams };
-    return this.http.get<Message<Page<BulletinDefine>>>(bulletin_define_uri, 
options);
-  }
-
-  public deleteBulletinDefine() {
-    console.log("deleteBulletinDefine");
-  }
-
-  public getMonitorMetricsData(bulletinId: number): Observable<Message<any>> {
-    return 
this.http.get<Message<any>>(`${bulletin_define_uri}/metrics/${bulletinId}`);
-  }
-
   public getAllMonitorMetricsData(): Observable<Message<any>> {
     return this.http.get<Message<any>>(`${bulletin_define_uri}/metrics`);
   }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to