From ecc3f1edcd2c8b3c4fbd986fc63f2b2babf973ce Mon Sep 17 00:00:00 2001 From: tomsun28 Date: Tue, 15 Mar 2022 16:18:02 +0800 Subject: [PATCH] =?UTF-8?q?[manager,webapp]feature=20=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=94=AF=E6=8C=81=E8=BF=87=E6=BB=A4=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MonitorsController.java | 7 ++ .../layout/basic/widgets/search.component.ts | 2 +- .../alert-center/alert-center.component.html | 1 + .../monitor-list/monitor-list.component.html | 76 +++++++++++++------ .../monitor-list/monitor-list.component.ts | 30 ++++++++ web-app/src/app/service/monitor.service.ts | 17 ++++- 6 files changed, 104 insertions(+), 29 deletions(-) diff --git a/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java b/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java index 474c3f8..369df01 100644 --- a/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java +++ b/manager/src/main/java/com/usthe/manager/controller/MonitorsController.java @@ -38,6 +38,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @RequestMapping(path = "/monitors", produces = {APPLICATION_JSON_VALUE}) public class MonitorsController { + private static final byte ALL_MONITOR_STATUS = 9; + @Autowired private MonitorService monitorService; @@ -48,6 +50,7 @@ public class MonitorsController { @ApiParam(value = "监控类型", example = "linux") @RequestParam(required = false) final String app, @ApiParam(value = "监控名称,模糊查询", example = "linux-127.0.0.1") @RequestParam(required = false) final String name, @ApiParam(value = "监控Host,模糊查询", example = "127.0.0.1") @RequestParam(required = false) final String host, + @ApiParam(value = "监控状态 0:未监控,1:可用,2:不可用,3:不可达,4:挂起,9:全部状态", example = "1") @RequestParam(required = false) final Byte status, @ApiParam(value = "排序字段,默认id", example = "name") @RequestParam(defaultValue = "id") final String sort, @ApiParam(value = "排序方式,asc:升序,desc:降序", example = "desc") @RequestParam(defaultValue = "desc") final String order, @ApiParam(value = "列表当前分页", example = "0") @RequestParam(defaultValue = "0") int pageIndex, @@ -66,6 +69,10 @@ public class MonitorsController { Predicate predicateApp = criteriaBuilder.equal(root.get("app"), app); andList.add(predicateApp); } + if (status != null && status >= 0 && status < ALL_MONITOR_STATUS) { + Predicate predicateStatus = criteriaBuilder.equal(root.get("status"), status); + andList.add(predicateStatus); + } Predicate[] andPredicates = new Predicate[andList.size()]; Predicate andPredicate = criteriaBuilder.and(andList.toArray(andPredicates)); diff --git a/web-app/src/app/layout/basic/widgets/search.component.ts b/web-app/src/app/layout/basic/widgets/search.component.ts index 05f37cb..2ee5219 100644 --- a/web-app/src/app/layout/basic/widgets/search.component.ts +++ b/web-app/src/app/layout/basic/widgets/search.component.ts @@ -90,7 +90,7 @@ export class HeaderSearchComponent implements AfterViewInit, OnDestroy { ) .subscribe(value => { // 远程加载搜索数据 - let searchMonitors$ = this.monitorSvc.searchMonitors(value, value, 0, 10).subscribe( + let searchMonitors$ = this.monitorSvc.searchMonitors(null, value, 9, 0, 10).subscribe( message => { this.loading = false; searchMonitors$.unsubscribe(); diff --git a/web-app/src/app/routes/alert/alert-center/alert-center.component.html b/web-app/src/app/routes/alert/alert-center/alert-center.component.html index 074f375..51972d0 100644 --- a/web-app/src/app/routes/alert/alert-center/alert-center.component.html +++ b/web-app/src/app/routes/alert/alert-center/alert-center.component.html @@ -37,6 +37,7 @@ type="text" placeholder="搜索告警内容" nzSize="default" + (keyup.enter)="onFilterSearchAlerts()" [(ngModel)]="filterContent" /> - - - - - - + +
+ + + + + + + + + + + + + + + + +
(); + // 过滤搜索 + filterContent!: string; + filterStatus: number = 9; ngOnInit(): void { this.route.queryParamMap.subscribe(paramMap => { @@ -42,6 +45,33 @@ export class MonitorListComponent implements OnInit { }); } + onFilterSearchMonitors() { + this.tableLoading = true; + let filter$ = this.monitorSvc + .searchMonitors(this.app, this.filterContent, this.filterStatus, this.pageIndex - 1, this.pageSize) + .subscribe( + message => { + filter$.unsubscribe(); + this.tableLoading = false; + this.checkedAll = false; + this.checkedMonitorIds.clear(); + if (message.code === 0) { + let page = message.data; + this.monitors = page.content; + this.pageIndex = page.number + 1; + this.total = page.totalElements; + } else { + console.warn(message.msg); + } + }, + error => { + this.tableLoading = false; + filter$.unsubscribe(); + console.error(error.msg); + } + ); + } + sync() { this.loadMonitorTable(); } diff --git a/web-app/src/app/service/monitor.service.ts b/web-app/src/app/service/monitor.service.ts index af68c60..ce188a1 100644 --- a/web-app/src/app/service/monitor.service.ts +++ b/web-app/src/app/service/monitor.service.ts @@ -88,17 +88,28 @@ export class MonitorService { return this.http.get>>(monitors_uri, options); } - public searchMonitors(monitorName: string, monitorHost: string, pageIndex: number, pageSize: number): Observable>> { + public searchMonitors( + app: string | null, + searchValue: string, + status: number, + pageIndex: number, + pageSize: number + ): Observable>> { pageIndex = pageIndex ? pageIndex : 0; pageSize = pageSize ? pageSize : 8; + status = status ? status : 9; // 注意HttpParams是不可变对象 需要保存set后返回的对象为最新对象 let httpParams = new HttpParams(); httpParams = httpParams.appendAll({ - name: monitorName, - host: monitorHost, + name: searchValue, + host: searchValue, + status: status, pageIndex: pageIndex, pageSize: pageSize }); + if (app != undefined) { + httpParams = httpParams.append('app', app); + } const options = { params: httpParams }; return this.http.get>>(monitors_uri, options); }