Skip to content

Commit 4ad953a

Browse files
committed
close #24
1 parent e387d8a commit 4ad953a

File tree

6 files changed

+88
-96
lines changed

6 files changed

+88
-96
lines changed

src/common/coderbot.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,75 @@ class CoderBot {
203203
},
204204
});
205205
}
206+
207+
getActivities() {
208+
return this.$axios.get(`${this.CB}/listActivities`);
209+
}
210+
211+
deleteActivity(name) {
212+
return this.$axios.post(`${this.CB}/deleteActivity`, {
213+
name,
214+
});
215+
}
216+
217+
saveActivity(an_activity) {
218+
return this.$axios.post(`${this.CB}/saveActivity`, {
219+
activity: an_activity
220+
});
221+
}
222+
223+
saveProgram(overwrite, name, dom_code, code, is_default) {
224+
return this.$axios.post(`${this.CB}/saveProgram`, {
225+
overwrite,
226+
name,
227+
dom_code,
228+
code,
229+
default: is_default
230+
});
231+
}
232+
233+
listPrograms() {
234+
return this.$axios.get(`${this.CB}/list`);
235+
}
236+
237+
loadProgram(name) {
238+
return this.$axios.get(`${this.CB}/load`, {
239+
params: {
240+
name
241+
},
242+
});
243+
}
244+
245+
deleteProgram(name) {
246+
return this.$axios.post(`${this.CB}/delete`, {
247+
name,
248+
});
249+
}
250+
251+
status() {
252+
return this.$axios.get(`${this.CB}/status`);
253+
}
254+
255+
info() {
256+
return this.$axios.get(`${this.CB}/info`);
257+
}
258+
259+
execProgram(dom_code, code, options) {
260+
return this.$axios.post(`${this.CB}/exec`, {
261+
name: 'run program',
262+
dom_code,
263+
code,
264+
options
265+
});
266+
}
267+
268+
stopProgram() {
269+
return this.$axios.post(`${this.CBv1}/program/end`);
270+
}
271+
272+
programStatus() {
273+
return this.$axios.get(`${this.CBv1}/program/status`);
274+
}
206275
}
207276

208277
export default CoderBot;

