Commit c38ed6a2 authored by wangqinghua's avatar wangqinghua

template

parent f20ba31c
...@@ -83,8 +83,12 @@ ...@@ -83,8 +83,12 @@
<span (click)="deleteMacro1(i)">移除</span> <span (click)="deleteMacro1(i)">移除</span>
</nz-form-control> </nz-form-control>
</div> </div>
<div nz-row [nzGutter]="24">
<div nz-col [nzOffset]="2" [nzSpan]="6">
<button nz-button (click)="addMacro1()" nzType="default">添加</button> <button nz-button (click)="addMacro1()" nzType="default">添加</button>
</div> </div>
</div>
</div>
<div *ngIf="macroTYpe == 'macroExpand'"> <div *ngIf="macroTYpe == 'macroExpand'">
<div nz-row [nzGutter]="24"> <div nz-row [nzGutter]="24">
<div nz-col [nzOffset]="2" [nzSpan]="6"> <div nz-col [nzOffset]="2" [nzSpan]="6">
......
...@@ -27,8 +27,8 @@ export class StrategyComponent implements OnInit { ...@@ -27,8 +27,8 @@ export class StrategyComponent implements OnInit {
//宏 //宏
macroTYpe = 'macro'; //宏tabs macroTYpe = 'macro'; //宏tabs
mainHost = 'hostType1'; //主机tabs mainHost = 'hostType1'; //主机tabs
macroList1: any[]; macroList1 = [];
macroList2: any[]; //配置宏数组 macroList2 = []; //配置宏数组
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router, constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) { private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) {
...@@ -41,6 +41,11 @@ export class StrategyComponent implements OnInit { ...@@ -41,6 +41,11 @@ export class StrategyComponent implements OnInit {
} }
initForm() { initForm() {
this.templateList.forEach(e => {
e.checked = false;
});
this.macroList1 = [];
this.macroList2 = [];
this.validateForm = { this.validateForm = {
host: null, host: null,
name: null, name: null,
...@@ -77,7 +82,7 @@ export class StrategyComponent implements OnInit { ...@@ -77,7 +82,7 @@ export class StrategyComponent implements OnInit {
); );
} }
tabsChange(e){ tabsChange(e) {
this.tabNum = e; this.tabNum = e;
} }
...@@ -86,125 +91,132 @@ export class StrategyComponent implements OnInit { ...@@ -86,125 +91,132 @@ export class StrategyComponent implements OnInit {
this.title = title; this.title = title;
} }
showEditModal(title,id){ showEditModal(title, id) {
this.isVisible = true; this.isVisible = true;
this.title = title; this.title = title;
this.tempId = id; this.tempId = id;
const data = { const data = {
templateids:[this.tempId] templateids: [this.tempId]
} };
this.overAllSer.findTemplates(data).subscribe( this.overAllSer.findTemplates(data).subscribe(
(res)=>{ (res) => {
const data = res.data[0]; const data = res.data[0];
this.validateForm.host = data.host; this.validateForm.host = data.host;
this.validateForm.name = data.name; this.validateForm.name = data.name;
if(data.groups){ if (data.groups) {
//所在组回显 //所在组回显
this.templateList.forEach(e1=>{ this.templateList.forEach(e1 => {
data.groups.forEach(e2=>{ data.groups.forEach(e2 => {
if(e1.value == e2.groupid){ if (e1.value == e2.groupid) {
e1.checked = true; e1.checked = true;
} }
}) });
}); });
} }
if(data.parentTemplates){ if (data.parentTemplates) {
//模版回显 //模版回显
this.validateForm.templates = data.parentTemplates.map(e=>{ this.validateForm.templates = data.parentTemplates.map(e => {
return e.templateid; return e.templateid;
}) });
} }
} }
) );
} }
check(){ check() {
const han = /.*[\u4e00-\u9fa5]+.*$/; const han = /.*[\u4e00-\u9fa5]+.*$/;
if (han.test(this.validateForm.host)) { if (han.test(this.validateForm.host)) {
this.message.error("模版真实名称不能输入中文"); this.message.error('模版真实名称不能输入中文');
return false; return false;
}; }
;
return true; return true;
} }
handleOk() { handleOk() {
if(!this.check()){ if (!this.check()) {
return false; return false;
} }
const arr = []; const arr = [];
this.templateList.forEach(e=>{ this.templateList.forEach(e => {
if(e.checked){ if (e.checked) {
const d = { const d = {
groupid:e.value groupid: e.value
} };
arr.push(d); arr.push(d);
} }
}); });
if(this.title == "添加模版"){ if (this.macroTYpe == 'macroExpand') {
this.validateForm.macros = this.macroList2;
}
if (this.macroTYpe == 'macro') {
this.validateForm.macros = this.macroList1;
}
if (this.title == '添加模版') {
this.create(arr); this.create(arr);
} }
if(this.title == "编辑模版"){ if (this.title == '编辑模版') {
this.update(arr); this.update(arr);
} }
} }
create(arr){ create(arr) {
const data = { const data = {
host: this.validateForm.host, host: this.validateForm.host,
name: this.validateForm.name, name: this.validateForm.name,
groups: arr, groups: arr,
templates: this.validateForm.templates.map(e=>{ templates: this.validateForm.templates.map(e => {
const d = { const d = {
templateid:e templateid: e
} };
return d; return d;
}), }),
macros: [], macros: this.validateForm.macros,
hosts: [], hosts: [],
}; };
this.overAllSer.createTemplates(data).subscribe( this.overAllSer.createTemplates(data).subscribe(
(res)=>{ (res) => {
if(res.errCode == 10000){ if (res.errCode == 10000) {
this.message.success("添加模版成功"); this.message.success('添加模版成功');
this.initForm(); this.initForm();
this.done.emit(); this.done.emit();
this.isVisible = false; this.isVisible = false;
}else{
} else {
this.message.error(res.errMsg); this.message.error(res.errMsg);
} }
} }
) );
} }
update(arr){ update(arr) {
const data = { const data = {
templateid:this.tempId, //模版id templateid: this.tempId, //模版id
host: this.validateForm.host, host: this.validateForm.host,
name: this.validateForm.name, name: this.validateForm.name,
groups: arr, groups: arr,
templates: this.validateForm.templates.map(e=>{ templates: this.validateForm.templates.map(e => {
const d = { const d = {
templateid:e templateid: e
} };
return d; return d;
}), }),
macros: [], macros: [],
hosts: [], hosts: [],
} };
this.overAllSer.updateTemplates(data).subscribe( this.overAllSer.updateTemplates(data).subscribe(
(res)=>{ (res) => {
if(res.errCode == 10000){ if (res.errCode == 10000) {
this.message.success("修改模版成功"); this.message.success('修改模版成功');
this.initForm(); this.initForm();
this.done.emit(); this.done.emit();
this.isVisible = false; this.isVisible = false;
}else{ } else {
this.message.error(res.errMsg); this.message.error(res.errMsg);
} }
} }
) );
} }
handleCancel(): void { handleCancel(): void {
......
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
<div nz-row class="search-form tag-form"> <div nz-row class="search-form tag-form">
<div nz-col nzSpan="12"> <div nz-col nzSpan="12">
<input style="width: 250px" (keyup.enter)="search('')" type="text" nz-input [(ngModel)]="searchName" placeholder="输入资源名称"> <input style="width: 250px" (keyup.enter)="search()" type="text" nz-input [(ngModel)]="searchName" placeholder="输入资源名称">
<button (click)="search('')" nz-button nzType="default"><i class="anticon anticon-search" style="color: #6097b7"></i>搜索</button> <button (click)="search()" nz-button nzType="default"><i class="anticon anticon-search" style="color: #6097b7"></i>搜索</button>
</div> </div>
<div nz-col nzSpan="12" class="text-right"> <div nz-col nzSpan="12" class="text-right">
<button nz-button nzType="default" (click)="showGroupModal()"> <button nz-button nzType="default" (click)="showGroupModal()">
...@@ -69,6 +69,7 @@ ...@@ -69,6 +69,7 @@
</td> </td>
<td></td> <td></td>
</ng-container> </ng-container>
<td class="handle main-color"> <td class="handle main-color">
<ng-container *ngIf="!item.level"> <ng-container *ngIf="!item.level">
<span (click)="showTempAddModal(item)">添加模版</span> <span (click)="showTempAddModal(item)">添加模版</span>
...@@ -84,11 +85,6 @@ ...@@ -84,11 +85,6 @@
</a> </a>
<ul nz-menu nzSelectable> <ul nz-menu nzSelectable>
<li *ngIf="!item.monitorTask" (click)="showTempStop(item)" nz-menu-item><a>临时暂停</a></li> <li *ngIf="!item.monitorTask" (click)="showTempStop(item)" nz-menu-item><a>临时暂停</a></li>
<li (click)="openHost(item)" nz-menu-item><a>
<ng-container *ngIf="item.status == 1">开启</ng-container>
<ng-container *ngIf="item.status == 0">停止</ng-container>
监控
</a></li>
<li nz-menu-item (click)="goDetail(item)"><a>查看监测点</a></li> <li nz-menu-item (click)="goDetail(item)"><a>查看监测点</a></li>
<li (click)="showAlarm(item)" nz-menu-item><a>添加告警</a></li> <li (click)="showAlarm(item)" nz-menu-item><a>添加告警</a></li>
</ul> </ul>
...@@ -107,63 +103,9 @@ ...@@ -107,63 +103,9 @@
<td nzShowCheckbox [nzIndeterminate]="indeterminate" (nzCheckedChange)="selectChecked($event,item)" <td nzShowCheckbox [nzIndeterminate]="indeterminate" (nzCheckedChange)="selectChecked($event,item)"
[(nzChecked)]="item.checked"></td> [(nzChecked)]="item.checked"></td>
<td class="cursor"> <td class="cursor">
<span (click)="goDetail(item)">{{item.name}}</span> <span >{{item.name}}</span>
</td>
<td class="round-tag tag-form default">
<ng-container *ngIf="item.status == 1">
<nz-tag [nzColor]="color.gray"></nz-tag>
</ng-container>
<ng-container *ngIf="item.status == 0">
<nz-tag *ngIf="item.maxLevel == 4 || item.maxLevel == 5" [nzColor]="color.red"></nz-tag>
<nz-tag *ngIf="item.maxLevel == 2 || item.maxLevel == 3" [nzColor]="color.yellow"></nz-tag>
<nz-tag *ngIf="item.maxLevel < 2 " [nzColor]="color.green"></nz-tag>
</ng-container>
</td>
<td class="cursor">
<span (click)="goTOInventory(item?.inventory?.id)">{{item?.inventory?.name}}</span>
</td>
<td class="default">
<ng-container *ngIf="item.available == 0">
<nz-tag>AGENT</nz-tag>
</ng-container>
<ng-container *ngIf="item.available == 1">
<nz-tag [nzColor]="'#3bae6a'">AGENT</nz-tag>
</ng-container>
<ng-container *ngIf="item.available == 2">
<nz-tag [nzColor]="'#d44f51'">AGENT</nz-tag>
</ng-container>
<ng-container *ngIf="item.snmp_available == 0">
<nz-tag>SNMP</nz-tag>
</ng-container>
<ng-container *ngIf="item.snmp_available == 1">
<nz-tag [nzColor]="'#3bae6a'">SNMP</nz-tag>
</ng-container>
<ng-container *ngIf="item.snmp_available == 2">
<nz-tag [nzColor]="'#d44f51'">SNMP</nz-tag>
</ng-container>
<ng-container *ngIf="item.jmx_available == 0">
<nz-tag>JMX</nz-tag>
</ng-container>
<ng-container *ngIf="item.jmx_available == 1">
<nz-tag [nzColor]="'#3bae6a'">JMX</nz-tag>
</ng-container>
<ng-container *ngIf="item.jmx_available == 2">
<nz-tag [nzColor]="'#d44f51'">JMX</nz-tag>
</ng-container>
<ng-container *ngIf="item.ipmi_available == 0">
<nz-tag>IPMI</nz-tag>
</ng-container>
<ng-container *ngIf="item.ipmi_available == 1">
<nz-tag [nzColor]="'#3bae6a'">IPMI</nz-tag>
</ng-container>
<ng-container *ngIf="item.ipmi_available == 2">
<nz-tag [nzColor]="'#d44f51'">IPMI</nz-tag>
</ng-container>
</td> </td>
<td></td>
<td class="handle main-color"> <td class="handle main-color">
<span (click)="showBasicCheckModal(item.hostid,item.host)">添加监测点</span> <span (click)="showBasicCheckModal(item.hostid,item.host)">添加监测点</span>
<span (click)="editBasicModal(item)">编辑</span> <span (click)="editBasicModal(item)">编辑</span>
...@@ -173,11 +115,6 @@ ...@@ -173,11 +115,6 @@
</a> </a>
<ul nz-menu nzSelectable> <ul nz-menu nzSelectable>
<li (click)="showTempStop(item)" nz-menu-item><a>临时暂停</a></li> <li (click)="showTempStop(item)" nz-menu-item><a>临时暂停</a></li>
<li (click)="openHost(item)" nz-menu-item><a>
<ng-container *ngIf="item.status == 1">开启</ng-container>
<ng-container *ngIf="item.status == 0">停止</ng-container>
监控
</a></li>
<li nz-menu-item (click)="goDetail(item)"><a>查看监测点</a></li> <li nz-menu-item (click)="goDetail(item)"><a>查看监测点</a></li>
<li (click)="showAlarm(item)" nz-menu-item><a>添加告警</a></li> <li (click)="showAlarm(item)" nz-menu-item><a>添加告警</a></li>
</ul> </ul>
......
...@@ -62,6 +62,7 @@ export class TemplateComponent implements OnInit { ...@@ -62,6 +62,7 @@ export class TemplateComponent implements OnInit {
//模版 //模版
templateList = []; templateList = [];
indeterminate;
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router, constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) { private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) {
...@@ -119,7 +120,6 @@ export class TemplateComponent implements OnInit { ...@@ -119,7 +120,6 @@ export class TemplateComponent implements OnInit {
} }
ngOnInit(): void { ngOnInit(): void {
// this.select();
this.getTemplateGroup(); this.getTemplateGroup();
} }
...@@ -138,17 +138,16 @@ export class TemplateComponent implements OnInit { ...@@ -138,17 +138,16 @@ export class TemplateComponent implements OnInit {
} }
//搜索 //搜索
search(status) { search() {
this.loading = true; this.loading = true;
this.searchStatus = true; this.searchStatus = true;
this.frontPagination = false; this.frontPagination = false;
const data = { const data = {
search: { search: {
status: status,
name: this.searchName name: this.searchName
} }
}; };
this.overAllSer.find(data).subscribe( this.overAllSer.findTemplates(data).subscribe(
(res) => { (res) => {
if (res.errCode == 10000) { if (res.errCode == 10000) {
this.searchData = res.data; this.searchData = res.data;
...@@ -179,115 +178,12 @@ export class TemplateComponent implements OnInit { ...@@ -179,115 +178,12 @@ export class TemplateComponent implements OnInit {
this.smartCheck.showAddModal(hostid, host); this.smartCheck.showAddModal(hostid, host);
} }
//选择分组
select() {
this.loading = true;
this.searchStatus = false;
this.frontPagination = true;
if (this.selectedValue == 'group') {
this.overAllSer.getgroups({}).subscribe(
(res) => {
this.loading = false;
if (res.errCode == 10000) {
this.dataSet = res.data;
// this.dataSet = this.dataSet.filter(d => d.list); //过滤无list的
for (let i = 0; i < this.dataSet.length; i++) {
this.dataSet[i].host = i;
this.dataSet[i].checked = false;
}
this.toTree(null);
} else {
this.message.info(res.errMsg);
}
}
);
} else if (this.selectedValue == 'type') {
this.overAllSer.findType().subscribe(
(res) => {
this.loading = false;
if (res.errCode == 10000) {
this.dataSet = res.data;
// this.dataSet = this.dataSet.filter(d => d.list); //过滤无list的
for (let i = 0; i < this.dataSet.length; i++) {
this.dataSet[i].host = i;
this.dataSet[i].checked = false;
}
this.toTree(null);
} else {
this.message.info(res.errMsg);
}
}
);
} else if (this.selectedValue == 'all') {
}
}
toTree(index) { toTree(index) {
this.dataSet.forEach(item => { this.dataSet.forEach(item => {
this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index); this.expandDataCache[item.host] = this.convertTreeToList(item, item.id, index);
}); });
} }
//删除单个资源
showDeleteConfirm(item) {
this.modalService.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该资源吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {
hostids: []
};
data.hostids.push(item.hostid);
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
});
}
//批量删除资源
batchDeleteConfirm() {
if (this.batchDelList.length == 0) {
this.message.info('请选择需要删除的设备');
return false;
}
this.modalService.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认要删除所选设备吗?</b>',
nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {
hostids: this.batchDelList
};
this.overAllSer.deleteHostPost(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.batchDelList = [];
this.select();
} else {
this.message.info(res.errMsg);
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
});
}
//添加分组 //添加分组
showGroupModal() { showGroupModal() {
this.smartCreateGroup.showModal('添加模版组'); this.smartCreateGroup.showModal('添加模版组');
...@@ -311,10 +207,10 @@ export class TemplateComponent implements OnInit { ...@@ -311,10 +207,10 @@ export class TemplateComponent implements OnInit {
this.overAllSer.deleteGroup(data).subscribe( this.overAllSer.deleteGroup(data).subscribe(
(res) => { (res) => {
if (res.errCode == 10000) { if (res.errCode == 10000) {
this.message.info('删除成功'); this.message.success('删除成功');
this.select(); this.getTemplateGroup();
} else { } else {
this.message.info(res.errMsg); this.message.error(res.errMsg);
} }
} }
); );
...@@ -330,7 +226,7 @@ export class TemplateComponent implements OnInit { ...@@ -330,7 +226,7 @@ export class TemplateComponent implements OnInit {
} }
handleOk(e) { handleOk(e) {
this.select(); this.getTemplateGroup();
this.smartStrategy.getTemplateGroup(); this.smartStrategy.getTemplateGroup();
} }
...@@ -396,53 +292,74 @@ export class TemplateComponent implements OnInit { ...@@ -396,53 +292,74 @@ export class TemplateComponent implements OnInit {
//选择 //选择
selectChecked(event, item) { selectChecked(event, item) {
if (event) { if (event) {
if (item.hostid) { if (item.templateid) {
this.batchDelList.push(item.hostid); this.batchDelList.push(item.templateid);
} }
} else { } else {
if (item.hostid) { if (item.templateid) {
const index = this.batchDelList.indexOf(item.hostid); const index = this.batchDelList.indexOf(item.templateid);
this.batchDelList.splice(index, 1); this.batchDelList.splice(index, 1);
} }
} }
} }
//开启or停止监控 //批量删除资源
openHost(item) { batchDeleteConfirm() {
if (this.batchDelList.length == 0) {
this.message.info('请选择需要删除的设备');
return false;
}
this.modalService.confirm({ this.modalService.confirm({
nzTitle: '监控', nzTitle: '删除',
nzContent: '确定开启监控设备' + item.name + '?', nzContent: '<b style="color: red;">确认要删除所选模版吗?</b>',
nzOkText: '确定', nzOkText: '确定',
nzCancelText: '取消', nzOkType: 'danger',
nzOnOk: () => { nzOnOk: () => {
let params1 = 0; const data = {
if (item.status == 0) { templateids: this.batchDelList
params1 = 1; };
} this.overAllSer.deleteTemplates(data).subscribe(
const params2 = item.hostid;
this.overAllSer.stopOrOpen(params1, params2).subscribe(
(res) => { (res) => {
if (res.errCode == 10000) { if (res.errCode == 10000) {
this.message.info('修改成功'); this.message.success('删除成功');
this.select(); this.batchDelList = [];
this.getTemplateGroup();
} else { } else {
this.message.info(res.errMsg); this.message.error(res.errMsg);
} }
} }
); );
}, },
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel') nzOnCancel: () => console.log('Cancel')
}); });
} }
//删除单个模版
//资产页面 showDeleteConfirm(item) {
goTOInventory(id) { this.modalService.confirm({
this.router.navigate(['app/main/assetsDetail'], { nzTitle: '删除',
queryParams: { nzContent: '<b style="color: red;">确认删除该模版吗?</b>',
invertoryId: id nzOkText: '确定',
nzOkType: 'danger',
nzOnOk: () => {
const data = {
templateids: []
};
data.templateids.push(item.templateid);
this.overAllSer.deleteTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.getTemplateGroup();
} else {
this.message.info(res.errMsg);
}
} }
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
}); });
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment