|
|
|
@ -1,4 +1,3 @@
|
|
|
|
|
import {ModelType} from '@ui/index'; |
|
|
|
|
import {LinkType} from '@ui/type'; |
|
|
|
|
import {deleteConnection, testConnection} from '@shared/crud/crud.request'; |
|
|
|
|
import {getCnnectionName} from './select/select.service'; |
|
|
|
@ -6,7 +5,7 @@ import {DATA_BASE_TYPE} from '@private/constants';
|
|
|
|
|
import dialog from '@shared/service/dialog.service'; |
|
|
|
|
import {saveConnection} from './link_set.service'; |
|
|
|
|
const className = 'dec.dcm.model.linkset'; |
|
|
|
|
const Model: ModelType = { |
|
|
|
|
const Model = { |
|
|
|
|
context: ['tab', 'linkList', 'linkSelected', 'linkUpdate', 'connectionNameErr'], |
|
|
|
|
actions: { |
|
|
|
|
/** |
|
|
|
@ -14,23 +13,10 @@ const Model: ModelType = {
|
|
|
|
|
* @param name |
|
|
|
|
*/ |
|
|
|
|
setLinkSelected(name: string) { |
|
|
|
|
this.noSaveConfirm(() => { |
|
|
|
|
this._noSaveConfirm(() => { |
|
|
|
|
this._setLinkSelected(name); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
_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) { |
|
|
|
|
case BI.i18nText('Dec-Dcm_Delete'): |
|
|
|
@ -44,7 +30,7 @@ const Model: ModelType = {
|
|
|
|
|
this._textLink(id); |
|
|
|
|
break; |
|
|
|
|
case BI.i18nText('Dec-Dcm_Copy'): |
|
|
|
|
this.noSaveConfirm(() => { |
|
|
|
|
this._noSaveConfirm(() => { |
|
|
|
|
this.copyLink(id); |
|
|
|
|
}); |
|
|
|
|
break; |
|
|
|
@ -52,20 +38,7 @@ const Model: ModelType = {
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
_textLink(id: string) { |
|
|
|
|
const link = this.model.linkList.find((item: LinkType) => item.connectionId === id); |
|
|
|
|
const loadingId = dialog.loading(BI.i18nText('Dec-Dcm_Connection_Testing')); |
|
|
|
|
testConnection(link, (res: any) => { |
|
|
|
|
dialog.remove(loadingId); |
|
|
|
|
if (res && res.errorCode) { |
|
|
|
|
dialog.linkFail(`${link.connectionName}${BI.i18nText('Dec-Dcm_Connection_Test_Fail')}`, res.errorMsg, () => { |
|
|
|
|
this._textLink(id); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
dialog.success(BI.i18nText('Dec-Dcm_Connection_Test_Success')); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
copyLink(id: string) { |
|
|
|
|
const connectionName = BI.find(this.model.linkList, (index: number, item: LinkType) => item.connectionId === id).connectionName; |
|
|
|
|
const name = getCnnectionName(this.model.linkList, connectionName); |
|
|
|
@ -129,56 +102,14 @@ const Model: ModelType = {
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
this.noSaveConfirm(() => { |
|
|
|
|
this._noSaveConfirm(() => { |
|
|
|
|
this._setNewLink(value); |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
_setNewLink(value: string) { |
|
|
|
|
const name = getCnnectionName(this.model.linkList, value); |
|
|
|
|
let data = {}; |
|
|
|
|
DATA_BASE_TYPE.forEach(item => { |
|
|
|
|
if (item.text === value) { |
|
|
|
|
data = item; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.model.linkList = [ |
|
|
|
|
{ |
|
|
|
|
connectionName: name, |
|
|
|
|
isSelected: true, |
|
|
|
|
...data, |
|
|
|
|
text: value, |
|
|
|
|
}, |
|
|
|
|
...this.model.linkList, |
|
|
|
|
]; |
|
|
|
|
this.model.linkSelected = { |
|
|
|
|
...data, |
|
|
|
|
connectionName: name, |
|
|
|
|
isSelected: true, |
|
|
|
|
text: value, |
|
|
|
|
}; |
|
|
|
|
this.model.linkUpdate = { |
|
|
|
|
...data, |
|
|
|
|
connectionName: name, |
|
|
|
|
text: value, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
setConnectionNameErr(err: string) { |
|
|
|
|
this.model.connectionNameErr = err; |
|
|
|
|
}, |
|
|
|
|
noSaveConfirm(cb: Function) { |
|
|
|
|
if (this.model.linkSelected && this.model.linkSelected.isSelected) { |
|
|
|
|
dialog.confirm(BI.i18nText('Dec-Dcm_Connection_Config_No_Save'), (isConfirm: boolean) => { |
|
|
|
|
if (isConfirm) { |
|
|
|
|
this.saveLink(); |
|
|
|
|
} else { |
|
|
|
|
this.setCancel(); |
|
|
|
|
} |
|
|
|
|
cb(); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
cb(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
saveLink() { |
|
|
|
|
const pluginData = this.model.linkUpdate.text ? BI.Constants.getConstant(`dec.constant.database.conf.connect.form.${this.model.linkUpdate.text.toLowerCase()}.value`) : {}; |
|
|
|
|
const update = { |
|
|
|
@ -190,6 +121,76 @@ const Model: ModelType = {
|
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
_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; |
|
|
|
|
}, |
|
|
|
|
_textLink(id: string) { |
|
|
|
|
const link = this.model.linkList.find((item: LinkType) => item.connectionId === id); |
|
|
|
|
const loadingId = dialog.loading(BI.i18nText('Dec-Dcm_Connection_Testing')); |
|
|
|
|
testConnection(link, (res: any) => { |
|
|
|
|
dialog.remove(loadingId); |
|
|
|
|
if (res && res.errorCode) { |
|
|
|
|
dialog.linkFail(`${link.connectionName}${BI.i18nText('Dec-Dcm_Connection_Test_Fail')}`, res.errorMsg, () => { |
|
|
|
|
this._textLink(id); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
dialog.success(BI.i18nText('Dec-Dcm_Connection_Test_Success')); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
_setNewLink(value: string) { |
|
|
|
|
const name = getCnnectionName(this.model.linkList, value); |
|
|
|
|
let data = {}; |
|
|
|
|
DATA_BASE_TYPE.forEach(item => { |
|
|
|
|
if (item.text === value) { |
|
|
|
|
data = item; |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
this.model.linkList = [ |
|
|
|
|
{ |
|
|
|
|
connectionName: name, |
|
|
|
|
isSelected: true, |
|
|
|
|
...data, |
|
|
|
|
text: value, |
|
|
|
|
}, |
|
|
|
|
...this.model.linkList, |
|
|
|
|
]; |
|
|
|
|
this.model.linkSelected = { |
|
|
|
|
...data, |
|
|
|
|
connectionName: name, |
|
|
|
|
isSelected: true, |
|
|
|
|
text: value, |
|
|
|
|
}; |
|
|
|
|
this.model.linkUpdate = { |
|
|
|
|
...data, |
|
|
|
|
connectionName: name, |
|
|
|
|
text: value, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
_noSaveConfirm(cb: Function) { |
|
|
|
|
if (this.model.linkSelected && this.model.linkSelected.isSelected) { |
|
|
|
|
dialog.confirm(BI.i18nText('Dec-Dcm_Connection_Config_No_Save'), (isConfirm: boolean) => { |
|
|
|
|
if (isConfirm) { |
|
|
|
|
this.saveLink(); |
|
|
|
|
} else { |
|
|
|
|
this.setCancel(); |
|
|
|
|
} |
|
|
|
|
cb(); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
cb(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
BI.model(className, BI.inherit(Fix.Model, Model)); |
|
|
|
|
export default className; |
|
|
|
|