app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.25.4 vs app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.28.0
- old
+ new
@@ -78,21 +78,19 @@
<category name="Operadores">
<block type="OperadorNumerico"></block>
<block type="OperadorDeComparacion"></block>
<block type="OperadorLogico"></block>
<block type="not"></block>
- <block type="siguiente"></block>
- <block type="previo"></block>
- <block type="opuesto"></block>
+ <block type="OperadoresDeEnumeracion"></block>
</category>
</category>
<category name="Definiciones">
<category name="Programas">
<block type="Program"></block>
<block type="InteractiveProgram"></block>
</category>
- <category name="Asociaciones">
+ <category name="Eventos">
<block type="InteractiveLetterBinding"></block>
<block type="InteractiveNumberBinding"></block>
<block type="InteractiveKeyBinding"></block>
</category>
<category name="Procedimientos">
@@ -103,11 +101,11 @@
<block type="procedures_defreturnsimple"></block>
<block type="procedures_defreturnsimplewithparams"></block>
<block type="procedures_defreturn"></block>
</category>
</category>
- <category name="Auxiliares Docente">
+ <category name="Auxiliares Docente" gbs_visible="teacher">
<block type="ComandoCompletar"></block>
<block type="ExpresionCompletar"></block>
<block type="AsociacionDeTeclaCompletar"></block>
</category>
</xml>
@@ -5278,18 +5276,16 @@
Blockly.Blocks.not = createSingleParameterExpressionBlock('no','Bool');
Blockly.Blocks.siguiente = createSingleParameterExpressionBlock('siguiente','*');
Blockly.Blocks.previo = createSingleParameterExpressionBlock('previo','*');
Blockly.Blocks.opuesto = createSingleParameterExpressionBlock('opuesto','*');
-
// Necesario para sanitizar nombres de procedimientos.
// En la interfaz de bloques de gobstones por ahora vamos a dejar pasar sólo espacios y letras con tilde
Blockly.Blocks.GobstonesSanitizer = function(name){
return name.replace(/[^A-Za-z0-9ÁÉÍÓÚÑáéíóúñ_ ]/g,'');
};
-
Blockly.Procedures.OldRename = Blockly.Procedures.rename;
Blockly.Procedures.rename = function(name){
return Blockly.Procedures.OldRename.call(this,
Blockly.Blocks.GobstonesSanitizer(name));
};
@@ -5300,10 +5296,39 @@
Blockly.Blocks.procedures_mutatorarg.validator_old = Blockly.Blocks.procedures_mutatorarg.validator_;
Blockly.Blocks.procedures_mutatorarg.validator_ = function(name){
return Blockly.Blocks.procedures_mutatorarg.validator_old.call(this,
Blockly.Blocks.GobstonesSanitizer(name));
};
+
+// Enable/Disable atomic
+const oldProceduresCustomContextMenu = Blockly.Blocks.procedures_defnoreturn.customContextMenu
+Blockly.Blocks.procedures_defnoreturn.customContextMenu = function(options) {
+ oldProceduresCustomContextMenu.call(this, options);
+
+ const block = this;
+ options.splice(1, 0, {
+ enabled: true,
+ text: block.$isAtomic ? "✗ Mostrar paso a paso" : "✓ Mostrar paso a paso",
+ callback: function() {
+ block.$isAtomic = !block.$isAtomic;
+ triggerRefresh(block);
+ }
+ })
+}
+const oldProceduresMutationToDom = Blockly.Blocks['procedures_defnoreturn'].mutationToDom;
+Blockly.Blocks.procedures_defnoreturn.mutationToDom = function() {
+ const container = oldProceduresMutationToDom.call(this);
+ container.setAttribute("isatomic", this.$isAtomic ? "true" : "false");
+ return container;
+}
+const oldProceduresDomToMutation = Blockly.Blocks['procedures_defnoreturn'].domToMutation;
+Blockly.Blocks.procedures_defnoreturn.domToMutation = function(xmlElement) {
+ const isAtomic = xmlElement.getAttribute("isatomic");
+ this.$isAtomic = isAtomic === "true";
+
+ return oldProceduresDomToMutation.call(this, xmlElement);
+}
</script>
<script>/* global Blockly, goog */
/* eslint camelcase: "off" */
/*
@@ -5842,15 +5867,15 @@
.map(arg => formatCallName(arg, false, Blockly.VARIABLE_CATEGORY_NAME))
.join(', ');
};
Blockly.GobstonesLanguage.procedures_defnoreturn = function (block) {
- var name = formatCallName(block.getFieldValue('NAME'),true);
- var body = Blockly.GobstonesLanguage.statementToCode(block, 'STACK');
+ var name = formatCallName(block.getFieldValue('NAME'),true);
+ var body = Blockly.GobstonesLanguage.statementToCode(block, 'STACK');
- var code = 'procedure ' + name + '(' + makeParameterList(block) + ') {\n' +
- body + '}\n';
+ var code = 'procedure ' + name + '(' + makeParameterList(block) + ') {\n' + body + '}\n';
+ if (block.$isAtomic) code = "/*@ATTRIBUTE@atomic@*/" + "\n" + code;
code = Blockly.GobstonesLanguage.scrub_(block, code);
Blockly.GobstonesLanguage.definitions_[name] = code;
return null;
@@ -6160,10 +6185,18 @@
workspaceCanEdit: {
type: Boolean,
},
/*
+ * `role` Indica el role del usuario ("teacher" || "student").
+ */
+ role: {
+ type: String,
+ value: "teacher"
+ },
+
+ /*
* `width` Ancho del elemento.
*/
width: {
type: Number,
observer: '_fixSize'
@@ -6867,35 +6900,40 @@
forEachNode(parsedXml, (node) => {
if (!node.getAttribute) return;
const name = node.getAttribute("name");
const custom = node.getAttribute("gbs_custom");
+ const visible = node.getAttribute("gbs_visible");
- if (custom === "SEPARATOR") {
+ if (custom === "SEPARATOR" || visible !== null) {
const toolbar = document.querySelector("#blocklyDiv div div div").childNodes[1];
forEachNode(toolbar, (toolbarNode) => {
const isLabel = toolbarNode.classList && toolbarNode.classList[0] === "blocklyTreeLabel";
const isTheRightCategory = toolbarNode.textContent === name;
if (isLabel && isTheRightCategory) {
- const row = toolbarNode.parentElement;
- row.style["pointer-elements"] = "none";
- row.style["background"] = "#15546f";
- row.style["color"] = "#ffffff";
- row.style["margin-top"] = "8px";
- row.style["margin-bottom"] = "8px";
- row.style["pointer-events"] = "none";
- row.style["user-select"] = "none";
+ if (custom === "SEPARATOR") {
+ const row = toolbarNode.parentElement;
+ row.style["pointer-elements"] = "none";
+ row.style["background-image"] = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4wEVFRcgIqOIVAAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAADUlEQVQI12MQDcn/DwADMgHYjceGPAAAAABJRU5ErkJggg==)";
+ row.style["color"] = "#ffffff";
+ row.style["margin-top"] = "8px";
+ row.style["margin-bottom"] = "8px";
+ row.style["pointer-events"] = "none";
+ row.style["user-select"] = "none";
- if (toolbarNode.innerHTML.startsWith("*")) {
- row.style["margin-top"] = "0";
- row.style["margin-bottom"] = "-8px";
- row.style["font-weight"] = "900";
- toolbarNode.innerHTML = toolbarNode.innerHTML.replace("*", "");
- }
+ if (toolbarNode.innerHTML.startsWith("*")) {
+ row.style["margin-top"] = "0";
+ row.style["margin-bottom"] = "-8px";
+ row.style["font-weight"] = "900";
+ toolbarNode.innerHTML = toolbarNode.innerHTML.replace("*", "");
+ }
- toolbarNode.innerHTML = `<span>${toolbarNode.innerHTML}</span>`;
+ toolbarNode.innerHTML = `<span>${toolbarNode.innerHTML}</span>`;
+ } else if (visible !== null && visible !== this.role) {
+ toolbarNode.remove();
+ }
}
});
}
});
},
\ No newline at end of file