mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
feat: Automatic param parsing
This commit is contained in:
parent
b4d774cde1
commit
fcc625cb0c
3 changed files with 71 additions and 12 deletions
|
|
@ -231,7 +231,7 @@ limitations under the License.
|
|||
class="input-group">
|
||||
<input type="text" class="form-control input-sm"
|
||||
style="font-weight: 400; font-size: 12px; vertical-align:middle; border-radius: 5px;"
|
||||
ng-keypress="keyEventOnDynamicParameter($event)"
|
||||
ng-keydown="saveConfigOnEnter($event)"
|
||||
data-ng-model="config.parameter[config.chart.current][paramSpec.name]" />
|
||||
</div>
|
||||
<div class="btn-group"
|
||||
|
|
@ -253,7 +253,7 @@ limitations under the License.
|
|||
|
||||
<div ng-if="isTextareaWidget(paramSpec)">
|
||||
<textarea class="form-control" rows="3"
|
||||
ng-keypress="keyEventOnDynamicParameter($event)"
|
||||
ng-keydown="saveConfigOnShiftEnter($event)"
|
||||
data-ng-model="config.parameter[config.chart.current][paramSpec.name]"
|
||||
style="font-weight: 400; font-size: 12px;">
|
||||
</textarea>
|
||||
|
|
|
|||
|
|
@ -59,14 +59,57 @@ export function isTextareaWidget(paramSpec) {
|
|||
return paramSpec && paramSpec.widget === Widget.TEXTAREA;
|
||||
}
|
||||
|
||||
export const AxisValueType = {
|
||||
NUMBER: 'number',
|
||||
export const ParameterValueType = {
|
||||
INT: 'int',
|
||||
FLOAT: 'float',
|
||||
JSON: 'json',
|
||||
BOOLEAN: 'boolean',
|
||||
STRING: 'string',
|
||||
JSON: 'JSON',
|
||||
}
|
||||
|
||||
export function parseParameter(paramSpecs, param) {
|
||||
/** copy original params */
|
||||
const parsed = JSON.parse(JSON.stringify(param))
|
||||
|
||||
for (let i = 0 ; i < paramSpecs.length; i++) {
|
||||
const paramSpec = paramSpecs[i]
|
||||
const name = paramSpec.name
|
||||
|
||||
if (paramSpec.valueType === ParameterValueType.INT &&
|
||||
typeof parsed[name] !== 'number') {
|
||||
|
||||
try { parsed[name] = parseInt(parsed[name]); }
|
||||
catch (error) { parsed[name] = paramSpec.defaultValue; }
|
||||
}
|
||||
else if (paramSpec.valueType === ParameterValueType.FLOAT &&
|
||||
typeof parsed[name] !== 'number') {
|
||||
|
||||
try { parsed[name] = parseFloat(parsed[name]); }
|
||||
catch (error) { parsed[name] = paramSpec.defaultValue; }
|
||||
}
|
||||
else if (paramSpec.valueType === ParameterValueType.BOOLEAN) {
|
||||
if (parsed[name] === 'false') {
|
||||
parsed[name] = false;
|
||||
} else if (parsed[name] === 'true') {
|
||||
parsed[name] = false;
|
||||
} else if (typeof parsed[name] !== 'boolean') {
|
||||
parsed[name] = paramSpec.defaultValue;
|
||||
}
|
||||
}
|
||||
else if (paramSpec.valueType === ParameterValueType.JSON) {
|
||||
if (parsed[name] !== null && typeof parsed[name] !== 'object') {
|
||||
try { parsed[name] = JSON.parse(parsed[name]); }
|
||||
catch (error) { parsed[name] = paramSpec.defaultValue; }
|
||||
} else if (parsed[name] === null) {
|
||||
parsed[name] = paramSpec.defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return parsed
|
||||
}
|
||||
|
||||
|
||||
export const Aggregator = {
|
||||
SUM: 'sum',
|
||||
COUNT: 'count',
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
import Transformation from './transformation';
|
||||
|
||||
import {
|
||||
getCurrentChart, getCurrentChartAxis, getCurrentChartAxisSpecs, getCurrentChartParam,
|
||||
getCurrentChart, getCurrentChartAxis, getCurrentChartParam,
|
||||
getCurrentChartAxisSpecs, getCurrentChartParamSpecs,
|
||||
isAggregatorAxis, isGroupAxis, isKeyAxis, isSingleDimensionAxis,
|
||||
clearConfig, initializeConfig,
|
||||
removeDuplicatedColumnsInMultiDimensionAxis, applyMaxAxisCount, getColumnsFromAxis,
|
||||
getTransformer,
|
||||
isInputWidget, isOptionWidget, isCheckboxWidget, isTextareaWidget,
|
||||
isInputWidget, isOptionWidget, isCheckboxWidget, isTextareaWidget, parseParameter,
|
||||
} from './advanced-transformation-util';
|
||||
|
||||
const SETTING_TEMPLATE = 'app/tabledata/advanced-transformation-setting.html';
|
||||
|
|
@ -136,12 +137,23 @@ class AdvancedTransformation extends Transformation {
|
|||
self.emitConfig(configInstance)
|
||||
},
|
||||
|
||||
keyEventOnDynamicParameter: (event) => {
|
||||
if (event.which === 13 || event.keyCode === 13) {
|
||||
/** enter */
|
||||
saveConfigOnEnter: function(event) {
|
||||
const code = event.keyCode || event.which;
|
||||
if (code === 13) {
|
||||
self.emitConfig(configInstance)
|
||||
}
|
||||
},
|
||||
|
||||
saveConfigOnShiftEnter: function(event) {
|
||||
const code = event.keyCode || event.which;
|
||||
|
||||
if (code === 13 && event.shiftKey) {
|
||||
event.stopPropagation(); /** avoid to run paragraph */
|
||||
self.emitConfig(configInstance)
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -152,8 +164,10 @@ class AdvancedTransformation extends Transformation {
|
|||
const conf = this.config
|
||||
const chart = getCurrentChart(conf)
|
||||
const axis = getCurrentChartAxis(conf)
|
||||
const param = getCurrentChartParam(conf)
|
||||
const axisSpecs = getCurrentChartAxisSpecs(conf)
|
||||
const param = getCurrentChartParam(conf)
|
||||
const paramSpecs = getCurrentChartParamSpecs(conf)
|
||||
const parsedParam = parseParameter(paramSpecs, param)
|
||||
|
||||
const columns = getColumnsFromAxis(axisSpecs, axis);
|
||||
const keyColumns = columns.key;
|
||||
|
|
@ -161,12 +175,14 @@ class AdvancedTransformation extends Transformation {
|
|||
const aggregatorColumns = columns.aggregator;
|
||||
const customColumns = columns.custom
|
||||
|
||||
console.log(parsedParam)
|
||||
|
||||
let transformer = getTransformer(conf, tableData.rows, keyColumns, groupColumns, aggregatorColumns)
|
||||
|
||||
return {
|
||||
chart: chart, /** current chart */
|
||||
axis: axis, /** persisted axis */
|
||||
parameter: param, /** persisted parameter */
|
||||
parameter: parsedParam, /** persisted parameter */
|
||||
column: {
|
||||
key: keyColumns, group: groupColumns, aggregator: aggregatorColumns, custom: customColumns,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue