|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
import { model, Model } from '@core/core'; |
|
|
|
|
import { AppModel } from '../../../../app.model'; |
|
|
|
|
import { ApiFactory } from 'src/modules/crud/apiFactory'; |
|
|
|
|
import { ApiFactory } from '../../../../crud/apiFactory'; |
|
|
|
|
import { ResultType } from '../../../../crud/crud.typings'; |
|
|
|
|
const api = new ApiFactory().create(); |
|
|
|
|
|
|
|
|
|
export const ListItemModelXtype = 'dec.dcm.model.connection.list_item'; |
|
|
|
@ -39,18 +40,16 @@ export class ListItemModel extends Model<{
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
setPageIndex(pageIndex: string) { |
|
|
|
|
setPageIndex: (pageIndex: string) => { |
|
|
|
|
this.model.pageIndex = pageIndex; |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
testConnection: (name: string) => api.testConnection(this.model.connections.find(item => item.connectionName === name)), |
|
|
|
|
getConnectionStatus() { |
|
|
|
|
return api.getConnectionStatus(this.model.connectionSelected); |
|
|
|
|
}, |
|
|
|
|
setDatebaseTypeSelected(name: string) { |
|
|
|
|
getConnectionStatus: () => api.getConnectionStatus(this.model.connectionSelected), |
|
|
|
|
setDatebaseTypeSelected: (name: string) => { |
|
|
|
|
this.model.datebaseTypeSelected = name; |
|
|
|
|
}, |
|
|
|
|
setIsEdit(isEdit: boolean, name: string) { |
|
|
|
|
setIsEdit: (isEdit: boolean, name: string) => { |
|
|
|
|
if (isEdit) { |
|
|
|
|
api.getConnectionStatus(name).then(re => { |
|
|
|
|
if (re.data && re.data === 'success') { |
|
|
|
@ -66,30 +65,42 @@ export class ListItemModel extends Model<{
|
|
|
|
|
this.model.isEdit = false; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
changeName(oldName: string, newName: string) { |
|
|
|
|
const connection = this.model.connections.find(item => item.connectionName === oldName); |
|
|
|
|
changeName: (oldName: string, newName: string): Promise<ResultType> => { |
|
|
|
|
if (!newName) { |
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
resolve({ errorCode: '1', errorMsg: 'Dec-Dcm_Connection_ConnectionName_Cannt_Null' }); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
const hasNamed = this.model.connections.some(item => item.connectionName === newName); |
|
|
|
|
if (hasNamed && oldName !== newName) { |
|
|
|
|
return new Promise(resolve => { |
|
|
|
|
resolve({ errorCode: '1', errorMsg: 'Dec-Dcm_Connection_Is_Existence' }); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
const connection = BI.clone(this.model.connections.find(item => item.connectionName === oldName)); |
|
|
|
|
connection.connectionId = oldName; |
|
|
|
|
connection.connectionName = newName; |
|
|
|
|
this.model.connections = this.model.connections.map(item => { |
|
|
|
|
return { |
|
|
|
|
...item, |
|
|
|
|
connectionName: item.connectionName === oldName ? newName : item.connectionName, |
|
|
|
|
connectionId: item.connectionName === oldName ? newName : item.connectionName, |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return api.updateConnection(connection).then(re => { |
|
|
|
|
this.setIsEdit(false, oldName); |
|
|
|
|
if (!re.errorCode) { |
|
|
|
|
this.store.setIsEdit(false, oldName); |
|
|
|
|
this.model.connections = this.model.connections.map(item => { |
|
|
|
|
return { |
|
|
|
|
...item, |
|
|
|
|
connectionName: item.connectionName === oldName ? newName : item.connectionName, |
|
|
|
|
connectionId: item.connectionName === oldName ? newName : item.connectionName, |
|
|
|
|
}; |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return re; |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
setIsCopy(isCopy: boolean) { |
|
|
|
|
setIsCopy: (isCopy: boolean) => { |
|
|
|
|
this.model.isCopy = isCopy; |
|
|
|
|
}, |
|
|
|
|
isDriverError(errorCode: string) { |
|
|
|
|
return api.isDriverError(errorCode); |
|
|
|
|
}, |
|
|
|
|
isDriverError: (errorCode: string) => api.isDriverError(errorCode), |
|
|
|
|
} |
|
|
|
|
removeConnection(name: string) { |
|
|
|
|
api.deleteConnection(name).then(re => api.getConnectionlist()) |
|
|
|
|