33
33
<v-main >
34
34
<!-- Blockly -->
35
35
<blockly-workspace
36
+ v-if =" activity.editor!='code'"
36
37
ref =" workspace"
37
38
:settings =" settings"
38
39
:toolbox =" toolbox"
39
40
:theme =" theme.global.name.value"
40
41
@workspace-changed =" onWorkspaceChanged()"
41
42
>
42
43
</blockly-workspace >
44
+ <CodeEditor
45
+ v-else
46
+ theme =" default"
47
+ :languages =" [['python', 'Python']]"
48
+ :tab-spaces =" 4"
49
+ border-radius =" 0px"
50
+ :line-nums =" true"
51
+ width =" 100%"
52
+ height =" 100%"
53
+ v-model =" code" >
54
+ </CodeEditor >
43
55
</v-main >
44
56
<!-- Hidden file input. Its file dialog it's event-click triggered by the "pickFile" method -->
45
57
<input type =" file" style =" display : none " ref =" file" @change =" importProgram" >
222
234
<v-card id =" card_program_code" >
223
235
<v-card-title class =" headline" >{{ $t("message.program_code") }}</v-card-title >
224
236
<v-card-text class =" text-xs-left" >
225
- <prism language =" python" >{{ code }} </prism >
237
+ <CodeEditor
238
+ theme =" default"
239
+ :languages =" [['python', 'Python']]"
240
+ :tab-spaces =" 4"
241
+ border-radius =" 0px"
242
+ :line-nums =" true"
243
+ width =" 100%"
244
+ height =" 100%"
245
+ v-model =" code"
246
+ :read-only =" true" >
247
+ </CodeEditor >
226
248
</v-card-text >
227
249
<v-divider ></v-divider >
228
250
<v-card-actions >
280
302
import ' prismjs' ;
281
303
import ' prismjs/components/prism-python.js' ;
282
304
import Prism from ' vue-prism-component' ;
305
+ import hljs from ' highlight.js' ;
306
+ import CodeEditor from " simple-code-editor" ;
283
307
import { useTheme } from ' vuetify' ;
284
308
import sidebar from ' ./Sidebar.vue' ;
285
309
import BlocklyWorkspace from ' ./BlocklyWorkspace.vue' ;
@@ -290,6 +314,7 @@ export default {
290
314
sidebar,
291
315
BlocklyWorkspace,
292
316
Prism,
317
+ CodeEditor,
293
318
},
294
319
setup () {
295
320
return {
@@ -340,10 +365,15 @@ export default {
340
365
}),
341
366
computed: {
342
367
remainingCapacity () {
343
- return this .$refs .workspace .remainingCapacity ();
368
+ if (this .$data .activity .editor == ' code' ) {
369
+ return 0 ;
370
+ } else if (this .$data .activity .editor == ' blockly' ) {
371
+ return this .$refs .workspace .remainingCapacity ();
372
+ }
344
373
},
345
374
},
346
375
mounted () {
376
+ console .log (this .$data .activity )
347
377
this .webcamStream = this .$coderbot .streamVideoURL ();
348
378
this .settings = this .$store .getters .settings ;
349
379
let activityName = this .$route .params .name ;
@@ -417,7 +447,15 @@ export default {
417
447
// Build the program object
418
448
const name = this .programName ;
419
449
const { isDefault } = this ;
420
- const { dom_code , code } = this .$refs .workspace .getProgramData ();
450
+ var code = ' ' ;
451
+ var dom_code = ' ' ;
452
+ if (this .activity .editor == ' code' ) {
453
+ code = this .code ;
454
+ } else if (this .activity .editor == ' blockly' ) {
455
+ const { _dom_code , _code } = this .$refs .workspace .getProgramCode ();
456
+ dom_code = _dom_code;
457
+ code = _code;
458
+ }
421
459
return {
422
460
name,
423
461
dom_code,
@@ -461,7 +499,15 @@ export default {
461
499
fr .readAsText (files[0 ]);
462
500
fr .addEventListener (' load' , () => {
463
501
const importedProgram = JSON .parse (fr .result );
464
- this .$refs .workspace .loadProgram (importedProgram .dom_code );
502
+ if (this .activity .editor == ' code' ) {
503
+ this .$data .code = importedProgram .code ;
504
+ } else if (this .activity .editor == ' blockly' && importedProgram .dom_code != ' ' ) {
505
+ this .$refs .workspace .loadProgram (importedProgram .dom_code );
506
+ } else if (this .activity .editor == ' blockly' && importedProgram .dom_code == ' ' ) {
507
+ this .$data .generalDialogTitle = ' Error' ;
508
+ this .$data .generalDialogText = ' Cannot load python program in blockly editor' ;
509
+ this .$data .generalDialog = true ;
510
+ }
465
511
});
466
512
} else {
467
513
console .error (' Something went wrong importing' );
@@ -528,7 +574,16 @@ export default {
528
574
this .$data .carica = false ;
529
575
this .$data .programName = program;
530
576
this .$coderbot .loadProgram (this .$data .programName ).then ((data ) => {
531
- this .$refs .workspace .loadProgram (data .data .dom_code );
577
+ if (this .activity .editor == ' code' ) {
578
+ this .$data .code = data .data .code ;
579
+ } else if (this .activity .editor == ' blockly' && data .data .dom_code != ' ' ) {
580
+ this .$refs .workspace .loadProgram (data .data .dom_code );
581
+ } else if (this .activity .editor == ' blockly' && data .data .dom_code == ' ' ) {
582
+ console .error (' Cannot load python program in blockly editor' );
583
+ this .$data .generalDialogTitle = ' Error' ;
584
+ this .$data .generalDialogText = ' Cannot load python program in blockly editor' ;
585
+ this .$data .generalDialog = true ;
586
+ }
532
587
this .$data .isDefault = data .data .default ;
533
588
});
534
589
},
@@ -540,7 +595,9 @@ export default {
540
595
clearProgram () {
541
596
this .$data .programName = ' ' ;
542
597
this .$data .code = ' ' ;
543
- this .$refs .workspace .clear ();
598
+ if (this .$data .activity .editor == ' blockly' ) {
599
+ this .$refs .workspace .clear ();
600
+ }
544
601
this .$data .clear = false ;
545
602
this .dirty = true ;
546
603
},
@@ -554,22 +611,33 @@ export default {
554
611
if (this .$data .programName == program) {
555
612
this .$data .programName = ' ' ;
556
613
this .$data .code = ' ' ;
557
- this .$refs .workspace .clear ();
614
+ if (this .$data .activity .editor == ' blockly' ) {
615
+ this .$refs .workspace .clear ();
616
+ }
558
617
}
559
618
this .$coderbot .deleteProgram (program).then (() => {
560
619
console .info (' deleted' );
561
620
});
562
621
},
563
622
564
623
getProgramCode () {
565
- this .code = this .$refs .workspace .getProgramCode ();
624
+ if (this .$data .activity .editor == ' code' ) {
625
+ this .code = this .$data .code ;
626
+ } else if (this .$data .activity .editor == ' blockly' ) {
627
+ this .code = this .$refs .workspace .getProgramCode ();
628
+ }
566
629
this .dialogCode = true ;
567
630
},
568
631
569
632
runProgram () {
570
633
// POST /program/save
571
634
console .info (" Startin program" );
572
- const { code } = this .$refs .workspace .getProgramData ();
635
+ var code = ' ' ;
636
+ if (this .$data .activity .editor == ' code' ) {
637
+ code = this .$data .code ;
638
+ } else if (this .$data .activity .editor == ' blockly' ) {
639
+ code = this .$refs .workspace .getProgramData ();
640
+ }
573
641
const programName = this .programName != ' ' ? this .programName : ' untitled' ;
574
642
this .$coderbot .runProgram (programName, code).then (() => {
575
643
this .runtimeDialog = true ;
0 commit comments