Skip to content

Commit 552f75e

Browse files
committed
wip #45
1 parent 634e8df commit 552f75e

File tree

6 files changed

+73
-42
lines changed

6 files changed

+73
-42
lines changed

package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"blockly": "^7.20211209.2",
2121
"core-js": "^3.6.5",
2222
"material-design-icons-iconfont": "^6.1.1",
23+
"@mdi/font": "^6.5.95",
2324
"prismjs": "^1.26.0",
2425
"stylus-loader": "^3.0.2",
2526
"typeface-fira-mono": "^1.1.13",

src/components/Activity.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -553,15 +553,19 @@ export default {
553553
// Extend the default blocks set
554554
this.blocksExtensions(settings);
555555
556-
const toolboxLevel = settings.prog_level;
557-
const toolbox = require(`../assets/toolbox_${toolboxLevel}.xml`);
556+
let serializedToolbox = null;
557+
if (this.activity.toolbox == null) {
558+
const toolboxLevel = settings.prog_level;
559+
const toolbox = require(`../assets/toolbox_${toolboxLevel}.xml`);
558560
559-
// Clean the base64 encoding of the resource, removing meta infos
560-
const b64Toolbox = toolbox.substring(toolbox.indexOf(',') + 1).toString();
561-
562-
// Decode it and get the clean serialized XML as plain string
563-
const serializedToolbox = this.$base64.decode(b64Toolbox);
561+
// Clean the base64 encoding of the resource, removing meta infos
562+
const b64Toolbox = toolbox.substring(toolbox.indexOf(',') + 1).toString();
564563
564+
// Decode it and get the clean serialized XML as plain string
565+
serializedToolbox = this.$base64.decode(b64Toolbox);
566+
} else {
567+
serializedToolbox = this.activity.toolbox;
568+
}
565569
// Initialise Blockly Instance
566570
// Blockly.Generator.prototype.INDENT = ' ';
567571
this.workspace = Blockly.inject(

src/components/ActivityEditor.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@
286286
</v-container>
287287
</v-tab-item>
288288
<v-tab-item>
289-
<toolbox-editor />
289+
<toolbox-editor
290+
v-model="activity.toolbox"
291+
:toolbox_in="activity.toolbox"
292+
/>
290293
</v-tab-item>
291294
</v-tabs-items>
292295
</v-main>
@@ -443,6 +446,7 @@ export default {
443446
availableViews: [],
444447
viewSource: null,
445448
autoRecVideo: null,
449+
toolbox: null
446450
},
447451
colors: ['red', 'pink', 'purple', 'yellow', 'deep-purple', 'indigo', 'blue', 'light-blue', 'cyan', 'teal',
448452
'green', 'light-green', 'lime', 'yellow', 'amber', 'orange', 'deep-orange', 'brown', 'blue-grey', 'black',
@@ -654,6 +658,9 @@ export default {
654658
},
655659
];
656660
},
661+
onToolboxSave() {
662+
console.log(this.activity.toolbox);
663+
},
657664
},
658665
};
659666
</script>

