diff --git a/client/public/lib/arduino_compressed.js b/client/public/lib/arduino_compressed.js index 5a5088a4..33ff5393 100644 --- a/client/public/lib/arduino_compressed.js +++ b/client/public/lib/arduino_compressed.js @@ -5,101 +5,1203 @@ Licensed under the Apache License, Version 2.0 (the "License"): http://www.apache.org/licenses/LICENSE-2.0 */ -Blockly.Arduino=new Blockly.Generator("Arduino");Blockly.Arduino.StaticTyping=new Blockly.StaticTyping;Blockly.Arduino.addReservedWords("Blockly,setup,loop,if,else,for,switch,case,while,do,break,continue,return,goto,define,include,HIGH,LOW,INPUT,OUTPUT,INPUT_PULLUP,true,false,integer,constants,floating,point,void,boolean,char,unsigned,byte,int,word,long,float,double,string,String,array,static,volatile,const,sizeof,pinMode,digitalWrite,digitalRead,analogReference,analogRead,analogWrite,tone,noTone,shiftOut,shitIn,pulseIn,millis,micros,delay,delayMicroseconds,min,max,abs,constrain,map,pow,sqrt,sin,cos,tan,randomSeed,random,lowByte,highByte,bitRead,bitWrite,bitSet,bitClear,bit,attachInterrupt,detachInterrupt,interrupts,noInterrupts"); -Blockly.Arduino.ORDER_ATOMIC=0;Blockly.Arduino.ORDER_UNARY_POSTFIX=1;Blockly.Arduino.ORDER_UNARY_PREFIX=2;Blockly.Arduino.ORDER_MULTIPLICATIVE=3;Blockly.Arduino.ORDER_ADDITIVE=4;Blockly.Arduino.ORDER_SHIFT=5;Blockly.Arduino.ORDER_RELATIONAL=6;Blockly.Arduino.ORDER_EQUALITY=7;Blockly.Arduino.ORDER_BITWISE_AND=8;Blockly.Arduino.ORDER_BITWISE_XOR=9;Blockly.Arduino.ORDER_BITWISE_OR=10;Blockly.Arduino.ORDER_LOGICAL_AND=11;Blockly.Arduino.ORDER_LOGICAL_OR=12;Blockly.Arduino.ORDER_CONDITIONAL=13; -Blockly.Arduino.ORDER_ASSIGNMENT=14;Blockly.Arduino.ORDER_NONE=99;Blockly.Arduino.PinTypes={INPUT:"INPUT",OUTPUT:"OUTPUT",PWM:"PWM",SERVO:"SERVO",STEPPER:"STEPPER",SERIAL:"SERIAL",I2C:"I2C/TWI",SPI:"SPI"};Blockly.Arduino.DEF_FUNC_NAME=Blockly.Arduino.FUNCTION_NAME_PLACEHOLDER_; -Blockly.Arduino.init=function(a){Blockly.Arduino.includes_=Object.create(null);Blockly.Arduino.definitions_=Object.create(null);Blockly.Arduino.variables_=Object.create(null);Blockly.Arduino.codeFunctions_=Object.create(null);Blockly.Arduino.userFunctions_=Object.create(null);Blockly.Arduino.functionNames_=Object.create(null);Blockly.Arduino.setups_=Object.create(null);Blockly.Arduino.pins_=Object.create(null);Blockly.Arduino.variableDB_?Blockly.Arduino.variableDB_.reset():Blockly.Arduino.variableDB_= -new Blockly.Names(Blockly.Arduino.RESERVED_WORDS_);var b=Blockly.Arduino.StaticTyping.collectVarsWithTypes(a);Blockly.Arduino.StaticTyping.setProcedureArgs(a,b);for(var c in b)Blockly.Arduino.addVariable(c,Blockly.Arduino.getArduinoType_(b[c])+" "+Blockly.Arduino.variableDB_.getName(c,Blockly.Variables.NAME_TYPE)+";")}; -Blockly.Arduino.finish=function(a){var b=[],c=[],d=[],e=[],f;for(f in Blockly.Arduino.includes_)b.push(Blockly.Arduino.includes_[f]);b.length&&b.push("\n");for(f in Blockly.Arduino.variables_)d.push(Blockly.Arduino.variables_[f]);d.length&&d.push("\n");for(f in Blockly.Arduino.definitions_)c.push(Blockly.Arduino.definitions_[f]);c.length&&c.push("\n");for(f in Blockly.Arduino.codeFunctions_)e.push(Blockly.Arduino.codeFunctions_[f]);for(f in Blockly.Arduino.userFunctions_)e.push(Blockly.Arduino.userFunctions_[f]); -e.length&&e.push("\n");var g=[""],h="";void 0!==Blockly.Arduino.setups_.userSetupCode&&(h="\n"+Blockly.Arduino.setups_.userSetupCode,delete Blockly.Arduino.setups_.userSetupCode);for(f in Blockly.Arduino.setups_)g.push(Blockly.Arduino.setups_[f]);h&&g.push(h);delete Blockly.Arduino.includes_;delete Blockly.Arduino.definitions_;delete Blockly.Arduino.codeFunctions_;delete Blockly.Arduino.userFunctions_;delete Blockly.Arduino.functionNames_;delete Blockly.Arduino.setups_;delete Blockly.Arduino.pins_; -Blockly.Arduino.variableDB_.reset();b=b.join("\n")+d.join("\n")+c.join("\n")+e.join("\n\n");g="void setup() {"+g.join("\n ")+"\n}\n\n";a="void loop() {\n "+a.replace(/\n/g,"\n ")+"\n}";return b+g+a};Blockly.Arduino.addInclude=function(a,b){void 0===Blockly.Arduino.includes_[a]&&(Blockly.Arduino.includes_[a]=b)};Blockly.Arduino.addDeclaration=function(a,b){void 0===Blockly.Arduino.definitions_[a]&&(Blockly.Arduino.definitions_[a]=b)}; -Blockly.Arduino.addVariable=function(a,b,c){var d=!1;if(c||void 0===Blockly.Arduino.variables_[a])Blockly.Arduino.variables_[a]=b,d=!0;return d};Blockly.Arduino.addSetup=function(a,b,c){var d=!1;if(c||void 0===Blockly.Arduino.setups_[a])Blockly.Arduino.setups_[a]=b,d=!0;return d}; -Blockly.Arduino.addFunction=function(a,b){if(void 0===Blockly.Arduino.codeFunctions_[a]){var c=Blockly.Arduino.variableDB_.getDistinctName(a,Blockly.Generator.NAME_TYPE);Blockly.Arduino.codeFunctions_[a]=b.replace(Blockly.Arduino.DEF_FUNC_NAME,c);Blockly.Arduino.functionNames_[a]=c}return Blockly.Arduino.functionNames_[a]}; -Blockly.Arduino.reservePin=function(a,b,c,d){void 0!==Blockly.Arduino.pins_[b]?Blockly.Arduino.pins_[b]!=c?a.setWarningText(Blockly.Msg.ARD_PIN_WARN1.replace("%1",b).replace("%2",d).replace("%3",c).replace("%4",Blockly.Arduino.pins_[b]),d):a.setWarningText(null,d):(Blockly.Arduino.pins_[b]=c,a.setWarningText(null,d))};Blockly.Arduino.scrubNakedValue=function(a){return a+";\n"}; -Blockly.Arduino.quote_=function(a){a=a.replace(/\\/g,"\\\\").replace(/\n/g,"\\\n").replace(/\$/g,"\\$").replace(/'/g,"\\'");return'"'+a+'"'}; -Blockly.Arduino.scrub_=function(a,b){if(null===b)return"";var c="";if(!a.outputConnection||!a.outputConnection.targetConnection){var d=a.getCommentText();d&&(c+=this.prefixLines(d,"// ")+"\n");for(var e=0;ec||255",GTE:">="}[a.getFieldValue("OP")],c="=="==b||"!="==b?Blockly.Arduino.ORDER_EQUALITY:Blockly.Arduino.ORDER_RELATIONAL,d=Blockly.Arduino.valueToCode(a,"A",c)||"0";a=Blockly.Arduino.valueToCode(a,"B",c)||"0";return[d+" "+b+" "+a,c]}; -Blockly.Arduino.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?"&&":"||",c="&&"==b?Blockly.Arduino.ORDER_LOGICAL_AND:Blockly.Arduino.ORDER_LOGICAL_OR,d=Blockly.Arduino.valueToCode(a,"A",c)||"false";a=Blockly.Arduino.valueToCode(a,"B",c)||"false";if(d||a){var e="&&"==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+" "+b+" "+a,c]}; -Blockly.Arduino.logic_negate=function(a){var b=Blockly.Arduino.ORDER_UNARY_PREFIX;return["!"+(Blockly.Arduino.valueToCode(a,"BOOL",b)||"false"),b]};Blockly.Arduino.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"true":"false",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.logic_null=function(a){return["NULL",Blockly.Arduino.ORDER_ATOMIC]}; -Blockly.Arduino.logic_ternary=function(a){var b=Blockly.Arduino.valueToCode(a,"IF",Blockly.Arduino.ORDER_CONDITIONAL)||"false",c=Blockly.Arduino.valueToCode(a,"THEN",Blockly.Arduino.ORDER_CONDITIONAL)||"null";a=Blockly.Arduino.valueToCode(a,"ELSE",Blockly.Arduino.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.Arduino.ORDER_CONDITIONAL]};Blockly.Arduino.loops={};Blockly.Arduino.controls_repeat=function(a){var b=Number(a.getFieldValue("TIMES")),c=Blockly.Arduino.statementToCode(a,"DO"),c=Blockly.Arduino.addLoopTrap(c,a.id);a=Blockly.Arduino.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE);return"for (int "+a+" = 0; "+a+" < "+b+"; "+a+"++) {\n"+c+"}\n"}; -Blockly.Arduino.controls_repeat_ext=function(a){var b=Blockly.Arduino.valueToCode(a,"TIMES",Blockly.Arduino.ORDER_ADDITIVE)||"0",c=Blockly.Arduino.statementToCode(a,"DO"),c=Blockly.Arduino.addLoopTrap(c,a.id);a="";var d=Blockly.Arduino.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.Arduino.variableDB_.getDistinctName("repeat_end",Blockly.Variables.NAME_TYPE),a+="int "+e+" = "+b+";\n");return a+("for (int "+d+" = 0; "+d+" < "+ -e+"; "+d+"++) {\n"+c+"}\n")};Blockly.Arduino.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Arduino.valueToCode(a,"BOOL",b?Blockly.Arduino.ORDER_LOGICAL_OR:Blockly.Arduino.ORDER_NONE)||"false",d=Blockly.Arduino.statementToCode(a,"DO"),d=Blockly.Arduino.addLoopTrap(d,a.id);b&&(c.match(/^\w+$/)||(c="("+c+")"),c="!"+c);return"while ("+c+") {\n"+d+"}\n"}; -Blockly.Arduino.controls_for=function(a){var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Arduino.valueToCode(a,"FROM",Blockly.Arduino.ORDER_ASSIGNMENT)||"0",d=Blockly.Arduino.valueToCode(a,"TO",Blockly.Arduino.ORDER_ASSIGNMENT)||"0",e=Blockly.Arduino.valueToCode(a,"BY",Blockly.Arduino.ORDER_ASSIGNMENT)||"1",f=Blockly.Arduino.statementToCode(a,"DO"),f=Blockly.Arduino.addLoopTrap(f,a.id);if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&Blockly.isNumber(e)){var g= -parseFloat(c)<=parseFloat(d);a="for ("+b+" = "+c+"; "+b+(g?" <= ":" >= ")+d+"; "+b;b=Math.abs(parseFloat(e));a=(1==b?a+(g?"++":"--"):a+((g?" += ":" -= ")+b))+(") {\n"+f+"}\n")}else a="",g=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(g=Blockly.Arduino.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),a+="int "+g+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.Arduino.variableDB_.getDistinctName(b+"_end",Blockly.Variables.NAME_TYPE),a+="int "+c+" = "+d+";\n"),d=Blockly.Arduino.variableDB_.getDistinctName(b+ -"_inc",Blockly.Variables.NAME_TYPE),a+="int "+d+" = ",a=Blockly.isNumber(e)?a+(Math.abs(e)+";\n"):a+("abs("+e+");\n"),a=a+("if ("+g+" > "+c+") {\n")+(Blockly.Arduino.INDENT+d+" = -"+d+";\n"),a+="}\n",a+="for ("+b+" = "+g+";\n "+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+";\n "+b+" += "+d+") {\n"+f+"}\n";return a};Blockly.Arduino.controls_forEach=Blockly.Arduino.noGeneratorCodeLine; -Blockly.Arduino.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};Blockly.Arduino.map={};Blockly.Arduino.base_map=function(a){var b=Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"DMAX",Blockly.Arduino.ORDER_ATOMIC)||"0";return["map("+b+", 0, 1024, 0, "+a+")",Blockly.Arduino.ORDER_NONE]};Blockly.Arduino.math={};Blockly.Arduino.math_number=function(a){a=parseFloat(a.getFieldValue("NUM"));Infinity==a?a="INFINITY":-Infinity==a&&(a="-INFINITY");return[a,Blockly.Arduino.ORDER_ATOMIC]}; -Blockly.Arduino.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Arduino.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Arduino.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Arduino.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Arduino.ORDER_MULTIPLICATIVE],POWER:[null,Blockly.Arduino.ORDER_NONE]}[a.getFieldValue("OP")],c=b[0],b=b[1],d=Blockly.Arduino.valueToCode(a,"A",b)||"0";a=Blockly.Arduino.valueToCode(a,"B",b)||"0";return c?[d+c+a,b]:["Math.pow("+d+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]}; -Blockly.Arduino.math_single=function(a){var b=a.getFieldValue("OP"),c;if("NEG"==b)return a=Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_UNARY_PREFIX)||"0","-"==a[0]&&(a=" "+a),["-"+a,Blockly.Arduino.ORDER_UNARY_PREFIX];a="ABS"==b||"ROUND"==b.substring(0,5)?Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_UNARY_POSTFIX)||"0":"SIN"==b||"COS"==b||"TAN"==b?Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0":Blockly.Arduino.valueToCode(a,"NUM",Blockly.Arduino.ORDER_NONE)|| -"0";switch(b){case "ABS":c="abs("+a+")";break;case "ROOT":c="sqrt("+a+")";break;case "LN":c="log("+a+")";break;case "EXP":c="exp("+a+")";break;case "POW10":c="pow(10,"+a+")";break;case "ROUND":c="round("+a+")";break;case "ROUNDUP":c="ceil("+a+")";break;case "ROUNDDOWN":c="floor("+a+")";break;case "SIN":c="sin("+a+" / 180 * Math.PI)";break;case "COS":c="cos("+a+" / 180 * Math.PI)";break;case "TAN":c="tan("+a+" / 180 * Math.PI)"}if(c)return[c,Blockly.Arduino.ORDER_UNARY_POSTFIX];switch(b){case "LOG10":c= -"log("+a+") / log(10)";break;case "ASIN":c="asin("+a+") / M_PI * 180";break;case "ACOS":c="acos("+a+") / M_PI * 180";break;case "ATAN":c="atan("+a+") / M_PI * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Arduino.ORDER_MULTIPLICATIVE]}; -Blockly.Arduino.math_constant=function(a){return{PI:["M_PI",Blockly.Arduino.ORDER_UNARY_POSTFIX],E:["M_E",Blockly.Arduino.ORDER_UNARY_POSTFIX],GOLDEN_RATIO:["(1 + sqrt(5)) / 2",Blockly.Arduino.ORDER_MULTIPLICATIVE],SQRT2:["M_SQRT2",Blockly.Arduino.ORDER_UNARY_POSTFIX],SQRT1_2:["M_SQRT1_2",Blockly.Arduino.ORDER_UNARY_POSTFIX],INFINITY:["INFINITY",Blockly.Arduino.ORDER_ATOMIC]}[a.getFieldValue("CONSTANT")]}; -Blockly.Arduino.math_number_property=function(a){var b=Blockly.Arduino.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY"),d;if("PRIME"==c)return a=Blockly.Arduino.addFunction("mathIsPrime",["boolean "+Blockly.Arduino.DEF_FUNC_NAME+"(int n) {"," // https://en.wikipedia.org/wiki/Primality_test#Naive_methods\n if (n == 2 || n == 3) {\n return true;\n }\n // False if n is NaN, negative, is 1.\n // And false if n is divisible by 2 or 3.\n if (isnan(n) || (n <= 1) || (n == 1) || (n % 2 == 0) || (n % 3 == 0)) {\n return false;\n }\n // Check all the numbers of form 6k +/- 1, up to sqrt(n).\n for (int x = 6; x <= sqrt(n) + 1; x += 6) {\n if (n % (x - 1) == 0 || n % (x + 1) == 0) {\n return false;\n }\n }\n return true;\n}"].join("\n")), -Blockly.Arduino.addInclude("math","#include "),[a+"("+b+")",Blockly.Arduino.ORDER_UNARY_POSTFIX];switch(c){case "EVEN":d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":Blockly.Arduino.addInclude("math","#include ");d="(floor("+b+") == "+b+")";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Arduino.valueToCode(a,"DIVISOR",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0",d=b+" % "+a+" == 0"}return[d,Blockly.Arduino.ORDER_EQUALITY]}; -Blockly.Arduino.math_change=function(a){var b=Blockly.Arduino.valueToCode(a,"DELTA",Blockly.Arduino.ORDER_ADDITIVE)||"0";return Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+" += "+b+";\n"};Blockly.Arduino.math_round=Blockly.Arduino.math_single;Blockly.Arduino.math_trig=Blockly.Arduino.math_single;Blockly.Arduino.math_on_list=Blockly.Arduino.noGeneratorCodeInline; -Blockly.Arduino.math_modulo=function(a){var b=Blockly.Arduino.valueToCode(a,"DIVIDEND",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Arduino.valueToCode(a,"DIVISOR",Blockly.Arduino.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Arduino.ORDER_MULTIPLICATIVE]}; -Blockly.Arduino.math_constrain=function(a){var b=Blockly.Arduino.valueToCode(a,"VALUE",Blockly.Arduino.ORDER_NONE)||"0",c=Blockly.Arduino.valueToCode(a,"LOW",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"HIGH",Blockly.Arduino.ORDER_NONE)||"0";return["("+b+" < "+c+" ? "+c+" : ( "+b+" > "+a+" ? "+a+" : "+b+"))",Blockly.Arduino.ORDER_UNARY_POSTFIX]}; -Blockly.Arduino.math_random_int=function(a){var b=Blockly.Arduino.valueToCode(a,"FROM",Blockly.Arduino.ORDER_NONE)||"0";a=Blockly.Arduino.valueToCode(a,"TO",Blockly.Arduino.ORDER_NONE)||"0";var c=Blockly.Arduino.variableDB_.getDistinctName("math_random_int",Blockly.Generator.NAME_TYPE);Blockly.Arduino.math_random_int.random_function=c;return[Blockly.Arduino.addFunction("mathRandomInt",["int "+Blockly.Arduino.DEF_FUNC_NAME+"(int min, int max) {"," if (min > max) {\n // Swap min and max to ensure min is smaller.\n int temp = min;\n min = max;\n max = temp;\n }\n return min + (rand() % (max - min + 1));\n}"].join("\n"))+ -"("+b+", "+a+")",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.math_random_float=function(a){return["(rand() / RAND_MAX)",Blockly.Arduino.ORDER_UNARY_POSTFIX]};Blockly.Arduino.procedures={}; -Blockly.Arduino.procedures_defreturn=function(a){var b=Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=Blockly.Arduino.statementToCode(a,"STACK");Blockly.Arduino.STATEMENT_PREFIX&&(c=Blockly.Arduino.prefixLines(Blockly.Arduino.STATEMENT_PREFIX.replace(/%1/g,"'"+a.id+"'"),Blockly.Arduino.INDENT)+c);Blockly.Arduino.INFINITE_LOOP_TRAP&&(c=Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g,"'"+a.id+"'")+c);var d=Blockly.Arduino.valueToCode(a,"RETURN",Blockly.Arduino.ORDER_NONE)|| -"";d&&(d=" return "+d+";\n");for(var e=[],f=0;f");Blockly.Arduino.addDeclaration("servo_"+b,"Servo "+d+";");Blockly.Arduino.addSetup("servo_"+b,d+".attach("+b+");",!0);return d+".write("+c+");\n"}; -Blockly.Arduino.servo_read=function(a){var b=a.getFieldValue("SERVO_PIN"),c="myServo"+b;Blockly.Arduino.reservePin(a,b,Blockly.Arduino.PinTypes.SERVO,"Servo Read");Blockly.Arduino.addInclude("servo","#include ");Blockly.Arduino.addDeclaration("servo_"+b,"Servo "+c+";");Blockly.Arduino.addSetup("servo_"+b,c+".attach("+b+");",!0);return[c+".read()",Blockly.Arduino.ORDER_ATOMIC]};Blockly.Arduino.spi={}; -Blockly.Arduino.spi_setup=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SHIFT_ORDER"),d=a.getFieldValue("SPI_CLOCK_DIVIDE");a=a.getFieldValue("SPI_MODE");Blockly.Arduino.addInclude("spi","#include ");Blockly.Arduino.addSetup("spi_order",b+".setBitOrder("+c+");",!0);Blockly.Arduino.addSetup("spi_mode",b+".setDataMode("+a+");",!0);Blockly.Arduino.addSetup("spi_div",b+".setClockDivider("+d+");",!0);Blockly.Arduino.addSetup("spi_begin",b+".begin();",!0);return""}; -Blockly.Arduino.spi_transfer=function(a){var b=a.getFieldValue("SPI_ID"),c=a.getFieldValue("SPI_SS"),d=Blockly.Arduino.valueToCode(a,"SPI_DATA",Blockly.Arduino.ORDER_ATOMIC)||"0";Blockly.Arduino.addInclude("spi","#include ");Blockly.Arduino.addSetup("spi_begin",b+".begin();",!1);for(var e=Blockly.Arduino.Boards.selected.spiPins[b],f=0;f");Blockly.Arduino.addDeclaration(c,e);Blockly.Arduino.addSetup(c,c+".setSpeed("+f+");",!0);return""}; -Blockly.Arduino.stepper_step=function(a){var b="stepper_"+a.getFieldValue("STEPPER_NAME");a=Blockly.Arduino.valueToCode(a,"STEPPER_STEPS",Blockly.Arduino.ORDER_ATOMIC)||"0";return b+".step("+a+");\n"};Blockly.Arduino.text={};Blockly.Arduino.text=function(a){return[Blockly.Arduino.quote_(a.getFieldValue("TEXT")),Blockly.Arduino.ORDER_ATOMIC]}; -Blockly.Arduino.text_join=function(a){var b;if(0==a.itemCount_)return['""',Blockly.Arduino.ORDER_ATOMIC];if(1==a.itemCount_)return["String("+(Blockly.Arduino.valueToCode(a,"ADD0",Blockly.Arduino.ORDER_UNARY_POSTFIX)||'""')+")",Blockly.Arduino.ORDER_UNARY_POSTFIX];var c;b=[];for(var d=0;d c || 255 < c ? a.setWarningText("The analogue value set must be between 0 and 255", "pwm_value") : a.setWarningText(null, "pwm_value"); + return "analogWrite(" + b + ", " + c + ");\n" +}; +Blockly.Arduino.io_analogread = function(a) { + var b = a.getFieldValue("PIN"); + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.INPUT, "Analogue Read"); + Blockly.Arduino.addSetup("io_" + b, "pinMode(" + b + ", INPUT);", !1); + return ["analogRead(" + b + ")", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.io_highlow = function(a) { + return [a.getFieldValue("STATE"), Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.io_pulsein = function(a) { + var b = a.getFieldValue("PULSEPIN"), + c = Blockly.Arduino.valueToCode(a, "PULSETYPE", Blockly.Arduino.ORDER_ATOMIC); + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.INPUT, "Pulse Pin"); + Blockly.Arduino.addSetup("io_" + b, "pinMode(" + b + ", INPUT);\n", !1); + return ["pulseIn(" + b + ", " + c + ")", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.io_pulsetimeout = function(a) { + var b = a.getFieldValue("PULSEPIN"), + c = Blockly.Arduino.valueToCode(a, "PULSETYPE", Blockly.Arduino.ORDER_ATOMIC), + d = Blockly.Arduino.valueToCode(a, "TIMEOUT", Blockly.Arduino.ORDER_ATOMIC); + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.INPUT, "Pulse Pin"); + Blockly.Arduino.addSetup("io_" + b, "pinMode(" + b + ", INPUT);\n", !1); + return ["pulseIn(" + b + ", " + c + ", " + d + ")", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.lists = {}; +Blockly.Arduino.lists_create_empty = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_create_with = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_repeat = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_length = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_isEmpty = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_indexOf = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_getIndex = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.lists_setIndex = Blockly.Arduino.noGeneratorCodeLine; +Blockly.Arduino.logic = {}; +Blockly.Arduino.controls_if = function(a) { + for (var b = 0, c = Blockly.Arduino.valueToCode(a, "IF" + b, Blockly.Arduino.ORDER_NONE) || "false", d = Blockly.Arduino.statementToCode(a, "DO" + b), e = "if (" + c + ") {\n" + d + "}", b = 1; b <= a.elseifCount_; b++) c = Blockly.Arduino.valueToCode(a, "IF" + b, Blockly.Arduino.ORDER_NONE) || "false", d = Blockly.Arduino.statementToCode(a, "DO" + b), e += " else if (" + c + ") {\n" + d + "}"; + a.elseCount_ && (d = Blockly.Arduino.statementToCode(a, "ELSE"), e += " else {\n" + d + "}"); + return e + "\n" +}; +Blockly.Arduino.logic_compare = function(a) { + var b = { + EQ: "==", + NEQ: "!=", + LT: "<", + LTE: "<=", + GT: ">", + GTE: ">=" + } [a.getFieldValue("OP")], + c = "==" == b || "!=" == b ? Blockly.Arduino.ORDER_EQUALITY : Blockly.Arduino.ORDER_RELATIONAL, + d = Blockly.Arduino.valueToCode(a, "A", c) || "0"; + a = Blockly.Arduino.valueToCode(a, "B", c) || "0"; + return [d + " " + b + " " + a, c] +}; +Blockly.Arduino.logic_operation = function(a) { + var b = "AND" == a.getFieldValue("OP") ? "&&" : "||", + c = "&&" == b ? Blockly.Arduino.ORDER_LOGICAL_AND : Blockly.Arduino.ORDER_LOGICAL_OR, + d = Blockly.Arduino.valueToCode(a, "A", c) || "false"; + a = Blockly.Arduino.valueToCode(a, "B", c) || "false"; + if (d || a) { + var e = "&&" == b ? "true" : "false"; + d || (d = e); + a || (a = e) + } else a = d = "false"; + return [d + " " + b + " " + a, c] +}; +Blockly.Arduino.logic_negate = function(a) { + var b = Blockly.Arduino.ORDER_UNARY_PREFIX; + return ["!" + (Blockly.Arduino.valueToCode(a, "BOOL", b) || "false"), b] +}; +Blockly.Arduino.logic_boolean = function(a) { + return ["TRUE" == a.getFieldValue("BOOL") ? "true" : "false", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.logic_null = function(a) { + return ["NULL", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.logic_ternary = function(a) { + var b = Blockly.Arduino.valueToCode(a, "IF", Blockly.Arduino.ORDER_CONDITIONAL) || "false", + c = Blockly.Arduino.valueToCode(a, "THEN", Blockly.Arduino.ORDER_CONDITIONAL) || "null"; + a = Blockly.Arduino.valueToCode(a, "ELSE", Blockly.Arduino.ORDER_CONDITIONAL) || "null"; + return [b + " ? " + c + " : " + a, Blockly.Arduino.ORDER_CONDITIONAL] +}; +Blockly.Arduino.loops = {}; +Blockly.Arduino.controls_repeat = function(a) { + var b = Number(a.getFieldValue("TIMES")), + c = Blockly.Arduino.statementToCode(a, "DO"), + c = Blockly.Arduino.addLoopTrap(c, a.id); + a = Blockly.Arduino.variableDB_.getDistinctName("count", Blockly.Variables.NAME_TYPE); + return "for (int " + a + " = 0; " + a + " < " + b + "; " + a + "++) {\n" + c + "}\n" +}; +Blockly.Arduino.controls_repeat_ext = function(a) { + var b = Blockly.Arduino.valueToCode(a, "TIMES", Blockly.Arduino.ORDER_ADDITIVE) || "0", + c = Blockly.Arduino.statementToCode(a, "DO"), + c = Blockly.Arduino.addLoopTrap(c, a.id); + a = ""; + var d = Blockly.Arduino.variableDB_.getDistinctName("count", Blockly.Variables.NAME_TYPE), + e = b; + b.match(/^\w+$/) || Blockly.isNumber(b) || (e = Blockly.Arduino.variableDB_.getDistinctName("repeat_end", Blockly.Variables.NAME_TYPE), a += "int " + e + " = " + b + ";\n"); + return a + ("for (int " + d + " = 0; " + d + " < " + + e + "; " + d + "++) {\n" + c + "}\n") +}; +Blockly.Arduino.controls_whileUntil = function(a) { + var b = "UNTIL" == a.getFieldValue("MODE"), + c = Blockly.Arduino.valueToCode(a, "BOOL", b ? Blockly.Arduino.ORDER_LOGICAL_OR : Blockly.Arduino.ORDER_NONE) || "false", + d = Blockly.Arduino.statementToCode(a, "DO"), + d = Blockly.Arduino.addLoopTrap(d, a.id); + b && (c.match(/^\w+$/) || (c = "(" + c + ")"), c = "!" + c); + return "while (" + c + ") {\n" + d + "}\n" +}; +Blockly.Arduino.controls_for = function(a) { + var b = Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE), + c = Blockly.Arduino.valueToCode(a, "FROM", Blockly.Arduino.ORDER_ASSIGNMENT) || "0", + d = Blockly.Arduino.valueToCode(a, "TO", Blockly.Arduino.ORDER_ASSIGNMENT) || "0", + e = Blockly.Arduino.valueToCode(a, "BY", Blockly.Arduino.ORDER_ASSIGNMENT) || "1", + f = Blockly.Arduino.statementToCode(a, "DO"), + f = Blockly.Arduino.addLoopTrap(f, a.id); + if (Blockly.isNumber(c) && Blockly.isNumber(d) && Blockly.isNumber(e)) { + var g = + parseFloat(c) <= parseFloat(d); + a = "for (" + b + " = " + c + "; " + b + (g ? " <= " : " >= ") + d + "; " + b; + b = Math.abs(parseFloat(e)); + a = (1 == b ? a + (g ? "++" : "--") : a + ((g ? " += " : " -= ") + b)) + (") {\n" + f + "}\n") + } else a = "", g = c, c.match(/^\w+$/) || Blockly.isNumber(c) || (g = Blockly.Arduino.variableDB_.getDistinctName(b + "_start", Blockly.Variables.NAME_TYPE), a += "int " + g + " = " + c + ";\n"), c = d, d.match(/^\w+$/) || Blockly.isNumber(d) || (c = Blockly.Arduino.variableDB_.getDistinctName(b + "_end", Blockly.Variables.NAME_TYPE), a += "int " + c + " = " + d + ";\n"), d = Blockly.Arduino.variableDB_.getDistinctName(b + + "_inc", Blockly.Variables.NAME_TYPE), a += "int " + d + " = ", a = Blockly.isNumber(e) ? a + (Math.abs(e) + ";\n") : a + ("abs(" + e + ");\n"), a = a + ("if (" + g + " > " + c + ") {\n") + (Blockly.Arduino.INDENT + d + " = -" + d + ";\n"), a += "}\n", a += "for (" + b + " = " + g + ";\n " + d + " >= 0 ? " + b + " <= " + c + " : " + b + " >= " + c + ";\n " + b + " += " + d + ") {\n" + f + "}\n"; + return a +}; + +Blockly.Arduino.controls_forEach = Blockly.Arduino.noGeneratorCodeLine; +Blockly.Arduino.controls_flow_statements = function(a) { + switch (a.getFieldValue("FLOW")) { + case "BREAK": + return "break;\n"; + case "CONTINUE": + return "continue;\n" + } + throw "Unknown flow statement."; +}; +Blockly.Arduino.map = {}; +Blockly.Arduino.base_map = function(a) { + var b = Blockly.Arduino.valueToCode(a, "NUM", Blockly.Arduino.ORDER_NONE) || "0"; + a = Blockly.Arduino.valueToCode(a, "DMAX", Blockly.Arduino.ORDER_ATOMIC) || "0"; + return ["map(" + b + ", 0, 1024, 0, " + a + ")", Blockly.Arduino.ORDER_NONE] +}; +Blockly.Arduino.math = {}; +Blockly.Arduino.math_number = function(a) { + a = parseFloat(a.getFieldValue("NUM")); + Infinity == a ? a = "INFINITY" : -Infinity == a && (a = "-INFINITY"); + return [a, Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.math_arithmetic = function(a) { + var b = { + ADD: [" + ", Blockly.Arduino.ORDER_ADDITIVE], + MINUS: [" - ", Blockly.Arduino.ORDER_ADDITIVE], + MULTIPLY: [" * ", Blockly.Arduino.ORDER_MULTIPLICATIVE], + DIVIDE: [" / ", Blockly.Arduino.ORDER_MULTIPLICATIVE], + POWER: [null, Blockly.Arduino.ORDER_NONE] + } [a.getFieldValue("OP")], + c = b[0], + b = b[1], + d = Blockly.Arduino.valueToCode(a, "A", b) || "0"; + a = Blockly.Arduino.valueToCode(a, "B", b) || "0"; + return c ? [d + c + a, b] : ["Math.pow(" + d + ", " + a + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.math_single = function(a) { + var b = a.getFieldValue("OP"), + c; + if ("NEG" == b) return a = Blockly.Arduino.valueToCode(a, "NUM", Blockly.Arduino.ORDER_UNARY_PREFIX) || "0", "-" == a[0] && (a = " " + a), ["-" + a, Blockly.Arduino.ORDER_UNARY_PREFIX]; + a = "ABS" == b || "ROUND" == b.substring(0, 5) ? Blockly.Arduino.valueToCode(a, "NUM", Blockly.Arduino.ORDER_UNARY_POSTFIX) || "0" : "SIN" == b || "COS" == b || "TAN" == b ? Blockly.Arduino.valueToCode(a, "NUM", Blockly.Arduino.ORDER_MULTIPLICATIVE) || "0" : Blockly.Arduino.valueToCode(a, "NUM", Blockly.Arduino.ORDER_NONE) || + "0"; + switch (b) { + case "ABS": + c = "abs(" + a + ")"; + break; + case "ROOT": + c = "sqrt(" + a + ")"; + break; + case "LN": + c = "log(" + a + ")"; + break; + case "EXP": + c = "exp(" + a + ")"; + break; + case "POW10": + c = "pow(10," + a + ")"; + break; + case "ROUND": + c = "round(" + a + ")"; + break; + case "ROUNDUP": + c = "ceil(" + a + ")"; + break; + case "ROUNDDOWN": + c = "floor(" + a + ")"; + break; + case "SIN": + c = "sin(" + a + " / 180 * Math.PI)"; + break; + case "COS": + c = "cos(" + a + " / 180 * Math.PI)"; + break; + case "TAN": + c = "tan(" + a + " / 180 * Math.PI)" + } + if (c) return [c, Blockly.Arduino.ORDER_UNARY_POSTFIX]; + switch (b) { + case "LOG10": + c = + "log(" + a + ") / log(10)"; + break; + case "ASIN": + c = "asin(" + a + ") / M_PI * 180"; + break; + case "ACOS": + c = "acos(" + a + ") / M_PI * 180"; + break; + case "ATAN": + c = "atan(" + a + ") / M_PI * 180"; + break; + default: + throw "Unknown math operator: " + b; + } + return [c, Blockly.Arduino.ORDER_MULTIPLICATIVE] +}; +Blockly.Arduino.math_constant = function(a) { + return { + PI: ["M_PI", Blockly.Arduino.ORDER_UNARY_POSTFIX], + E: ["M_E", Blockly.Arduino.ORDER_UNARY_POSTFIX], + GOLDEN_RATIO: ["(1 + sqrt(5)) / 2", Blockly.Arduino.ORDER_MULTIPLICATIVE], + SQRT2: ["M_SQRT2", Blockly.Arduino.ORDER_UNARY_POSTFIX], + SQRT1_2: ["M_SQRT1_2", Blockly.Arduino.ORDER_UNARY_POSTFIX], + INFINITY: ["INFINITY", Blockly.Arduino.ORDER_ATOMIC] + } [a.getFieldValue("CONSTANT")] +}; +Blockly.Arduino.math_number_property = function(a) { + var b = Blockly.Arduino.valueToCode(a, "NUMBER_TO_CHECK", Blockly.Arduino.ORDER_MULTIPLICATIVE) || "0", + c = a.getFieldValue("PROPERTY"), + d; + if ("PRIME" == c) return a = Blockly.Arduino.addFunction("mathIsPrime", ["boolean " + Blockly.Arduino.DEF_FUNC_NAME + "(int n) {", " // https://en.wikipedia.org/wiki/Primality_test#Naive_methods\n if (n == 2 || n == 3) {\n return true;\n }\n // False if n is NaN, negative, is 1.\n // And false if n is divisible by 2 or 3.\n if (isnan(n) || (n <= 1) || (n == 1) || (n % 2 == 0) || (n % 3 == 0)) {\n return false;\n }\n // Check all the numbers of form 6k +/- 1, up to sqrt(n).\n for (int x = 6; x <= sqrt(n) + 1; x += 6) {\n if (n % (x - 1) == 0 || n % (x + 1) == 0) {\n return false;\n }\n }\n return true;\n}"].join("\n")), + Blockly.Arduino.addInclude("math", "#include "), [a + "(" + b + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX]; + switch (c) { + case "EVEN": + d = b + " % 2 == 0"; + break; + case "ODD": + d = b + " % 2 == 1"; + break; + case "WHOLE": + Blockly.Arduino.addInclude("math", "#include "); + d = "(floor(" + b + ") == " + b + ")"; + break; + case "POSITIVE": + d = b + " > 0"; + break; + case "NEGATIVE": + d = b + " < 0"; + break; + case "DIVISIBLE_BY": + a = Blockly.Arduino.valueToCode(a, "DIVISOR", Blockly.Arduino.ORDER_MULTIPLICATIVE) || "0", d = b + " % " + a + " == 0" + } + return [d, Blockly.Arduino.ORDER_EQUALITY] +}; +Blockly.Arduino.math_change = function(a) { + var b = Blockly.Arduino.valueToCode(a, "DELTA", Blockly.Arduino.ORDER_ADDITIVE) || "0"; + return Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE) + " += " + b + ";\n" +}; +Blockly.Arduino.math_round = Blockly.Arduino.math_single; +Blockly.Arduino.math_trig = Blockly.Arduino.math_single; +Blockly.Arduino.math_on_list = Blockly.Arduino.noGeneratorCodeInline; +Blockly.Arduino.math_modulo = function(a) { + var b = Blockly.Arduino.valueToCode(a, "DIVIDEND", Blockly.Arduino.ORDER_MULTIPLICATIVE) || "0"; + a = Blockly.Arduino.valueToCode(a, "DIVISOR", Blockly.Arduino.ORDER_MULTIPLICATIVE) || "0"; + return [b + " % " + a, Blockly.Arduino.ORDER_MULTIPLICATIVE] +}; +Blockly.Arduino.math_constrain = function(a) { + var b = Blockly.Arduino.valueToCode(a, "VALUE", Blockly.Arduino.ORDER_NONE) || "0", + c = Blockly.Arduino.valueToCode(a, "LOW", Blockly.Arduino.ORDER_NONE) || "0"; + a = Blockly.Arduino.valueToCode(a, "HIGH", Blockly.Arduino.ORDER_NONE) || "0"; + return ["(" + b + " < " + c + " ? " + c + " : ( " + b + " > " + a + " ? " + a + " : " + b + "))", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.math_random_int = function(a) { + var b = Blockly.Arduino.valueToCode(a, "FROM", Blockly.Arduino.ORDER_NONE) || "0"; + a = Blockly.Arduino.valueToCode(a, "TO", Blockly.Arduino.ORDER_NONE) || "0"; + var c = Blockly.Arduino.variableDB_.getDistinctName("math_random_int", Blockly.Generator.NAME_TYPE); + Blockly.Arduino.math_random_int.random_function = c; + return [Blockly.Arduino.addFunction("mathRandomInt", ["int " + Blockly.Arduino.DEF_FUNC_NAME + "(int min, int max) {", " if (min > max) {\n // Swap min and max to ensure min is smaller.\n int temp = min;\n min = max;\n max = temp;\n }\n return min + (rand() % (max - min + 1));\n}"].join("\n")) + + "(" + b + ", " + a + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX + ] +}; +Blockly.Arduino.math_random_float = function(a) { + return ["(rand() / RAND_MAX)", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.procedures = {}; +Blockly.Arduino.procedures_defreturn = function(a) { + var b = Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE), + c = Blockly.Arduino.statementToCode(a, "STACK"); + Blockly.Arduino.STATEMENT_PREFIX && (c = Blockly.Arduino.prefixLines(Blockly.Arduino.STATEMENT_PREFIX.replace(/%1/g, "'" + a.id + "'"), Blockly.Arduino.INDENT) + c); + Blockly.Arduino.INFINITE_LOOP_TRAP && (c = Blockly.Arduino.INFINITE_LOOP_TRAP.replace(/%1/g, "'" + a.id + "'") + c); + var d = Blockly.Arduino.valueToCode(a, "RETURN", Blockly.Arduino.ORDER_NONE) || + ""; + d && (d = " return " + d + ";\n"); + for (var e = [], f = 0; f < a.arguments_.length; f++) e[f] = Blockly.Arduino.getArduinoType_(a.getArgType(a.arguments_[f])) + " " + Blockly.Arduino.variableDB_.getName(a.arguments_[f], Blockly.Variables.NAME_TYPE); + f = Blockly.Types.NULL; + a.getReturnType && (f = a.getReturnType()); + f = Blockly.Arduino.getArduinoType_(f); + c = f + " " + b + "(" + e.join(", ") + ") {\n" + c + d + "}"; + c = Blockly.Arduino.scrub_(a, c); + Blockly.Arduino.userFunctions_[b] = c; + return null +}; +Blockly.Arduino.procedures_defnoreturn = Blockly.Arduino.procedures_defreturn; +Blockly.Arduino.procedures_callreturn = function(a) { + for (var b = Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE), c = [], d = 0; d < a.arguments_.length; d++) c[d] = Blockly.Arduino.valueToCode(a, "ARG" + d, Blockly.Arduino.ORDER_NONE) || "null"; + return [b + "(" + c.join(", ") + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.procedures_callnoreturn = function(a) { + for (var b = Blockly.Arduino.variableDB_.getName(a.getFieldValue("NAME"), Blockly.Procedures.NAME_TYPE), c = [], d = 0; d < a.arguments_.length; d++) c[d] = Blockly.Arduino.valueToCode(a, "ARG" + d, Blockly.Arduino.ORDER_NONE) || "null"; + return b + "(" + c.join(", ") + ");\n" +}; +Blockly.Arduino.procedures_ifreturn = function(a) { + var b = "if (" + (Blockly.Arduino.valueToCode(a, "CONDITION", Blockly.Arduino.ORDER_NONE) || "false") + ") {\n"; + a.hasReturnValue_ ? (a = Blockly.Arduino.valueToCode(a, "VALUE", Blockly.Arduino.ORDER_NONE) || "null", b += " return " + a + ";\n") : b += " return;\n"; + return b + "}\n" +}; +Blockly.Arduino.arduino_functions = function(a) { + var b = Blockly.Arduino.statementToCode(a, "SETUP_FUNC"); + b && Blockly.Arduino.addSetup("userSetupCode", b, !0); + a = a.getInputTargetBlock("LOOP_FUNC"); + b = Blockly.Arduino.blockToCode(a); + if (!goog.isString(b)) throw 'Expecting code from statement block "' + a.type + '".'; + return b +}; +Blockly.Arduino.serial = {}; +Blockly.Arduino.serial_print = function(a) { + for (var b = a.getFieldValue("SERIAL_ID"), c = Blockly.Arduino.valueToCode(a, "CONTENT", Blockly.Arduino.ORDER_ATOMIC) || "0", d = "TRUE" == a.getFieldValue("NEW_LINE"), e = Blockly.Arduino.Boards.selected.serialPins[b], f = 0; f < e.length; f++) Blockly.Arduino.reservePin(a, e[f][1], Blockly.Arduino.PinTypes.SERIAL, "SERIAL " + e[f][0]); + return d ? b + ".println(" + c + ");\n" : b + ".print(" + c + ");\n" +}; +Blockly.Arduino.serial_setup = function(a) { + var b = a.getFieldValue("SERIAL_ID"); + a = a.getFieldValue("SPEED"); + Blockly.Arduino.addSetup("serial_" + b, b + ".begin(" + a + ");", !0); + return "" +}; +Blockly.Arduino.servo = {}; +Blockly.Arduino.servo_write = function(a) { + var b = a.getFieldValue("SERVO_PIN"), + c = Blockly.Arduino.valueToCode(a, "SERVO_ANGLE", Blockly.Arduino.ORDER_ATOMIC) || "90", + d = "myServo" + b; + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.SERVO, "Servo Write"); + Blockly.Arduino.addInclude("servo", "#include "); + Blockly.Arduino.addDeclaration("servo_" + b, "Servo " + d + ";"); + Blockly.Arduino.addSetup("servo_" + b, d + ".attach(" + b + ");", !0); + return d + ".write(" + c + ");\n" +}; +Blockly.Arduino.servo_read = function(a) { + var b = a.getFieldValue("SERVO_PIN"), + c = "myServo" + b; + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.SERVO, "Servo Read"); + Blockly.Arduino.addInclude("servo", "#include "); + Blockly.Arduino.addDeclaration("servo_" + b, "Servo " + c + ";"); + Blockly.Arduino.addSetup("servo_" + b, c + ".attach(" + b + ");", !0); + return [c + ".read()", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.spi = {}; +Blockly.Arduino.spi_setup = function(a) { + var b = a.getFieldValue("SPI_ID"), + c = a.getFieldValue("SPI_SHIFT_ORDER"), + d = a.getFieldValue("SPI_CLOCK_DIVIDE"); + a = a.getFieldValue("SPI_MODE"); + Blockly.Arduino.addInclude("spi", "#include "); + Blockly.Arduino.addSetup("spi_order", b + ".setBitOrder(" + c + ");", !0); + Blockly.Arduino.addSetup("spi_mode", b + ".setDataMode(" + a + ");", !0); + Blockly.Arduino.addSetup("spi_div", b + ".setClockDivider(" + d + ");", !0); + Blockly.Arduino.addSetup("spi_begin", b + ".begin();", !0); + return "" +}; +Blockly.Arduino.spi_transfer = function(a) { + var b = a.getFieldValue("SPI_ID"), + c = a.getFieldValue("SPI_SS"), + d = Blockly.Arduino.valueToCode(a, "SPI_DATA", Blockly.Arduino.ORDER_ATOMIC) || "0"; + Blockly.Arduino.addInclude("spi", "#include "); + Blockly.Arduino.addSetup("spi_begin", b + ".begin();", !1); + for (var e = Blockly.Arduino.Boards.selected.spiPins[b], f = 0; f < e.length; f++) Blockly.Arduino.reservePin(a, e[f][1], Blockly.Arduino.PinTypes.SPI, "SPI " + e[f][0]); + "none" !== c && (Blockly.Arduino.reservePin(a, c, Blockly.Arduino.PinTypes.OUTPUT, + "SPI Slave pin"), Blockly.Arduino.addSetup("io_" + c, "pinMode(" + c + ", OUTPUT);", !1)); + a = []; + "none" !== c && a.push("digitalWrite(" + c + ", HIGH);"); + a.push(b + ".transfer(" + d + ");"); + "none" !== c && a.push("digitalWrite(" + c + ", LOW);"); + return a.join("\n") + "\n" +}; +Blockly.Arduino.spi_transfer_return = function(a) { + var b = a.getFieldValue("SPI_ID"), + c = a.getFieldValue("SPI_SS"), + d = Blockly.Arduino.valueToCode(a, "SPI_DATA", Blockly.Arduino.ORDER_ATOMIC) || "0"; + Blockly.Arduino.spi_transfer(a); + return ["none" === c ? b + ".transfer(" + d + ")" : Blockly.Arduino.addFunction("spiReturnSlave" + c, ["int " + Blockly.Arduino.DEF_FUNC_NAME + "() {", " int spiReturn = 0;", " digitalWrite(" + c + ", HIGH);", " spiReturn = " + b + ".transfer(" + d + ");", " digitalWrite(" + c + ", LOW);", " return spiReturn;\n}"].join("\n")) + + "()", Blockly.Arduino.ORDER_UNARY_POSTFIX + ] +}; +Blockly.Arduino.stepper = {}; +Blockly.Arduino.stepper_config = function(a) { + var b = Blockly.Arduino.PinTypes.STEPPER, + c = a.getFieldValue("STEPPER_NAME"), + d = a.getFieldValue("STEPPER_NUMBER_OF_PINS"), + e = Blockly.Arduino.valueToCode(a, "STEPPER_STEPS", Blockly.Arduino.ORDER_ATOMIC) || "360", + f = Blockly.Arduino.valueToCode(a, "STEPPER_SPEED", Blockly.Arduino.ORDER_ATOMIC) || "90", + g = [a.getFieldValue("STEPPER_PIN1"), a.getFieldValue("STEPPER_PIN2")]; + "FOUR" === d && (g.push(a.getFieldValue("STEPPER_PIN3")), g.push(a.getFieldValue("STEPPER_PIN4"))); + for (var d = + "int " + c + "[" + g.length + "] = {", e = "Stepper stepper_" + c + "(" + e + ", ", h = 0; h < g.length; h++) Blockly.Arduino.reservePin(a, g[h], b, "Stepper"), d += g[h] + ", ", e += g[h] + ", "; + d = d.slice(0, -2) + "};"; + e = e.slice(0, -2) + ");"; + Blockly.Arduino.addVariable(c, d, !0); + c = "stepper_" + c; + Blockly.Arduino.addInclude("stepper", "#include "); + Blockly.Arduino.addDeclaration(c, e); + Blockly.Arduino.addSetup(c, c + ".setSpeed(" + f + ");", !0); + return "" +}; +Blockly.Arduino.stepper_step = function(a) { + var b = "stepper_" + a.getFieldValue("STEPPER_NAME"); + a = Blockly.Arduino.valueToCode(a, "STEPPER_STEPS", Blockly.Arduino.ORDER_ATOMIC) || "0"; + return b + ".step(" + a + ");\n" +}; +Blockly.Arduino.text = {}; +Blockly.Arduino.text = function(a) { + return [Blockly.Arduino.quote_(a.getFieldValue("TEXT")), Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.text_join = function(a) { + var b; + if (0 == a.itemCount_) return ['""', Blockly.Arduino.ORDER_ATOMIC]; + if (1 == a.itemCount_) return ["String(" + (Blockly.Arduino.valueToCode(a, "ADD0", Blockly.Arduino.ORDER_UNARY_POSTFIX) || '""') + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX]; + var c; + b = []; + for (var d = 0; d < a.itemCount_; d++) c = Blockly.Arduino.valueToCode(a, "ADD" + d, Blockly.Arduino.ORDER_NONE), b[d] = "" == c ? '""' : "String(" + c + ")"; + b = b.join(" + "); + return [b, Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_append = function(a) { + var b = Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE); + a = Blockly.Arduino.valueToCode(a, "TEXT", Blockly.Arduino.ORDER_UNARY_POSTFIX); + return b + " += " + ("" == a ? '""' : "String(" + a + ")") + ";\n" +}; +Blockly.Arduino.text_length = function(a) { + return ["String(" + (Blockly.Arduino.valueToCode(a, "VALUE", Blockly.Arduino.ORDER_UNARY_POSTFIX) || '""') + ").length()", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_isEmpty = function(a) { + var b = []; + b.push("boolean " + Blockly.Arduino.DEF_FUNC_NAME + "(String msg) {"); + b.push(" if (msg.length() == 0) {"); + b.push(" return true;"); + b.push(" } else {"); + b.push(" return false;"); + b.push(" }"); + b.push("}"); + b = Blockly.Arduino.addFunction("isStringEmpty", b.join("\n")); + a = Blockly.Arduino.valueToCode(a, "VALUE", Blockly.Arduino.ORDER_UNARY_POSTFIX); + return [b + "(" + ("" == a ? '""' : "String(" + a + ")") + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_trim = function(a) { + Blockly.Arduino.text_trim.OPERATORS = { + LEFT: ".trim()", + RIGHT: ".trim()", + BOTH: ".trim()" + }; + var b = a.getFieldValue("MODE"), + b = Blockly.Arduino.text_trim.OPERATORS[b]; + a = Blockly.Arduino.valueToCode(a, "TEXT", Blockly.Arduino.ORDER_UNARY_POSTFIX); + return [("" == a ? '""' : "String(" + a + ")") + b, Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_print = function(a) { + var b = Blockly.Arduino.Boards.selected.serial[0][1]; + Blockly.Arduino.addSetup("serial_" + b, b + ".begin(9600);", !1); + a = Blockly.Arduino.valueToCode(a, "TEXT", Blockly.Arduino.ORDER_NONE); + return b + ".print(" + ("" == a ? '""' : "String(" + a + ")") + ");\n" +}; +Blockly.Arduino.text_prompt_ext = function(a) { + var b = Blockly.Arduino.Boards.selected.serial[0][1], + c = a.getFieldValue("TYPE"), + d = [], + e = c == Blockly.Types.NUMBER.output; + e ? d.push("int " + Blockly.Arduino.DEF_FUNC_NAME + "(String msg) {") : d.push("String " + Blockly.Arduino.DEF_FUNC_NAME + "(String msg) {"); + d.push(" " + b + ".println(msg);"); + d.push(" boolean stringComplete = false;"); + e ? d.push(" int content = 0;") : d.push(' String content = "";'); + d.push(" while (stringComplete == false) {"); + d.push(" if (" + b + ".available()) {"); + e ? (d.push(" content = " + b + ".parseInt();"), d.push(" stringComplete = true;")) : (d.push(" char readChar = (char)" + b + ".read();"), d.push(" if (readChar == '\\n' || readChar == '\\r') {"), d.push(" stringComplete = true;"), d.push(" } else {"), d.push(" content += readChar;"), d.push(" }")); + d.push(" }"); + d.push(" }"); + d.push(" // Empty incoming serial buffer"); + d.push(" while(Serial.available()) { Serial.read(); };"); + d.push(" return content;"); + d.push("}"); + c = Blockly.Arduino.addFunction("getUserInputPrompt" + + c, d.join("\n")); + Blockly.Arduino.addSetup("serial_" + b, b + ".begin(9600);", !1); + a = Blockly.Arduino.valueToCode(a, "TEXT", Blockly.Arduino.ORDER_NONE) || '""'; + return [c + "(" + a + ")", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_endString = function(a) { + return ["", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_indexOf = function(a) { + return ["", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_charAt = function(a) { + return ["", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_getSubstring = function(a) { + return ["", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_changeCase = function(a) { + return ["", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.text_prompt = function(a) { + return ["", Blockly.Arduino.ORDER_UNARY_POSTFIX] +}; +Blockly.Arduino.time = {}; +Blockly.Arduino.time_delay = function(a) { + return "delay(" + (Blockly.Arduino.valueToCode(a, "DELAY_TIME_MILI", Blockly.Arduino.ORDER_ATOMIC) || "0") + ");\n" +}; +Blockly.Arduino.time_delaymicros = function(a) { + return "delayMicroseconds(" + (Blockly.Arduino.valueToCode(a, "DELAY_TIME_MICRO", Blockly.Arduino.ORDER_ATOMIC) || "0") + ");\n" +}; +Blockly.Arduino.time_millis = function(a) { + return ["millis()", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.time_micros = function(a) { + return ["micros()", Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.infinite_loop = function(a) { + return "while(true);\n" +}; +Blockly.Arduino.tone = {}; +Blockly.Arduino.io_tone = function(a) { + var b = a.getFieldValue("TONEPIN"), + c = Blockly.Arduino.valueToCode(a, "FREQUENCY", Blockly.Arduino.ORDER_ATOMIC); + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.OUTPUT, "Tone Pin"); + Blockly.Arduino.addSetup("io_" + b, "pinMode(" + b + ", OUTPUT);\n", !1); + return "tone(" + b + "," + c + ");\n" +}; +Blockly.Arduino.io_notone = function(a) { + var b = a.getFieldValue("TONEPIN"); + Blockly.Arduino.reservePin(a, b, Blockly.Arduino.PinTypes.OUTPUT, "Tone Pin"); + Blockly.Arduino.addSetup("io_" + b, "pinMode(" + b + ", OUTPUT);\n", !1); + return "noTone(" + b + ");\n" +}; +Blockly.Arduino.variables = {}; +Blockly.Arduino.variables_get = function(a) { + return [Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE), Blockly.Arduino.ORDER_ATOMIC] +}; +Blockly.Arduino.variables_set = function(a) { + var b = Blockly.Arduino.valueToCode(a, "VALUE", Blockly.Arduino.ORDER_ASSIGNMENT) || "0"; + return Blockly.Arduino.variableDB_.getName(a.getFieldValue("VAR"), Blockly.Variables.NAME_TYPE) + " = " + b + ";\n" +}; +Blockly.Arduino.variables_set_type = function(a) { + var b = Blockly.Arduino.valueToCode(a, "VARIABLE_SETTYPE_INPUT", Blockly.Arduino.ORDER_ASSIGNMENT) || "0"; + return ["(" + Blockly.Arduino.getArduinoType_(Blockly.Types[a.getFieldValue("VARIABLE_SETTYPE_TYPE")]) + ")(" + b + ")", Blockly.Arduino.ORDER_ATOMIC] +}; \ No newline at end of file diff --git a/client/src/Utils/requests.js b/client/src/Utils/requests.js index ed09f710..8763500a 100644 --- a/client/src/Utils/requests.js +++ b/client/src/Utils/requests.js @@ -332,7 +332,7 @@ export const deleteLearningStandard = async (id) => ( }) ); -export const createLearningStandard = async (description,name,number,unit) =>( +export const createLearningStandard = async (description,name,number,unit, teks) =>( makeRequest({ method: POST, path: `${server}/learning-standards`, @@ -340,7 +340,8 @@ export const createLearningStandard = async (description,name,number,unit) =>( "expectations": description, "name": name, "number": number, - "unit": unit + "unit": unit, + "teks": teks }, auth: true, error: "Login failed." diff --git a/client/src/views/Classroom/Roster/ListView.js b/client/src/views/Classroom/Roster/ListView.js index 76ab170d..43d8c5f7 100644 --- a/client/src/views/Classroom/Roster/ListView.js +++ b/client/src/views/Classroom/Roster/ListView.js @@ -100,7 +100,7 @@ export default function ListView(props) { ) }, { - title: 'Edit', + title: 'Edit----', dataIndex: 'edit', key: 'edit', width: '10%', diff --git a/client/src/views/ContentCreator/ContentCreator.js b/client/src/views/ContentCreator/ContentCreator.js index 52ac8975..c100940b 100644 --- a/client/src/views/ContentCreator/ContentCreator.js +++ b/client/src/views/ContentCreator/ContentCreator.js @@ -7,7 +7,7 @@ import { QuestionCircleOutlined } from '@ant-design/icons'; import DayEditor from './LearningStandardDayCreator/DayEditor' import UnitCreator from './UnitCreator/UnitCreator'; import LearningStandardDayCreator from './LearningStandardCreator/LearningStandardCreator' -import {getLearningStandard, getLearningStandardAll,deleteLearningStandard, getGrades} from '../../Utils/requests' +import {getLearningStandard, getLearningStandardAll,deleteLearningStandard, getGrades, getUnits, getAllUnits} from '../../Utils/requests' import ViewDayModal from './viewDayModal/viewDayModal'; import UnitEditor from './UnitEditor/UnitEditor' @@ -16,8 +16,9 @@ const { TabPane } = Tabs; export default function ContentCreator(props) { const [dataSource, setDataSource] = useState([]) - const [dataSourceGrade5, setDataSourceGrade5] = useState([]) + const [dataSourceMap, setDataSourceMap] = useState([]) const [dataSourceGrade6, setDataSourceGrade6] = useState([]) + const [dataSourceGrade5, setDataSourceGrade5] = useState([]) const [gradeMenu, setGradeMenu] = useState([]) useEffect(() => { @@ -25,23 +26,28 @@ export default function ContentCreator(props) { getGrades().then(res => { if(res.data){ setGradeMenu(res.data) - console.log("this is the grade menu", gradeMenu) + // console.log("this is the grade menu", gradeMenu, res.data) }else{ message.error(res.err) } }) axiosCallAll() - axiosCallgrade(4) + // axiosCallgrade(4) }, []) + + const columns = [ { - title: 'Name', + title: 'Learning Standard', dataIndex: 'name', key: 'name', editable: true, width: '22.5%', align: 'left', + render: (_, key) => ( + + ) }, { title: 'Unit', @@ -50,17 +56,20 @@ export default function ContentCreator(props) { editable: true, width: '22.5%', align: 'left', - }, - { - title: 'Edit', - dataIndex: 'edit', - key: 'edit', - width: '10%', - align: 'right', render: (_, key) => ( - + ) }, + // { + // title: 'Edit', + // dataIndex: 'edit', + // key: 'edit', + // width: '10%', + // align: 'right', + // render: (_, key) => ( + // + // ) + // }, { title: 'Desciption', dataIndex: 'description', @@ -69,16 +78,16 @@ export default function ContentCreator(props) { width: '22.5%', align: 'left', }, - { - title: 'View', - dataIndex: 'view', - key: 'view', - width: '10%', - align: 'right', - render: (_, key) => ( - - ) - }, + // { + // title: 'View', + // dataIndex: 'view', + // key: 'view', + // width: '10%', + // align: 'right', + // render: (_, key) => ( + // + // ) + // }, // { // title: 'Edit', // dataIndex: 'edit', @@ -133,27 +142,17 @@ export default function ContentCreator(props) { } const getDays = (i) => { - //console.log(i.edit) const day1 = [] - //console.log(i) - const request = getLearningStandard(i.edit); - //console.log(request) - var j = 1; - //console.log(request) + // console.log(i) + + const request = getLearningStandard(i.id); + request.then(function (result) { - //console.log(result) - //console.log(result.data.days) - result.data.days.forEach(el => { - day1.push({ - id: el.id, - day: j, - template: el.template - }) - j++; - //console.log(day1) - }); - //console.log(day1) + + day1.push(...result.data.days) + }) + // console.log("Day ",day1) return day1; } @@ -161,80 +160,53 @@ export default function ContentCreator(props) { const axiosCallAll = async() =>{ const newArr=[] + const newMap={} const allreq = getLearningStandardAll(); //console.log(allreq) const allres1 = await allreq + console.log("all Learning Standards", allres1) allres1.data.forEach(learningStand => { - getTempStandard(learningStand, newArr) - }) - - } - - const axiosCallgrade = async(grade) =>{ - setDataSource([]) - const newArr=[] - const allreq = getLearningStandardAll(); - //console.log(allreq) - const allres1 = await allreq - allres1.data.forEach(learningStand=>{ - getTempStandardGrade(learningStand,newArr,grade) - }) - } - - const getTempStandardGrade = async(learningStand, newArr, grade)=>{ - - const request = getLearningStandard(learningStand.id); - const result = await request; - console.log(result,result.data.unit.grade ,grade) - if(result.data.unit.grade === grade){ const value = { - name: result.data.name, - unit: result.data.unit.name, - description: result.data.expectations.length > 5 ? result.data.expectations.substring(0,30) + "..." : result.data.expectations, + name: learningStand.name, + unit: learningStand.unit.name, + description: learningStand.expectations.length > 5 ? learningStand.expectations.substring(0, 30) + "..." : learningStand.expectations, view: learningStand.id, - edit: learningStand.id, + id: learningStand.id, delete: learningStand.id } newArr.push(value) - // console.log(newArr) - // console.log(value) - if(grade === 4){ - setDataSourceGrade5(dataSourceGrade5.concat(newArr)) - } - else{ - setDataSourceGrade6(dataSourceGrade6.concat(newArr)) - } - } - - } - - const getTempStandard = async(learningStand, newArr)=>{ - - const request = getLearningStandard(learningStand.id); - const result = await request; - console.log(result) - - const value = { - name: result.data.name, - unit: result.data.unit.name, - description: result.data.expectations.length > 5 ? result.data.expectations.substring(0, 30) + "..." : result.data.expectations, - view: learningStand.id, - edit: learningStand.id, - delete: learningStand.id - } - newArr.push(value) - // console.log(newArr) - // console.log(value) + newMap[learningStand.unit.grade] = newMap[learningStand.unit.grade] || []; + newMap[learningStand.unit.grade].push(value); + + }) setDataSource(dataSource.concat(newArr)) - + setDataSourceMap(newMap) } + const addTodataSource = (val) => { setDataSource(dataSource.concat(val)); } + const setTabs = (grade) => { + + return ( + + +
+ + + +
+
+
+ ) + } return ( +
@@ -249,40 +221,26 @@ export default function ContentCreator(props) {
- +
-
-
- - -
- - - -
-
-
- - -
- - - -
-
+
- - + { + gradeMenu.map(grade => { + // console.log("logging grades", grade) + return setTabs(grade) + + }) + } + + + ) diff --git a/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.js b/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.js index b41c82ef..8151ccf3 100644 --- a/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.js +++ b/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.js @@ -1,5 +1,5 @@ -import React,{useState} from 'react' -import {Form, Input, Button, Modal} from 'antd' +import React,{useState, useEffect} from 'react' +import {Form, Input, Button, Modal, message} from 'antd' import {PlusOutlined} from '@ant-design/icons' import {createUnit,createLearningStandard, createDay,getUnit, getUnits, getAllUnits} from '../../../Utils/requests' @@ -10,13 +10,30 @@ export default function LearningStandardCreator(props){ const [visible, setVisible] = useState(false); const [numOfdays, setNumofDays] = useState(0); - - const [learningObj, setLearnObj] = useState({ - learningName: "", - learningdescrip: 0, - learningNum: 0, - learningStandUnit: "", - learningNumOfDays: 0,}) + const [unitsMenu, setUnitsMenu] = useState([]) + + const defaultLearningObj = { + learningName: "", + learningdescrip: "", + learningNum: "", + learningStandUnit: "", + learningNumOfDays: "", + learningTeks: "" + } + + const [learningObj, setLearnObj] = useState({defaultLearningObj}) + + useEffect(() => { + + getAllUnits().then(res => { + if(res.data){ + setUnitsMenu(res.data) + console.log("this is the Units menu", res.data) + }else{ + message.error(res.err) + } + }) + }, []) const showModal = () => { @@ -27,6 +44,9 @@ export default function LearningStandardCreator(props){ setVisible(false) }; + const completeLearningStandard = () => { + setVisible(false) + } const addButtonStyle={ background: "#F4F4F5", @@ -38,33 +58,46 @@ export default function LearningStandardCreator(props){ const onclickhandler= async()=>{ //(props.dataSource) const newArr = [] - const units1 = await getAllUnits() - //console.log(units1) - units1.data.forEach(element => { - creaStandard(element,newArr) - }); + // const units1 = await getAllUnits() + // //console.log(units1) + // units1.data.forEach(element => { + // creaStandard(element,newArr) + // }); + creaStandard(newArr) - - } - const creaStandard = async(element,newArr)=>{ + const setUnitsOption = () => { + let options = []; + for(let i = 0; i < unitsMenu.length; i++){ + options.push() + } + return options + }; + + const creaStandard = async(newArr)=>{ // if(element.name === learningObj.learningStandUnit){ //console.log(element) - const learningStand = createLearningStandard(learningObj.learningdescrip,learningObj.learningName,learningObj.learningNum,element) - const getLearn = await learningStand; - console.log(getLearn) - for(var i=0;i 5 ? getLearn.data.expectations.substring(0,30) + "...": getLearn.data.expectations, - view: getLearn.data.id, - edit: getLearn.data.id, - delete: getLearn.data.id}) - props.changeDataSource(newArr) + const learningStand = createLearningStandard(learningObj.learningdescrip,learningObj.learningName,learningObj.learningNum, + learningObj.learningStandUnit, learningObj.learningTeks) + const getLearn = await learningStand; + console.log("got from adding a learning standard", getLearn) + for(var i=0;i 5 ? getLearn.data.expectations.substring(0,30) + "...": getLearn.data.expectations, + view: getLearn.data.id, + edit: getLearn.data.id, + id: getLearn.data.id, + delete: getLearn.data.id}) + props.changeDataSource(newArr) + + setLearnObj(defaultLearningObj) + + completeLearningStandard() // } // else{ // const val = { @@ -91,17 +124,68 @@ export default function LearningStandardCreator(props){ // } } + const lsNameOnChange = (e) => { + const {value} = e.target; + setLearnObj((learningObj) => ({ + ...learningObj, + learningName: value + })); + } + + + const lsNumberOnChange = (e) => { + const {value} = e.target; + setLearnObj((learningObj) => ({ + ...learningObj, + learningNum: parseInt(value,10) + })); + } + + const lsDescriptionOnChange = (e) => { + const {value} = e.target; + setLearnObj((learningObj) => ({ + ...learningObj, + learningdescrip: value + })); + } + + const lsTeksOnChange = (e) => { + const {value} = e.target; + setLearnObj((learningObj) => ({ + ...learningObj, + learningTeks: value + })); + } + + const lsNoOfDaysOnChange = (e) => { + const {value} = e.target; + setLearnObj((learningObj) => ({ + ...learningObj, + learningNumOfDays: parseInt(value,10) + })); + } + + const lsUnitsOnChange = (e) => { + const {value} = e.target; + setLearnObj((learningObj) => ({ + ...learningObj, + learningStandUnit: value + })); + } + + return(
-
- { const {value} = e.target; setLearnObj((learningObj) => ({ - ...learningObj, - learningName: value - }));}}/> + - { const {value} = e.target; setLearnObj((learningObj) => ({ - ...learningObj, - learningNum: parseInt(value,10) - }));}}> - + + + - { const {value} = e.target; setLearnObj((learningObj) => ({ - ...learningObj, - learningStandUnit: value - }));}}> - - - { const {value} = e.target; setLearnObj((learningObj) => ({ - ...learningObj, - learningdescrip: value - }));}}> - + + - - + + + - - + + + - { const {value} = e.target; setLearnObj((learningObj) => ({ - ...learningObj, - learningNumOfDays: parseInt(value,10) - }));}}> - + + + - - - - +
-
+ ) } \ No newline at end of file diff --git a/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.less b/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.less index 0909a18e..2a39b850 100644 --- a/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.less +++ b/client/src/views/ContentCreator/LearningStandardCreator/LearningStandardCreator.less @@ -10,4 +10,46 @@ border: solid 4px; border-color: #colors[secondary]; border-radius: 10px; +} + +#add-learning-standard { + input[type = "text"] { + display: block; + margin: 5px auto 0px; + background: none; + border: 2px solid; + border-color: #colors[secondary]; + padding: 10px 10px; + width: 95%; + outline: none; + color: #colors[text-primary]; + border-radius: 8px; + transition: 0.25s; + } + + input[type = "text"]:focus { + width: 100%; + } + + label { + margin: 10px auto 10px; + } +} + +#unit { + display: block; + background: none; + margin: 5px auto 0px; + border: 2px solid; + border-color: #colors[secondary]; + padding: 14px 10px; + width: 95%; + outline: none; + color: #colors[text-primary]; + border-radius: 8px; + transition: 0.25s; +} + +#unit:focus { + width: 100%; } \ No newline at end of file diff --git a/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.js b/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.js index 89d2b25b..94b137d2 100644 --- a/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.js +++ b/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.js @@ -1,72 +1,58 @@ -import React, { useState } from 'react' -import { Button, List, Card, Modal } from 'antd' +import React, { useState, useEffect } from 'react' +import { Button, List, Card, Modal, message, Form, Input } from 'antd' import { PlusOutlined, CloseOutlined } from '@ant-design/icons'; -import { createDay, deleteDay, getDayToolboxAll } from '../../../Utils/requests' +import { createDay, deleteDay, getDayToolboxAll, getLearningStandard } from '../../../Utils/requests' import './DayEditor.less' +// import Form from 'antd/lib/form/Form'; export default function ContentCreator(props) { const [visible, setVisible] = useState(false); const [days, setDay] = useState([]); const linkBtn = props.linkBtn; - const learningStandard = props.learningStandard - + const [newDay, setNewDay] = useState(); + const learningStandardId = props.learningStandardId + const learningStandardName = props.learningStandardName + const handleCancel = () => { setVisible(false) }; + const showModal = () => { + console.log("got days", props.days) setDay([...props.days]) - + console.log("set days", days) setVisible(true) }; const addBasicDay = () => { - const res = createDay(days.length + 1, learningStandard) - res.then(function (res1) { + const res = createDay(newDay, learningStandardId) + res.then(function (a) { //console.log(res1) - setDay([...days, { id: res1.data.id, day: days.length + 1 }]) + let res1 = getLearningStandard(learningStandardId) + res1.then((result) => { + console.log("update the days") + setDay([...result.data.days]) + }) + }) + setNewDay() } const removeBasicDay = (currDay) => { - if (days.length === 1) { - setDay([]) - } else { - const currIndex = days.indexOf(currDay) - // console.log(days) - // console.log(currIndex) - // console.log(currDay) - if (currIndex === 0) { - let pos = 0 - setDay(days.forEach(currDay => { - if (currIndex === 0 && pos === 0) { - currDay.day = -1 - } else { - currDay.day -= 1 - } - pos++; - })) - setDay(days.filter((e) => (e.day !== -1))) - } else { - let pos = 0 - setDay(days.forEach(currDay => { - if (pos > currIndex) { - currDay.day -= 1 - } else if (pos === currIndex) { - currDay.day = -1 - } - pos++; - })) - setDay(days.filter((e) => (e.day !== -1))) - } - } + alert("Deleting ", currDay.name) + const res = deleteDay(currDay.id) res.then(function (a) { - //console.log(res) + let res1 = getLearningStandard(learningStandardId) + res1.then((result) => { + console.log("update the days") + setDay([...result.data.days]) + }) }) } @@ -85,40 +71,84 @@ export default function ContentCreator(props) { }; //figure out how to set these up in the css file colors[] stuff causes problems + const handleDayChange = (e) => { + let {value} = e.target + setNewDay(parseInt(value)) + } + + const handleSubmit = (e) => { + e.preventDefault(); + addBasicDay(newDay) + setNewDay() + } + return (
{/* {console.log(props)} */} - +
{(days.length > 0) ? ( - - {/*
- -
*/} -
- handleViewDay(item)} extra={
+ + handleViewDay(item)} /> + removeBasicDay(item)}>× )} /> : null}
- + + {/*
+ Add Day + + +
*/} + {/*
+{/* +
+ {days ? days.map(day => +
+ + removeBasicDay(day)}>× +
+ ) + : null} +
*/}
diff --git a/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.less b/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.less index 163f483b..d0e51bc5 100644 --- a/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.less +++ b/client/src/views/ContentCreator/LearningStandardDayCreator/DayEditor.less @@ -33,4 +33,50 @@ width: 18vw; } } - } \ No newline at end of file + } + + .border-card-info { + width : 50px + } + + .delete-btn { + cursor:pointer; + font-weight: bolder; + font-size: 1.4em; + position:absolute; + right: 18px; + top: 5px; + } + + + + #card-day { + background: #colors[tertiary]; + border: 2px solid; + border-color: #colors[secondary]; + } + + + #add-day { + input[type = "text"] { + display: block; + margin: 5px auto 0px; + background: none; + border: 2px solid; + border-color: #colors[secondary]; + padding: 10px 10px; + width: 90%; + outline: none; + color: #colors[text-primary]; + border-radius: 8px; + transition: 0.25s; + } + + input[type = "text"]:focus { + width: 95%; + } + + label { + margin: 10px auto 10px; + } +} \ No newline at end of file diff --git a/client/src/views/ContentCreator/UnitCreator/UnitCreator.js b/client/src/views/ContentCreator/UnitCreator/UnitCreator.js index c74ca0e9..9e464542 100644 --- a/client/src/views/ContentCreator/UnitCreator/UnitCreator.js +++ b/client/src/views/ContentCreator/UnitCreator/UnitCreator.js @@ -90,6 +90,7 @@ export default function UnitCreator(props){ description:getLearn.data.expectations.length> 5 ? getLearn.data.expectations.substring(0,30) + "...": getLearn.data.expectations, view: getLearn.data.id, edit: getLearn.data.id, + id: getLearn.data.id, delete: getLearn.data.id}) // props.changeDataSource({ // name:getLearn.data.name, @@ -169,7 +170,7 @@ export default function UnitCreator(props){ Add Unit - + { const {value} = e.target; setUnitObject((unitObject) => ({ - ...unitObject, - unitNumber: parseInt(value,10) - }));}}> - - + onChange={(e)=>{ + const {value} = e.target; + setUnitObject((unitObject) => ({ + ...unitObject, + unitNumber: parseInt(value,10) + })); + }}> + + { - const { value } = e.target; - setUnitObject((unitObject) => ({ - ...unitObject, - unitDescrip: value - })); - }}> + onChange={(e) => { + const { value } = e.target; + setUnitObject((unitObject) => ({ + ...unitObject, + unitDescrip: value + })); + }}> - + */} diff --git a/server/api/day/models/day.settings.json b/server/api/day/models/day.settings.json index 29b4dd8b..c299cdc8 100644 --- a/server/api/day/models/day.settings.json +++ b/server/api/day/models/day.settings.json @@ -10,8 +10,8 @@ }, "attributes": { "learning_standard": { - "model": "learning-standard", - "via": "days" + "via": "days", + "model": "learning-standard" }, "number": { "type": "biginteger", diff --git a/server/api/learning-standard/models/learning-standard.settings.json b/server/api/learning-standard/models/learning-standard.settings.json index d20d3fa4..01ed129a 100644 --- a/server/api/learning-standard/models/learning-standard.settings.json +++ b/server/api/learning-standard/models/learning-standard.settings.json @@ -9,10 +9,6 @@ "timestamps": true }, "attributes": { - "unit": { - "via": "learning_standards", - "model": "unit" - }, "number": { "type": "decimal", "required": true @@ -25,8 +21,16 @@ "type": "text" }, "days": { - "via": "learning_standard", - "collection": "day" + "collection": "day", + "via": "learning_standard" + }, + "unit": { + "model": "unit", + "via": "learning_standards" + }, + "teks": { + "type": "string", + "unique": true } } } diff --git a/server/api/unit/models/unit.settings.json b/server/api/unit/models/unit.settings.json index e67a4033..51e155a5 100644 --- a/server/api/unit/models/unit.settings.json +++ b/server/api/unit/models/unit.settings.json @@ -23,13 +23,13 @@ "teks_description": { "type": "text" }, - "learning_standards": { - "collection": "learning-standard", - "via": "unit" + "number": { + "type": "integer", + "required": true }, - "number": { - "type": "integer", - "required": true + "learning_standards": { + "via": "unit", + "collection": "learning-standard" } } }