monitor-new.component.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { Component, OnInit } from '@angular/core';
  2. import {ParamDefine} from "../../../pojo/ParamDefine";
  3. import {AppDefineService} from "../../../service/app-define.service";
  4. import {ActivatedRoute, ParamMap, Router} from "@angular/router";
  5. import {switchMap} from "rxjs/operators";
  6. import {FormBuilder, FormControl, FormGroup} from "@angular/forms";
  7. import {I18NService} from "@core";
  8. import {Param} from "../../../pojo/Param";
  9. import {Monitor} from "../../../pojo/Monitor";
  10. import {MonitorService} from "../../../service/monitor.service";
  11. import {NzNotificationService} from "ng-zorro-antd/notification";
  12. @Component({
  13. selector: 'app-monitor-add',
  14. templateUrl: './monitor-new.component.html',
  15. styles: [
  16. ]
  17. })
  18. export class MonitorNewComponent implements OnInit {
  19. paramDefines!: ParamDefine[];
  20. params!: Param[];
  21. monitor!: Monitor;
  22. profileForm: FormGroup = new FormGroup({});
  23. detected: boolean = true;
  24. passwordVisible!: boolean;
  25. constructor(private appDefineSvc: AppDefineService,
  26. private monitorSvc: MonitorService,
  27. private route: ActivatedRoute,
  28. private router: Router,
  29. private notifySvc: NzNotificationService,
  30. private i18n: I18NService,
  31. private formBuilder: FormBuilder) {
  32. this.monitor = new Monitor();
  33. }
  34. ngOnInit(): void {
  35. const paramDefine$ = this.route.queryParamMap.pipe(
  36. switchMap((paramMap: ParamMap) => {
  37. this.monitor.app = paramMap.get("app") || '';
  38. return this.appDefineSvc.getAppParamsDefine(this.monitor.app);
  39. })
  40. ).subscribe(message => {
  41. if (message.code === 0) {
  42. this.paramDefines = message.data;
  43. this.params = [];
  44. this.paramDefines.forEach(define => {
  45. let param = new Param();
  46. param.field = define.field;
  47. param.type = define.type === "number" ? 0 : 1;
  48. this.params.push(param);
  49. })
  50. } else {
  51. console.warn(message.msg);
  52. }
  53. paramDefine$.unsubscribe();
  54. });
  55. }
  56. onSubmit() {
  57. let addMonitor = {
  58. "detected": this.detected,
  59. "monitor": this.monitor,
  60. "params": this.params
  61. };
  62. this.monitorSvc.newMonitor(addMonitor)
  63. .subscribe(message => {
  64. if (message.code === 0) {
  65. this.notifySvc.success("新增监控成功", "");
  66. this.router.navigateByUrl("/monitors")
  67. } else {
  68. this.notifySvc.error("新增监控失败", message.msg);
  69. }
  70. })
  71. }
  72. }