src/components/Activity.vue

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ export default {
393393
} else {
394394
toolboxJSON = this.activity.toolbox;
395395
}
396-
console.log(this.settings);
397396
this.toolbox = toolboxJSON;
398397
});
399398
@@ -537,21 +536,8 @@ export default {
537536
538537
saveProgram() {
539538
if (this.programName != '') {
540-
const axios = this.$axios;
541-
const {
542-
CB
543-
} = this;
544-
const {
545-
overwrite
546-
} = this.$data;
547-
console.log('save');
548539
const data = this.getProgramData();
549-
axios.post(`${CB}/saveProgram?overwrite=${overwrite}`, {
550-
name: data.name,
551-
dom_code: data.dom_code,
552-
code: data.code,
553-
default: '',
554-
}).then((prog_data) => {
540+
this.$coderbot.saveProgram(this.$data.overwrite, data.name, data.dom_code, data.code, '').then((prog_data) => {
555541
if (prog_data.data == 'defaultOverwrite' || prog_data.data == 'askOverwrite') {
556542
if (prog_data.data == 'askOverwrite') {
557543
this.$data.overwriteDialog = true;
@@ -574,29 +560,17 @@ export default {
574560
575561
loadProgramList() {
576562
// Get the list of available programs and populate the popup
577-
const axios = this.$axios;
578-
const {
579-
CB
580-
} = this.$data;
581-
axios.get(`${CB}/list`)
563+
this.$coderbot.listPrograms()
582564
.then((response) => {
583565
this.$data.carica = true;
584566
this.$data.programList = response.data;
585567
});
586568
},
587569
588570
loadProgram(program) {
589-
const axios = this.$axios;
590-
const {
591-
CB
592-
} = this.$data;
593571
this.$data.carica = false;
594572
this.$data.programName = program;
595-
axios.get(`${CB}/load`, {
596-
params: {
597-
name: program,
598-
},
599-
}).then((data) => {
573+
this.$coderbot.loadProgram(this.$data.programName).then((data) => {
600574
this.$refs.workspace.loadProgram(data.data.dom_code);
601575
this.$data.isDefault = data.data.default;
602576
});
@@ -625,24 +599,14 @@ export default {
625599
this.$data.code = '';
626600
this.$data.workspace.clear();
627601
}
628-
const axios = this.$axios;
629-
const {
630-
CB
631-
} = this.$data;
632602
console.log('delete');
633-
axios.post(`${CB}/delete`, {
634-
name: program,
635-
}).then(() => {
603+
this.$coderbot.deleteProgram(program).then(() => {
636604
console.log('deleted');
637605
});
638606
},
639607
640608
pollStatus() {
641-
const axios = this.$axios;
642-
const {
643-
CB
644-
} = this;
645-
axios.get(`${CB}/status`)
609+
this.$coderbot.status()
646610
.then((response) => {
647611
// If the reconnection happened while in this component, send a notification
648612
if (this.status == 0 && response.status) {
@@ -652,7 +616,7 @@ export default {
652616
this.statusData = response.data;
653617
this.status = response.status;
654618
});
655-
axios.get(`${this.CB}/info`)
619+
this.$coderbot.info()
656620
.then((response) => {
657621
this.info = response.data;
658622
})
@@ -668,27 +632,16 @@ export default {
668632
},
669633
670634
getProgramCode() {
671-
this.code = this.workspace.getProgramCode();
635+
this.code = this.$refs.workspace.getProgramCode();
672636
this.dialogCode = true;
673637
},
674638
675639
runProgram() {
676640
if (this.status) {
677-
const axios = this.$axios;
678-
const {
679-
CB
680-
} = this;
681641
// POST /program/save
682642
const options = this.activity;
683-
684643
const { dom_code, code } = this.$refs.workspace.getProgramData();
685-
686-
axios.post(`${CB}/exec`, {
687-
name: 'run program',
688-
dom_code,
689-
code,
690-
options,
691-
}).then(() => {
644+
this.$coderbot.execProgram(dom_code, code, options).then(() => {
692645
this.runtimeDialog = true;
693646
setTimeout(() => {
694647
this.updateExecStatus();
@@ -703,14 +656,12 @@ export default {
703656
704657
stopProgram() {
705658
console.log('Stopping');
706-
const axios = this.$axios;
707-
axios.post(`${this.CBv1}/program/end`);
659+
this.$coderbot.stopProgram();
708660
},
709661
710662
updateExecStatus() {
711-
const axios = this.$axios;
712663
console.log('Updating Execution status');
713-
axios.get(`${this.CBv1}/program/status`)
664+
this.$coderbot.programStatus()
714665
.then((response) => {
715666
this.program_status = response.data.running;
716667
if (this.program_status) {

src/components/ActivityEditor.vue

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -578,32 +578,23 @@ export default {
578578
viewSource: { },
579579
autoRecVideo: { },
580580
name: { required: true, alphaNum },
581-
description: { alphaNum },
581+
description: { },
582582
maxBlocks: { integer, minValue: 0 },
583583
},
584584
};
585585
},
586586
mounted() {
587587
if (this.$route.params.name) {
588-
const axios = this.$axios;
589-
const {
590-
CB
591-
} = this;
592588
console.log('Loading activity', this.$route.params.name);
593589
this.saved = true;
594-
axios.get(`${CB}/loadActivity`, {
595-
params: {
596-
name: this.$route.params.name,
597-
},
598-
}).then((response) => {
599-
this.activity = response.data;
590+
this.$coderbot.loadActivity(this.$route.params.name, false).then((activity) => {
591+
this.activity = activity;
600592
if (this.activity.toolbox == null) {
601593
this.activity.toolbox = {
602594
kind: 'flyoutToolbox',
603595
contents: []
604596
};
605597
}
606-
console.log(this.activity);
607598
});
608599
} else {
609600
this.restoreDefaults();
@@ -617,15 +608,8 @@ export default {
617608
},
618609
methods: {
619610
save() {
620-
console.log(this.activity);
621611
if (this.activity.name) {
622-
const axios = this.$axios;
623-
const {
624-
CB
625-
} = this;
626-
axios.post(`${CB}/saveActivity`, {
627-
activity: this.activity,
628-
}).then(() => {
612+
this.$coderbot.saveActivity(this.activity).then(() => {
629613
this.snackbarText = this.$i18n.t('message.activity_saved');
630614
this.snackbar = true;
631615
this.saved = true;
@@ -728,7 +712,6 @@ export default {
728712
];
729713
},
730714
onToolboxSave() {
731-
console.log(this.activity.toolbox);
732715
},
733716
},
734717
};

src/components/ActivityList.vue

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<b>{{ activity.name }}</b>
3535
<small> {{activity.description}} </small>
3636
</v-list-item-title>
37+
<v-icon v-if="activity.default">mdi-star</v-icon>
3738
<v-btn text icon color="grey darken-1" v-if="activity.stock!=true" ripple @click="confirmDeleteDlg = true">
3839
<v-icon>delete</v-icon>
3940
<template>
@@ -100,25 +101,14 @@ export default {
100101
this.$router.push({ name: 'activity_open', params: { name } });
101102
},
102103
getActivities() {
103-
const axios = this.$axios;
104-
const {
105-
CB
106-
} = this.$data;
107104
// let programList = this.$data.programList
108-
axios.get(`${CB}/listActivities`)
105+
this.$coderbot.getActivities()
109106
.then((response) => {
110107
this.$data.activityList = response.data;
111108
});
112109
},
113110
deleteActivity(name) {
114-
const axios = this.$axios;
115-
const {
116-
CB
117-
} = this.$data;
118-
// let programList = this.$data.programList
119-
axios.post(`${CB}/deleteActivity`, {
120-
name,
121-
}).then(() => {
111+
this.$coderbot.deleteActivity(name).then(() => {
122112
this.getActivities();
123113
});
124114
},

src/components/BlocklyWorkspace.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export default {
5757
// whenever settings changes, this function will run
5858
settings(newSettings, oldSettings) {
5959
if (newSettings != oldSettings) {
60-
console.log('initBlockly.1');
6160
this.initBlockly(this.settings);
6261
}
6362
},
@@ -67,7 +66,6 @@ export default {
6766
if (this.workspace) {
6867
if (newToolbox.kind != this.toolbox_kind) {
6968
this.workspace.dispose();
70-
console.log('initBlockly.2');
7169
this.initBlockly(this.settings);
7270
this.toolbox_kind = this.toolbox.kind;
7371
} else {

src/i18n/locales/it/messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"activity_program_clear": "Pulisci",
5858
"activity_program_run": "Esegui",
5959
"activity_program_load": "Carica Programma",
60+
"activity_program_save": "Salva",
6061
"activity_program_save_as": "Salva con nome",
6162
"activity_program_export": "Esporta",
6263
"activity_program_import": "Importa",
@@ -73,7 +74,6 @@
7374
"activity_saved": "Attività salvata",
7475
"activity_save_error": "Salvataggio non riuscito: inserisci un nome all'attività!",
7576
"activity_program_save_as_name": "Nome del programma",
76-
"activity_program_save": "Salva",
7777
"activity_program_remaining_blocks": "Blocchi rimanenti",
7878
"activity_description": "Description",
7979
"activity_predefined_view": "Vista predefinita",
@@ -100,6 +100,7 @@
100100
"activity_tabs_toolbox": "Menù Blocchi",
101101
"activity_toolbox_category_add": "Aggiungi Nuova Categoria",
102102
"activity_toolbox_category_add_all": "Aggiungi Tutte",
103+
"activity_default": "Attività predefinita",
103104
"control_speak": "Pronuncia",
104105
"control_speaking": "Sto pronunciando",
105106
"control_photo_take": "Scatta foto",

0 commit comments

Comments
 (0)