197 lines
6.0 KiB
197 lines
6.0 KiB
6 years ago
|
import {ModelType} from '@ui/index';
|
||
6 years ago
|
import {LinkType} from '@ui/type';
|
||
6 years ago
|
import {deleteConnection, testConnection} from '@shared/crud/crud.request';
|
||
6 years ago
|
import {getCnnectionName} from './select/select.service';
|
||
|
import {DATA_BASE_TYPE} from '@private/constants';
|
||
6 years ago
|
import dialog from '@shared/service/dialog.service';
|
||
6 years ago
|
import {saveConnection} from './link_set.service';
|
||
6 years ago
|
|
||
|
const className = 'fr.model.linkset';
|
||
|
const Model: ModelType = {
|
||
6 years ago
|
context: ['tab', 'linkList', 'linkSelected', 'linkUpdate', 'connectionNameErr'],
|
||
6 years ago
|
actions: {
|
||
6 years ago
|
/**
|
||
|
* 左侧点击链接选中
|
||
|
* @param name
|
||
|
*/
|
||
|
setLinkSelected(name: string) {
|
||
6 years ago
|
this.noSaveConfirm(() => {
|
||
6 years ago
|
this._setLinkSelected(name);
|
||
6 years ago
|
});
|
||
6 years ago
|
},
|
||
|
_setLinkSelected(name: string) {
|
||
|
this.model.linkList.forEach((item: LinkType) => {
|
||
|
item.isSelected = item.connectionName === name;
|
||
|
if (item.connectionName === name) {
|
||
|
this.model.linkSelected = {
|
||
|
...item,
|
||
|
isSelected: false,
|
||
|
};
|
||
|
}
|
||
|
});
|
||
|
this.model.linkList = [...this.model.linkList];
|
||
|
this.model.linkUpdate = this.model.linkSelected;
|
||
|
},
|
||
|
onIconClick(title: string, id: string) {
|
||
|
switch (title) {
|
||
6 years ago
|
case BI.i18nText('Dec-Dcm_Delete'):
|
||
6 years ago
|
deleteConnection(id, () => {
|
||
6 years ago
|
this.model.linkList = [...this.model.linkList.filter((item: LinkType) => item.connectionId !== id)];
|
||
|
this.model.linkSelected = {};
|
||
|
this.model.linkUpdate = {};
|
||
6 years ago
|
});
|
||
|
break;
|
||
6 years ago
|
case BI.i18nText('Dec-Dcm_Test_Connection'):
|
||
6 years ago
|
this._textLink(id);
|
||
6 years ago
|
break;
|
||
6 years ago
|
case BI.i18nText('Dec-Dcm_Copy'):
|
||
6 years ago
|
this.noSaveConfirm(() => {
|
||
|
this.copyLink(id);
|
||
|
});
|
||
6 years ago
|
break;
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
},
|
||
6 years ago
|
_textLink(id: string) {
|
||
6 years ago
|
const loadingId = dialog.loading(BI.i18nText('Dec-Dcm_Connection_Testing'));
|
||
6 years ago
|
const link = this.model.linkList.find((item: LinkType) => item.connectionId === id);
|
||
|
testConnection(link, (res: any) => {
|
||
|
dialog.close(loadingId);
|
||
|
if (res && res.errorCode) {
|
||
6 years ago
|
dialog.linkFail(`${link.connectionName}${BI.i18nText('Dec-Dcm_Connection_Test_Fail')}`, res.errorMsg, () => {
|
||
6 years ago
|
this._textLink(id);
|
||
|
});
|
||
|
} else {
|
||
6 years ago
|
dialog.success(BI.i18nText('Dec-Dcm_Connection_Test_Success'));
|
||
6 years ago
|
}
|
||
|
});
|
||
|
},
|
||
6 years ago
|
copyLink(id: string) {
|
||
6 years ago
|
const connectionName = BI.find(this.model.linkList, (index: number, item: LinkType) => item.connectionId === id).connectionName;
|
||
|
const name = getCnnectionName(this.model.linkList, connectionName);
|
||
6 years ago
|
let data = {};
|
||
|
this.model.linkList.forEach((item: LinkType) => {
|
||
|
if (item.connectionId === id) {
|
||
|
data = item;
|
||
|
}
|
||
|
});
|
||
6 years ago
|
const newCopy = {
|
||
|
...data,
|
||
|
isSelected: true,
|
||
6 years ago
|
connectionName: name,
|
||
6 years ago
|
connectionId: '',
|
||
|
};
|
||
6 years ago
|
this.model.linkList = [
|
||
6 years ago
|
newCopy,
|
||
6 years ago
|
...this.model.linkList,
|
||
|
];
|
||
|
this.model.linkSelected = {
|
||
6 years ago
|
...newCopy,
|
||
6 years ago
|
};
|
||
|
this.model.linkUpdate = {
|
||
6 years ago
|
...newCopy,
|
||
6 years ago
|
};
|
||
|
},
|
||
|
setLinkUpdate(value: any) {
|
||
|
this.model.linkUpdate = value;
|
||
|
},
|
||
|
setEdit(type: boolean) {
|
||
|
this.model.linkSelected = {
|
||
|
...this.model.linkSelected,
|
||
|
isSelected: type,
|
||
|
};
|
||
|
this.model.linkUpdate = this.model.linkSelected;
|
||
|
},
|
||
|
setCancel() {
|
||
|
const linkSelected: LinkType = this.model.linkSelected;
|
||
|
const linkList: LinkType[] = this.model.linkList;
|
||
|
if (linkSelected.connectionId) {
|
||
|
this.setEdit(false);
|
||
|
} else {
|
||
|
this.model.linkList = [
|
||
|
...linkList.filter(item => !!item.connectionId),
|
||
|
];
|
||
|
if (this.model.linkList.length > 0) {
|
||
|
this.model.linkList[0].isSelected = true;
|
||
|
this.model.linkSelected = {
|
||
|
...this.model.linkList[0],
|
||
|
isSelected: false,
|
||
|
};
|
||
|
} else {
|
||
|
this.model.linkSelected = {};
|
||
|
}
|
||
|
this.model.linkUpdate = this.model.linkSelected;
|
||
|
}
|
||
|
},
|
||
|
setNewLink(value: string) {
|
||
6 years ago
|
if (!DATA_BASE_TYPE.some(item => item.text === value) && !BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${value.toLowerCase()}.edit`)) {
|
||
6 years ago
|
dialog.error(BI.i18nText('Dec-Dcm_Connection_Option_Cannot_Find'));
|
||
6 years ago
|
|
||
|
return;
|
||
|
}
|
||
6 years ago
|
this.noSaveConfirm(() => {
|
||
6 years ago
|
this._setNewLink(value);
|
||
6 years ago
|
});
|
||
6 years ago
|
},
|
||
|
_setNewLink(value: string) {
|
||
6 years ago
|
const name = getCnnectionName(this.model.linkList, value);
|
||
6 years ago
|
let data = {};
|
||
6 years ago
|
DATA_BASE_TYPE.forEach(item => {
|
||
6 years ago
|
if (item.text === value) {
|
||
|
data = item;
|
||
|
}
|
||
|
});
|
||
|
this.model.linkList = [
|
||
|
{
|
||
6 years ago
|
connectionName: name,
|
||
6 years ago
|
isSelected: true,
|
||
|
...data,
|
||
6 years ago
|
text: value,
|
||
6 years ago
|
},
|
||
|
...this.model.linkList,
|
||
|
];
|
||
|
this.model.linkSelected = {
|
||
6 years ago
|
...data,
|
||
6 years ago
|
connectionName: name,
|
||
6 years ago
|
isSelected: true,
|
||
6 years ago
|
text: value,
|
||
6 years ago
|
};
|
||
|
this.model.linkUpdate = {
|
||
|
...data,
|
||
6 years ago
|
connectionName: name,
|
||
6 years ago
|
text: value,
|
||
6 years ago
|
};
|
||
|
},
|
||
6 years ago
|
setConnectionNameErr(err: string) {
|
||
|
this.model.connectionNameErr = err;
|
||
|
},
|
||
6 years ago
|
noSaveConfirm(cb: Function) {
|
||
|
if (this.model.linkSelected && this.model.linkSelected.isSelected) {
|
||
6 years ago
|
dialog.confirm(BI.i18nText('Dec-Dcm_Connection_Config_No_Save'), (isConfirm: boolean) => {
|
||
6 years ago
|
if (isConfirm) {
|
||
6 years ago
|
this.saveLink();
|
||
6 years ago
|
} else {
|
||
|
this.setCancel();
|
||
|
}
|
||
|
cb();
|
||
|
});
|
||
|
} else {
|
||
|
cb();
|
||
|
}
|
||
|
},
|
||
6 years ago
|
saveLink() {
|
||
|
const pluginData = this.model.linkUpdate.text ? BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${this.model.linkUpdate.text.toLowerCase()}.value`) : {};
|
||
|
const update = {
|
||
|
...this.model.linkUpdate,
|
||
|
...pluginData,
|
||
|
};
|
||
|
saveConnection(update).then(() => {
|
||
|
this.setEdit(false);
|
||
|
});
|
||
|
},
|
||
6 years ago
|
},
|
||
|
};
|
||
|
BI.model(className, BI.inherit(Fix.Model, Model));
|
||
|
export default className;
|