Skip to content

Commit

Permalink
Merge branch 'master' into patch-32
Browse files Browse the repository at this point in the history
  • Loading branch information
kerwin612 authored Jul 3, 2024
2 parents 8bf722c + 2ffdda8 commit bb36cde
Show file tree
Hide file tree
Showing 13 changed files with 853 additions and 1,257 deletions.
468 changes: 16 additions & 452 deletions web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.html

Large diffs are not rendered by default.

161 changes: 8 additions & 153 deletions web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ import { I18NService } from '@core';
import { ALAIN_I18N_TOKEN, TitleService } from '@delon/theme';
import { NzNotificationService } from 'ng-zorro-antd/notification';
import { throwError } from 'rxjs';
import { finalize, switchMap } from 'rxjs/operators';
import { switchMap } from 'rxjs/operators';

import { Collector } from '../../../pojo/Collector';
import { Message } from '../../../pojo/Message';
import { Monitor } from '../../../pojo/Monitor';
import { Param } from '../../../pojo/Param';
import { ParamDefine } from '../../../pojo/ParamDefine';
import { Tag } from '../../../pojo/Tag';
import { AppDefineService } from '../../../service/app-define.service';
import { CollectorService } from '../../../service/collector.service';
import { MonitorService } from '../../../service/monitor.service';
import { TagService } from '../../../service/tag.service';

