Skip to content

Commit affcaa1

Browse files
committed
fix run new unsaved program
1 parent 5daa8a3 commit affcaa1

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/common/coderbot.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class CoderBot {
2222
this.loadActivity(null, true).then((activity) => {
2323
if (activity.data == '') {
2424
const defaultActivity = {
25+
id: '744d9de0-4680-426f-8962-163fd2473148',
2526
kind: 'stock',
2627
status: "active",
2728
default: true,

src/components/Activity.vue

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ export default defineComponent({
526526
this.$data.overwrite = true;
527527
console.log('saved');
528528
this.dirty = false;
529+
this.programId = prog_data.data.id;
530+
this.programName = prog_data.name;
529531
}
530532
}).catch((error) => {
531533
if(error.response.status == 400 && error.response.data == 'defaultCannotOverwrite') {
@@ -565,6 +567,7 @@ export default defineComponent({
565567
566568
clearProgram() {
567569
this.$data.programId = '';
570+
this.$data.programName = '';
568571
this.$data.code = '';
569572
this.$refs.workspace.clear();
570573
this.$data.clear = false;
@@ -594,18 +597,44 @@ export default defineComponent({
594597
},
595598
596599
runProgram() {
597-
// POST /program/save
598-
console.info("Startin program");
600+
const data = this.getProgramData();
601+
if (this.programId == '') {
602+
this.$coderbot.saveNewProgram(this.$data.overwrite, 'untitled', data.dom_code, data.code, false).then((prog_data) => {
603+
if (prog_data.data == 'askOverwrite') {
604+
this.$data.overwriteDialog = true;
605+
} else {
606+
this.$data.isStock = '';
607+
this.$data.overwrite = true;
608+
console.log('saved');
609+
this.dirty = false;
610+
this.programId = prog_data.data.id;
611+
this.programName = prog_data.name;
612+
this.runProgramInternal();
613+
}
614+
}).catch((error) => {
615+
if(error.response.status == 400 && error.response.data == 'defaultCannotOverwrite') {
616+
console.warn('trying to overwrite a default program');
617+
this.$data.programName = this.$data.defaultProgramName;
618+
this.$data.defaultProgramName = '';
619+
this.$data.cannotOverwrite = true;
620+
}
621+
});
622+
} else {
623+
this.$coderbot.saveProgram(this.$data.overwrite, data.id, data.name, data.dom_code, data.code, false).then((prog_data) => {
624+
this.runProgramInternal();
625+
});
626+
}
627+
},
628+
runProgramInternal() {
599629
const { code } = this.$refs.workspace.getProgramData();
600-
const programId = this.programId != '' ? this.programId : 'untitled';
630+
const programId = this.programId;
601631
this.$coderbot.runProgram(programId, code).then(() => {
602632
this.runtimeDialog = true;
603633
setTimeout(() => {
604634
this.updateExecStatus();
605635
}, 1000);
606636
});
607637
},
608-
609638
stopProgram() {
610639
console.info('Stopping program');
611640
this.$coderbot.stopProgram();

0 commit comments

Comments
 (0)