From ec2bcc3db94bc55215cd99f5f5a9ba04ecf6cc29 Mon Sep 17 00:00:00 2001 From: alan Date: Tue, 20 Aug 2019 10:47:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20DEC-9068=20=E5=A6=82=E6=9E=9C=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E8=A2=AB=E5=8D=A0=E7=94=A8=E5=88=99=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- i18n/zh_cn.properties | 1 + src/modules/crud/api.ts | 14 +++++++- src/modules/crud/crud.typings.d.ts | 6 ++++ src/modules/crud/decision.api.ts | 21 +++++++++++- src/modules/crud/design.api.ts | 14 +++++++- .../pages/connection/connection.model.ts | 6 +++- src/modules/pages/connection/connection.ts | 15 ++++++--- .../list/list_item/list_item.model.ts | 32 +++++++++++++------ src/modules/pages/database/database.model.ts | 4 +++ src/modules/pages/database/database.ts | 1 + src/modules/pages/maintain/forms/form.ts | 2 +- .../title_maintain/title_maintain.model.ts | 4 ++- .../title/title_maintain/title_maintain.ts | 7 ++-- 13 files changed, 103 insertions(+), 24 deletions(-) diff --git a/i18n/zh_cn.properties b/i18n/zh_cn.properties index 7a781eb..4978f39 100644 --- a/i18n/zh_cn.properties +++ b/i18n/zh_cn.properties @@ -94,6 +94,7 @@ Dec-Dcm_Connection_Form_JNDI_Collapse-Attributes= 收起 Dec-Dcm_Connection_JNDI= JNDI数据连接 Dec-Dcm_Connection_JNDI_Warning= 注意:需要把包含INTIAL_CONTEXT_FACTORY类的.jar文件复制到软件安装目录下的/lib目录下 Dec-Dcm_Connection_Error= 接口访问错误 +Dec-Dcm_Connection_Is_Using= 该连接正在被{R1}编辑,请稍后再试 BI-Multi_Date_Quarter_End= 季度末 BI-Multi_Date_Month_Begin= 月初 diff --git a/src/modules/crud/api.ts b/src/modules/crud/api.ts index b6f241b..f8628ac 100644 --- a/src/modules/crud/api.ts +++ b/src/modules/crud/api.ts @@ -1,4 +1,4 @@ -import { Connection, TestRequest, ConnectionPoolType } from './crud.typings'; +import { Connection, TestRequest, ConnectionPoolType, SocketResult } from './crud.typings'; export interface Api { /** @@ -39,4 +39,16 @@ export interface Api { * @param name */ getConnectionPool(name: string): Promise<{data: ConnectionPoolType}>; + + /** + * 获取连接状态 + * @param name + */ + getConnectionStatus(name: string): Promise; + + /** + * 关闭连接 + * @param name + */ + shutdownConnectionStatus(name: string): Promise; } diff --git a/src/modules/crud/crud.typings.d.ts b/src/modules/crud/crud.typings.d.ts index b8e9640..5f51438 100644 --- a/src/modules/crud/crud.typings.d.ts +++ b/src/modules/crud/crud.typings.d.ts @@ -204,3 +204,9 @@ export interface ConnectionPoolType { numActive: number; numIdle: number; } + +export interface SocketResult { + data?: string; + errorCode?: string; + errorMsg?: string; +} diff --git a/src/modules/crud/decision.api.ts b/src/modules/crud/decision.api.ts index 11b0b7c..22378c1 100644 --- a/src/modules/crud/decision.api.ts +++ b/src/modules/crud/decision.api.ts @@ -1,6 +1,7 @@ import { Api } from './api'; -import { Connection, TestRequest, ConnectionPoolType } from './crud.typings'; +import { Connection, TestRequest, ConnectionPoolType, SocketResult } from './crud.typings'; import { requestGet, requestDelete, requestPost, requestPut } from './crud.service'; +import { editStatusEvent } from '@constants/env'; export class DecisionApi implements Api { isDec = true; @@ -47,4 +48,22 @@ export class DecisionApi implements Api { getConnectionPool(name: string): Promise<{data: ConnectionPoolType}> { return requestGet(`pool/info?connectionName=${name}`); } + + getConnectionStatus(name: string): Promise { + return this.sendEditStatusEvent(name, editStatusEvent.OPEN); + } + + shutdownConnectionStatus(name: string): Promise { + return this.sendEditStatusEvent(name, editStatusEvent.SHUTDOWN); + } + + private sendEditStatusEvent(name: string, type: string): Promise { + return new Promise(resolve => { + if (Dec) { + const re = Dec.socket.emit(editStatusEvent.SHUTDOWN, name); + resolve(JSON.parse(re)); + } + resolve({ data: 'success' }); + }); + } } diff --git a/src/modules/crud/design.api.ts b/src/modules/crud/design.api.ts index 4b14027..a4e5609 100644 --- a/src/modules/crud/design.api.ts +++ b/src/modules/crud/design.api.ts @@ -1,5 +1,5 @@ import { Api } from './api'; -import { Connection, TestRequest, ConnectionPoolType } from './crud.typings'; +import { Connection, TestRequest, ConnectionPoolType, SocketResult } from './crud.typings'; // TODO: 此页面的接口等待设计器提供相应的方法 export class DesignApi implements Api { @@ -44,4 +44,16 @@ export class DesignApi implements Api { } }); }); } + + getConnectionStatus(name: string): Promise { + return new Promise(resolve => { + resolve({ data: 'success' }); + }); + } + + shutdownConnectionStatus(name: string): Promise { + return new Promise(resolve => { + resolve({ data: 'success' }); + }); + } } diff --git a/src/modules/pages/connection/connection.model.ts b/src/modules/pages/connection/connection.model.ts index a545f27..1c50111 100644 --- a/src/modules/pages/connection/connection.model.ts +++ b/src/modules/pages/connection/connection.model.ts @@ -1,6 +1,7 @@ import { model, Model } from '@core/core'; import { AppModel } from '../../app.model'; - +import { ApiFactory } from 'src/modules/crud/apiFactory'; +const api = new ApiFactory().create(); export const ConnectionModelXtype = 'dec.dcm.model.connection'; @model(ConnectionModelXtype) export class ConnectionModel extends Model<{ @@ -24,5 +25,8 @@ export class ConnectionModel extends Model<{ setConnectionSelected(name: string) { this.model.connectionSelected = name; }, + getConnectionStatus() { + return api.getConnectionStatus(this.model.connectionSelected); + }, } } diff --git a/src/modules/pages/connection/connection.ts b/src/modules/pages/connection/connection.ts index 3a7a3ed..088bcd3 100644 --- a/src/modules/pages/connection/connection.ts +++ b/src/modules/pages/connection/connection.ts @@ -6,7 +6,7 @@ import { ConnectionListXtype } from './list/list'; import { ConnectionJdbcXtype } from './connection_jdbc/connection_jdbc'; import { ConnectionJndiXtype } from './connection_jndi/connection_jndi'; import { ConnectionPluginXtype } from './connection_plugin/connection_plugin'; -import { connectionType, editStatusEvent } from '@constants/env'; +import { connectionType } from '@constants/env'; import { getAllDatabaseTypes } from '../../app.service'; export const ConnectionXtype = 'dec.dcm.connection'; @@ -102,9 +102,16 @@ export class Connection extends BI.Widget { this.connectionEditWidget = _ref; }, handler: () => { - this.store.setPageIndex(PAGE_INDEX.MAINTAIN); - this.store.setDatebaseTypeSelected(''); - Dec ? Dec.socket.emit(editStatusEvent.OPEN, this.model.connectionSelected) : null; + this.store.getConnectionStatus().then(re => { + if (re.data && re.data === 'success') { + this.store.setPageIndex(PAGE_INDEX.MAINTAIN); + this.store.setDatebaseTypeSelected(''); + } else { + BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Is_Using', re.errorMsg), { + level: 'error', + }); + } + }); }, }, ], 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 f96fec3..82c3f87 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 @@ -21,17 +21,15 @@ export class ListItemModel extends Model<{ this.model.connectionSelected = name; }, deleteConnection: (name: string) => { - api.deleteConnection(name).then(re => api.getConnectionlist()) - .then(connections => { - this.model.connections = connections.data; - this.model.connections.forEach(item => { - // 后端传过来的是字符串,转为对象 - item.connectionData = JSON.parse(item.connectionData); + api.getConnectionStatus(name).then(re => { + if (re.data && re.data === 'success') { + this.removeConnection(name); + } else { + BI.Msg.toast(BI.i18nText('Dec-Dcm_Connection_Is_Using', re.errorMsg), { + level: 'error', }); - if (name === this.model.connectionSelected) { - this.model.connectionSelected = ''; - } - }); + } + }); }, setPageIndex(pageIndex: string) { this.model.pageIndex = pageIndex; @@ -39,4 +37,18 @@ export class ListItemModel extends Model<{ testConnection: () => api.testConnection(this.model.connectionSelectedOne), } + removeConnection(name: string) { + api.deleteConnection(name).then(re => api.getConnectionlist()) + .then(connections => { + this.model.connections = connections.data; + this.model.connections.forEach(item => { + // 后端传过来的是字符串,转为对象 + item.connectionData = JSON.parse(item.connectionData); + }); + if (name === this.model.connectionSelected) { + this.model.connectionSelected = ''; + } + api.shutdownConnectionStatus(name); + }); + } } diff --git a/src/modules/pages/database/database.model.ts b/src/modules/pages/database/database.model.ts index 2982874..88b5e21 100644 --- a/src/modules/pages/database/database.model.ts +++ b/src/modules/pages/database/database.model.ts @@ -29,6 +29,7 @@ export class DatebaseModel extends Model<{ }, setDatebaseTypes: (datebaseTypes: DatabaseType[]) => { this.model.datebaseTypes = datebaseTypes; + this.model.datebaseTypeSelected = ''; }, setInternal:(isInternal: boolean) => { this.model.isInternal = isInternal; @@ -36,5 +37,8 @@ export class DatebaseModel extends Model<{ setPlugin: (isPlugin: boolean) => { this.model.isPlugin = isPlugin; }, + setDatebaseTypeSelected(datebaseType: string) { + this.model.datebaseTypeSelected = datebaseType; + }, } } diff --git a/src/modules/pages/database/database.ts b/src/modules/pages/database/database.ts index 3b7b329..a8fb786 100644 --- a/src/modules/pages/database/database.ts +++ b/src/modules/pages/database/database.ts @@ -63,6 +63,7 @@ export class Datebase extends BI.Widget { mounted() { this.store.setFilter(DATEBASE_FILTER_TYPE.COMMONLY); + this.store.setDatebaseTypeSelected(''); } render() { diff --git a/src/modules/pages/maintain/forms/form.ts b/src/modules/pages/maintain/forms/form.ts index 1912f27..703b5cc 100644 --- a/src/modules/pages/maintain/forms/form.ts +++ b/src/modules/pages/maintain/forms/form.ts @@ -203,7 +203,7 @@ export class MaintainForm extends BI.Widget { if (connections.length === 0) { return name; } - let index = 1; + let index = 0; connections.forEach(item => { const num = parseFloat(item.connectionName.replace(name, '')); if (num > index) { diff --git a/src/modules/title/title_maintain/title_maintain.model.ts b/src/modules/title/title_maintain/title_maintain.model.ts index 26a89a3..6e091c3 100644 --- a/src/modules/title/title_maintain/title_maintain.model.ts +++ b/src/modules/title/title_maintain/title_maintain.model.ts @@ -1,6 +1,7 @@ import { model, Model } from '@core/core'; import { AppModel } from 'src/modules/app.model'; - +import { ApiFactory } from 'src/modules/crud/apiFactory'; +const api = new ApiFactory().create(); export const TitleMaintainModelXtype = 'dec.dcm.model.title_maintain'; @model(TitleMaintainModelXtype) export class TitleMaintainModel extends Model<{ @@ -23,5 +24,6 @@ export class TitleMaintainModel extends Model<{ setTestEvent: () => { this.model.testEvent = BI.UUID(); }, + shutdownConnectionStatus: () => api.shutdownConnectionStatus(this.model.connectionSelected), } } diff --git a/src/modules/title/title_maintain/title_maintain.ts b/src/modules/title/title_maintain/title_maintain.ts index 52697f5..6f6d4d4 100644 --- a/src/modules/title/title_maintain/title_maintain.ts +++ b/src/modules/title/title_maintain/title_maintain.ts @@ -2,7 +2,6 @@ import { shortcut, store } from '@core/core'; import { Right, Button, VerticalAdapt } from 'ui'; import { TitleMaintainModel, TitleMaintainModelXtype } from './title_maintain.model'; import { PAGE_INDEX } from '@constants/constant'; -import { editStatusEvent } from '@constants/env'; export const TitleMaintain = 'dec.dcm.title.maintain'; @shortcut(TitleMaintain) @@ -24,7 +23,7 @@ export class TitleMaintainWidget extends BI.Widget { level: 'ignore', handler: () => { this.store.setPageIndex(PAGE_INDEX.CONNECTION); - Dec ? Dec.socket.emit(editStatusEvent.SHUTDOWN, this.model.connectionSelected) : null; + this.store.shutdownConnectionStatus(); }, }, { @@ -40,7 +39,7 @@ export class TitleMaintainWidget extends BI.Widget { text: BI.i18nText('BI-Basic_Save'), handler: () => { this.store.setSaveEvent(); - Dec ? Dec.socket.emit(editStatusEvent.SHUTDOWN, this.model.connectionSelected) : null; + this.store.shutdownConnectionStatus(); }, }, ], @@ -50,7 +49,7 @@ export class TitleMaintainWidget extends BI.Widget { mounted () { window.onunload = () => { - Dec ? Dec.socket.emit(editStatusEvent.SHUTDOWN, this.model.connectionSelected) : null; + this.store.shutdownConnectionStatus(); }; } }