@Component({
selector: 'app-monitor-modify',
Expand All @@ -50,7 +48,6 @@ export class MonitorEditComponent implements OnInit {
private router: Router,
private titleSvc: TitleService,
private notifySvc: NzNotificationService,
private tagSvc: TagService,
private collectorSvc: CollectorService,
@Inject(ALAIN_I18N_TOKEN) private i18nSvc: I18NService
) {}
Expand All @@ -64,7 +61,6 @@ export class MonitorEditComponent implements OnInit {
monitor = new Monitor();
collectors!: Collector[];
collector: string = '';
profileForm: FormGroup = new FormGroup({});
detected: boolean = false;
isSpinning: boolean = false;
spinningTip: string = 'Loading...';
Expand Down Expand Up @@ -203,21 +199,6 @@ export class MonitorEditComponent implements OnInit {
});
}

onParamBooleanChanged(booleanValue: boolean, field: string) {
// 对SSL的端口联动处理, 不开启SSL默认80端口,开启SSL默认443
if (field === 'ssl') {
this.params.forEach(param => {
if (param.field === 'port') {
if (booleanValue) {
param.paramValue = '443';
} else {
param.paramValue = '80';
}
}
});
}
}

onDependChanged(dependValue: string, dependField: string) {
this.paramDefines.forEach((paramDefine, index) => {
if (paramDefine.depend) {
Expand All @@ -243,37 +224,12 @@ export class MonitorEditComponent implements OnInit {
});
}

onSubmit(formGroup: FormGroup) {
if (formGroup.invalid) {
Object.values(formGroup.controls).forEach(control => {
if (control.invalid) {
control.markAsDirty();
control.updateValueAndValidity({ onlySelf: true });
}
});
return;
}
this.monitor.host = this.monitor.host.trim();
this.monitor.name = this.monitor.name.trim();
// todo 暂时单独设置host属性值
this.params.forEach(param => {
if (param.field === 'host') {
param.paramValue = this.monitor.host;
}
if (param.paramValue != null && typeof param.paramValue == 'string') {
param.paramValue = (param.paramValue as string).trim();
}
});
this.advancedParams.forEach(param => {
if (param.paramValue != null && typeof param.paramValue == 'string') {
param.paramValue = (param.paramValue as string).trim();
}
});
onSubmit(info: any) {
let addMonitor = {
detected: this.detected,
monitor: this.monitor,
monitor: info.monitor,
collector: this.collector,
params: this.params.concat(this.advancedParams)
params: info.params.concat(info.advancedParams)
};
if (this.detected) {
this.spinningTip = this.i18nSvc.fanyi('monitors.spinning-tip.detecting');
Expand All @@ -286,7 +242,7 @@ export class MonitorEditComponent implements OnInit {
this.isSpinning = false;
if (message.code === 0) {
this.notifySvc.success(this.i18nSvc.fanyi('monitors.edit.success'), '');
this.router.navigateByUrl(`/monitors?app=${this.monitor.app}`);
this.router.navigateByUrl(`/monitors?app=${info.monitor.app}`);
} else {
this.notifySvc.error(this.i18nSvc.fanyi('monitors.edit.failed'), message.msg);
}
Expand All @@ -298,37 +254,12 @@ export class MonitorEditComponent implements OnInit {
);
}

onDetect(formGroup: FormGroup) {
if (formGroup.invalid) {
Object.values(formGroup.controls).forEach(control => {
if (control.invalid) {
control.markAsDirty();
control.updateValueAndValidity({ onlySelf: true });
}
});
return;
}
this.monitor.host = this.monitor.host.trim();
this.monitor.name = this.monitor.name.trim();
// todo 暂时单独设置host属性值
this.params.forEach(param => {
if (param.field === 'host') {
param.paramValue = this.monitor.host;
}
if (param.paramValue != null && typeof param.paramValue == 'string') {
param.paramValue = (param.paramValue as string).trim();
}
});
this.advancedParams.forEach(param => {
if (param.paramValue != null && typeof param.paramValue == 'string') {
param.paramValue = (param.paramValue as string).trim();
}
});
onDetect(info: any) {
let detectMonitor = {
detected: this.detected,
monitor: this.monitor,
monitor: info.monitor,
collector: this.collector,
params: this.params.concat(this.advancedParams)
params: info.params.concat(info.advancedParams)
};
this.spinningTip = this.i18nSvc.fanyi('monitors.spinning-tip.detecting');
this.isSpinning = true;
Expand All @@ -353,80 +284,4 @@ export class MonitorEditComponent implements OnInit {
app = app ? app : '';
this.router.navigateByUrl(`/monitors?app=${app}`);
}

onRemoveTag(tag: Tag) {
if (this.monitor != undefined && this.monitor.tags != undefined) {
this.monitor.tags = this.monitor.tags.filter(item => item !== tag);
}
}

sliceTagName(tag: Tag): string {
if (tag.tagValue != undefined && tag.tagValue.trim() != '') {
return `${tag.name}:${tag.tagValue}`;
} else {
return tag.name;
}
}

// start Tag model
isManageModalVisible = false;
isManageModalOkLoading = false;
tagCheckedAll: boolean = false;
tagTableLoading = false;
tagSearch!: string;
tags!: Tag[];
checkedTags = new Set<Tag>();
loadTagsTable() {
this.tagTableLoading = true;
let tagsReq$ = this.tagSvc.loadTags(this.tagSearch, 1, 0, 1000).subscribe(
message => {
this.tagTableLoading = false;
this.tagCheckedAll = false;
this.checkedTags.clear();
if (message.code === 0) {
let page = message.data;
this.tags = page.content;
} else {
console.warn(message.msg);
}
tagsReq$.unsubscribe();
},
error => {
this.tagTableLoading = false;
tagsReq$.unsubscribe();
}
);
}
onShowTagsModal() {
this.isManageModalVisible = true;
this.loadTagsTable();
}
onManageModalCancel() {
this.isManageModalVisible = false;
}
onManageModalOk() {
this.isManageModalOkLoading = true;
this.checkedTags.forEach(item => {
if (this.monitor.tags.find(tag => tag.id == item.id) == undefined) {
this.monitor.tags.push(item);
}
});
this.isManageModalOkLoading = false;
this.isManageModalVisible = false;
}
onAllChecked(checked: boolean) {
if (checked) {
this.tags.forEach(tag => this.checkedTags.add(tag));
} else {
this.checkedTags.clear();
}
}
onItemChecked(tag: Tag, checked: boolean) {
if (checked) {
this.checkedTags.add(tag);
} else {
this.checkedTags.delete(tag);
}
}
// end tag model
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<nz-spin [nzSpinning]="loading" [nzTip]="loadingTip" nzSize="large">
<div class="-inner-content">
<form nz-form #form="ngForm">
<app-form-item
[item]="{
field: 'host',
type: 'text',
name: hostName ? hostName : ('monitor.host' | i18n),
required: true,
placeholder: 'monitor.host.tip' | i18n
}"
[(value)]="monitor.host"
(valueChange)="onHostChange($event)"
/>

<app-form-item
[item]="{
field: 'name',
type: 'text',
name: 'monitor.name' | i18n,
required: true,
placeholder: 'monitor.name.tip' | i18n
}"
[(value)]="monitor.name"
/>

<ng-container *ngFor="let paramDefine of paramDefines; let i = index">
<app-form-item
*ngIf="params[i].display && paramDefine.field !== 'host'"
[item]="paramDefine"
[(value)]="params[i].paramValue"
(valueChange)="
paramDefine.type === 'boolean'
? onParamBooleanChanged($event, paramDefine.field)
: paramDefine.type === 'radio'
? onDependChanged($event, paramDefine.field)
: null
"
/>
</ng-container>

<nz-collapse [nzGhost]="true" style="background: ghostwhite; margin-bottom: 24px">
<ng-template #extraColHeader>
<button style="margin-left: 40%" nz-button nzType="dashed" nz-tooltip [nzTooltipTitle]="'monitors.advanced.tip' | i18n">
<span>{{ 'monitors.advanced' | i18n }}</span>
<i nz-icon nzType="down-circle" nzTheme="outline"></i>
</button>
</ng-template>
<nz-collapse-panel [nzHeader]="extraColHeader" [nzShowArrow]="false">
<ng-container *ngFor="let paramDefine of advancedParamDefines; let i = index">
<app-form-item
*ngIf="advancedParams[i].display && paramDefine.field !== 'host'"
[item]="paramDefine"
[(value)]="advancedParams[i].paramValue"
/>
</ng-container>
</nz-collapse-panel>
</nz-collapse>

<app-form-item
[item]="{
field: 'collector',
type: 'collectors-selection',
name: 'monitor.collector' | i18n,
tooltip: 'monitor.collector.tip' | i18n
}"
[extra]="{collectors}"
[(value)]="collector"
/>

<app-form-item
[item]="{
field: 'intervals',
type: 'intervals',
name: 'monitor.intervals' | i18n,
tooltip: 'monitor.intervals.tip' | i18n
}"
[extra]="{ interval_type: monitor.app }"
[(value)]="monitor.intervals"
/>

<app-form-item
[item]="{
field: 'tags',
type: 'tags-selection',
name: 'tag.bind' | i18n,
tooltip: 'tag.bind.tip' | i18n
}"
[(value)]="monitor.tags"
/>

<app-form-item
[item]="{
field: 'description',
type: 'textarea-limit',
name: 'monitor.description' | i18n,
tooltip: 'monitor.description.tip' | i18n
}"
[(value)]="monitor.description"
/>

<div nz-row>
<div nz-col [nzXs]="{ span: 24 }" [nzLg]="{ span: 8, offset: 7 }" style="text-align: center">
<button
nz-button
nzType="primary"
type="submit"
nz-tooltip
[nzTooltipTitle]="'monitors.detect.tip' | i18n"
(click)="onDetect(form.form)"
>
{{ 'common.button.detect' | i18n }}
</button>
<button nz-button nzType="primary" type="submit" (click)="onSubmit(form.form)"> {{ 'common.button.ok' | i18n }} </button>
<button nz-button nzType="primary" type="reset" (click)="onCancel()"> {{ 'common.button.cancel' | i18n }} </button>
</div>
</div>
</form>
</div>
</nz-spin>
Loading

0 comments on commit bb36cde

Please sign in to comment.