private static ReactCode DrawSelect(RequestDesign design, int grid) { ReactCode codeGen = new ReactCode(); StringBuilder sbHtml = new StringBuilder(); sbHtml.AppendLine("<Grid item xs={" + grid.ToString() + "}>"); sbHtml.AppendLineFormat("<InputLabel id='{0}'>{1}</InputLabel>", design.ObjectName, design.Level); sbHtml.AppendLineFormat("<Select labelId = '{0}' {1} fullWidth {2}>", design.ObjectName, design.Required ? "required" : "", "onChange={ e=>Set_" + design.ObjectName + "(e.target.value)}"); foreach (var value in design.Values) { sbHtml.AppendLineFormat("<MenuItem value={0}>{1}</MenuItem>", "{'" + value + "'}", value); } sbHtml.AppendLine("</Select>"); sbHtml.AppendLineFormat("<FormHelperText>{0}</FormHelperText>", design.Description); sbHtml.AppendLine("</Grid>"); codeGen.Html = sbHtml.ToString(); codeGen.States.Add(design.ObjectName, string.Format("const [{0}, {1}] = useState('{2}')", design.ObjectName, "Set_" + design.ObjectName, design.Value)); codeGen.Imports.Add("import Select from '@material-ui/core/Select';"); codeGen.Imports.Add("import MenuItem from '@material-ui/core/MenuItem';"); codeGen.Imports.Add("import InputLabel from '@material-ui/core/InputLabel';"); codeGen.Imports.Add("import FormHelperText from '@material-ui/core/FormHelperText';"); return(codeGen); }
private static ReactCode DrawTextBox(RequestDesign design, string type, int grid) { ReactCode codeGen = new ReactCode(); StringBuilder sbHtml = new StringBuilder(); sbHtml.AppendLine("<Grid item xs={" + grid.ToString() + "}>"); sbHtml.AppendLineFormat("<TextField label='{0}' helperText='{1}' type='{2}' {3} {4} fullWidth />", design.Level, design.Description, type, design.Required ? "required" : "", "onInput={ e=>Set_" + design.ObjectName + "(e.target.value)}"); sbHtml.AppendLine("</Grid>"); codeGen.Html = sbHtml.ToString(); codeGen.States.Add(design.ObjectName, string.Format("const [{0}, {1}] = useState('{2}')", design.ObjectName, "Set_" + design.ObjectName, design.Value)); codeGen.Imports.Add("import TextField from '@material-ui/core/TextField';"); return(codeGen); }
private static ReactCode DrawArray(RequestDesign design, int grid) { ReactCode codeGen = new ReactCode(); StringBuilder sbHtml = new StringBuilder(); sbHtml.AppendLine("<Grid item xs={" + grid.ToString() + "}>"); sbHtml.AppendLine("<Grid item xs={12}>"); sbHtml.AppendLine("<Grid item xs={12} className={classes.rightMargin}>"); sbHtml.AppendLineFormat("<TextField label='{0}' helperText='{1}' type='text' {2} {3} fullWidth />", design.Level, design.Description, design.Required ? "required" : "", "onInput={ e=>Set_" + design.ObjectName + "(e.target.value, 0)}"); sbHtml.AppendLine("</Grid>"); sbHtml.AppendLineFormat("<Button variant='contained' className={0} onClick={1}>Add</Button>", "{classes.rightFloat}", "{Add_" + design.ObjectName + "}"); sbHtml.AppendLine("</Grid>"); sbHtml.AppendLine("{" + design.ObjectName + ".map((value, index) => {"); sbHtml.AppendLine("if (index > 0) {"); sbHtml.AppendLine("return ("); sbHtml.AppendLine("<Grid key={`tag-${index}`} item xs={12}>"); sbHtml.AppendLine("<Grid item xs={12} className={classes.rightMargin}>"); sbHtml.AppendLineFormat("<TextField label='{0}' type='text' {1} fullWidth />", design.Level, "onInput={ e=>Set_" + design.ObjectName + "(e.target.value, index)}"); sbHtml.AppendLine("</Grid>"); sbHtml.AppendLineFormat("<Button variant='contained' className={0} onClick={1}>Remove</Button>", "{classes.rightFloat}", "{e=> Remove_" + design.ObjectName + "(index)}"); sbHtml.AppendLine("</Grid>"); sbHtml.AppendLine(")"); sbHtml.AppendLine("}"); sbHtml.AppendLine("})}"); sbHtml.AppendLine("</Grid>"); codeGen.Html = sbHtml.ToString(); codeGen.States.Add(design.ObjectName, string.Format("const [{0}, {1}] = useState(['{2}'])", design.ObjectName, "Set_Array_" + design.ObjectName, design.Value)); StringBuilder sbFunc = new StringBuilder(); //Set Array value function sbFunc.AppendLineFormat("function Set_{0}(val, index)", design.ObjectName); sbFunc.AppendLine("{"); sbFunc.AppendLineFormat("{0}[index]=val;", design.ObjectName); sbFunc.AppendLineFormat("Set_Array_{0}([...{0}]);", design.ObjectName); sbFunc.AppendLine("}"); // Add Array sbFunc.AppendLineFormat("function Add_{0}()", design.ObjectName); sbFunc.AppendLine("{"); sbFunc.AppendLineFormat("Set_Array_{0}([...{0}, '']);", design.ObjectName); sbFunc.AppendLine("}"); //Remove Array sbFunc.AppendLineFormat("function Remove_{0}(index)", design.ObjectName); sbFunc.AppendLine("{"); sbFunc.AppendLineFormat("{0}.splice(index,1);", design.ObjectName); sbFunc.AppendLineFormat("Set_Array_{0}([...{0}]);", design.ObjectName); sbFunc.AppendLine("}"); codeGen.Function.Add(sbFunc.ToString()); codeGen.Imports.Add("import TextField from '@material-ui/core/TextField';"); return(codeGen); }