alan
5 years ago
25 changed files with 1666 additions and 987 deletions
@ -0,0 +1,19 @@
|
||||
window.DecCst = { |
||||
Schedule: { |
||||
Parameter: { |
||||
Type: { |
||||
BOOLEAN: "Boolean", |
||||
DATA_SET: "TableColumn", |
||||
DATE: "Date", |
||||
DOUBLE: "Double", |
||||
FORMULA: "Formula", |
||||
INTEGER: "Integer", |
||||
STRING: "String", |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
window.Dec = { |
||||
fineServletURL: '/webroot/decision', |
||||
} |
@ -1,12 +1,13 @@
|
||||
@import "../../node_modules/fineui/src/less/resource/font.less"; |
||||
@import "./lib/font.less"; |
||||
|
||||
.font(refresh-font, @font-refresh); |
||||
.font(redis-refresh-font, @font-redis-refresh); |
||||
.font(input-string-font, @font-input-string); |
||||
.font(input-formula-font, @font-input-formula); |
||||
.font(input-date-font, @font-input-date); |
||||
.font(input-boolean-font, @font-input-boolean); |
||||
.font(input-int-font, @font-input-int); |
||||
.font(input-number-font, @font-input-number); |
||||
.font(site-font, @font-site); |
||||
.font(column-font, @font-column); |
||||
.font(redis-site-font, @font-redis-site); |
||||
.font(redis-column-font, @font-redis-column); |
||||
.font(redis-preview-font, @font-redis-preview); |
@ -0,0 +1,33 @@
|
||||
export const redisParamHeader = [{ |
||||
text: BI.i18nText('Plugin-Redis_Set_Parameter_Name'), |
||||
}, { |
||||
text: BI.i18nText('Plugin-Redis_Set_Parameter_Type'), |
||||
}, { |
||||
text: BI.i18nText('Plugin-Redis_Set_Parameter_Value'), |
||||
}]; |
||||
|
||||
export const redisField = [{ |
||||
text: BI.i18nText('Dec-Basic_String'), |
||||
value: DecCst.Schedule.Parameter.Type.STRING, |
||||
iconCls: 'string-field-font', |
||||
}, { |
||||
text: BI.i18nText('Dec-Basic_Integer'), |
||||
value: DecCst.Schedule.Parameter.Type.INTEGER, |
||||
iconCls: 'number-field-font', |
||||
}, { |
||||
text: BI.i18nText('Dec-Basic_Double'), |
||||
value: DecCst.Schedule.Parameter.Type.DOUBLE, |
||||
iconCls: 'number-field-font', |
||||
}, { |
||||
text: BI.i18nText('Dec-Basic_Date'), |
||||
value: DecCst.Schedule.Parameter.Type.DATE, |
||||
iconCls: 'date-field-font', |
||||
}, { |
||||
text: BI.i18nText('Dec-Basic_Boolean'), |
||||
value: DecCst.Schedule.Parameter.Type.BOOLEAN, |
||||
iconCls: 'string-field-font', |
||||
}, { |
||||
text: BI.i18nText('Dec-Basic_Formula'), |
||||
value: DecCst.Schedule.Parameter.Type.FORMULA, |
||||
iconCls: 'string-field-font', |
||||
}]; |
@ -0,0 +1,46 @@
|
||||
import { model, Model } from './core/core'; |
||||
import { redisParamHeader } from './app.constant'; |
||||
@model() |
||||
export class RedisDatasetModel extends Model { |
||||
static xtype = 'dec.model.dcm.connection.plugin.redis.dataset' |
||||
|
||||
context = ['dataSetName', 'ableSave'] |
||||
|
||||
state() { |
||||
return { |
||||
parameters: [{ name: '123', type: 'String' }] as { |
||||
name: string; |
||||
type: string; |
||||
value: string; |
||||
}[], |
||||
}; |
||||
} |
||||
|
||||
actions = { |
||||
setAbleSave(ableSave: boolean) { |
||||
this.model.ableSave = ableSave; |
||||
}, |
||||
setParameters: (parameters: { |
||||
name: string; |
||||
type: string; |
||||
value: string; |
||||
}[]) => { |
||||
this.model.parameters = parameters; |
||||
}, |
||||
setParamType: (index: number, type: string) => { |
||||
if (this.model.parameters[index].type !== type) { |
||||
this.model.parameters[index].type = type; |
||||
this.model.parameters[index].value = BI.Services.getService('dec.service.data.set').getDefaultValueByType(type); |
||||
this.model.parameters.splice(0, 0); |
||||
} |
||||
}, |
||||
} |
||||
|
||||
computed = { |
||||
paramHeader: () => redisParamHeader.map(item => BI.extend({ |
||||
textAlign: 'left', |
||||
height: 30, |
||||
hgap: 10, |
||||
}, item)), |
||||
} |
||||
} |
@ -0,0 +1,7 @@
|
||||
@import '../less/index.less'; |
||||
|
||||
.param-table { |
||||
.dec-dynamic-date-combo .even-row { |
||||
background-color: @background-color-default; |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
import { model, Model } from '../../core/core'; |
||||
|
||||
@model() |
||||
export class DatabaseIndexModel extends Model { |
||||
static xtype = 'plugin.model.report.redis.components.database_index' |
||||
|
||||
state() { |
||||
return { |
||||
inputValue: '', |
||||
}; |
||||
} |
||||
|
||||
actions = { |
||||
setInpueValue: (value: string) => { |
||||
this.model.inputValue = value; |
||||
}, |
||||
} |
||||
} |
@ -0,0 +1,70 @@
|
||||
import { shortcut, store } from '@core/core'; |
||||
import { TabXtype, TextEditorXtype } from 'ui'; |
||||
import { DatabaseIndexModel } from './database_index.model'; |
||||
|
||||
@shortcut() |
||||
@store(DatabaseIndexModel) |
||||
export class DatabaseIndex extends BI.Widget { |
||||
static xtype = 'plugin.report.redis.components.database_index' |
||||
|
||||
databaseIndexTab: any; |
||||
textEditor: any; |
||||
|
||||
model: DatabaseIndexModel['model'] |
||||
store: DatabaseIndexModel['store'] |
||||
|
||||
props = { |
||||
value: '', |
||||
} |
||||
|
||||
render() { |
||||
const { value } = this.options; |
||||
this.store.setInpueValue(value); |
||||
|
||||
return { |
||||
type: TabXtype, |
||||
single: true, |
||||
showIndex: 'int', |
||||
ref: (_ref: any) => { |
||||
this.databaseIndexTab = _ref; |
||||
}, |
||||
cardCreator: (index: 'int'|'formula') => { |
||||
if (index === 'int') { |
||||
return { |
||||
type: TextEditorXtype, |
||||
warningTitle: '', |
||||
value: this.model.inputValue, |
||||
validationChecker: (v: string) => this.checkInteger(v), |
||||
errorText: BI.i18nText('Plugin-Redis_Check_Integer'), |
||||
listeners: [{ |
||||
eventName: 'EVENT_CHANGE', |
||||
action: () => { |
||||
this.store.setInpueValue(this.textEditor.getValue()); |
||||
}, |
||||
}], |
||||
ref: (_ref: any) => { |
||||
this.textEditor = _ref; |
||||
}, |
||||
}; |
||||
} |
||||
|
||||
return { |
||||
type: TextEditorXtype, |
||||
allowBlank: true, |
||||
value: this.model.inputValue, |
||||
}; |
||||
}, |
||||
}; |
||||
} |
||||
private checkInteger(value: string) { |
||||
return /^[\d]+$/.test(value); |
||||
} |
||||
|
||||
public setSelect(value: string) { |
||||
this.databaseIndexTab.setSelect(value); |
||||
} |
||||
|
||||
public getValue() { |
||||
return this.model.inputValue; |
||||
} |
||||
} |
@ -0,0 +1,4 @@
|
||||
export const fineServletURL = Dec.fineServletURL; |
||||
export const ReqPrefix = `${fineServletURL}/v10/config/connection`; |
||||
export const ImgPrefix = `${fineServletURL}/resources?path=/com/fr/web/resources/dist/images/2x/icon/database/`; |
||||
export const PluginImgPrefix = `${fineServletURL}/resources?path=`; |
@ -0,0 +1,22 @@
|
||||
import { requestGet } from './crud.service'; |
||||
export function getConnectionlist(): Promise<{data?: Connection[]}> { |
||||
return requestGet('/v10/config/connection/list'); |
||||
} |
||||
|
||||
export function getTableList(database: string, pattern = ''): Promise<{data?: string[]}> { |
||||
return requestGet('com.fr.solution.plugin.db.redis.v10/redis/keys', { |
||||
database, |
||||
pattern, |
||||
}); |
||||
} |
||||
|
||||
export interface Connection { |
||||
connectionId: string; |
||||
connectionType: string; |
||||
connectionName: string; |
||||
creator?: string; |
||||
privilegeDetailBeanList?: { |
||||
privilegeType: number; |
||||
privilegeValue: number; |
||||
}[] |
||||
} |
@ -0,0 +1,135 @@
|
||||
import 'es6-promise/auto'; |
||||
import axios, { AxiosResponse, AxiosError } from 'axios'; |
||||
import { fineServletURL } from '../constants/env'; |
||||
const defaultHeaders = { |
||||
'Content-Type': 'application/json', |
||||
'X-Requested-With': 'XMLHttpRequest', |
||||
}; |
||||
|
||||
export function paramsSerializer(params: { [key: string]: any }) { |
||||
return Object.keys(params || {}) |
||||
.map(paramKey => { |
||||
const paramValue = params[paramKey]; |
||||
|
||||
let value = ''; |
||||
|
||||
if (BI.isObject(paramValue)) { |
||||
value = encodeURIComponent(JSON.stringify(paramValue)); |
||||
} else { |
||||
value = paramValue; |
||||
} |
||||
|
||||
return BI.isNull(value) ? '' : `${paramKey}=${value}`; |
||||
}) |
||||
.filter(v => v !== '') |
||||
.join('&'); |
||||
} |
||||
function getCookieByName(name: string):string { |
||||
let value = null; |
||||
const regExpName = new RegExp(name); |
||||
document.cookie.split(';').forEach((item: string) => { |
||||
if (item.match(regExpName)) { |
||||
value = item.split(`${name}=`)[1]; |
||||
|
||||
return false; |
||||
} |
||||
}); |
||||
|
||||
return value; |
||||
} |
||||
|
||||
function checkStatus(response: AxiosResponse) { |
||||
const status = response.status; |
||||
|
||||
const resData = status === 200 |
||||
? typeof response.data === 'string' |
||||
? BI.jsonDecode(response.data) |
||||
: response.data |
||||
: {}; |
||||
|
||||
return resData; |
||||
} |
||||
|
||||
export async function request(reqOptions: CrudReqOpts = {}): Promise<ResultType> { |
||||
const { url, type, headers, data, params } = reqOptions; |
||||
|
||||
return axios |
||||
.request({ |
||||
url, |
||||
baseURL: fineServletURL, |
||||
method: type, |
||||
headers: { |
||||
...defaultHeaders, |
||||
...headers, |
||||
Authorization: `Bearer ${getCookieByName('fine_auth_token')}`, |
||||
'Content-Type': 'application/json;charset=UTF-8', |
||||
}, |
||||
params, |
||||
paramsSerializer, |
||||
data, |
||||
}) |
||||
.then(checkStatus) |
||||
.catch((error: AxiosError) => { |
||||
console.log(error); |
||||
}); |
||||
} |
||||
|
||||
export function requestGet(url: string, params: CrudParams = {}) { |
||||
const timeStamp = new Date().getTime(); |
||||
|
||||
return request({ |
||||
url, |
||||
type: 'GET', |
||||
params: { |
||||
...params, |
||||
_: timeStamp, |
||||
}, |
||||
}); |
||||
} |
||||
|
||||
export function requestPost(url: string, data = {}, params: CrudParams = {}) { |
||||
return request({ |
||||
url, |
||||
type: 'POST', |
||||
data, |
||||
params, |
||||
}); |
||||
} |
||||
|
||||
export function requestDelete(url: string, data = {}) { |
||||
return request({ |
||||
url, |
||||
type: 'DELETE', |
||||
data, |
||||
}); |
||||
} |
||||
|
||||
export function requestPut(url: string, data = {}, params: CrudParams = {}) { |
||||
return request({ |
||||
url, |
||||
type: 'PUT', |
||||
data, |
||||
params, |
||||
}); |
||||
} |
||||
|
||||
interface CrudReqOpts { |
||||
url?: string; |
||||
type?: 'GET' | 'POST' | 'DELETE' | 'PUT'; |
||||
data?: any; |
||||
headers?: { |
||||
[key: string]: string; |
||||
}; |
||||
noProgress?: boolean; |
||||
params?: CrudParams; |
||||
} |
||||
|
||||
interface CrudParams { |
||||
[key: string]: string | number | { [key: string]: any }; |
||||
} |
||||
|
||||
interface ResultType { |
||||
data?: any; |
||||
errorCode?: string; |
||||
errorMsg?: string; |
||||
} |
@ -0,0 +1,38 @@
|
||||
import { model, Model } from '@core/core'; |
||||
import { getConnectionlist, getTableList } from '../crud/crud.request'; |
||||
@model() |
||||
export class TableModelModel extends Model { |
||||
static xtype = 'dec.model.dcm.connection.plugin.redis.table_list'; |
||||
|
||||
state() { |
||||
return { |
||||
connections: [] as string[], |
||||
tables: [] as string[], |
||||
search: '', |
||||
selectedConnection: '', |
||||
}; |
||||
} |
||||
|
||||
actions = { |
||||
initData: () => { |
||||
getConnectionlist().then(re => { |
||||
this.model.connections = re.data.filter(item => item.connectionType === 'Redis').map(item => item.connectionName); |
||||
}); |
||||
}, |
||||
initTableList: () => { |
||||
if (this.model.selectedConnection) { |
||||
getTableList(this.model.selectedConnection, this.model.search).then(re => { |
||||
this.model.tables = re ? re.data : []; |
||||
}); |
||||
} else { |
||||
this.model.tables = []; |
||||
} |
||||
}, |
||||
setSearch(value: string) { |
||||
this.model.search = value; |
||||
}, |
||||
setSelectedConnection(name: string) { |
||||
this.model.selectedConnection = name; |
||||
}, |
||||
} |
||||
} |
Loading…
Reference in new issue