Skip to content

Commit 9e2812e

Browse files
authored
Merge pull request simosathan9#6 from AUEB-BALab/simosathan9-main
UBlocks refactoring
2 parents fd69952 + 8882796 commit 9e2812e

File tree

126 files changed

+6786
-3158
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+6786
-3158
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
node_modules
22
.DS_Store
33
npm-debug.log
4-
.env
4+
.env
5+
.history
6+
bin/pre-commit
7+
.idea

README.md

Lines changed: 134 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,21 @@
22

33
This is a development environment based on **Blockly** where users can easily construct data processing pipelines
44
by visually plugging together processing blocks. The pipeline will be implemented underneath using Unix tools.
5-
![Picture2](https://github.com/vcipi/blockly_unix/assets/108274884/8bb6be00-a88b-4145-bb61-8be70e9b5c58)
5+
![Picture2](public/img/README_cover.png)
66

77
# Summary
88

99
The purpose of this project is to present a unique framework that makes use of Blockly, a visual programming language, to represent Unix commands as graphical blocks and to convey their abstractions. Through simplifying the way of their operation and the elimination of the requirement for specialist programming expertise, this method intends to make Unix utilities more accessible to a wider audience.The thesis provides an explanation of the development of a visual programming interface that simplifies the utilization of Unix command-line tools by allowing users to design data processing pipelines by dragging and dropping components. Visual blocks are connected to Unix instructions through the use of JSON specification files, which are utilized by the system in order to facilitate the conversion process.
1010

1111
The user-friendliness of data processing activities is improved as a result of this deliberate design choice, and users are encouraged to develop a deeper understanding of Unix commands. Increasing the accessibility of complex data manipulation is one of the goals of this initiative, which also aims to encourage more people to participate in computational data analysis.The findings of the project underline the significance of visual programming in the process of combining complex command-line activities with user-friendly interfaces. This, in turn, broadens the range of tools that are available to data scientists and researchers working in a variety of fields. This research not only makes a contribution to the field of visual programming, but it also opens up new possibilities for instructional tools that facilitate the acquisition of command-line interfaces using approaches that are both interactive and interesting.
1212

13-
# Installation Instructions
13+
# Set up instructions
1414

15-
1. Follow the instructions on how to download and install **Blockly** locally on your PC on the official **Blockly** repository : https://github.com/google/blockly
16-
2. Clone this project into the **_demos_** directory of **Blockly** you installed
15+
To run UBlocks on a local server, navigate to the top-level directory and start the development server by running the following command:
1716

18-
![Picture5](https://github.com/vcipi/blockly_unix/assets/108274884/53cfa7bf-2c1f-4ac4-a211-524376e28ebf)
17+
`npm run devStart`
1918

20-
4. Run the **_index.html_** file.
21-
22-
![Picture4](https://github.com/vcipi/blockly_unix/assets/108274884/9b70b5a0-c3f0-4973-9ed4-fbbe62479835)
23-
24-
5. Your browser should initiate the application so you can begin.
25-
26-
![Picture3](https://github.com/vcipi/blockly_unix/assets/108274884/67304620-7e13-4718-973e-55cf3f2e296c)
27-
28-
# Setting Up Pre-commit Hook
19+
## Setting Up Pre-commit Hook
2920

3021
To ensure that code is properly formatted before committing, set up the pre-commit hook by following these steps :
3122

@@ -37,6 +28,135 @@ To ensure that code is properly formatted before committing, set up the pre-comm
3728

3829
`chmod +x .git/hooks/pre-commit bin/pre-commit`
3930

31+
# How to Create a New Block
32+
33+
Below are the instructions on how to create a new block in a separate file (e.g., `[blockName]Block.js`), and how to integrate it into the existing code generation system (`UnixGenerator`) that we have already implemented.
34+
35+
## 1. Create a New File for Your Block
36+
37+
Inside the folder where you keep your blocks (`blocks/`), create a new file named `[blockName]Block.js`.
38+
For instance, if you want to create a block for a command called `foo`, you can name it `fooBlock.js`.
39+
40+
## 2. Define the Block Using a JSON Schema
41+
42+
In this new file, define your block using the JSON schema required by Blockly. Below is a basic structure:
43+
44+
```js
45+
var fooBlock = {
46+
type: 'foo', // Unique name for the block
47+
category: 'My Custom Category', // Category in which the block will appear in the toolbox
48+
unix_description: [
49+
// The "unix_description" array defines how totranslate the block into a Unix command.
50+
{
51+
foo: 'customFoo',
52+
printName: true, // "printName" specifies whether the block's type should appear explicitly in the generated command.
53+
// Static Handling
54+
myStaticField: '-s',
55+
myDynamicField: (fieldValues) => {
56+
// Example: Append the field value with a prefix
57+
return `--option=${fieldValues['myDynamicField']}`;
58+
}
59+
}
60+
],
61+
message0: 'Message displayed on the block %1',
62+
args0: [
63+
{
64+
type: 'field_input',
65+
name: 'myStaticField',
66+
text: 'default value'
67+
}
68+
],
69+
message1: 'Message displayed on the block %1',
70+
args1: [
71+
{
72+
type: 'field_input',
73+
name: 'myDynamicField',
74+
text: 'default value'
75+
}
76+
],
77+
// Configuration for block connections (input, output, statement, etc.)
78+
previousStatement: 'Action',
79+
nextStatement: 'Action',
80+
style: 'My Custom Category',
81+
tooltip: 'Description of what this block does',
82+
helpUrl: '' // Optional: link to further documentation
83+
};
84+
85+
// Register the block with Blockly
86+
Blockly.defineBlocksWithJsonArray([fooBlock]);
87+
88+
// Register the generator handler for this block
89+
window.unixGenerator.forBlock['foo'] = window.unixGenerator.forBlock.generic;
90+
```
91+
92+
### 2.1 Managing `unix_description`
93+
94+
In the **UnixGenerator** architecture, each **Blockly** block has an associated `unix_description`, which describes how its fields (`fieldValues`) and child blocks (`childCode`) should be translated into a Unix command. Also it is crucial that the keys used in unix_description correspond exactly to the names of the fields defined in args. This ensures that the generator can correctly map field values to their respective parts in the Unix command. Below is a high-level overview of how this works:
95+
96+
#### 2.1.1 **`unix_description` Structure**
97+
98+
- Typically, `unix_description` is an array of one or more objects. Each object specifies functions and/or flags that define how to compose the final command.
99+
- Example:
100+
```js
101+
unix_description: [
102+
{
103+
printName: true, // Determines if the block's type should be printed in the command
104+
someFieldName: '-f', // Static string to be added if the field is active
105+
// Function to dynamically process fieldValues and childCode
106+
someInputStatementName: (fieldValues, childCode) => {
107+
// process fieldValues and childCode
108+
return `-x ${childCode}`;
109+
}
110+
}
111+
];
112+
```
113+
114+
#### 2.1.2 **Using Functions vs. Static Strings**
115+
116+
- **Functions**: If you need to dynamically combine or manipulate `fieldValues` and `childCode`, you can define a function in `unix_description`:
117+
```js
118+
someFieldName: (fieldValues, childCode) => {
119+
return `-o ${fieldValues['someParam']} ${childCode}`;
120+
};
121+
```
122+
This function will be called by the generator, and whatever string it returns will be appended to the command.
123+
- **Static Strings**: If you only need a fixed flag (e.g., `-r`, `--verbose`), you can simply specify a string:
124+
```js
125+
someFieldName: '-r';
126+
```
127+
The generator will automatically add `-r` when the corresponding field is “checked” or “selected,” depending on your field definition.
128+
129+
#### 2.1.3 **Choosing `generic` vs. `concat` Block Handlers**
130+
131+
- In your main generator setup, you decide how each block’s code is combined with subsequent blocks. You can choose:
132+
```js
133+
window.unixGenerator.forBlock['foo'] = window.unixGenerator.forBlock.generic;
134+
```
135+
or
136+
```js
137+
window.unixGenerator.forBlock['foo'] = window.unixGenerator.forBlock.concat;
138+
```
139+
- **`generic`**: This handler typically adds a pipe symbol (`|`) between commands, following the standard Unix “piping” convention.
140+
- **`concat`**: This handler concatenates the output without a pipe or spaces, or uses a different connector if defined. It’s useful for scenarios where multiple arguments are strung together (e.g., building up a filename or a single argument line).
141+
142+
#### 2.1.4 Customizing Output with Block Names
143+
144+
**Specifying the Block's Name in `unix_description`:**
145+
You can override the default block name in the generated command by specifying a different key in `unix_description`. For example:
146+
147+
```js
148+
unix_description: [
149+
{
150+
foo: 'customFoo', // Instead of printing 'foo', it will print 'customFoo' in the command
151+
printName: true
152+
}
153+
];
154+
```
155+
156+
In this case, if the block's type is 'foo' and you set 'foo': 'customFoo' in unix_description, the generated command will include 'customFoo' instead of 'foo'. 3. Format the code by running the following command:
157+
158+
`npm run prettier-fix`
159+
40160
# Further information
41161

42162
The work behind this project is further documented in MSc theses by

0 commit comments

Comments
 (0)