Commit c38ed6a2 authored by wangqinghua's avatar wangqinghua

template

parent f20ba31c
......@@ -83,7 +83,11 @@
<span (click)="deleteMacro1(i)">移除</span>
</nz-form-control>
</div>
<button nz-button (click)="addMacro1()" nzType="default">添加</button>
<div nz-row [nzGutter]="24">
<div nz-col [nzOffset]="2" [nzSpan]="6">
<button nz-button (click)="addMacro1()" nzType="default">添加</button>
</div>
</div>
</div>
<div *ngIf="macroTYpe == 'macroExpand'">
<div nz-row [nzGutter]="24">
......
......@@ -27,8 +27,8 @@ export class StrategyComponent implements OnInit {
//宏
macroTYpe = 'macro'; //宏tabs
mainHost = 'hostType1'; //主机tabs
macroList1: any[];
macroList2: any[]; //配置宏数组
macroList1 = [];
macroList2 = []; //配置宏数组
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) {
......@@ -41,6 +41,11 @@ export class StrategyComponent implements OnInit {
}
initForm() {
this.templateList.forEach(e => {
e.checked = false;
});
this.macroList1 = [];
this.macroList2 = [];
this.validateForm = {
host: null,
name: null,
......@@ -77,7 +82,7 @@ export class StrategyComponent implements OnInit {
);
}
tabsChange(e){
tabsChange(e) {
this.tabNum = e;
}
......@@ -86,125 +91,132 @@ export class StrategyComponent implements OnInit {
this.title = title;
}
showEditModal(title,id){
showEditModal(title, id) {
this.isVisible = true;
this.title = title;
this.tempId = id;
const data = {
templateids:[this.tempId]
}
templateids: [this.tempId]
};
this.overAllSer.findTemplates(data).subscribe(
(res)=>{
(res) => {
const data = res.data[0];
this.validateForm.host = data.host;
this.validateForm.name = data.name;
if(data.groups){
if (data.groups) {
//所在组回显
this.templateList.forEach(e1=>{
data.groups.forEach(e2=>{
if(e1.value == e2.groupid){
this.templateList.forEach(e1 => {
data.groups.forEach(e2 => {
if (e1.value == e2.groupid) {
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;
})
});
}
}
)
);
}
check(){
check() {
const han = /.*[\u4e00-\u9fa5]+.*$/;
if (han.test(this.validateForm.host)) {
this.message.error("模版真实名称不能输入中文");
this.message.error('模版真实名称不能输入中文');
return false;
};
}
;
return true;
}
handleOk() {
if(!this.check()){
if (!this.check()) {
return false;
}
const arr = [];
this.templateList.forEach(e=>{
if(e.checked){
this.templateList.forEach(e => {
if (e.checked) {
const d = {
groupid:e.value
}
groupid: e.value
};
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);
}
if(this.title == "编辑模版"){
if (this.title == '编辑模版') {
this.update(arr);
}
}
create(arr){
create(arr) {
const data = {
host: this.validateForm.host,
name: this.validateForm.name,
groups: arr,
templates: this.validateForm.templates.map(e=>{
templates: this.validateForm.templates.map(e => {
const d = {
templateid:e
}
templateid: e
};
return d;
}),
macros: [],
macros: this.validateForm.macros,
hosts: [],
};
this.overAllSer.createTemplates(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.message.success("添加模版成功");
(res) => {
if (res.errCode == 10000) {
this.message.success('添加模版成功');
this.initForm();
this.done.emit();
this.isVisible = false;
}else{
} else {
this.message.error(res.errMsg);
}
}
)
);
}
update(arr){
update(arr) {
const data = {
templateid:this.tempId, //模版id
templateid: this.tempId, //模版id
host: this.validateForm.host,
name: this.validateForm.name,
groups: arr,
templates: this.validateForm.templates.map(e=>{
templates: this.validateForm.templates.map(e => {
const d = {
templateid:e
}
templateid: e
};
return d;
}),
macros: [],
hosts: [],
}
};
this.overAllSer.updateTemplates(data).subscribe(
(res)=>{
if(res.errCode == 10000){
this.message.success("修改模版成功");
(res) => {
if (res.errCode == 10000) {
this.message.success('修改模版成功');
this.initForm();
this.done.emit();
this.isVisible = false;
}else{
} else {
this.message.error(res.errMsg);
}
}
)
);
}
handleCancel(): void {
......
......@@ -24,8 +24,8 @@
<div nz-row class="search-form tag-form">
<div nz-col nzSpan="12">
<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>
<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>
</div>
<div nz-col nzSpan="12" class="text-right">
<button nz-button nzType="default" (click)="showGroupModal()">
......@@ -69,6 +69,7 @@
</td>
<td></td>
</ng-container>
<td class="handle main-color">
<ng-container *ngIf="!item.level">
<span (click)="showTempAddModal(item)">添加模版</span>
......@@ -84,11 +85,6 @@
</a>
<ul nz-menu nzSelectable>
<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 (click)="showAlarm(item)" nz-menu-item><a>添加告警</a></li>
</ul>
......@@ -107,63 +103,9 @@
<td nzShowCheckbox [nzIndeterminate]="indeterminate" (nzCheckedChange)="selectChecked($event,item)"
[(nzChecked)]="item.checked"></td>
<td class="cursor">
<span (click)="goDetail(item)">{{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>
<span >{{item.name}}</span>
</td>
<td></td>
<td class="handle main-color">
<span (click)="showBasicCheckModal(item.hostid,item.host)">添加监测点</span>
<span (click)="editBasicModal(item)">编辑</span>
......@@ -173,11 +115,6 @@
</a>
<ul nz-menu nzSelectable>
<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 (click)="showAlarm(item)" nz-menu-item><a>添加告警</a></li>
</ul>
......
......@@ -62,6 +62,7 @@ export class TemplateComponent implements OnInit {
//模版
templateList = [];
indeterminate;
constructor(private fb: FormBuilder, private overAllSer: OverAllService, private router: Router,
private modalService: NzModalService, private message: NzMessageService, private main: JhiMainComponent) {
......@@ -119,7 +120,6 @@ export class TemplateComponent implements OnInit {
}
ngOnInit(): void {
// this.select();
this.getTemplateGroup();
}
......@@ -138,17 +138,16 @@ export class TemplateComponent implements OnInit {
}
//搜索
search(status) {
search() {
this.loading = true;
this.searchStatus = true;
this.frontPagination = false;
const data = {
search: {
status: status,
name: this.searchName
}
};
this.overAllSer.find(data).subscribe(
this.overAllSer.findTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.searchData = res.data;
......@@ -179,115 +178,12 @@ export class TemplateComponent implements OnInit {
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) {
this.dataSet.forEach(item => {
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() {
this.smartCreateGroup.showModal('添加模版组');
......@@ -311,10 +207,10 @@ export class TemplateComponent implements OnInit {
this.overAllSer.deleteGroup(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('删除成功');
this.select();
this.message.success('删除成功');
this.getTemplateGroup();
} else {
this.message.info(res.errMsg);
this.message.error(res.errMsg);
}
}
);
......@@ -330,7 +226,7 @@ export class TemplateComponent implements OnInit {
}
handleOk(e) {
this.select();
this.getTemplateGroup();
this.smartStrategy.getTemplateGroup();
}
......@@ -396,53 +292,74 @@ export class TemplateComponent implements OnInit {
//选择
selectChecked(event, item) {
if (event) {
if (item.hostid) {
this.batchDelList.push(item.hostid);
if (item.templateid) {
this.batchDelList.push(item.templateid);
}
} else {
if (item.hostid) {
const index = this.batchDelList.indexOf(item.hostid);
if (item.templateid) {
const index = this.batchDelList.indexOf(item.templateid);
this.batchDelList.splice(index, 1);
}
}
}
//开启or停止监控
openHost(item) {
//批量删除资源
batchDeleteConfirm() {
if (this.batchDelList.length == 0) {
this.message.info('请选择需要删除的设备');
return false;
}
this.modalService.confirm({
nzTitle: '监控',
nzContent: '确定开启监控设备' + item.name + '?',
nzTitle: '删除',
nzContent: '<b style="color: red;">确认要删除所选模版吗?</b>',
nzOkText: '确定',
nzCancelText: '取消',
nzOkType: 'danger',
nzOnOk: () => {
let params1 = 0;
if (item.status == 0) {
params1 = 1;
}
const params2 = item.hostid;
this.overAllSer.stopOrOpen(params1, params2).subscribe(
const data = {
templateids: this.batchDelList
};
this.overAllSer.deleteTemplates(data).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.info('修改成功');
this.select();
this.message.success('删除成功');
this.batchDelList = [];
this.getTemplateGroup();
} else {
this.message.info(res.errMsg);
this.message.error(res.errMsg);
}
}
);
},
nzCancelText: '取消',
nzOnCancel: () => console.log('Cancel')
});
}
//资产页面
goTOInventory(id) {
this.router.navigate(['app/main/assetsDetail'], {
queryParams: {
invertoryId: id
}
//删除单个模版
showDeleteConfirm(item) {
this.modalService.confirm({
nzTitle: '删除',
nzContent: '<b style="color: red;">确认删除该模版吗?</b>',
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