This is an automated email from the ASF dual-hosted git repository. gongchao pushed a commit to branch integte-extern-alarm in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
commit 243a87178a995dff2eab5399a943ce02e69f429b Author: tomsun28 <tomsu...@outlook.com> AuthorDate: Fri Jan 10 23:36:14 2025 +0800 [webapp] add alert integration Signed-off-by: tomsun28 <tomsu...@outlook.com> --- .../alert-integration.component.ts | 38 ++++++++++++++++++---- .../src/app/routes/alert/alert-routing.module.ts | 2 +- web-app/src/assets/app-data.json | 2 +- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts b/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts index aef7601346..c424d1ff88 100644 --- a/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts +++ b/web-app/src/app/routes/alert/alert-integration/alert-integration.component.ts @@ -1,6 +1,7 @@ import { CommonModule } from '@angular/common'; import { HttpClient, HttpClientModule } from '@angular/common/http'; import { Component, Inject, OnInit } from '@angular/core'; +import { Router, ActivatedRoute } from '@angular/router'; import { I18NService } from '@core'; import { ALAIN_I18N_TOKEN, I18nPipe } from '@delon/theme'; import { SharedModule } from '@shared'; @@ -38,7 +39,7 @@ export class AlertIntegrationComponent implements OnInit { id: 'alertmanager', name: this.i18nSvc.fanyi('alert.integration.source.alertmanager'), icon: 'assets/img/integration/prometheus.svg' - }, + } // { // id: 'tencent', // name: this.i18nSvc.fanyi('alert.integration.source.tencent'), @@ -49,19 +50,42 @@ export class AlertIntegrationComponent implements OnInit { selectedSource: DataSource | null = null; markdownContent: string = ''; - constructor(private http: HttpClient, @Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService) { - this.selectedSource = this.dataSources[0]; - } + constructor( + private http: HttpClient, + @Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService, + private router: Router, + private route: ActivatedRoute + ) {} ngOnInit() { - if (this.selectedSource) { - this.loadMarkdownContent(this.selectedSource); - } + this.route.params.subscribe(params => { + const sourceId = params['source']; + if (sourceId) { + // 查找匹配的数据源 + const source = this.dataSources.find(s => s.id === sourceId); + if (source) { + this.selectedSource = source; + } else { + // 如果找不到匹配的数据源,使用第一个作为默认值 + this.selectedSource = this.dataSources[0]; + this.router.navigate(['/alert/integration/', this.selectedSource.id]); + } + } else { + // 没有路由参数时使用第一个数据源 + this.selectedSource = this.dataSources[0]; + this.router.navigate(['/alert/integration/', this.selectedSource.id]); + } + + if (this.selectedSource) { + this.loadMarkdownContent(this.selectedSource); + } + }); } selectSource(source: DataSource) { this.selectedSource = source; this.loadMarkdownContent(source); + this.router.navigate(['/alert/integration', source.id]); } private loadMarkdownContent(source: DataSource) { diff --git a/web-app/src/app/routes/alert/alert-routing.module.ts b/web-app/src/app/routes/alert/alert-routing.module.ts index a644668ef0..0200c4887b 100644 --- a/web-app/src/app/routes/alert/alert-routing.module.ts +++ b/web-app/src/app/routes/alert/alert-routing.module.ts @@ -36,7 +36,7 @@ const routes: Routes = [ { path: 'silence', component: AlertSilenceComponent }, { path: 'group', component: AlertGroupConvergeComponent }, { path: 'inhibit', component: AlertInhibitComponent }, - { path: 'integration', component: AlertIntegrationComponent } + { path: 'integration/:source', component: AlertIntegrationComponent } ]; @NgModule({ diff --git a/web-app/src/assets/app-data.json b/web-app/src/assets/app-data.json index 1d37777a5b..726700a432 100644 --- a/web-app/src/assets/app-data.json +++ b/web-app/src/assets/app-data.json @@ -153,7 +153,7 @@ "text": "Integration", "i18n": "menu.alert.integration", "icon": "anticon-api", - "link": "/alert/integration" + "link": "/alert/integration/webhook" }, { "text": "Group", --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@hertzbeat.apache.org For additional commands, e-mail: notifications-h...@hertzbeat.apache.org