Browse Source

Merge pull request #8045 in DEC/decision-webui-dcm from bugfix/11.0 to release/11.0

* commit 'fa2f4807c09bdf42d7f1d779dfb46e0897e96c4c':
  REPORT-102763 fix:【开个接口】数据连接支持对接业务系统-补充
  REPORT-102763 fix:【开个接口】数据连接支持对接业务系统
release/11.0
superman 1 year ago
parent
commit
674bf79b13
  1. 65
      README.md
  2. 3
      src/modules/app.model.ts
  3. 1
      src/modules/app.typings.d.ts
  4. 9
      src/modules/pages/connection/connection.model.ts
  5. 13
      src/modules/pages/connection/connection.ts
  6. 1
      src/modules/pages/connection/list/list.constant.ts
  7. 4
      src/modules/pages/connection/list/list.model.ts
  8. 2
      src/modules/pages/connection/list/list.ts
  9. 5
      src/modules/pages/connection/list/list_item/list_item.ts
  10. 17
      src/modules/pages/database/database.constant.ts
  11. 28
      src/modules/pages/database/database.ts
  12. 7
      src/modules/pages/database/database_type/database_type.model.ts
  13. 4
      src/modules/pages/database/database_type/database_type.ts
  14. 4
      src/modules/pages/maintain/forms/components/form.plugin.ts
  15. 86
      src/modules/pages/maintain/forms/form.ts
  16. 3
      src/modules/title/title_maintain/title_maintain.model.ts
  17. 6
      src/modules/title/title_maintain/title_maintain.ts

65
README.md

