Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {
FormBuilder,
FormGroup,
Validators
} from '@angular/forms';
import {OverAllService} from '../../overAll/overAll.service';
import {NzMessageService} from 'ng-zorro-antd';
selector: 'smart-basic-edit',
templateUrl: './basic-edit.component.html',
styles: []
})
export class BasicEditComponent implements OnInit {
@Output() done = new EventEmitter<string>();
modalTitle; //modal标题
nzSize = 'large';
hostId; //主机ID
style = {
panel1 = {name: '配置IPMI', active: true};
panel2 = {name: '配置宏', active: true};
macroList1: any[];
macroList2: any[]; //配置宏数组
interfaceslist: any[]; //接口list
constructor(private fb: FormBuilder, private overAllSer: OverAllService,
(res) => {
for (let i = 0; i < res.data.length; i++) {
const gObj = {
label: res.data[i].name, value: res.data[i].groupid, checked: false
};
this.groupList.push(gObj);
}
}
);
this.getParentType();
}
//父级分类
getParentType(){
this.workSer.findByParentType().subscribe(
(res)=>{
const data = res.data;
this.parentTypeList = data;
}
)
}
//通过父级分类查询子级分类
getTypeByParent(parentid){
this.workSer.findByParentidCount(parentid).subscribe(
(res)=>{
const data = res.data;
this.typeList = data;
}
)
this.hostId = hostId;
this.modalTitle = '编辑资源';
this.overAllSer.findDetailed(this.hostId).subscribe(
const data = res.data[0];
this.validateForm.name = data.name;
this.validateForm.host = data.host;
this.validateForm.ipmi_authtype = data.ipmi_authtype + '';
this.validateForm.ipmi_username = data.ipmi_username + '';
this.validateForm.ipmi_privilege = data.ipmi_privilege + '';
this.validateForm.ipmi_password = data.ipmi_password + '';
this.validateForm.tls_psk_identity = data.tls_psk_identity + '';
this.validateForm.tls_issuer = data.tls_issuer + '';
this.validateForm.tls_subject = data.tls_subject + '';
this.validateForm.tls_psk = data.tls_psk + '';
this.validateForm.inventoryExtend = data.inventory;
this.validateForm.hostExtend = data.hostExtend;
return res.templateid;
});
this.validateForm.templates = tempArr;
this.interfaceslist.forEach(res => {
res.main = res.main + '';
res.type = res.type + '';
this.hostTypeChildrenList = [];
this.hostTypeList.forEach(res => {
if (this.validateForm.hostExtend.equipmentTypeid == res.id) {
this.hostTypeChildrenList = res.childs;
}
});
if (data.macros) {
this.macroList1 = data.macros;
}
for (let i = 0; i < this.validateForm.groups.length; i++) {
for (let j = 0; j < this.groupList.length; j++) {
if (this.validateForm.groups[i].groupid == this.groupList[j].value) {
handEditleOk() {
if (!this.validateForm.hostExtend.equipmentTypeid) {
if(this.isInVentory){
if(!this.validateForm.inventoryExtend.name){
this.message.info('请输入资产名称');
return false;
}
}
const groupArr = [];
for (let i = 0; i < this.groupList.length; i++) {
if (this.groupList[i].checked == true) {
const groupid = {'groupid': this.groupList[i].value};
this.interfaceslist.forEach(res => {
if (res.bulk) {
res.bulk = '1';
} else {
res.bulk = '0';
}
create() {
if (this.macroTYpe == 'macroExpand') {
this.validateForm.macros = this.macroList2;
}
if(!this.isInVentory){
this.validateForm.inventoryExtend = null;
}
(res) => {
if (res.errCode == 10000) {
this.isBasicEdit = false;
this.message.success("创建成功");
}else{
this.message.error(res.errMsg);
}
},
(err) => {
this.message.info('系统错误');
}
);
}
//更新
if(!this.isInVentory){
this.validateForm.inventoryExtend = null;
}
this.templatesResoure.forEach(res => {
if (this.validateForm.templates.indexOf(res) == -1) {
if (this.macroTYpe == 'macroExpand') {
this.validateForm.macros = this.macroList2;
}
this.validateForm.hostid = this.hostId;
this.validateForm.interfaces = this.interfaceslist;
this.validateForm.macros = this.macroList1;
this.message.success("修改成功");
}else{
this.message.error(res.errMsg);
getTemplate() {
this.overAllSer.templates().subscribe(
(res) => {
this.hostTypeChildrenList = [];
this.validateForm.hostExtend.secondLevelTypeid = null;
this.hostTypeList.forEach(res => {
if (item == res.id) {
this.hostTypeChildrenList = res.childs;
}
});
addInterfaces() {
const demo = {
main: '0',
ip: '',
dns: '',
type: '1',
port: '10050',
useip: 1,
deleteInterfaces(index) {
this.interfaceslist.splice(index, 1);
}
changePort(index) {
switch (this.interfaceslist[index].type) {
case '1': {
this.interfaceslist[index].port = '10050';
break;
}
case '2': {
this.interfaceslist[index].port = '161';
break;
}
case '3': {
this.interfaceslist[index].port = '12345';
break;
}
case '4': {
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
//新增宏
addMacro1() {
const data = {
macro: '{$SNMP_COMMUNITY}',
value: 'public',
};
this.macroList1.push(data);
}
//移除宏
deleteMacro1(index) {
this.macroList1.splice(index, 1);
}
//新增主机宏
addMacro2() {
const data = {
macro: '{$SNMP_COMMUNITY}',
value: 'public',
};
this.macroList2.push(data);
}
//移除主机宏
deleteMacro2(index) {
this.macroList2.splice(index, 1);
}
//登记资产
checkChange(e){
if(e == "yes"){
this.isInVentory = true;
}
if(e == "no"){
this.isInVentory = false;
}
}
this.macroList1 = [ //配置宏数组
{
macro: '{$SNMP_COMMUNITY}',
value: 'public',
}
];
this.macroList2 = [ //配置宏数组
{
macro: '{$SNMP_COMMUNITY}',
value: 'public',
}
];
this.interfaceslist = [ //接口list
{
main: '1',
ip: '',
dns: '',
type: '1',
port: '10050',
useip: 1,
this.tabNum = 0;
this.validateForm = {
groups: [],
hostExtend: {
serviceid: ''
},
macros: this.macroList1,
interfaces: this.interfaceslist, //接口
serialnoA: null,
invertoryname: null,
mac: null,
storageLocation: null,
name: null,
person: null,
ip: null,
usedcount: null,
stock: null,
lendcount: null,
repaircount: null,
scrapcount: null,
name: null,
host: null,
ipmi_authtype: null,
ipmi_username: null,
ipmi_privilege: null,
ipmi_password: null,
tls_psk_identity: null,
tls_issuer: null,
tls_subject: null,
tls_psk: null,
};
}