Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Add a copy button to the monitoring center #2060

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@
<i nz-icon nzType="edit" nzTheme="outline"></i>
</button>
</li>
<li nz-menu-item>
<button nz-button nzType="primary" (click)="onCopyMonitor(data)" nz-tooltip [nzTooltipTitle]="'monitors.copy-monitor' | i18n">
<i nz-icon nzType="copy" nzTheme="outline"></i>
</button>
</li>
<li nz-menu-item>
<button
*ngIf="data.status == 0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ export class MonitorListComponent implements OnInit, OnDestroy {
});
}

onCopyMonitor(data: any) {
this.monitorSvc.setMonitorData(data);
// 传入action 用于区分是复制还是新建
this.router.navigate(['/monitors/new'], { queryParams: { action: 'copy' } }).then(r => {});
}

onDeleteMonitors() {
if (this.checkedMonitorIds == null || this.checkedMonitorIds.size === 0) {
this.notifySvc.warning(this.i18nSvc.fanyi('common.notify.no-select-delete'), '');
Expand Down
167 changes: 90 additions & 77 deletions web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { I18NService } from '@core';
import { ALAIN_I18N_TOKEN, TitleService } from '@delon/theme';
import { List } from 'echarts';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { switchMap } from 'rxjs/operators';
import { switchMap, take } from 'rxjs/operators';

import { Collector } from '../../../pojo/Collector';
import { Message } from '../../../pojo/Message';
Expand Down Expand Up @@ -74,86 +74,99 @@ export class MonitorNewComponent implements OnInit {
}

ngOnInit(): void {
this.route.queryParamMap
.pipe(
switchMap((paramMap: ParamMap) => {
this.monitor.app = paramMap.get('app') || '';
if (this.monitor.app == '') {
this.router.navigateByUrl('/monitors/new?app=website');
}
this.titleSvc.setTitleByI18n(`monitor.app.${this.monitor.app}`);
this.detected = false;
this.passwordVisible = false;
this.isSpinning = true;
return this.appDefineSvc.getAppParamsDefine(this.monitor.app);
})
)
.pipe(
switchMap((message: Message<ParamDefine[]>) => {
if (message.code === 0) {
this.params = [];
this.advancedParams = [];
this.paramDefines = [];
this.advancedParamDefines = [];
message.data.forEach(define => {
let param = new Param();
param.field = define.field;
if (define.type === 'number') {
param.type = 0;
} else if (define.type === 'key-value') {
param.type = 3;
} else if (define.type === 'array') {
param.type = 4;
} else {
param.type = 1;
}
if (define.type === 'boolean') {
param.paramValue = false;
}
if (define.defaultValue != undefined) {
// In the ngOnInit method, we distinguish between the 'copy' operation and the 'new' operation.
// If the 'action' query parameter is 'copy', we retrieve the data from the service and use it to initialize the form.
// If the 'action' query parameter is not 'copy' (or is not present), we assume it's a 'new' operation and initialize the form with default values.
let action = this.route.snapshot.queryParamMap.get('action');
if (action != null && action === 'copy') {
this.monitorSvc.getMonitorData().subscribe(data => {
if (data != null) {
this.monitor = data;
this.titleSvc.setTitleByI18n(`monitors.copy-monitor`);
}
});
} else {
this.route.queryParamMap
.pipe(
switchMap((paramMap: ParamMap) => {
this.monitor.app = paramMap.get('app') || '';
if (this.monitor.app == '') {
this.router.navigateByUrl('/monitors/new?app=website');
}
this.titleSvc.setTitleByI18n(`monitor.app.${this.monitor.app}`);
this.detected = false;
this.passwordVisible = false;
this.isSpinning = true;
return this.appDefineSvc.getAppParamsDefine(this.monitor.app);
})
)
.pipe(
switchMap((message: Message<ParamDefine[]>) => {
if (message.code === 0) {
this.params = [];
this.advancedParams = [];
this.paramDefines = [];
this.advancedParamDefines = [];
message.data.forEach(define => {
let param = new Param();
param.field = define.field;
if (define.type === 'number') {
param.paramValue = Number(define.defaultValue);
} else if (define.type === 'boolean') {
param.paramValue = define.defaultValue.toLowerCase() == 'true';
param.type = 0;
} else if (define.type === 'key-value') {
param.type = 3;
} else if (define.type === 'array') {
param.type = 4;
} else {
param.paramValue = define.defaultValue;
param.type = 1;
}
}
define.name = this.i18nSvc.fanyi(`monitor.app.${this.monitor.app}.param.${define.field}`);
if (define.hide) {
this.advancedParams.push(param);
this.advancedParamDefines.push(define);
} else {
this.params.push(param);
this.paramDefines.push(define);
}
if (
define.field == 'host' &&
define.type == 'host' &&
define.name != `monitor.app.${this.monitor.app}.param.${define.field}`
) {
this.hostName = define.name;
}
});
} else {
console.warn(message.msg);
}
return this.collectorSvc.getCollectors();
})
)
.subscribe(
message => {
if (message.code === 0) {
this.collectors = message.data.content?.map(item => item.collector);
} else {
console.warn(message.msg);
if (define.type === 'boolean') {
param.paramValue = false;
}
if (define.defaultValue != undefined) {
if (define.type === 'number') {
param.paramValue = Number(define.defaultValue);
} else if (define.type === 'boolean') {
param.paramValue = define.defaultValue.toLowerCase() == 'true';
} else {
param.paramValue = define.defaultValue;
}
}
define.name = this.i18nSvc.fanyi(`monitor.app.${this.monitor.app}.param.${define.field}`);
if (define.hide) {
this.advancedParams.push(param);
this.advancedParamDefines.push(define);
} else {
this.params.push(param);
this.paramDefines.push(define);
}
if (
define.field == 'host' &&
define.type == 'host' &&
define.name != `monitor.app.${this.monitor.app}.param.${define.field}`
) {
this.hostName = define.name;
}
});
} else {
console.warn(message.msg);
}
return this.collectorSvc.getCollectors();
})
)
.subscribe(
message => {
if (message.code === 0) {
this.collectors = message.data.content?.map(item => item.collector);
} else {
console.warn(message.msg);
}
this.isSpinning = false;
},
error => {
this.isSpinning = true;
}
this.isSpinning = false;
},
error => {
this.isSpinning = true;
}
);
);
}
}

onHostChange(hostValue: string) {
Expand Down
12 changes: 11 additions & 1 deletion web-app/src/app/service/monitor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { HttpClient, HttpParams, HttpResponse } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { BehaviorSubject, Observable } from 'rxjs';

import { Message } from '../pojo/Message';
import { Monitor } from '../pojo/Monitor';
Expand Down Expand Up @@ -110,6 +110,16 @@ export class MonitorService {
return this.http.get<Message<Monitor[]>>(`${monitors_uri}/${app}`);
}

private monitorDataSubject: BehaviorSubject<any> = new BehaviorSubject(null);

setMonitorData(data: any): void {
this.monitorDataSubject.next(data);
}

getMonitorData(): Observable<any> {
return this.monitorDataSubject.asObservable();
}

public getMonitors(
app: string | undefined,
tag: string | undefined,
Expand Down
1 change: 1 addition & 0 deletions web-app/src/assets/i18n/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
"monitors.delete": "Delete",
"monitors.edit-monitor": "Edit Monitor",
"monitors.delete-monitor": "Delete Monitor",
"monitors.copy-monitor": "Copy Monitor",
"monitors.enable": "Resume Monitor",
"monitors.cancel": "Pause Monitor",
"monitors.export": "Export Monitor",
Expand Down
1 change: 1 addition & 0 deletions web-app/src/assets/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
"monitors.delete": "删除",
"monitors.edit-monitor": "编辑监控",
"monitors.delete-monitor": "删除监控",
"monitors.copy-monitor": "复制监控",
"monitors.enable": "恢复监控",
"monitors.cancel": "暂停监控",
"monitors.export": "导出监控",
Expand Down
1 change: 1 addition & 0 deletions web-app/src/assets/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@
"monitors.delete": "刪除",
"monitors.edit-monitor": "編輯監控",
"monitors.delete-monitor": "刪除監控",
"monitors.copy-monitor": "複製監控",
"monitors.enable": "恢復監控",
"monitors.cancel": "暫停監控",
"monitors.export": "導出監控",
Expand Down
Loading