mirror of
https://git.rwth-aachen.de/acs/public/villas/web/
synced 2025-03-09 00:00:01 +01:00
refactor NumberInputWidget to InputWidget
This commit is contained in:
parent
d4f02c2961
commit
7aacc61e3d
5 changed files with 13 additions and 13 deletions
|
@ -37,7 +37,7 @@ describe('edit widget control creator', () => {
|
|||
{ args: { widgetType: 'Box' }, result: { controlNumber: 1, controlTypes: [EditWidgetColorControl] } },
|
||||
{ args: { widgetType: 'Label' }, result: { controlNumber: 3, controlTypes: [EditWidgetTextControl, EditWidgetTextSizeControl, EditWidgetColorControl] } },
|
||||
{ args: { widgetType: 'HTML' }, result: { controlNumber: 1, controlTypes: [EditWidgetHTMLContent] } },
|
||||
{ args: { widgetType: 'NumberInput'}, result: { controlNumber: 3, controlTypes: [EditWidgetTextControl, EditWidgetSimulatorControl, EditWidgetSignalControl] } }
|
||||
{ args: { widgetType: 'Input'}, result: { controlNumber: 3, controlTypes: [EditWidgetTextControl, EditWidgetSimulatorControl, EditWidgetSignalControl] } }
|
||||
];
|
||||
|
||||
runs.forEach( (run) => {
|
||||
|
|
|
@ -162,7 +162,7 @@ export default function createControls(widgetType = null, widget = null, session
|
|||
);
|
||||
break;
|
||||
|
||||
case 'NumberInput':
|
||||
case 'Input':
|
||||
dialogControls.push(
|
||||
<EditWidgetTextControl key={0} widget={widget} controlId={'name'} label={'Text'} placeholder={'Enter text'} validate={id => validateForm(id)} handleChange={e => handleChange(e)} />,
|
||||
<EditWidgetSimulatorControl key={1} widget={widget} validate={(id) => validateForm(id)} simulationModels={simulationModels} handleChange={(e) => valueBoundOnChange(e)} />,
|
||||
|
|
|
@ -108,7 +108,7 @@ class WidgetFactory {
|
|||
widget.simulationModel = defaultSimulationModel;
|
||||
widget.signal = 0;
|
||||
break;
|
||||
case 'NumberInput':
|
||||
case 'Input':
|
||||
widget.minWidth = 200;
|
||||
widget.minHeight = 50;
|
||||
widget.width = 200;
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
import React, { Component } from 'react';
|
||||
import { Form, FormGroup, Col, ControlLabel, FormControl } from 'react-bootstrap';
|
||||
|
||||
class WidgetNumberInput extends Component {
|
||||
|
||||
class WidgetInput extends Component {
|
||||
|
||||
static whichValidationStateIs( condition ) {
|
||||
switch(condition) {
|
||||
case 'ok': return null;
|
||||
|
@ -25,23 +25,23 @@ class WidgetNumberInput extends Component {
|
|||
|
||||
this.state = {
|
||||
value: '',
|
||||
validationState: WidgetNumberInput.whichValidationStateIs('ok')
|
||||
validationState: WidgetInput.whichValidationStateIs('ok')
|
||||
};
|
||||
}
|
||||
|
||||
validateInput(e) {
|
||||
if (e.target.value === '' || e.target.value.endsWith('.')) {
|
||||
this.setState({
|
||||
validationState: WidgetNumberInput.whichValidationStateIs('ok'),
|
||||
validationState: WidgetInput.whichValidationStateIs('ok'),
|
||||
value: e.target.value });
|
||||
} else {
|
||||
var num = Number(e.target.value);
|
||||
if (Number.isNaN(num)) {
|
||||
this.setState({ validationState: WidgetNumberInput.whichValidationStateIs('error'),
|
||||
this.setState({ validationState: WidgetInput.whichValidationStateIs('error'),
|
||||
value: e.target.value });
|
||||
} else {
|
||||
this.setState({
|
||||
validationState: WidgetNumberInput.whichValidationStateIs('ok'),
|
||||
validationState: WidgetInput.whichValidationStateIs('ok'),
|
||||
value: num });
|
||||
}
|
||||
}
|
||||
|
@ -66,4 +66,4 @@ class WidgetNumberInput extends Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default WidgetNumberInput;
|
||||
export default WidgetInput;
|
|
@ -39,7 +39,7 @@ import WidgetLabel from '../components/widget-label';
|
|||
import WidgetPlotTable from '../components/widget-plot-table';
|
||||
import WidgetImage from '../components/widget-image';
|
||||
import WidgetButton from '../components/widget-button';
|
||||
import WidgetNumberInput from '../components/widget-number-input';
|
||||
import WidgetInput from '../components/widget-input';
|
||||
import WidgetSlider from '../components/widget-slider';
|
||||
import WidgetGauge from '../components/widget-gauge';
|
||||
import WidgetBox from '../components/widget-box';
|
||||
|
@ -218,8 +218,8 @@ class Widget extends React.Component {
|
|||
element = <WidgetImage widget={widget} files={this.state.files} token={this.state.sessionToken} />
|
||||
} else if (widget.type === 'Button') {
|
||||
element = <WidgetButton widget={widget} editing={this.props.editing} />
|
||||
} else if (widget.type === 'NumberInput') {
|
||||
element = <WidgetNumberInput widget={widget} editing={this.props.editing} simulationModel={simulationModel} />
|
||||
} else if (widget.type === 'Input') {
|
||||
element = <WidgetInput widget={widget} editing={this.props.editing} simulationModel={simulationModel} />
|
||||
} else if (widget.type === 'Slider') {
|
||||
element = <WidgetSlider widget={widget} editing={this.props.editing} simulationModel={simulationModel} onWidgetChange={(w) => this.props.onWidgetStatusChange(w, this.props.index) } onInputChanged={(value) => this.inputDataChanged(widget, value)} />
|
||||
} else if (widget.type === 'Gauge') {
|
||||
|
|
Loading…
Add table
Reference in a new issue