src/components/ToolboxEditor.vue

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
</v-list-item-content>
2727
<v-list-item-icon>
2828
<v-icon @click="editCategory(i)">edit</v-icon>
29-
<v-icon @click="upCategory(i)">sort</v-icon>
30-
<v-icon @click="downCategory(i)">stop</v-icon>
29+
<v-icon @click="upCategory(i)">mdi-arrow-up</v-icon>
30+
<v-icon @click="downCategory(i)">mdi-arrow-down</v-icon>
3131
<v-icon @click="deleteCategory(i)">delete</v-icon>
3232
</v-list-item-icon>
3333
</v-list-item>
@@ -71,44 +71,46 @@
7171
<script>
7272
import * as Blockly from 'blockly/core';
7373
import 'blockly/blocks';
74+
import 'blockly/python';
75+
7476
import * as blockly_it from 'blockly/msg/it';
7577
import * as blockly_en from 'blockly/msg/en';
7678
import * as blockly_fr from 'blockly/msg/fr';
77-
/*
79+
7880
import '../assets/js/blockly/blocks';
7981
import * as bot_it from '../assets/js/blockly/bot_it.json';
8082
import * as bot_en from '../assets/js/blockly/bot_en.json';
8183
import * as bot_fr from '../assets/js/blockly/bot_fr.json';
82-
*/
84+
8385
import i18n from '../i18n/index';
8486
8587
const locale = i18n.locale.substring(0, 2);
86-
/*
88+
8789
const coderbot_locales = {
8890
it: bot_it.default,
8991
en: bot_en.default,
9092
fr: bot_fr.default
9193
};
9294
Blockly.Msg = { ...Blockly.Msg, ...coderbot_locales[locale] };
93-
*/
95+
9496
const blockly_locales = {
9597
it: blockly_it,
9698
en: blockly_en,
9799
fr: blockly_fr
98100
};
99101
Blockly.setLocale(blockly_locales[locale]);
100102
101-
// Blockly.Blocks.CoderBotSettings.instrumentlist = [];
102-
// Blockly.Blocks.CoderBotSettings.animalist = [];
103+
Blockly.Blocks.CoderBotSettings.instrumentlist = [];
104+
Blockly.Blocks.CoderBotSettings.animalist = [];
103105
104106
export default {
105-
components: {
106-
},
107+
props: ['toolbox_in'],
107108
data: () => ({
108109
CB: process.env.CB_ENDPOINT + process.env.APIv2,
109110
CBv1: process.env.CB_ENDPOINT,
110111
workspace_toolbox_editor: null,
111112
workspace_toolbox_test: null,
113+
in_changing_category: true,
112114
toolbox: {
113115
kind: 'categoryToolbox',
114116
contents: []
@@ -122,10 +124,11 @@ export default {
122124
category_index: null
123125
}),
124126
125-
computed: {
126-
},
127-
128127
mounted() {
128+
if (this.toolbox_in) {
129+
this.toolbox = this.toolbox_in;
130+
}
131+
129132
this.loadMusicPackages();
130133
131134
const axios = this.$axios;
@@ -136,6 +139,9 @@ export default {
136139
const settings = response.data;
137140
this.settings = settings;
138141
this.initBlockly(settings);
142+
if (this.toolbox.contents.length) {
143+
this.onChangeCategory();
144+
}
139145
});
140146
},
141147
beforeRouteLeave(to, from, next) {
@@ -165,22 +171,20 @@ export default {
165171
},
166172
167173
onChangeCategory() {
168-
this.workspace_toolbox_editor.clear();
169-
this.in_changing_category = true;
170-
this.toolbox.contents[this.category_index].contents.forEach((block) => {
171-
const parentBlock = this.workspace_toolbox_editor.newBlock(block.type);
172-
parentBlock.initSvg();
173-
parentBlock.render();
174-
parentBlock.bumpNeighbours();
175-
});
176-
/* const blocks = this.workspace_toolbox_editor.getTopBlocks();
177-
let y = 0;
178-
for (let i = 0; i < blocks.length; i++) {
179-
blocks[i].moveTo(0, y);
180-
y += blocks[i].getHeightWidth().height;
181-
y += 10; // buffer
182-
} */
183-
this.in_changing_category = false;
174+
if (this.category_index != null
175+
&& this.workspace_toolbox_editor != null) {
176+
this.in_changing_category = true;
177+
this.workspace_toolbox_editor.clear();
178+
let y = 0;
179+
this.toolbox.contents[this.category_index].contents.forEach((block) => {
180+
const parentBlock = this.workspace_toolbox_editor.newBlock(block.type);
181+
parentBlock.initSvg();
182+
parentBlock.render();
183+
parentBlock.moveTo(new Blockly.utils.Coordinate(5, y));
184+
y += parentBlock.getHeightWidth().height + 10;
185+
});
186+
this.in_changing_category = false;
187+
}
184188
},
185189
186190
addCategory() {
@@ -201,6 +205,7 @@ export default {
201205
this.category_index = i;
202206
this.category = this.toolbox.contents[i];
203207
this.category_edit = true;
208+
this.category_dialog = true;
204209
},
205210
206211
saveCategory() {
@@ -236,7 +241,7 @@ export default {
236241
// Extend the default blocks set
237242
this.blocksExtensions();
238243
239-
const toolbox_full = require('../assets/toolbox_less.xml');
244+
const toolbox_full = require('../assets/toolbox_adv.xml');
240245
241246
// Clean the base64 encoding of the resource, removing meta infos
242247
const b64Toolbox = toolbox_full.substring(toolbox_full.indexOf(',') + 1).toString();
@@ -264,6 +269,7 @@ export default {
264269
},
265270
},
266271
);
272+
267273
// Initialise Blockly Instance Toolbox Editor
268274
this.workspace_toolbox_test = Blockly.inject(
269275
// Blockly container
@@ -289,9 +295,10 @@ export default {
289295
const toolbox = this.toolbox;
290296
const state = this;
291297
function onToolboxEditorChange(event) {
292-
if (event.type == Blockly.Events.BLOCK_CREATE
293-
|| (event.type == Blockly.Events.BLOCK_DELETE && state.in_changing_category == false)) {
294-
// || event.type == Blockly.Events.BLOCK_MOVE) {
298+
if ((event.type == Blockly.Events.BLOCK_CREATE
299+
|| event.type == Blockly.Events.BLOCK_DELETE
300+
|| event.type == Blockly.Events.BLOCK_MOVE)
301+
&& state.in_changing_category == false) {
295302
toolbox.contents[state.category_index].contents = [];
296303
workspace_toolbox_editor.getTopBlocks(true).forEach((ablock) => {
297304
toolbox.contents[state.category_index].contents.push({

src/plugins/vuetify.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import Vue from 'vue';
22
import Vuetify from 'vuetify/lib/framework';
33
import 'material-design-icons-iconfont/dist/material-design-icons.css'; // Ensure you are using css-loader
4+
import '@mdi/font/css/materialdesignicons.css';
45

56
Vue.use(Vuetify);
67

78
export default new Vuetify({
89
icons: {
9-
iconfont: 'md',
10+
iconfont: 'mdi',
1011
},
1112
});

0 commit comments

Comments
 (0)