/** * File: edit-widget-control-creator.js * Author: Ricardo Hernandez-Montoya * Date: 23.05.2017 * * This file is part of VILLASweb. * * VILLASweb is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VILLASweb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VILLASweb. If not, see . **********************************************************************************/ import React from 'react'; import EditWidgetTextControl from './edit-widget-text-control'; import EditWidgetNumberControl from './edit-widget-number-control'; import EditWidgetColorControl from './edit-widget-color-control'; import EditWidgetTimeControl from './edit-widget-time-control'; import EditImageWidgetControl from './edit-widget-image-control'; import EditWidgetSimulationControl from './edit-widget-simulation-control'; import EditWidgetSignalControl from './edit-widget-signal-control'; import EditWidgetSignalsControl from './edit-widget-signals-control'; import EditWidgetOrientation from './edit-widget-orientation'; import EditWidgetAspectControl from './edit-widget-aspect-control'; import EditWidgetTextSizeControl from './edit-widget-text-size-control'; import EditWidgetCheckboxControl from './edit-widget-checkbox-control'; import EditWidgetColorZonesControl from './edit-widget-color-zones-control'; import EditWidgetMinMaxControl from './edit-widget-min-max-control'; import EditWidgetHTMLContent from './edit-widget-html-content'; import EditWidgetParametersControl from './edit-widget-parameters-control'; export default function CreateControls(widgetType = null, widget = null, sessionToken = null, files = null, validateForm, simulationModels, handleChange) { // Use a list to concatenate the controls according to the widget type var DialogControls = []; switch(widgetType) { case 'CustomAction': DialogControls.push( validateForm(id)} handleChange={e => handleChange(e)} />, validateForm(id)} handleChange={e => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} /> ) break; case 'Action': DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} /> ) break; case 'Value': let valueBoundOnChange = (e) => { handleChange([e, {target: {id: 'signal', value: 0}}]); } DialogControls.push( validateForm(id)} handleChange={e => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => valueBoundOnChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> ); break; case 'Lamp': let lampBoundOnChange = (e) => { handleChange([e, {target: {id: 'signal', value: 0}}]); } DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => lampBoundOnChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, validateForm(id)} handleChange={e => handleChange(e)} />, validateForm(id)} handleChange={(e) => handleChange(e)} />, validateForm(id)} handleChange={(e) => handleChange(e)} />, ); break; case 'Plot': let plotBoundOnChange = (e) => { handleChange([e, {target: {id: 'signals', value: []}}]); } DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => plotBoundOnChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> ); break; case 'Table': DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} /> ); break; case 'Image': // Restrict to only image file types (MIME) let imageControlFiles = files == null? [] : files.filter(file => file.type.includes('image')); DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} /> ); break; case 'Gauge': let gaugeBoundOnChange = (e) => { handleChange([e, {target: {id: 'signal', value: ''}}]); } DialogControls.push( validateForm(id)} handleChange={e => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => gaugeBoundOnChange(e) } />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> ); break; case 'PlotTable': let plotTableBoundOnChange = (e) => { handleChange([e, {target: {id: 'preselectedSignals', value: []}}]); } DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => plotTableBoundOnChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} /> ); break; case 'Slider': DialogControls.push( handleChange(e)} validate={id => validateForm(id)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> ); break; case 'Button': let buttonBoundOnChange = (e) => { handleChange([e, {target: {id: 'signal', value: 0}}]); } DialogControls.push( handleChange(e)} validate={id => validateForm(id)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => buttonBoundOnChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} />, handleChange(e)} />, handleChange(e)} />, handleChange(e)} /> ); break; case 'Box': DialogControls.push( validateForm(id)} handleChange={(e) => handleChange(e)} />, handleChange(e)} /> ); break; case 'Label': DialogControls.push( handleChange(e)} validate={id => validateForm(id)} />, handleChange(e)} />, handleChange(e)} /> ); break; case 'HTML': DialogControls.push( handleChange(e)} /> ); break; case 'Topology': // Restrict to only xml files (MIME) let topologyControlFiles = files == null? [] : files.filter( file => file.type.includes('xml')); DialogControls.push( validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} /> ); break; case 'Input': let inputBoundOnChange = (e) => { handleChange([e, {target: {id: 'signal', value: 0}}]); } DialogControls.push( validateForm(id)} handleChange={e => handleChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => inputBoundOnChange(e)} />, validateForm(id)} simulationModels={simulationModels} handleChange={(e) => handleChange(e)} /> ); break; default: console.log('Non-valid widget type: ' + widgetType); } return DialogControls; }