diff --git a/blockly_unix_database.db b/blockly_unix_database.db
index c6f0392..ea98031 100644
Binary files a/blockly_unix_database.db and b/blockly_unix_database.db differ
diff --git a/index.html b/index.html
index df23161..94bcafe 100644
--- a/index.html
+++ b/index.html
@@ -85,7 +85,7 @@
-
+
-
-
-
{
- const state = Blockly.serialization.workspaces.save(workspace);
- localStorage.setItem('blocklyWorkspace', JSON.stringify(state));
- });
- */
- document.addEventListener('DOMContentLoaded', () => {
- fetch('/auth-token')
- .then((response) => response.json())
- .then((data) => {
- const token = data.authToken;
- const user = data.user;
- if (token) {
- document.getElementById('savedWorkspaces').style.display =
- 'inline-block';
-
- fetch(`/getUserWorkspaces?userId=${user.id}`)
- .then((response) => response.json())
- .then((data) => {
- const workspaces = data.workspaces;
- const savedWorkspacesSelect =
- document.getElementById('savedWorkspaces');
-
- // Clear any existing options
- savedWorkspacesSelect.innerHTML = '';
-
- // Add a default option
- const defaultOption = document.createElement('option');
- defaultOption.value = '';
- defaultOption.text = 'Select a workspace';
- savedWorkspacesSelect.appendChild(defaultOption);
-
- // Populate dropdown with the user's saved workspaces
- workspaces.forEach((workspace) => {
- const option = document.createElement('option');
- option.value = workspace.id; // use the ID as the option value
- option.text = workspace.workspaceName; // display the workspace name
- savedWorkspacesSelect.appendChild(option);
- });
-
- savedWorkspacesSelect.addEventListener('change', () => {
- const selectedWorkspaceId = savedWorkspacesSelect.value;
-
- if (selectedWorkspaceId) {
- fetch(`/getWorkspace?workspaceId=${selectedWorkspaceId}`)
- .then((response) => response.json())
- .then((data) => {
- if (data.workspaceData) {
- const workspaceState = JSON.parse(
- data.workspaceData
- );
- // Deserialize and load the workspace
- Blockly.serialization.workspaces.load(
- workspaceState,
- workspace
- );
- console.log('Workspace loaded successfully.');
- } else {
- console.error(
- 'Failed to load workspace: Invalid workspace data.'
- );
- alert(
- 'Failed to load workspace. Please try again.'
- );
- }
- })
- .catch((error) => {
- console.error('Error loading workspace:', error);
- alert('Failed to load workspace. Please try again.');
- });
- }
- });
- })
- .catch((error) => {
- console.error('Error fetching user workspaces:', error);
- });
-
- document.getElementById('saveButton').style.display =
- 'inline-block';
-
- document
- .getElementById('saveButton')
- .addEventListener('click', (event) => {
- event.preventDefault(); // Prevent default form submission behavior
-
- // Ask the user for the workspace name
- const workspaceName = prompt(
- 'Enter a name for your workspace:'
- );
-
- if (!workspaceName || workspaceName.trim() === '') {
- alert('Workspace name cannot be empty.');
- return;
- }
-
- // Serialize the workspace state to JSON
- const state =
- Blockly.serialization.workspaces.save(workspace);
- const jsonState = JSON.stringify(state);
-
- // Ensure jsonState, user.id, and workspaceName are valid before submitting
- if (jsonState && user.id && workspaceName.trim() !== '') {
- // Set the value of the hidden input fields in the form
- document.getElementById('workspaceData').value = jsonState;
- document.getElementById('userId').value = user.id;
- document.getElementById('workspaceName').value =
- workspaceName;
-
- // Use AJAX to send the data to the server without redirecting
- fetch('/saveWorkspace', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- workspaceData: jsonState,
- userId: user.id,
- workspaceName: workspaceName
- })
- })
- .then((response) => response.json())
- .then((result) => {
- if (result.error) {
- console.error(
- 'Error saving workspace:',
- result.error
- );
- alert('Failed to save workspace. Please try again.');
- } else {
- console.log(
- 'Workspace saved successfully:',
- result.message
- );
- alert('Workspace saved successfully.');
- }
- })
- .catch((error) => {
- console.error('Error saving workspace:', error);
- alert('Failed to save workspace. Please try again.');
- });
- } else {
- console.error(
- 'Invalid workspace data, user ID, or workspace name.'
- );
- alert('Failed to save workspace. Invalid data.');
- }
- });
- }
- })
- .catch((error) => {
- console.error('Error fetching the token:', error);
- });
- });
-
const backpackOptions = {
allowEmptyBackpackOpen: false,
useFilledBackpackImage: true,
@@ -834,11 +635,7 @@
};
const crossTabCopyPaste = new CrossTabCopyPaste();
- crossTabCopyPaste.init(crossTabCopyPasteOptions, () => {
- console.log(
- 'Use this error callback to handle TypeError while pasting'
- );
- });
+ crossTabCopyPaste.init(crossTabCopyPasteOptions, () => {});
// Optional: Remove the duplication command from Blockly's context menu
Blockly.ContextMenuRegistry.registry.unregister('blockDuplicate');
diff --git a/msg/el.js b/msg/el.js
deleted file mode 100644
index 0c786c1..0000000
--- a/msg/el.js
+++ /dev/null
@@ -1,36 +0,0 @@
-var MSG_EL = {
- TEXT_PROCESSING: 'Επεξεργασία Κειμένου',
- FILE_INPUTS: 'Είσοδοι Αρχείων',
- FILE_DIR_OPERATIONS: 'Λειτουργίες Αρχείων και Καταλόγων',
- IO_REDIRECTION: 'Ανακατεύθυνση Εισόδου/Εξόδου',
- REGULAR_EXPRESSIONS: 'Κανονικές Εκφράσεις',
- DATA_PROCESSING: 'Επεξεργασία Δεδομένων',
- VARIABLES: 'Μεταβλητές',
- title: 'Κώδικας',
- blocks: 'Μπλοκ',
- linkTooltip: 'Αποθήκευση και σύνδεση με τα μπλοκ.',
- runTooltip:
- 'Εκτελέστε το πρόγραμμα που ορίζεται από τα μπλοκ στον χώρο εργασίας.',
- badCode: 'Σφάλμα προγράμματος:\n%1',
- timeout: 'Υπερβήκατε τον μέγιστο αριθμό επαναλήψεων εκτέλεσης.',
- trashTooltip: 'Απόρριψη όλων των μπλοκ.',
- catLogic: 'Λογική',
- catLoops: 'Βρόχοι',
- catMath: 'Μαθηματικά',
- catText: 'Κείμενο',
- catLists: 'Λίστες',
- catColour: 'Χρώμα',
- catVariables: 'Μεταβλητές',
- catFunctions: 'Συναρτήσεις',
- listVariable: 'λίστα',
- textVariable: 'κείμενο',
- httpRequestError: 'Υπήρξε πρόβλημα με το αίτημα.',
- linkAlert:
- 'Μοιραστείτε τα μπλοκ σας με αυτόν τον δημόσιο σύνδεσμο. Θα τα διαγράψουμε αν δεν χρησιμοποιηθούν για έναν χρόνο. Δεν συνδέονται με τον λογαριασμό σας και διαχειρίζονται σύμφωνα με την Πολιτική Απορρήτου της Google. Παρακαλούμε να μην συμπεριλάβετε προσωπικές πληροφορίες.\n\n%1',
- hashError:
- "Συγνώμη, το '%1' δεν αντιστοιχεί σε κανένα αποθηκευμένο πρόγραμμα.",
- loadError:
- 'Δεν ήταν δυνατή η φόρτωση του αποθηκευμένου αρχείου σας. Ίσως δημιουργήθηκε με διαφορετική έκδοση του Blockly;',
- parseError:
- "Σφάλμα ανάλυσης %1:\n%2\n\nΕπιλέξτε 'OK' για να εγκαταλείψετε τις αλλαγές σας ή 'Ακύρωση' για να συνεχίσετε να επεξεργάζεστε το %1."
-};
diff --git a/public/blocks/outOfUse/andBlock.js b/public/blocks/outOfUse/andBlock.js
deleted file mode 100644
index 2a6188b..0000000
--- a/public/blocks/outOfUse/andBlock.js
+++ /dev/null
@@ -1,45 +0,0 @@
-var andBlock = {
- // type: "and",
- // category: "File and Directory Operations",
- // unix_description: [
- // {
- // and: "&&"
- // }
- // ],
- // message0: "AND",
-
- // colour: 250,
- // previousStatement: "Action",
- // nextStatement: "Action",
- // tooltip: "AND condition",
- // helpUrl: "" // URL to further information or documentation.
- type: 'and',
- message0: '%1 %2 %3',
- args0: [
- {
- type: 'input_value',
- name: 'A',
- check: 'Boolean'
- },
- {
- type: 'field_dropdown',
- name: 'OP',
- options: [
- ['%{BKY_LOGIC_OPERATION_AND}', 'AND'],
- ['%{BKY_LOGIC_OPERATION_OR}', 'OR']
- ]
- },
- {
- type: 'input_value',
- name: 'B',
- check: 'Boolean'
- }
- ],
- inputsInline: true,
- output: 'Boolean',
- style: 'logic_blocks',
- helpUrl: '%{BKY_LOGIC_OPERATION_HELPURL}',
- extensions: ['logic_op_tooltip']
-};
-
-Blockly.defineBlocksWithJsonArray([andBlock]);
diff --git a/public/blocks/outOfUse/andOrBlock.js b/public/blocks/outOfUse/andOrBlock.js
deleted file mode 100644
index 75b40f2..0000000
--- a/public/blocks/outOfUse/andOrBlock.js
+++ /dev/null
@@ -1,52 +0,0 @@
-var andOrBlock = {
- // type: "and",
- // category: "File and Directory Operations",
- // unix_description: [
- // {
- // and: "&&"
- // }
- // ],
- // message0: "AND",
-
- // colour: 250,
- // previousStatement: "Action",
- // nextStatement: "Action",
- // tooltip: "AND condition",
- // helpUrl: "" // URL to further information or documentation.
- type: 'andOr',
- category: 'awk',
- unix_description: [
- {
- or: '||',
- and: '&&'
- }
- ],
- message0: '%1 %2 %3',
- args0: [
- {
- type: 'input_value',
- name: 'A',
- check: 'Boolean'
- },
- {
- type: 'field_dropdown',
- name: 'OP',
- options: [
- ['and', 'AND'],
- ['or', 'OR']
- ]
- },
- {
- type: 'input_value',
- name: 'B',
- check: 'Boolean'
- }
- ],
- inputsInline: true,
- output: 'Boolean',
- style: 'logic_blocks',
- helpUrl: '%{BKY_LOGIC_OPERATION_HELPURL}',
- extensions: ['logic_op_tooltip']
-};
-
-Blockly.defineBlocksWithJsonArray([andOrBlock]);
diff --git a/public/blocks/outOfUse/calculateBlock.js b/public/blocks/outOfUse/calculateBlock.js
deleted file mode 100644
index 33b476e..0000000
--- a/public/blocks/outOfUse/calculateBlock.js
+++ /dev/null
@@ -1,50 +0,0 @@
-var calculateBlock = {
- type: 'calculate',
- message0: 'calculate data',
- category: 'awk',
- unix_description: [
- {
- add: '+=',
- multiply: '*=',
- var: 'var'
- }
- ],
- message1: 'variable name %1',
- args1: [
- {
- type: 'field_input',
- name: 'var',
- text: ''
- }
- ],
- message2: 'math operation %1',
- args2: [
- {
- type: 'field_dropdown',
- name: 'operation',
- options: [
- ['add', 'add'],
- ['multiply', 'multiply']
- ]
- }
- ],
- message3: 'by column %1 \n or\n number %2',
- args3: [
- {
- type: 'input_value',
- name: 'column'
- },
- {
- type: 'field_input',
- name: 'number',
- text: ''
- }
- ],
- tooltip: 'Do math operations in awk action',
- previousStatement: 'Action',
- nextStatement: 'Action',
- colour: 250,
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([calculateBlock]);
diff --git a/public/blocks/outOfUse/compBlock.js b/public/blocks/outOfUse/compBlock.js
deleted file mode 100644
index 54a9d54..0000000
--- a/public/blocks/outOfUse/compBlock.js
+++ /dev/null
@@ -1,34 +0,0 @@
-var compBlock = {
- type: 'logic_compare',
- category: 'awk',
- message0: '%1 %2 %3',
- args0: [
- {
- type: 'input_value',
- name: 'A'
- },
- {
- type: 'field_dropdown',
- name: 'OP',
- options: [
- ['=', 'EQ'],
- ['\u2260', 'NEQ'],
- ['\u200F<', 'LT'],
- ['\u200F\u2264', 'LTE'],
- ['\u200F>', 'GT'],
- ['\u200F\u2265', 'GTE']
- ]
- },
- {
- type: 'input_value',
- name: 'B'
- }
- ],
- inputsInline: true,
- output: 'Boolean',
- style: 'logic_blocks',
- helpUrl: '%{BKY_LOGIC_COMPARE_HELPURL}',
- extensions: ['logic_compare', 'logic_op_tooltip']
-};
-
-Blockly.defineBlocksWithJsonArray([compBlock]);
diff --git a/public/blocks/outOfUse/doBlock.js b/public/blocks/outOfUse/doBlock.js
deleted file mode 100644
index cfe5411..0000000
--- a/public/blocks/outOfUse/doBlock.js
+++ /dev/null
@@ -1,16 +0,0 @@
-var doBlock = {
- type: 'do',
- category: 'awk',
- message0: 'Do %1',
- args0: [
- {
- type: 'input_statement',
- name: 'DO'
- }
- ],
- output: 'String',
- nextStatement: null,
- colour: 320
-};
-
-Blockly.defineBlocksWithJsonArray([doBlock]);
diff --git a/public/blocks/outOfUse/fieldInputBlock.js b/public/blocks/outOfUse/fieldInputBlock.js
deleted file mode 100644
index 51837cc..0000000
--- a/public/blocks/outOfUse/fieldInputBlock.js
+++ /dev/null
@@ -1,18 +0,0 @@
-var fieldInputBlock = {
- type: 'field_input',
- category: 'awk',
- message0: 'input %1',
- args0: [
- {
- type: 'field_input',
- name: 'field_input',
- text: 'type your search string...'
- }
- ],
- output: 'String',
- style: 'logic_blocks',
- tooltip: '%{BKY_LOGIC_NEGATE_TOOLTIP}',
- helpUrl: '%{BKY_LOGIC_NEGATE_HELPURL}'
-};
-
-Blockly.defineBlocksWithJsonArray([fieldInputBlock]);
diff --git a/public/blocks/outOfUse/fileContainsBlock.js b/public/blocks/outOfUse/fileContainsBlock.js
deleted file mode 100644
index 85894c7..0000000
--- a/public/blocks/outOfUse/fileContainsBlock.js
+++ /dev/null
@@ -1,39 +0,0 @@
-var fileContainsBlock = {
- type: 'fileContains',
- unix_description: [
- {
- contains: 'pattStart[contains]pattEnd'
- }
- ],
- message0: 'File contains %1\n',
- args1: [
- {
- type: 'field_input',
- name: 'contains',
- text: '............'
- }
- ],
- message2: 'file start %1\n file end %2',
- args2: [
- {
- type: 'field_input',
- name: 'pattStart',
- text: '............' // empty text for user to define filename
- },
- {
- type: 'field_input',
- name: 'pattEnd',
- text: '............' // empty text for user to define filename
- }
- ],
-
- output: 'filename',
- // colour: 160,
- style: 'filename_style',
- nextStatement: 'Action',
- tooltip:
- 'Represents a wildcard for filenames. For wildcard in start or end leave relevant field empty',
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([fileContainsBlock]);
diff --git a/public/blocks/outOfUse/fileSearchListBlock.js b/public/blocks/outOfUse/fileSearchListBlock.js
deleted file mode 100644
index 47a3cf3..0000000
--- a/public/blocks/outOfUse/fileSearchListBlock.js
+++ /dev/null
@@ -1,38 +0,0 @@
-var fileSearchListBlock = {
- type: 'fileSearchList',
- unix_description: [
- {
- list_contains: 'pattStart{list_contains}pattEnd'
- }
- ],
- message0: 'File contains %1\n',
- args1: [
- {
- type: 'field_input',
- name: 'list_contains',
- text: '............'
- }
- ],
- message2: 'file start %1\n file end %2',
- args2: [
- {
- type: 'field_input',
- name: 'pattStart',
- text: '............' // empty text for user to define filename
- },
- {
- type: 'field_input',
- name: 'pattEnd',
- text: '............' // empty text for user to define filename
- }
- ],
-
- output: 'filename',
- colour: 160,
- nextStatement: 'Action',
- tooltip:
- 'Represents a wildcard for filenames. For wildcard in start or end leave relevant field empty',
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([fileSearchListBlock]);
diff --git a/public/blocks/outOfUse/fileTypeSearchBlock.js b/public/blocks/outOfUse/fileTypeSearchBlock.js
deleted file mode 100644
index bb84bbf..0000000
--- a/public/blocks/outOfUse/fileTypeSearchBlock.js
+++ /dev/null
@@ -1,24 +0,0 @@
-var fileTypeSearchBlock = {
- type: 'fileTypeSearch',
- category: 'File and Directory Operations',
- unix_description: [
- {
- fileTypeSearch: '*.str'
- }
- ],
- message0: 'search files of type %1',
- args0: [
- {
- type: 'field_input',
- name: 'fileTypeSearch',
- text: 'csv' // default text for the input
- }
- ],
- tooltip: 'search in the directory files of chosen type',
- previousStatement: 'Action',
- nextStatement: 'Action',
- colour: 340,
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([fileTypeSearchBlock]);
diff --git a/public/blocks/outOfUse/fileWildcardBlock.js b/public/blocks/outOfUse/fileWildcardBlock.js
deleted file mode 100644
index 734b5c7..0000000
--- a/public/blocks/outOfUse/fileWildcardBlock.js
+++ /dev/null
@@ -1,40 +0,0 @@
-var fileWildcardBlock = {
- type: 'fileWildcard',
- unix_description: [
- {
- wildcard: 'pattStart?pattEnd'
- }
- ],
- message0: 'Use wildcard in file searching\n',
- message1: 'Number of times %1 \n',
- args1: [
- {
- type: 'field_number',
- name: 'METRIC',
- value: 1
- }
- ],
- message2: 'file start %1\n file end %2',
- args2: [
- {
- type: 'field_input',
- name: 'pattStart',
- text: '............' // empty text for user to define filename
- },
- {
- type: 'field_input',
- name: 'pattEnd',
- text: '............' // empty text for user to define filename
- }
- ],
-
- output: 'filename',
- // colour: 160,
- style: 'filename_style',
- nextStatement: 'Action',
- tooltip:
- 'Represents a wildcard for filenames. For wildcard in start or end leave relevant field empty',
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([fileWildcardBlock]);
diff --git a/public/blocks/outOfUse/headersBlock.js b/public/blocks/outOfUse/headersBlock.js
deleted file mode 100644
index d49be0c..0000000
--- a/public/blocks/outOfUse/headersBlock.js
+++ /dev/null
@@ -1,31 +0,0 @@
-var headersBlock = {
- type: 'headers',
- category: 'Data Processing',
- unix_description: [
- {
- headersBegin: 'BEGIN {print "str"}'
- }
- ],
- message0: 'file headers %1\n separate with commas',
- args0: [
- {
- type: 'field_input',
- name: 'headersBegin',
- text: ''
- }
- ],
- message1: 'delimeter %1',
- args1: [
- {
- type: 'field_input',
- name: 'awkInput_delimiter',
- text: ''
- }
- ],
- colour: 450,
- nextStatement: 'Action',
- tooltip: 'put headers in the outpu results data',
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([headersBlock]);
diff --git a/public/blocks/outOfUse/lastFieldBlock.js b/public/blocks/outOfUse/lastFieldBlock.js
deleted file mode 100644
index 3247575..0000000
--- a/public/blocks/outOfUse/lastFieldBlock.js
+++ /dev/null
@@ -1,11 +0,0 @@
-var lastFieldBlock = {
- type: 'NF',
- category: 'awk',
- message0: 'get last column %1',
- args0: [{}],
- output: 'String',
- nextStatement: null,
- colour: 510
-};
-
-Blockly.defineBlocksWithJsonArray([lastFieldBlock]);
diff --git a/public/blocks/outOfUse/loopOutputBlock.js b/public/blocks/outOfUse/loopOutputBlock.js
deleted file mode 100644
index 99c6d2f..0000000
--- a/public/blocks/outOfUse/loopOutputBlock.js
+++ /dev/null
@@ -1,17 +0,0 @@
-var loopOutputBlock = {
- type: 'loopOutput',
- category: 'awk',
- message0: 'Put loop',
- message1: '%1',
- args1: [
- {
- type: 'input_statement',
- name: 'DO'
- }
- ],
- output: 'String',
- nextStatement: null,
- colour: 510
-};
-
-Blockly.defineBlocksWithJsonArray([loopOutputBlock]);
diff --git a/public/blocks/outOfUse/multipleVariablesBlock.js b/public/blocks/outOfUse/multipleVariablesBlock.js
deleted file mode 100644
index a0bf61d..0000000
--- a/public/blocks/outOfUse/multipleVariablesBlock.js
+++ /dev/null
@@ -1,167 +0,0 @@
-var multipleVariablesBlock = {
- type: 'multipleVariables',
- category: 'awk',
- message0: '%{BKY_VAR_CREATE_WITH} %1',
- args0: [
- {
- type: 'input_dummy',
- name: 'EMPTY'
- }
- ],
- output: 'String',
- style: 'list_blocks',
- helpUrl: '%{BKY_VAR_CREATE_WITH_HELPURL}',
- tooltip: '%{BKY_VAR_CREATE_WITH_TOOLTIP}',
- mutator: 'new_list_create_with_mutator_Var'
-};
-
-Blockly.defineBlocksWithJsonArray([multipleVariablesBlock]);
-
-const listCreateMutator_Var = {
- /**
- * Number of item inputs the block has.
- * @type {number}
- */
- itemCount_: 0,
-
- /**
- * Creates XML to represent number of text inputs.
- * @returns {!Element} XML storage element.
- * @this {Blockly.Block}
- */
- mutationToDom: function () {
- const container = Blockly.utils.xml.createElement('mutation');
- container.setAttribute('items', this.itemCount_);
- return container;
- },
- /**
- * Parses XML to restore the text inputs.
- * @param {!Element} xmlElement XML storage element.
- * @this {Blockly.Block}
- */
- domToMutation: function (xmlElement) {
- const targetCount = parseInt(xmlElement.getAttribute('items'), 10);
- this.updateShape_(targetCount);
- },
-
- /**
- * Returns the state of this block as a JSON serializable object.
- * @returns {{itemCount: number}} The state of this block, ie the item count.
- */
- saveExtraState: function () {
- return {
- itemCount: this.itemCount_
- };
- },
-
- /**
- * Applies the given state to this block.
- * @param {*} state The state to apply to this block, ie the item count.
- */
- loadExtraState: function (state) {
- this.updateShape_(state['itemCount']);
- },
-
- /**
- * Adds inputs to the block until it reaches the target number of inputs.
- * @param {number} targetCount The target number of inputs for the block.
- * @this {Blockly.Block}
- * @private
- */
- updateShape_: function (targetCount) {
- while (this.itemCount_ < targetCount) {
- this.addPart_();
- }
- while (this.itemCount_ > targetCount) {
- this.removePart_();
- }
- this.updateMinus_();
- },
-
- /**
- * Callback for the plus image. Adds an input to the end of the block and
- * updates the state of the minus.
- */
- plus: function () {
- this.addPart_();
- this.updateMinus_();
- },
-
- /**
- * Callback for the minus image. Removes an input from the end of the block
- * and updates the state of the minus.
- */
- minus: function () {
- if (this.itemCount_ == 0) {
- return;
- }
- this.removePart_();
- this.updateMinus_();
- },
-
- // To properly keep track of indices we have to increment before/after adding
- // the inputs, and decrement the opposite.
- // Because we want our first input to be ADD0 (not ADD1) we increment after.
-
- /**
- * Adds an input to the end of the block. If the block currently has no
- * inputs it updates the top 'EMPTY' input to receive a block.
- * @this {Blockly.Block}
- * @private
- */
- addPart_: function () {
- if (this.itemCount_ == 0) {
- this.removeInput('EMPTY');
- this.topInput_ = this.appendValueInput('ADD' + this.itemCount_)
- .appendField(createPlusField(), 'PLUS')
- .appendField(Blockly.Msg['VAR_CREATE_WITH']);
- } else {
- this.appendValueInput('ADD' + this.itemCount_);
- }
- this.itemCount_++;
- },
-
- /**
- * Removes an input from the end of the block. If we are removing the last
- * input this updates the block to have an 'EMPTY' top input.
- * @this {Blockly.Block}
- * @private
- */
- removePart_: function () {
- this.itemCount_--;
- this.removeInput('ADD' + this.itemCount_);
- if (this.itemCount_ == 0) {
- this.topInput_ = this.appendDummyInput('EMPTY')
- .appendField(createPlusField(), 'PLUS')
- .appendField(Blockly.Msg['VAR_CREATE_EMPTY_TITLE']);
- }
- },
-
- /**
- * Makes it so the minus is visible iff there is an input available to remove.
- * @private
- */
- updateMinus_: function () {
- const minusField = this.getField('MINUS');
- if (!minusField && this.itemCount_ > 0) {
- this.topInput_.insertFieldAt(1, createMinusField(), 'MINUS');
- } else if (minusField && this.itemCount_ < 1) {
- this.topInput_.removeField('MINUS');
- }
- }
-};
-
-/**
- * Updates the shape of the block to have 3 inputs if no mutation is provided.
- * @this {Blockly.Block}
- */
-const listCreateHelper_Var = function () {
- this.getInput('EMPTY').insertFieldAt(0, createPlusField(), 'PLUS');
- this.updateShape_(2);
-};
-
-Blockly.Extensions.registerMutator(
- 'new_list_create_with_mutator_Var',
- listCreateMutator_Var,
- listCreateHelper_Var
-);
diff --git a/public/blocks/outOfUse/negateBlock.js b/public/blocks/outOfUse/negateBlock.js
deleted file mode 100644
index 4033b22..0000000
--- a/public/blocks/outOfUse/negateBlock.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var negateBlock = {
- type: 'negate',
- category: 'awk',
- unix_description: [
- {
- negate: '!'
- }
- ],
- message0: '%{BKY_NEGATE_NOT}',
- args0: [
- {
- type: 'input_value',
- name: 'negate'
- }
- ],
- output: 'Boolean',
- style: 'logic_blocks',
- tooltip: '%{BKY_NEGATE_TOOLTIP}',
- helpUrl: '%{BKY_NEGATE_HELPURL}'
-};
-
-Blockly.defineBlocksWithJsonArray([negateBlock]);
diff --git a/public/blocks/outOfUse/readBlock.js b/public/blocks/outOfUse/readBlock.js
deleted file mode 100644
index 8e34d09..0000000
--- a/public/blocks/outOfUse/readBlock.js
+++ /dev/null
@@ -1,24 +0,0 @@
-var readBlock = {
- type: 'read',
- category: 'I/O Redirection',
- unix_description: [
- {
- read: 'read str'
- }
- ],
- message0: 'User variable input %1\n',
- args0: [
- {
- type: 'field_input',
- name: 'read',
- text: '............'
- }
- ],
- colour: 876,
- previousStatement: 'Action',
- nextStatement: 'Action',
- tooltip: 'Prompt action to user for input variable',
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([readBlock]);
diff --git a/public/blocks/outOfUse/regDigitBlock.js b/public/blocks/outOfUse/regDigitBlock.js
deleted file mode 100644
index bc8119d..0000000
--- a/public/blocks/outOfUse/regDigitBlock.js
+++ /dev/null
@@ -1,28 +0,0 @@
-var regDigitBlock = {
- type: 'regDigit',
- unix_description: [
- {
- digit: '\\d',
- nonDigit: '\\D'
- }
- ],
- category: 'Regular Expressions',
- message0: 'Digit matching \n %1',
- args0: [
- {
- type: 'field_dropdown',
- name: 'digit_match',
- options: [
- ['Match a digit ', 'digit'],
- ['Match Non digit', 'nonDigit']
- ]
- }
- ],
- tooltip: 'Match any digit or match all except a digit',
- previousStatement: 'Action',
- nextStatement: 'Action',
- colour: 510,
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([regDigitBlock]);
diff --git a/public/blocks/outOfUse/regWhitespaceBlock.js b/public/blocks/outOfUse/regWhitespaceBlock.js
deleted file mode 100644
index 88f755d..0000000
--- a/public/blocks/outOfUse/regWhitespaceBlock.js
+++ /dev/null
@@ -1,28 +0,0 @@
-var regWhitespaceBlock = {
- type: 'regWhitespace',
- unix_description: [
- {
- whitespace: '\\s',
- nonWhitespace: '\\S'
- }
- ],
- category: 'Regular Expressions',
- message0: 'Whitespace matching\n %1',
- args0: [
- {
- type: 'field_dropdown',
- name: 'char_match',
- options: [
- ['Match a whitespace ', 'whitespace'],
- ['Match Non whitespaces', 'nonWhitespace']
- ]
- }
- ],
- tooltip: 'Match any whitespace or all except whitespaces',
- previousStatement: 'Action',
- nextStatement: 'Action',
- colour: 590,
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([regWhitespaceBlock]);
diff --git a/public/blocks/outOfUse/regWordCharBlock.js b/public/blocks/outOfUse/regWordCharBlock.js
deleted file mode 100644
index 1c77478..0000000
--- a/public/blocks/outOfUse/regWordCharBlock.js
+++ /dev/null
@@ -1,28 +0,0 @@
-var regWordCharBlock = {
- type: 'regWordChar',
- unix_description: [
- {
- wordChar: '\\w',
- nonWordChar: '\\W'
- }
- ],
- category: 'Regular Expressions',
- message0: 'Word character matcthing \n %1',
- args0: [
- {
- type: 'field_dropdown',
- name: 'char_match',
- options: [
- ['Match a word char ', 'wordChar'],
- ['Match Non word chars', 'nonWordChar']
- ]
- }
- ],
- tooltip: 'Match any word character or match all except word characters',
- previousStatement: 'Action',
- nextStatement: 'Action',
- colour: 550,
- helpUrl: '' // URL to further information or documentation.
-};
-
-Blockly.defineBlocksWithJsonArray([regWordCharBlock]);
diff --git a/public/blocks/outOfUse/variableBlock.js b/public/blocks/outOfUse/variableBlock.js
deleted file mode 100644
index 32a2b42..0000000
--- a/public/blocks/outOfUse/variableBlock.js
+++ /dev/null
@@ -1,30 +0,0 @@
-var variableBlock = {
- type: 'variableDefine',
- category: 'awk',
- unix_description: [
- {
- var: 'var', // Change to awk_delimiter
- init: 'init' // Change to awk_delimiter
- }
- ],
- message0: 'Define variable\n',
- message1: '%1 = %2',
- args1: [
- {
- type: 'input_value',
- name: 'var'
- },
- {
- type: 'input_value',
- name: 'init'
- }
- ],
- inputsInline: true,
- output: 'String',
- nextStatement: 'Action',
- style: 'logic_blocks',
- helpUrl: '',
- tooltip: 'define a variable'
-};
-
-Blockly.defineBlocksWithJsonArray([variableBlock]);
diff --git a/public/blocks/outOfUse/variablePassBlock.js b/public/blocks/outOfUse/variablePassBlock.js
deleted file mode 100644
index 93d7896..0000000
--- a/public/blocks/outOfUse/variablePassBlock.js
+++ /dev/null
@@ -1,18 +0,0 @@
-var variablePassBlock = {
- type: 'variablePass',
- category: 'awk',
- message0: 'Include variable in pipeline \n %1',
- args0: [
- {
- type: 'input_value',
- name: 'varPass'
- }
- ],
- previousStatement: 'Action',
- nextStatement: 'Action',
- style: 'logic_blocks',
- helpUrl: '',
- tooltip: 'Include variable in pipeline'
-};
-
-Blockly.defineBlocksWithJsonArray([variablePassBlock]);
diff --git a/public/main.js b/public/main.js
index 8c38489..228bc1b 100644
--- a/public/main.js
+++ b/public/main.js
@@ -10,6 +10,137 @@ function initBlockly() {
loadWorkspace(); // Load the workspace after initialization
}
+const state = Blockly.serialization.workspaces.save(workspace);
+
+document.addEventListener('DOMContentLoaded', () => {
+ fetch('/auth-token')
+ .then((response) => response.json())
+ .then((data) => {
+ const token = data.authToken;
+ const user = data.user;
+ if (token) {
+ document.getElementById('savedWorkspaces').style.display =
+ 'inline-block';
+
+ fetch(`/getUserWorkspaces?userId=${user.id}`)
+ .then((response) => response.json())
+ .then((data) => {
+ const workspaces = data.workspaces;
+ const savedWorkspacesSelect =
+ document.getElementById('savedWorkspaces');
+
+ // Clear any existing options
+ savedWorkspacesSelect.innerHTML = '';
+
+ // Add a default option
+ const defaultOption = document.createElement('option');
+ defaultOption.value = '';
+ defaultOption.text = 'Select a workspace';
+ savedWorkspacesSelect.appendChild(defaultOption);
+
+ // Populate dropdown with the user's saved workspaces
+ workspaces.forEach((workspace) => {
+ const option = document.createElement('option');
+ option.value = workspace.id; // use the ID as the option value
+ option.text = workspace.workspaceName; // display the workspace name
+ savedWorkspacesSelect.appendChild(option);
+ });
+
+ savedWorkspacesSelect.addEventListener('change', () => {
+ const selectedWorkspaceId = savedWorkspacesSelect.value;
+
+ if (selectedWorkspaceId) {
+ fetch(`/getWorkspace?workspaceId=${selectedWorkspaceId}`)
+ .then((response) => response.json())
+ .then((data) => {
+ if (data.workspaceData) {
+ const workspaceState = JSON.parse(data.workspaceData);
+ // Deserialize and load the workspace
+ Blockly.serialization.workspaces.load(
+ workspaceState,
+ workspace
+ );
+ } else {
+ console.error(
+ 'Failed to load workspace: Invalid workspace data.'
+ );
+ alert('Failed to load workspace. Please try again.');
+ }
+ })
+ .catch((error) => {
+ console.error('Error loading workspace:', error);
+ alert('Failed to load workspace. Please try again.');
+ });
+ }
+ });
+ })
+ .catch((error) => {
+ console.error('Error fetching user workspaces:', error);
+ });
+
+ document.getElementById('saveButton').style.display = 'inline-block';
+
+ document
+ .getElementById('saveButton')
+ .addEventListener('click', (event) => {
+ event.preventDefault(); // Prevent default form submission behavior
+
+ // Ask the user for the workspace name
+ const workspaceName = prompt('Enter a name for your workspace:');
+
+ if (!workspaceName || workspaceName.trim() === '') {
+ alert('Workspace name cannot be empty.');
+ return;
+ }
+
+ // Serialize the workspace state to JSON
+ const state = Blockly.serialization.workspaces.save(workspace);
+ const jsonState = JSON.stringify(state);
+
+ // Ensure jsonState, user.id, and workspaceName are valid before submitting
+ if (jsonState && user.id && workspaceName.trim() !== '') {
+ // Set the value of the hidden input fields in the form
+ document.getElementById('workspaceData').value = jsonState;
+ document.getElementById('userId').value = user.id;
+ document.getElementById('workspaceName').value = workspaceName;
+
+ // Use AJAX to send the data to the server without redirecting
+ fetch('/saveWorkspace', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ workspaceData: jsonState,
+ userId: user.id,
+ workspaceName: workspaceName
+ })
+ })
+ .then((response) => response.json())
+ .then((result) => {
+ if (result.error) {
+ console.error('Error saving workspace:', result.error);
+ alert('Failed to save workspace. Please try again.');
+ } else {
+ alert('Workspace saved successfully.');
+ }
+ })
+ .catch((error) => {
+ alert('Failed to save workspace. Please try again.');
+ });
+ } else {
+ console.error(
+ 'Invalid workspace data, user ID, or workspace name.'
+ );
+ alert('Failed to save workspace. Invalid data.');
+ }
+ });
+ }
+ })
+ .catch((error) => {
+ console.error('Error fetching the token:', error);
+ });
+});
document
.getElementById('themeDropdown')
.addEventListener('change', function (event) {
diff --git a/server.js b/server.js
index ea4d325..7bafb6e 100644
--- a/server.js
+++ b/server.js
@@ -26,7 +26,6 @@ const db = new sqlite3.Database('blockly_unix_database.db', (err) => {
if (err) {
console.error(err.message);
}
- console.log('Connected to the blockly_unix database.');
});
const { body, validationResult } = require('express-validator');