diff --git a/src/modules/app.service.ts b/src/modules/app.service.ts index c01d9dd..194feb5 100644 --- a/src/modules/app.service.ts +++ b/src/modules/app.service.ts @@ -50,7 +50,7 @@ export function resolveUrlInfo (url: string) { if (result) { return { host: result[5], - port: result[7], + port: result[7] === 'port' ? '' : result[7], databaseName: result[9], urlInfo: result[10], }; @@ -64,7 +64,7 @@ export function resolveUrlInfo (url: string) { return { host: host ? host[1] : '', - port: port ? port[1] : '', + port: port && port[1] !== 'port' ? port[1] : '', databaseName: databaseName ? databaseName[1] : '', urlInfo: '', }; diff --git a/src/modules/pages/connection/list/list_item/list_item.model.ts b/src/modules/pages/connection/list/list_item/list_item.model.ts index 37d2217..28a5e84 100644 --- a/src/modules/pages/connection/list/list_item/list_item.model.ts +++ b/src/modules/pages/connection/list/list_item/list_item.model.ts @@ -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 => { + 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()) diff --git a/src/modules/pages/connection/list/list_item/list_item.ts b/src/modules/pages/connection/list/list_item/list_item.ts index ee039f6..b2b3378 100644 --- a/src/modules/pages/connection/list/list_item/list_item.ts +++ b/src/modules/pages/connection/list/list_item/list_item.ts @@ -71,8 +71,15 @@ export class ListItem extends BI.BasicButton { eventName: BI.SignEditor.EVENT_BLUR, action: () => { const newName = this.nameEditor.getValue(); - this.store.changeName(name, newName).then(() => { - this.nameLabel.setText(newName); + this.store.changeName(name, newName).then(re => { + if (re.errorCode) { + BI.Msg.toast(BI.i18nText(re.errorMsg), { + level: 'error', + }); + this.nameEditor.focus(); + } else { + this.nameLabel.setText(newName); + } }); }, }], diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index 54f38c7..acddee8 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -40,8 +40,13 @@ export class MaintainForm extends BI.Widget { this.store.setIsCopy(false); }, testEvent: () => { - if (!this.testValue()) { - return; + const value = this.form.getSubmitValue(); + if (!value.connectionName) { + BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_ConnectionName_Cannt_Null'), { + level: 'error', + }); + + return false; } const id = BI.UUID(); const testConnection = () => { diff --git a/src/modules/pages/maintain/maintain.ts b/src/modules/pages/maintain/maintain.ts index dd5ca6e..c9a003d 100644 --- a/src/modules/pages/maintain/maintain.ts +++ b/src/modules/pages/maintain/maintain.ts @@ -17,7 +17,7 @@ export class Maintain extends BI.Widget { listView: any; render() { - const { text, isEdit } = this.getEditConnection(); + const { text } = this.getEditConnection(); return { type: Vtape, @@ -32,7 +32,7 @@ export class Maintain extends BI.Widget { type: IconButton, hgap: 5, cls: 'dcm-back-font', - invisible: isEdit, + invisible: this.model.isCopy, handler: () => { this.store.setPageIndex(PAGE_INDEX.DATEBASE); },