@ -114,7 +114,8 @@ BI.config("dec.connection.provider.datebase", function (provider) {
版本和平台保持一致
## 接口文档:
### 增加数据连接类型
### A 增加数据连接类型
#### 1. 增加数据连接类型
使用`BI.config`,ConstantName名称为`dec.constant.database.conf.connect.types`,值为连接的名称
例如增加`Redis`的连接:
@ -128,25 +129,25 @@ BI.config(ConstantPluginTyps, (datas: string[]) => [...datas, {
}]);
```
### 数据连接填写页面
#### 2. 数据连接填写页面
edit属性值为填写组件shortcut的名称
### 数据连接展示页面
#### 3. 数据连接展示页面
show属性值为组件shortcut的名称
### 示例
```
#### 4. 示例
```js
const DataBaseConfigProvider = 'dec.connection.provider.datebase';
const RedisShowName = 'dec.dcm.connection.plugin.redis.show';
const RedisEditName = 'dec.dcm.connection.plugin.redis.edit';
BI.config(DataBaseConfigProvider, function (provider) {
provider.registerDatabaseType({
provider.registerDatabaseType([{
text: "Redis",
databaseType: "Redis",
edit: "dec.dcm.connection.plugin.demo.edit",
show: "dec.dcm.connection.plugin.demo.show",
});
}]);
});
const RedisShow = BI.inherit(BI.Widget, {
@ -214,7 +215,7 @@ const RedisShow = BI.inherit(BI.Widget, {
],
},
],
};
},
},
});
BI.shortcut(RedisShowName, RedisShow);
@ -309,7 +310,55 @@ const RedisEdit = BI.inherit(BI.Widget, {
password: this.password.getValue(),
};
},
//可以触发组件的数据save方法,不需要则可不写
async save() {
let result = false;
await Promise.resolve().then(() => {result = true});
//要求返回是否成功的boolean变量
return result;
},
});
BI.shortcut(RedisEditName, RedisEdit);
```
### B 添加数据连接实例
#### 1. 增加数据连接
```js
BI.config('dec.constant.connection.list', function (value) {
const result = [{
"connectionType": "Redis",//和databaseType一致
"connectionName": "CHART",//类似于id,唯一性
"pluginConnection": true,//表示是外来添加的插件
"connectionData": {
//表单保存数据
},
"connectionId": null,
}];
return value.concat(result);
})
```
### C 添加数据连接类型分类
#### 1. 添加分类DEMO
```js
BI.config('dec.constant.database.filter.type', (value) => {
value.push({
text:"DEMO",
value:"DEMO_VALUE"
});
return value;
});
```
#### 2. 添加数据连接类型进DEMO
```js
BI.config('dec.connection.provider.datebase', function (provider) {
text: "Redis",//必填
databaseType: "Redis",//唯一值
marker: 'DEMO_VALUE',//marker对标dec.constant.database.filter.type常量item的value,用于过滤
isHideConnection: true, //是否隐藏测试连接按钮
isNoSave: true,//是否不执行平台的保存逻辑
iconUrl:'https://work.fineres.com/secure/projectavatar?pid=10301&avatarId=10011',
driver: 'com.amazon.redshift.jdbc41.Driver',
drivers: ['com.amazon.redshift.jdbc4.Driver', 'com.amazon.redshift.jdbc41.Driver'],
url: 'jdbc:redshift://endpoint:port/database',
}
```

3
src/modules/app.model.ts

@ -7,7 +7,7 @@ import { getAllDatabaseTypes } from './app.service';
export class AppModel extends Model {
static xtype = 'dec.dcm.model.main';
childContext = <const>['pageIndex', 'datebaseTypeSelected', 'datebaseTypeSelectedOne', 'filter', 'connections', 'connectionSelected', 'connectionSelectedOne', 'saveEvent', 'testEvent', 'isCopy', 'connectionLicInfo'];
childContext = <const>['pageIndex', 'datebaseTypeSelected', 'datebaseTypeSelectedOne', 'filter', 'connections', 'connectionSelected', 'connectionSelectedOne', 'saveEvent', 'testEvent', 'isCopy', 'connectionLicInfo', 'noTestConnection'];
state() {
return {
@ -23,6 +23,7 @@ export class AppModel extends Model {
currentConnectionNum: 0,
maxConnectionNum: 0,
},
noTestConnection: false,
};
}

1
src/modules/app.typings.d.ts vendored

@ -17,4 +17,5 @@ export interface DatabaseType {
urls?: {
[key: string]: string;
};
marker?: string;
}

9
src/modules/pages/connection/connection.model.ts

@ -13,13 +13,14 @@ export class ConnectionModel extends Model<{
connectionSelected: AppModel['TYPE']['connectionSelected'];
connectionSelectedOne: AppModel['TYPE']['connectionSelectedOne'];
datebaseTypeSelected: AppModel['TYPE']['datebaseTypeSelected'];
noTestConnection: AppModel['TYPE']['noTestConnection'];
},
childContext: ConnectionModel['childContext'];
context: ConnectionModel['context'];
}> {
static xtype = 'dec.dcm.model.connection';
context = <const>['pageIndex', 'connectionSelected', 'connectionSelectedOne', 'datebaseTypeSelected', 'connectionLicInfo'];
context = <const>['pageIndex', 'connectionSelected', 'connectionSelectedOne', 'datebaseTypeSelected', 'connectionLicInfo', 'noTestConnection'];
actions = {
initConnectionLicInfo: (cb: Function) => {
@ -53,8 +54,14 @@ export class ConnectionModel extends Model<{
this.model.connectionSelected = name;
},
getConnectionStatus() {
if (this.model.connectionSelectedOne.pluginConnection) {
return Promise.resolve();
}
return api.getConnectionStatus(this.model.connectionSelected);
},
setNoTestConnection(value: boolean) {
this.model.noTestConnection = value;
},
checkConnectionLic() {
return this.model.connectionLicInfo.currentConnectionNum > this.model.connectionLicInfo.maxConnectionNum;
},

13
src/modules/pages/connection/connection.ts

@ -137,9 +137,11 @@ export class Connection extends BI.Widget {
},
handler: () => {
this.store.getConnectionStatus()
.then(re => {
this.store.setPageIndex(PAGE_INDEX.MAINTAIN);
this.store.setDatebaseTypeSelected('');
.then(() => {
const databaseType = this.model.connectionSelectedOne.connectionType;
const database = BI.find(getAllDatabaseTypes(), (_index, value) => value.databaseType === databaseType);
this.setMaintainPage();
this.store.setNoTestConnection(database.isHideConnection);
})
.catch(() => {
});
@ -239,4 +241,9 @@ export class Connection extends BI.Widget {
return databaseType;
}
private setMaintainPage() {
this.store.setPageIndex(PAGE_INDEX.MAINTAIN);
this.store.setDatebaseTypeSelected('');
}
}

1
src/modules/pages/connection/list/list.constant.ts

@ -0,0 +1 @@
BI.constant('dec.constant.connection.list', []);

4
src/modules/pages/connection/list/list.model.ts

@ -21,10 +21,10 @@ export class ConnectionListModel extends Model<{
actions = {
setConnections: ():Promise<void> => api.getConnectionList().then(data => {
if (BI.size(data.data) > 0) {
this.model.connections = data.data;
this.model.connections = data.data.concat(BI.Constants.getConstant('dec.constant.connection.list'));
this.model.connections.forEach(item => {
// 后端传过来的是字符串,转为对象
item.connectionData = JSON.parse(item.connectionData as string);
BI.isString(item.connectionData) && (item.connectionData = JSON.parse(item.connectionData as string));
});
this.model.connectionSelected = data.data[0].connectionName;
} else {

2
src/modules/pages/connection/list/list.ts

@ -3,6 +3,7 @@ import { ListItem } from './list_item/list_item';
import { ConnectionListModel } from './list.model';
import { getDatabaseType } from './list.service';
import { Tab } from '@fui/core';
import './list.constant'
@shortcut()
@store(ConnectionListModel)
@ -91,6 +92,7 @@ export class ConnectionList extends BI.Pane {
creator: item.creator,
databaseType: getDatabaseType(item),
selected: this.model.connectionSelected ? this.model.connectionSelected === item.connectionName : index === 0,
pluginConnection: item.pluginConnection,
};
});
}

5
src/modules/pages/connection/list/list_item/list_item.ts

@ -20,6 +20,7 @@ export class ListItem extends BI.BasicButton {
name: '',
creator: '',
databaseType: '',
pluginConnection: false,
height: 25,
baseCls: 'dec-dcm-connection-list-item bi-list-item-active2',
$testId: 'dec-dcm-connection-list-item',
@ -43,7 +44,7 @@ export class ListItem extends BI.BasicButton {
};
render() {
const { name, databaseType } = this.options;
const { name, databaseType, pluginConnection } = this.options;
return {
type: BI.HTapeLayout.xtype,
@ -118,7 +119,7 @@ export class ListItem extends BI.BasicButton {
},
],
}, {
el: databaseType ? {
el: databaseType && !pluginConnection ? {
type: BI.DownListCombo.xtype,
cls: 'link-item-icon',
stopPropagation: true,

17
src/modules/pages/database/database.constant.ts

@ -0,0 +1,17 @@
import { DATEBASE_FILTER_TYPE } from "@constants/constant";
BI.constant('dec.constant.database.filter.type', [
{
text: BI.i18nText('Dec-Dcm_Connection_Commonly'),
value: DATEBASE_FILTER_TYPE.COMMONLY,
selected: true,
},
{
text: BI.i18nText('Dec-Dcm_Connection_All'),
value: DATEBASE_FILTER_TYPE.ALL,
},
{
text: BI.i18nText('Dec-Dcm_Connection_Other'),
value: DATEBASE_FILTER_TYPE.OTHER,
},
]);

28
src/modules/pages/database/database.ts

@ -7,6 +7,7 @@ import { DatebaseType } from './database_type/database_type';
import { getAllDatabaseTypes } from '../../app.service';
import { ButtonGroup, MultiSelectItem, SearchEditor } from '@fui/core';
import { ApiFactory } from 'src/modules/crud/apiFactory';
import './database.constant'
const api = new ApiFactory().create();
@ -121,24 +122,12 @@ export class Datebase extends BI.Widget {
ref: (_ref: ButtonGroup) => {
this.filter = _ref;
},
items: [
{
items: () => BI.map(BI.Constants.getConstant('dec.constant.database.filter.type'), (_, value) => {
return {
type: Filter.xtype,
text: BI.i18nText('Dec-Dcm_Connection_Commonly'),
value: DATEBASE_FILTER_TYPE.COMMONLY,
selected: true,
},
{
type: Filter.xtype,
text: BI.i18nText('Dec-Dcm_Connection_All'),
value: DATEBASE_FILTER_TYPE.ALL,
},
{
type: Filter.xtype,
text: BI.i18nText('Dec-Dcm_Connection_Other'),
value: DATEBASE_FILTER_TYPE.OTHER,
},
],
...value,
}
}),
},
width: 200,
},
@ -254,9 +243,12 @@ export class Datebase extends BI.Widget {
case DATEBASE_FILTER_TYPE.OTHER:
this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => this.model.otherDatabases.includes(item.type)));
break;
default:
case DATEBASE_FILTER_TYPE.ALL:
this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.type !== connectionType.JNDI && item.type !== OTHER_JDBC));
break;
default:
this.store.setDatebaseTypes(this.allDatabaseTypes.filter(item => item.marker && (item.marker === filter)));
break;
}
}

7
src/modules/pages/database/database_type/database_type.model.ts

@ -6,11 +6,13 @@ export class DatebaseTypeModel extends Model<
types: {
datebaseTypeSelected: AppModel['TYPE']['datebaseTypeSelected'];
pageIndex: AppModel['TYPE']['pageIndex'];
noTestConnection: AppModel['TYPE']['noTestConnection'];
datebaseTypeSelectedOne: AppModel['TYPE']['datebaseTypeSelectedOne'];
},
context: DatebaseTypeModel['context'];
}> {
static xtype = 'dec.dcm.model.datebase.type';
context = <const>['datebaseTypeSelected', 'pageIndex'];
context = <const>['datebaseTypeSelected', 'pageIndex', 'noTestConnection', 'datebaseTypeSelectedOne'];
actions = {
setDatebaseTypeSelected: (datebaseTypeSelected: string) => {
@ -19,5 +21,8 @@ export class DatebaseTypeModel extends Model<
setPageIndex: (index: string) => {
this.model.pageIndex = index;
},
setNoTestConnection: (value: boolean) => {
this.model.noTestConnection = value;
}
}
}

4
src/modules/pages/database/database_type/database_type.ts

@ -70,6 +70,7 @@ export class DatebaseType extends BI.BasicButton {
const { value } = this.options;
this.store.setDatebaseTypeSelected(value);
this.store.setPageIndex(PAGE_INDEX.MAINTAIN);
this.store.setNoTestConnection(this.model.datebaseTypeSelectedOne.isHideConnection);
}
mounted() {
@ -88,6 +89,9 @@ export class DatebaseType extends BI.BasicButton {
if (url.startsWith('/')) {
return `${PluginImgPrefix}${url}`;
}
if (url.startsWith('http')) {
return url;
}
return `${PluginImgPrefix}/${url}`;
}

4
src/modules/pages/maintain/forms/components/form.plugin.ts

@ -37,4 +37,8 @@ export class FormPlugin extends BI.Widget {
connectionData: <ConnectionPlugin>BI.extend({}, connectionData, this.plugin.getValue()),
};
}
public getSaveFn() {
return this.plugin.save;
}
}

86
src/modules/pages/maintain/forms/form.ts

@ -6,7 +6,7 @@ import { FormPlugin } from './components/form.plugin';
import { connectionType, errorCode } from '@constants/env';
import { ConnectionJDBC, Connection, ResultType } from 'src/modules/crud/crud.typings';
import { DEFAULT_JNDI_DATA, DEFAULT_JDBC_POOL, DATEBASE_FILTER_TYPE } from '@constants/constant';
import { getJdbcDatabaseType, getChartLength } from '../../../app.service';
import { getJdbcDatabaseType, getChartLength, getAllDatabaseTypes } from '../../../app.service';
import { NAME_MAX_LENGTH } from '../../../app.constant';
import { checkIllegalStrings } from "@core/index";
@ -14,6 +14,7 @@ import { checkIllegalStrings } from "@core/index";
@store(MaintainFormModel)
export class MaintainForm extends BI.Widget {
static xtype = 'dec.dcm.maintain.form';
static EVENT_TESTCONNECTION = 'EVENT_TEST_CONNECTION';
props = {
connectionType: '',
@ -29,34 +30,36 @@ export class MaintainForm extends BI.Widget {
watch = {
saveEvent: () => {
if (!this.testValue()) {
return;
}
if (this.connectionName && !this.model.isCopy) {
const value = this.form.getSubmitValue();
(value.connectionData as ConnectionJDBC).creator = BI.get(this.getFormData(), 'creator');
// DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段
value.creator = BI.get(this.getFormData(), 'creator');
this.store.updateConnection(this.connectionName, value).then(result => {
if (result.errorCode) {
if (result.errorCode === DecCst.ErrorCode.NO_IP_AUTHORIZED) {
BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), {
level: "error",
});
}
this.showError(result);
const sonSave = this.form.getSaveFn?.();
if (sonSave) {
sonSave().then((success: boolean) => {
if (success) {
BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Success"), {
level: "success",
});
} else {
BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), {
level: "error",
});
}
});
//只有外来插件才可以使用是否不执行平台的保存逻辑
if (this.model.datebaseTypeSelected) {
const isPluginDatabase = BI.some(BI.Providers.getProvider('dec.connection.provider.datebase').customDatabaseType, (_index, value) => value.databaseType === this.model.datebaseTypeSelected);
if (isPluginDatabase && this.model.datebaseTypeSelectedOne.isNoSave) {
return;
}
this.store.goFirstPage();
});
} else {
const form = this.form.getSubmitValue();
form.connectionId = this.connectionName;
// DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段
form.creator = Dec ? Dec.personal.username : '';
this.addConnection(form);
} else {
const databaseType = this.model.connectionSelectedOne.connectionType;
const database = BI.find(getAllDatabaseTypes(), (_index, value) => value.databaseType === databaseType);
if (this.model.connectionSelectedOne.pluginConnection && database?.isNoSave) {
return;
}
}
}
this.save();
},
testEvent: () => {
this.testConnection();
@ -77,7 +80,7 @@ export class MaintainForm extends BI.Widget {
this.form = _ref;
},
listeners: [{
eventName: 'EVENT_TEST_CONNECTION',
eventName: MaintainForm.EVENT_TESTCONNECTION,
action: () => {
this.testConnection();
},
@ -295,4 +298,35 @@ export class MaintainForm extends BI.Widget {
this.store.setIsCopy(false);
});
}
private save() {
if (!this.testValue()) {
return;
}
if (this.connectionName && !this.model.isCopy) {
const value = this.form.getSubmitValue();
(value.connectionData as ConnectionJDBC).creator = BI.get(this.getFormData(), 'creator');
// DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段
value.creator = BI.get(this.getFormData(), 'creator');
this.store.updateConnection(this.connectionName, value).then(result => {
if (result.errorCode) {
if (result.errorCode === DecCst.ErrorCode.NO_IP_AUTHORIZED) {
BI.Msg.toast(BI.i18nText("Dec-Basic_Save_Fail"), {
level: "error",
});
}
this.showError(result);
return;
}
this.store.goFirstPage();
});
} else {
const form = this.form.getSubmitValue();
form.connectionId = this.connectionName;
// DEC-10155 为了适配插件的数据连接,在外层也加一个creator字段
form.creator = Dec ? Dec.personal.username : '';
this.addConnection(form);
}
}
}

3
src/modules/title/title_maintain/title_maintain.model.ts

@ -11,12 +11,13 @@ export class TitleMaintainModel extends Model<{
connectionSelected: AppModel['TYPE']['connectionSelected'];
testEvent: AppModel['TYPE']['testEvent'];
isCopy: AppModel['TYPE']['isCopy'];
noTestConnection: AppModel['TYPE']['noTestConnection'];
},
context: TitleMaintainModel['context'];
}> {
static xtype = 'dec.dcm.model.title_maintain';
context = <const>['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy'];
context = <const>['pageIndex', 'saveEvent', 'testEvent', 'connectionSelected', 'isCopy', 'noTestConnection'];
actions = {
setPageIndex: (index: string) => {

6
src/modules/title/title_maintain/title_maintain.ts

@ -1,6 +1,7 @@
import { shortcut, store } from '@core/core';
import { TitleMaintainModel } from './title_maintain.model';
import { PAGE_INDEX } from '@constants/constant';
import { Button } from '@fui/core';
@shortcut()
@store(TitleMaintainModel)
@ -9,6 +10,7 @@ export class TitleMaintain extends BI.Widget {
store: TitleMaintainModel['store'];
model: TitleMaintainModel['model'];
render() {
return {
type: BI.FloatRightLayout.xtype,
@ -30,6 +32,10 @@ export class TitleMaintain extends BI.Widget {
},
{
type: BI.Button.xtype,
ref: (_ref) => {
this.testConnectionBtn = _ref;
},
invisible: () => this.model.noTestConnection,
_rgap: 16,
$value: 'title-maintain-connection-test',
text: BI.i18nText('Dec-Dcm_Connection_Test'),

Loading…
Cancel
Save