Skip to content

Commit 1452a77

Browse files
committed
wip #92
1 parent 49ccf70 commit 1452a77

File tree

8 files changed

+223
-253
lines changed

8 files changed

+223
-253
lines changed

src/App.vue

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,97 @@
11
<template>
22
<div id="app">
3+
<template v-if="status == 200">
34
<router-view />
5+
</template>
6+
<template v-else>
7+
<v-app id="inspire">
8+
<sidebar></sidebar>
9+
<v-app-bar color="indigo" dark fixed app>
10+
<v-app-bar-nav-icon></v-app-bar-nav-icon>
11+
<v-app-bar-title class="title"><div>CoderBot</div></v-app-bar-title>
12+
</v-app-bar>
13+
<v-main>
14+
<v-container class="d-flex align-center flex-column">
15+
<div style="font-size: 24px;"> {{ $t("message.welcome") }} </div>
16+
<div class="logo">CoderBot</div>
17+
<v-col xs12 md8 offset-md2>
18+
<v-carousel hide-delimiters>
19+
<v-carousel-item v-for="(item,i) in carouselItems" :key="i" :src="item.src">
20+
</v-carousel-item>
21+
</v-carousel>
22+
</v-col>
23+
</v-container>
24+
</v-main>
25+
</v-app>
26+
<v-row justify="center">
27+
<v-dialog
28+
v-model="dialog"
29+
persistent
30+
>
31+
<v-card>
32+
<v-card-text>
33+
<p class="text-center">
34+
{{ $t("message.coderbot_status_offline_1") }}
35+
<v-icon large icon="mdi-wifi-off"></v-icon>
36+
</p>
37+
</v-card-text>
38+
</v-card>
39+
</v-dialog>
40+
</v-row>
41+
</template>
442
</div>
543
</template>
644
<script>
45+
import image_1 from './assets/images/coderbot_wide1.jpg';
46+
import image_2 from './assets/images/coderbot_wide3.jpg';
47+
748
export default {
849
data() {
950
return {
1051
drawer: null,
52+
status: null,
53+
dialog: true,
54+
carouselItems: [
55+
{
56+
src: image_1,
57+
},
58+
{
59+
src: image_2,
60+
}
61+
],
1162
};
1263
},
1364
name: 'App',
65+
mounted() {
66+
this.pollStatus();
67+
setInterval(() => {
68+
this.pollStatus();
69+
}, 1000);
70+
},
71+
methods: {
72+
pollStatus() {
73+
this.$coderbot.status()
74+
.then((response) => {
75+
if (this.status == 0 && response.status) {
76+
this.snackText = this.$i18n.t('message.coderbot_status_online');
77+
this.snackbar = true;
78+
}
79+
80+
this.statusData = response.data;
81+
this.status = response.status;
82+
})
83+
.catch((error) => {
84+
// handle error
85+
console.log(`pollStatus error: ${error}`);
86+
87+
if (this.status) {
88+
this.snackText = this.$i18n.t('message.coderbot_offline_2');
89+
this.snackbar = true;
90+
}
91+
this.status = 0;
92+
});
93+
}
94+
}
1495
};
1596
1697
</script>

src/common/coderbot.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,14 @@ class CoderBot {
229229
return this.$axios.put(`${this.CB}/settings`, legacySettings);
230230
}
231231

232+
reset() {
233+
return this.$axios.post(`${this.CB}}/system/reset`);
234+
}
235+
236+
restart() {
237+
return this.$axios.post(`${this.CB}}/system/restart`);
238+
}
239+
232240
reboot() {
233241
return this.$axios.post(`${this.CB}/system/reboot`);
234242
}
@@ -263,10 +271,6 @@ class CoderBot {
263271
return this.$axios.post(`${this.CB}/updateFromPackage`, formdata, config);
264272
}
265273

