From 57e70eb0a5a22802299ba82127b79f8925a21742 Mon Sep 17 00:00:00 2001 From: alan Date: Fri, 8 Nov 2019 16:49:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/src/modules/app.dataset.ts | 20 +++++++++++-------- src/web/src/modules/app.model.ts | 2 -- src/web/src/modules/app.program.ts | 19 ++++++++++-------- .../database_index/database_index.model.ts | 4 ++-- .../database_index/database_index.ts | 20 +++++++++++-------- src/web/src/modules/crud/crud.request.ts | 2 +- src/web/src/modules/crud/crud.service.ts | 7 +------ .../modules/table_list/table_list.model.ts | 2 +- src/web/src/modules/table_list/table_list.ts | 12 +++++++++++ 9 files changed, 52 insertions(+), 36 deletions(-) diff --git a/src/web/src/modules/app.dataset.ts b/src/web/src/modules/app.dataset.ts index 62b4256..370507c 100644 --- a/src/web/src/modules/app.dataset.ts +++ b/src/web/src/modules/app.dataset.ts @@ -1,5 +1,5 @@ import { shortcut, store } from '@core/core'; -import { VerticalXtype, HtapeXtype, LabelXtype, IconComboXtype, CodeEditorXtype, ComponentsStyleTable, ButtonXtype, IconTextValue_Combo } from 'ui'; +import { VerticalXtype, HtapeXtype, LabelXtype, IconComboXtype, ComponentsStyleTable, ButtonXtype, IconTextValue_Combo, TextAreaEditorXtype } from 'ui'; import { TableList } from './table_list/table_list'; import '../less/index.less'; import { DatabaseIndex } from './components/database_index/database_index'; @@ -27,7 +27,7 @@ export class RedisDataset extends BI.Widget { value: { datasetData: { database: '', - orderValue: '0', + orderValue: 0, query: '', parameters: [], }, @@ -38,14 +38,16 @@ export class RedisDataset extends BI.Widget { parameters: () => { this.parameterEditor.populate(this.renderItems(), [this.model.paramHeader]); }, - ablePreview: (ablePreview: boolean) => { - this.previewButton.setEnable(ablePreview); + ableSave: (ableSave: boolean) => { + this.previewButton.setEnable(ableSave); }, } render() { - const { database = '', orderValue = '0', query = '', parameters = [] } = this.options.value.datasetData || {}; + const { database = '', orderValue = 0, query = '', parameters = [] } = this.options.value.datasetData || {}; this.store.setParameters(parameters); + this.store.setAbleSave(!!query); + const inputType = typeof orderValue === 'string' ? 'formula' : 'int'; return { type: HtapeXtype, @@ -81,7 +83,7 @@ export class RedisDataset extends BI.Widget { type: IconComboXtype, height: 22, width: 28, - value: 'int', + value: inputType, items: [{ text: BI.i18nText('Plugin-Redis_Parameter_Type_Int'), value: 'int', @@ -107,6 +109,7 @@ export class RedisDataset extends BI.Widget { type: DatabaseIndex.xtype, rgap: 11, value: orderValue, + inputType, ref: (_ref: any) => { this.databaseIndex = _ref; }, @@ -124,9 +127,10 @@ export class RedisDataset extends BI.Widget { }, width: this.textWidth, }, { - type: CodeEditorXtype, + type: TextAreaEditorXtype, cls: 'bi-border', height: 200, + allowBlank: true, value: query, ref: (_ref: any) => { this.queryCondition = _ref; @@ -165,7 +169,7 @@ export class RedisDataset extends BI.Widget { el: { type: ButtonXtype, text: BI.i18nText('Plugin-Redis_Preview'), - disabled: !this.model.ablePreview, + disabled: !BI.get(this.model, 'ableSave'), handler: () => { this.openPreview(); }, diff --git a/src/web/src/modules/app.model.ts b/src/web/src/modules/app.model.ts index 36fd240..f1dd4c8 100644 --- a/src/web/src/modules/app.model.ts +++ b/src/web/src/modules/app.model.ts @@ -8,14 +8,12 @@ export class RedisModel extends Model { state() { return { parameters: [] as ParameterType[], - ablePreview: false, }; } actions = { setAbleSave(ableSave: boolean) { this.model.ableSave = ableSave; - this.model.ablePreview = ableSave; }, setParameters: (parameters: ParameterType[]) => { this.model.parameters = parameters; diff --git a/src/web/src/modules/app.program.ts b/src/web/src/modules/app.program.ts index 5437b4d..ab5428e 100644 --- a/src/web/src/modules/app.program.ts +++ b/src/web/src/modules/app.program.ts @@ -1,5 +1,5 @@ import { shortcut, store } from '@core/core'; -import { VerticalXtype, HtapeXtype, LabelXtype, IconComboXtype, TextValueComboXtype, CodeEditorXtype, ComponentsStyleTable, ButtonXtype, IconTextValue_Combo } from 'ui'; +import { VerticalXtype, HtapeXtype, LabelXtype, IconComboXtype, TextValueComboXtype, TextAreaEditorXtype, ComponentsStyleTable, ButtonXtype, IconTextValue_Combo } from 'ui'; import { TableList } from './table_list/table_list'; import '../less/index.less'; import { DatabaseIndex } from './components/database_index/database_index'; @@ -29,7 +29,7 @@ export class RedisProgram extends BI.Widget { value: { datasetData: { database: '', - orderValue: '0', + orderValue: 0, script: '', engineType: 0, parameters: [], @@ -41,14 +41,15 @@ export class RedisProgram extends BI.Widget { parameters: () => { this.parameterEditor.populate(this.renderItems(), [this.model.paramHeader]); }, - ablePreview: (ablePreview: boolean) => { - this.previewButton.setEnable(ablePreview); + ableSave: (ableSave: boolean) => { + this.previewButton.setEnable(ableSave); }, } render() { - const { database = '', orderValue = '0', script = '', parameters = [], engineType = 0 } = this.options.value.datasetData || {}; + const { database = '', orderValue = 0, script = '', parameters = [], engineType = 0 } = this.options.value.datasetData || {}; this.store.setParameters(parameters); + const inputType = typeof orderValue === 'string' ? 'formula' : 'int'; return { type: HtapeXtype, @@ -84,7 +85,7 @@ export class RedisProgram extends BI.Widget { type: IconComboXtype, height: 22, width: 28, - value: 'int', + value: inputType, items: [{ text: BI.i18nText('Plugin-Redis_Parameter_Type_Int'), value: 'int', @@ -110,6 +111,7 @@ export class RedisProgram extends BI.Widget { type: DatabaseIndex.xtype, rgap: 11, value: orderValue, + inputType, ref: (_ref: any) => { this.databaseIndex = _ref; }, @@ -152,9 +154,10 @@ export class RedisProgram extends BI.Widget { }, width: this.textWidth, }, { - type: CodeEditorXtype, + type: TextAreaEditorXtype, cls: 'bi-border', height: 200, + allowBlank: true, value: script, ref: (_ref: any) => { this.queryCondition = _ref; @@ -193,7 +196,7 @@ export class RedisProgram extends BI.Widget { el: { type: ButtonXtype, text: BI.i18nText('Plugin-Redis_Preview'), - disabled: !this.model.ablePreview, + disabled: !BI.get(this.model, 'ableSave'), handler: () => { this.openPreview(); }, diff --git a/src/web/src/modules/components/database_index/database_index.model.ts b/src/web/src/modules/components/database_index/database_index.model.ts index bf43dad..b315a7e 100644 --- a/src/web/src/modules/components/database_index/database_index.model.ts +++ b/src/web/src/modules/components/database_index/database_index.model.ts @@ -6,12 +6,12 @@ export class DatabaseIndexModel extends Model { state() { return { - inputValue: '', + inputValue: '' as string | number, }; } actions = { - setInpueValue: (value: string) => { + setInpueValue: (value: string | number) => { this.model.inputValue = value; }, } diff --git a/src/web/src/modules/components/database_index/database_index.ts b/src/web/src/modules/components/database_index/database_index.ts index 3538a97..face893 100644 --- a/src/web/src/modules/components/database_index/database_index.ts +++ b/src/web/src/modules/components/database_index/database_index.ts @@ -10,23 +10,24 @@ export class DatabaseIndex extends BI.Widget { databaseIndexTab: any; textEditor: any; - formulaPane: typeof BI.FormulaOpeartingPanel; + formulaPane: any; model: DatabaseIndexModel['model'] store: DatabaseIndexModel['store'] props = { value: '', + inputType: 'int', } render() { - const { value } = this.options; + const { value, inputType } = this.options; this.store.setInpueValue(value); return { type: TabXtype, single: true, - showIndex: 'int', + showIndex: inputType, ref: (_ref: any) => { this.databaseIndexTab = _ref; }, @@ -35,13 +36,13 @@ export class DatabaseIndex extends BI.Widget { return { type: TextEditorXtype, warningTitle: '', - value: this.model.inputValue, + value: parseInt(this.model.inputValue as string, 10) || 0, validationChecker: (v: string) => this.checkInteger(v), errorText: BI.i18nText('Plugin-Redis_Check_Integer'), listeners: [{ eventName: 'EVENT_CHANGE', action: () => { - this.store.setInpueValue(this.textEditor.getValue()); + this.store.setInpueValue(parseInt(this.textEditor.getValue(), 10)); }, }], ref: (_ref: any) => { @@ -54,7 +55,7 @@ export class DatabaseIndex extends BI.Widget { type: TextEditorXtype, allowBlank: true, value: this.model.inputValue, - ref: (_ref: typeof BI.FormulaOpeartingPanel) => { + ref: (_ref: any) => { this.formulaPane = _ref; }, }; @@ -69,8 +70,11 @@ export class DatabaseIndex extends BI.Widget { this.databaseIndexTab.setSelect(value); if (value === 'formula') { openFormulaPopover({ - formula: '', - }, BI.ComplexFormulaInserter.xtype); + formula: this.model.inputValue === 0 ? '' : this.model.inputValue as string, + }, BI.ComplexFormulaInserter.xtype).then(value => { + this.store.setInpueValue(value.formula); + this.formulaPane.setValue(value.formula); + }); } } diff --git a/src/web/src/modules/crud/crud.request.ts b/src/web/src/modules/crud/crud.request.ts index a59498a..cfa4471 100644 --- a/src/web/src/modules/crud/crud.request.ts +++ b/src/web/src/modules/crud/crud.request.ts @@ -4,7 +4,7 @@ export function getConnectionlist(): Promise<{data?: Connection[]}> { return requestGet('/v10/config/connection/list'); } -export function getTableList(database: string, pattern = ''): Promise<{data?: string[]}> { +export function getTableList(database: string, pattern = ''): Promise { return requestGet('plugin/private/com.fr.solution.plugin.db.redis.v10/redis/keys', { database, pattern, diff --git a/src/web/src/modules/crud/crud.service.ts b/src/web/src/modules/crud/crud.service.ts index 1958510..424bf35 100644 --- a/src/web/src/modules/crud/crud.service.ts +++ b/src/web/src/modules/crud/crud.service.ts @@ -50,7 +50,7 @@ function checkStatus(response: AxiosResponse) { return resData; } -export async function request(reqOptions: CrudReqOpts = {}): Promise { +export async function request(reqOptions: CrudReqOpts = {}): Promise { const { url, type, headers, data, params } = reqOptions; return axios @@ -128,8 +128,3 @@ interface CrudParams { [key: string]: string | number | { [key: string]: any }; } -interface ResultType { - data?: any; - errorCode?: string; - errorMsg?: string; -} diff --git a/src/web/src/modules/table_list/table_list.model.ts b/src/web/src/modules/table_list/table_list.model.ts index 87c6039..d69a462 100644 --- a/src/web/src/modules/table_list/table_list.model.ts +++ b/src/web/src/modules/table_list/table_list.model.ts @@ -22,7 +22,7 @@ export class TableModelModel extends Model { initTableList: () => { if (this.model.selectedConnection) { getTableList(this.model.selectedConnection, this.model.search).then(re => { - this.model.tables = re ? re.data : []; + this.model.tables = re ? re : []; }); } else { this.model.tables = []; diff --git a/src/web/src/modules/table_list/table_list.ts b/src/web/src/modules/table_list/table_list.ts index c0253f5..af4b383 100644 --- a/src/web/src/modules/table_list/table_list.ts +++ b/src/web/src/modules/table_list/table_list.ts @@ -30,6 +30,9 @@ export class TableList extends BI.Widget { 'selectedConnection || search': () => { this.store.initTableList(); }, + tables: (tables: string[]) => { + this.buttonGroup.populate(this.renderTableList()); + }, } render() { @@ -118,6 +121,15 @@ export class TableList extends BI.Widget { private renderConnectionList() { return this.model.connections.map(item => { + return { + text: item, + value: item, + }; + }); + } + + private renderTableList() { + return this.model.tables.map(item => { return { type: ListItem.xtype, text: item,