Browse Source

fix: 修改bug

refactor
alan 5 years ago
parent
commit
57e70eb0a5
  1. 20
      src/web/src/modules/app.dataset.ts
  2. 2
      src/web/src/modules/app.model.ts
  3. 19
      src/web/src/modules/app.program.ts
  4. 4
      src/web/src/modules/components/database_index/database_index.model.ts
  5. 20
      src/web/src/modules/components/database_index/database_index.ts
  6. 2
      src/web/src/modules/crud/crud.request.ts
  7. 7
      src/web/src/modules/crud/crud.service.ts
  8. 2
      src/web/src/modules/table_list/table_list.model.ts
  9. 12
      src/web/src/modules/table_list/table_list.ts

20
src/web/src/modules/app.dataset.ts

@ -1,5 +1,5 @@
import { shortcut, store } from '@core/core'; 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 { TableList } from './table_list/table_list';
import '../less/index.less'; import '../less/index.less';
import { DatabaseIndex } from './components/database_index/database_index'; import { DatabaseIndex } from './components/database_index/database_index';
@ -27,7 +27,7 @@ export class RedisDataset extends BI.Widget {
value: { value: {
datasetData: { datasetData: {
database: '', database: '',
orderValue: '0', orderValue: 0,
query: '', query: '',
parameters: [], parameters: [],
}, },
@ -38,14 +38,16 @@ export class RedisDataset extends BI.Widget {
parameters: () => { parameters: () => {
this.parameterEditor.populate(this.renderItems(), [this.model.paramHeader]); this.parameterEditor.populate(this.renderItems(), [this.model.paramHeader]);
}, },
ablePreview: (ablePreview: boolean) => { ableSave: (ableSave: boolean) => {
this.previewButton.setEnable(ablePreview); this.previewButton.setEnable(ableSave);
}, },
} }
render() { 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.setParameters(parameters);
this.store.setAbleSave(!!query);
const inputType = typeof orderValue === 'string' ? 'formula' : 'int';
return { return {
type: HtapeXtype, type: HtapeXtype,
@ -81,7 +83,7 @@ export class RedisDataset extends BI.Widget {
type: IconComboXtype, type: IconComboXtype,
height: 22, height: 22,
width: 28, width: 28,
value: 'int', value: inputType,
items: [{ items: [{
text: BI.i18nText('Plugin-Redis_Parameter_Type_Int'), text: BI.i18nText('Plugin-Redis_Parameter_Type_Int'),
value: 'int', value: 'int',
@ -107,6 +109,7 @@ export class RedisDataset extends BI.Widget {
type: DatabaseIndex.xtype, type: DatabaseIndex.xtype,
rgap: 11, rgap: 11,
value: orderValue, value: orderValue,
inputType,
ref: (_ref: any) => { ref: (_ref: any) => {
this.databaseIndex = _ref; this.databaseIndex = _ref;
}, },
@ -124,9 +127,10 @@ export class RedisDataset extends BI.Widget {
}, },
width: this.textWidth, width: this.textWidth,
}, { }, {
type: CodeEditorXtype, type: TextAreaEditorXtype,
cls: 'bi-border', cls: 'bi-border',
height: 200, height: 200,
allowBlank: true,
value: query, value: query,
ref: (_ref: any) => { ref: (_ref: any) => {
this.queryCondition = _ref; this.queryCondition = _ref;
@ -165,7 +169,7 @@ export class RedisDataset extends BI.Widget {
el: { el: {
type: ButtonXtype, type: ButtonXtype,
text: BI.i18nText('Plugin-Redis_Preview'), text: BI.i18nText('Plugin-Redis_Preview'),
disabled: !this.model.ablePreview, disabled: !BI.get(this.model, 'ableSave'),
handler: () => { handler: () => {
this.openPreview(); this.openPreview();
}, },

2
src/web/src/modules/app.model.ts

@ -8,14 +8,12 @@ export class RedisModel extends Model {
state() { state() {
return { return {
parameters: [] as ParameterType[], parameters: [] as ParameterType[],
ablePreview: false,
}; };
} }
actions = { actions = {
setAbleSave(ableSave: boolean) { setAbleSave(ableSave: boolean) {
this.model.ableSave = ableSave; this.model.ableSave = ableSave;
this.model.ablePreview = ableSave;
}, },
setParameters: (parameters: ParameterType[]) => { setParameters: (parameters: ParameterType[]) => {
this.model.parameters = parameters; this.model.parameters = parameters;

19
src/web/src/modules/app.program.ts

@ -1,5 +1,5 @@
import { shortcut, store } from '@core/core'; 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 { TableList } from './table_list/table_list';
import '../less/index.less'; import '../less/index.less';
import { DatabaseIndex } from './components/database_index/database_index'; import { DatabaseIndex } from './components/database_index/database_index';
@ -29,7 +29,7 @@ export class RedisProgram extends BI.Widget {
value: { value: {
datasetData: { datasetData: {
database: '', database: '',
orderValue: '0', orderValue: 0,
script: '', script: '',
engineType: 0, engineType: 0,
parameters: [], parameters: [],
@ -41,14 +41,15 @@ export class RedisProgram extends BI.Widget {
parameters: () => { parameters: () => {
this.parameterEditor.populate(this.renderItems(), [this.model.paramHeader]); this.parameterEditor.populate(this.renderItems(), [this.model.paramHeader]);
}, },
ablePreview: (ablePreview: boolean) => { ableSave: (ableSave: boolean) => {
this.previewButton.setEnable(ablePreview); this.previewButton.setEnable(ableSave);
}, },
} }
render() { 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); this.store.setParameters(parameters);
const inputType = typeof orderValue === 'string' ? 'formula' : 'int';
return { return {
type: HtapeXtype, type: HtapeXtype,
@ -84,7 +85,7 @@ export class RedisProgram extends BI.Widget {
type: IconComboXtype, type: IconComboXtype,
height: 22, height: 22,
width: 28, width: 28,
value: 'int', value: inputType,
items: [{ items: [{
text: BI.i18nText('Plugin-Redis_Parameter_Type_Int'), text: BI.i18nText('Plugin-Redis_Parameter_Type_Int'),
value: 'int', value: 'int',
@ -110,6 +111,7 @@ export class RedisProgram extends BI.Widget {
type: DatabaseIndex.xtype, type: DatabaseIndex.xtype,
rgap: 11, rgap: 11,
value: orderValue, value: orderValue,
inputType,
ref: (_ref: any) => { ref: (_ref: any) => {
this.databaseIndex = _ref; this.databaseIndex = _ref;
}, },
@ -152,9 +154,10 @@ export class RedisProgram extends BI.Widget {
}, },
width: this.textWidth, width: this.textWidth,
}, { }, {
type: CodeEditorXtype, type: TextAreaEditorXtype,
cls: 'bi-border', cls: 'bi-border',
height: 200, height: 200,
allowBlank: true,
value: script, value: script,
ref: (_ref: any) => { ref: (_ref: any) => {
this.queryCondition = _ref; this.queryCondition = _ref;
@ -193,7 +196,7 @@ export class RedisProgram extends BI.Widget {
el: { el: {
type: ButtonXtype, type: ButtonXtype,
text: BI.i18nText('Plugin-Redis_Preview'), text: BI.i18nText('Plugin-Redis_Preview'),
disabled: !this.model.ablePreview, disabled: !BI.get(this.model, 'ableSave'),
handler: () => { handler: () => {
this.openPreview(); this.openPreview();
}, },

4
src/web/src/modules/components/database_index/database_index.model.ts

@ -6,12 +6,12 @@ export class DatabaseIndexModel extends Model {
state() { state() {
return { return {
inputValue: '', inputValue: '' as string | number,
}; };
} }
actions = { actions = {
setInpueValue: (value: string) => { setInpueValue: (value: string | number) => {
this.model.inputValue = value; this.model.inputValue = value;
}, },
} }

20
src/web/src/modules/components/database_index/database_index.ts

@ -10,23 +10,24 @@ export class DatabaseIndex extends BI.Widget {
databaseIndexTab: any; databaseIndexTab: any;
textEditor: any; textEditor: any;
formulaPane: typeof BI.FormulaOpeartingPanel; formulaPane: any;
model: DatabaseIndexModel['model'] model: DatabaseIndexModel['model']
store: DatabaseIndexModel['store'] store: DatabaseIndexModel['store']
props = { props = {
value: '', value: '',
inputType: 'int',
} }
render() { render() {
const { value } = this.options; const { value, inputType } = this.options;
this.store.setInpueValue(value); this.store.setInpueValue(value);
return { return {
type: TabXtype, type: TabXtype,
single: true, single: true,
showIndex: 'int', showIndex: inputType,
ref: (_ref: any) => { ref: (_ref: any) => {
this.databaseIndexTab = _ref; this.databaseIndexTab = _ref;
}, },
@ -35,13 +36,13 @@ export class DatabaseIndex extends BI.Widget {
return { return {
type: TextEditorXtype, type: TextEditorXtype,
warningTitle: '', warningTitle: '',
value: this.model.inputValue, value: parseInt(this.model.inputValue as string, 10) || 0,
validationChecker: (v: string) => this.checkInteger(v), validationChecker: (v: string) => this.checkInteger(v),
errorText: BI.i18nText('Plugin-Redis_Check_Integer'), errorText: BI.i18nText('Plugin-Redis_Check_Integer'),
listeners: [{ listeners: [{
eventName: 'EVENT_CHANGE', eventName: 'EVENT_CHANGE',
action: () => { action: () => {
this.store.setInpueValue(this.textEditor.getValue()); this.store.setInpueValue(parseInt(this.textEditor.getValue(), 10));
}, },
}], }],
ref: (_ref: any) => { ref: (_ref: any) => {
@ -54,7 +55,7 @@ export class DatabaseIndex extends BI.Widget {
type: TextEditorXtype, type: TextEditorXtype,
allowBlank: true, allowBlank: true,
value: this.model.inputValue, value: this.model.inputValue,
ref: (_ref: typeof BI.FormulaOpeartingPanel) => { ref: (_ref: any) => {
this.formulaPane = _ref; this.formulaPane = _ref;
}, },
}; };
@ -69,8 +70,11 @@ export class DatabaseIndex extends BI.Widget {
this.databaseIndexTab.setSelect(value); this.databaseIndexTab.setSelect(value);
if (value === 'formula') { if (value === 'formula') {
openFormulaPopover({ openFormulaPopover({
formula: '', formula: this.model.inputValue === 0 ? '' : this.model.inputValue as string,
}, BI.ComplexFormulaInserter.xtype); }, BI.ComplexFormulaInserter.xtype).then(value => {
this.store.setInpueValue(value.formula);
this.formulaPane.setValue(value.formula);
});
} }
} }

2
src/web/src/modules/crud/crud.request.ts

@ -4,7 +4,7 @@ export function getConnectionlist(): Promise<{data?: Connection[]}> {
return requestGet('/v10/config/connection/list'); return requestGet('/v10/config/connection/list');
} }
export function getTableList(database: string, pattern = ''): Promise<{data?: string[]}> { export function getTableList(database: string, pattern = ''): Promise<string[]> {
return requestGet('plugin/private/com.fr.solution.plugin.db.redis.v10/redis/keys', { return requestGet('plugin/private/com.fr.solution.plugin.db.redis.v10/redis/keys', {
database, database,
pattern, pattern,

7
src/web/src/modules/crud/crud.service.ts

@ -50,7 +50,7 @@ function checkStatus(response: AxiosResponse) {
return resData; return resData;
} }
export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> { export async function request(reqOptions: CrudReqOpts = {}): Promise<any> {
const { url, type, headers, data, params } = reqOptions; const { url, type, headers, data, params } = reqOptions;
return axios return axios
@ -128,8 +128,3 @@ interface CrudParams {
[key: string]: string | number | { [key: string]: any }; [key: string]: string | number | { [key: string]: any };
} }
interface ResultType {
data?: any;
errorCode?: string;
errorMsg?: string;
}

2
src/web/src/modules/table_list/table_list.model.ts

@ -22,7 +22,7 @@ export class TableModelModel extends Model {
initTableList: () => { initTableList: () => {
if (this.model.selectedConnection) { if (this.model.selectedConnection) {
getTableList(this.model.selectedConnection, this.model.search).then(re => { getTableList(this.model.selectedConnection, this.model.search).then(re => {
this.model.tables = re ? re.data : []; this.model.tables = re ? re : [];
}); });
} else { } else {
this.model.tables = []; this.model.tables = [];

12
src/web/src/modules/table_list/table_list.ts

@ -30,6 +30,9 @@ export class TableList extends BI.Widget {
'selectedConnection || search': () => { 'selectedConnection || search': () => {
this.store.initTableList(); this.store.initTableList();
}, },
tables: (tables: string[]) => {
this.buttonGroup.populate(this.renderTableList());
},
} }
render() { render() {
@ -118,6 +121,15 @@ export class TableList extends BI.Widget {
private renderConnectionList() { private renderConnectionList() {
return this.model.connections.map(item => { return this.model.connections.map(item => {
return {
text: item,
value: item,
};
});
}
private renderTableList() {
return this.model.tables.map(item => {
return { return {
type: ListItem.xtype, type: ListItem.xtype,
text: item, text: item,

Loading…
Cancel
Save