266-
reset() {
267-
return this.$axios.post(`${this.CB}/reset`);
268-
}
269-
270274
test(checkedTests) {
271275
return this.$axios.post(`${this.CB}/testCoderbot`, {
272276
params: checkedTests

src/components/Activity.vue

Lines changed: 23 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,22 @@
1212
<v-spacer></v-spacer>
1313
<v-chip class="ma-2" v-if="activity.maxBlocks > 0" label>{{ $t("message.activity_program_remaining_blocks") }}: {{ remainingCapacity }}</v-chip>
1414
<!-- If the API is available, show the desired buttons -->
15-
<template v-if="status == 200">
16-
<template v-for="button in activity.buttons">
17-
<template v-if="button.type == 'text'">
18-
<v-btn @click="this[button.action]()">
19-
<v-icon :icon="button.icon"></v-icon>
20-
<span v-if="activity.showButtonLabel">{{ button.label }}</span>
21-
</v-btn>
22-
</template>
23-
<template v-else>
24-
<v-btn @click="this[button.action]()" style="height: 70%" :color="button.colorBtn"
25-
:class="button.colorText">
26-
<v-icon :icon="button.icon"></v-icon>
27-
<span v-if="activity.showButtonLabel">{{ button.label }}</span>
28-
</v-btn>
29-
</template>
30-
&nbsp;&nbsp;
15+
<template v-for="button in activity.buttons">
16+
<template v-if="button.type == 'text'">
17+
<v-btn @click="this[button.action]()">
18+
<v-icon :icon="button.icon"></v-icon>
19+
<span v-if="activity.showButtonLabel">{{ button.label }}</span>
20+
</v-btn>
21+
</template>
22+
<template v-else>
23+
<v-btn @click="this[button.action]()" style="height: 70%" :color="button.colorBtn"
24+
:class="button.colorText">
25+
<v-icon :icon="button.icon"></v-icon>
26+
<span v-if="activity.showButtonLabel">{{ button.label }}</span>
27+
</v-btn>
3128
</template>
29+
&nbsp;&nbsp;
3230
</template>
33-
<!-- If the API is not responding, show an error icon -->
34-
<v-btn @click="dialog = true" icon v-if="status != 200">
35-
<v-icon icon="mdi-error"></v-icon>
36-
</v-btn>
3731
</v-app-bar>
3832
<!-- Page content -->
3933
<v-main>
@@ -239,21 +233,6 @@
239233
</v-card-actions>
240234
</v-card>
241235
</v-dialog>
242-
<!-- Status -->
243-
<v-dialog v-model="dialog" max-width="290">
244-
<v-card>
245-
<v-card-title class="headline">{{ $t("message.coderbot_status") }}</v-card-title>
246-
<v-card-text>
247-
{{ statusText }}
248-
</v-card-text>
249-
<v-card-actions>
250-
<v-spacer></v-spacer>
251-
<v-btn color="green darken-1" text="text" @click="dialog = false">
252-
{{ $t("message.ok") }}
253-
</v-btn>
254-
</v-card-actions>
255-
</v-card>
256-
</v-dialog>
257236
<!-- Generic dialog -->
258237
<v-dialog v-model="generalDialog" max-width="290">
259238
<v-card>
@@ -336,8 +315,6 @@ export default {
336315
snackText: null,
337316
snackbar: false,
338317
drawer: false,
339-
status: null,
340-
info: null,
341318
code: '',
342319
generalDialog: false,
343320
generalDialogText: null,
@@ -362,12 +339,6 @@ export default {
362339
program_status: null
363340
}),
364341
computed: {
365-
statusText() {
366-
if (this.status) {
367-
return this.$i18n.t('message.coderbot_status_online');
368-
}
369-
return this.$i18n.t('message.coderbot_status_offline');
370-
},
371342
remainingCapacity() {
372343
return this.$refs.workspace.remainingCapacity();
373344
},
@@ -393,14 +364,6 @@ export default {
393364
394365
this.toolbox = this.activity.toolbox;
395366
});
396-
397-
this.status = null;
398-
this.pollStatus();
399-
400-
// Start the polling
401-
setInterval(() => {
402-
this.pollStatus();
403-
}, 1000);
404367
},
405368
beforeRouteLeave(to, from, next) {
406369
if (this.dirty) {
@@ -603,53 +566,21 @@ export default {
603566
});
604567
},
605568
606-
pollStatus() {
607-
this.$coderbot.status()
608-
.then((response) => {
609-
// If the reconnection happened while in this component, send a notification
610-
if (this.status == 0 && response.status) {
611-
this.snackText = this.$i18n.t('message.coderbot_status_online');
612-
this.snackbar = true;
613-
}
614-
this.statusData = response.data;
615-
this.status = response.status;
616-
});
617-
this.$coderbot.info()
618-
.then((response) => {
619-
this.info = response.data;
620-
})
621-
.catch((error) => {
622-
console.log(`pollStatus error: ${error}`);
623-
// If the disconnection happened while in this component, send a notification
624-
if (this.status) {
625-
this.snackText = this.$i18n.t('coderbot_offline_2');
626-
this.snackbar = true;
627-
}
628-
this.status = 0;
629-
});
630-
},
631-
632569
getProgramCode() {
633570
this.code = this.$refs.workspace.getProgramCode();
634571
this.dialogCode = true;
635572
},
636573
637574
runProgram() {
638-
if (this.status) {
639-
// POST /program/save
640-
const { code } = this.$refs.workspace.getProgramData();
641-
const programName = this.programName != '' ? this.programName : 'untitled';
642-
this.$coderbot.runProgram(programName, code).then(() => {
643-
this.runtimeDialog = true;
644-
setTimeout(() => {
645-
this.updateExecStatus();
646-
}, 1000);
647-
});
648-
} else {
649-
this.generalDialog = true;
650-
this.generalDialogTitle = this.$i18n.t('error');
651-
this.generalDialogText = this.$i18n.t('coderbot_offline_3');
652-
}
575+
// POST /program/save
576+
const { code } = this.$refs.workspace.getProgramData();
577+
const programName = this.programName != '' ? this.programName : 'untitled';
578+
this.$coderbot.runProgram(programName, code).then(() => {
579+
this.runtimeDialog = true;
580+
setTimeout(() => {
581+
this.updateExecStatus();
582+
}, 1000);
583+
});
653584
},
654585
655586
stopProgram() {

0 commit comments

Comments
 (0)