Skip to content

Commit 6adb05a

Browse files
committed
fix #23
1 parent b71b7ef commit 6adb05a

File tree

4 files changed

+282
-56
lines changed

4 files changed

+282
-56
lines changed

src/components/Activity.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,26 @@
184184
</v-card-actions>
185185
</v-card>
186186
</v-dialog>
187+
<!-- Clear Program -->
188+
<v-dialog v-model="clear" max-width="500">
189+
<v-card>
190+
<v-card-title class="headline">
191+
{{ $t("message.delete") }}
192+
</v-card-title>
193+
<v-card-actions>
194+
<v-card-text>
195+
{{ $t('message.clear_sure') }}
196+
</v-card-text>
197+
<v-btn color="red darken-1" text="text" @click="clear = false">
198+
{{ $t("message.no") }}
199+
</v-btn>
200+
<v-btn color="green darken-1" text="text"
201+
@click="del = false, carica = false, clearProgram()">
202+
{{ $t("message.yes") }}
203+
</v-btn>
204+
</v-card-actions>
205+
</v-card>
206+
</v-dialog>
187207
<!-- Delete Program -->
188208
<v-dialog v-model="del" max-width="500">
189209
<v-card>
@@ -370,6 +390,7 @@ export default {
370390
newProgramName: '',
371391
unvalidName: false,
372392
del: false,
393+
clear: false,
373394
webcamStream: `${process.env.CB_ENDPOINT + process.env.APIv1}/video/stream`,
374395
runtimeDialog: false,
375396
isDefault: '',
@@ -401,6 +422,12 @@ export default {
401422
this.activity = {
402423
bodyFont: 'Roboto',
403424
buttons: [
425+
{
426+
action: 'clearProgramDlg',
427+
icon: 'clear',
428+
label: this.$i18n.t('message.activity_program_clear'),
429+
type: 'text',
430+
},
404431
{
405432
action: 'saveProgram',
406433
icon: 'save',
@@ -784,6 +811,17 @@ export default {
784811
});
785812
},
786813
814+
clearProgramDlg() {
815+
this.$data.clear = true;
816+
},
817+
818+
clearProgram() {
819+
this.$data.programName = '';
820+
this.$data.code = '';
821+
this.$data.workspace.clear();
822+
this.$data.clear = false;
823+
},
824+
787825
deleteProgramDlg(program) {
788826
this.$data.newProgramName = program;
789827
this.$data.del = true;

src/components/ActivityEditor.vue

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,19 @@
3232
<h3 class="text-xs-left">{{ $t("message.activity_data") }} </h3>
3333
<v-card>
3434
<v-form class="cardContent">
35-
<v-text-field v-model="activity.name" label="Nome" required></v-text-field>
36-
<v-text-field v-model="activity.description" v-bind:label="$t('message.activity_description')">
35+
<v-text-field v-model="activity.name" label="Nome" required
36+
@input="$v.activity.name.$touch"
37+
v-bind:error-messages="$v.activity.name.$error == true ? $t('message.validation_alphanum') : null"
38+
></v-text-field>
39+
<v-text-field v-model="activity.description" v-bind:label="$t('message.activity_description')"
40+
@input="$v.activity.description.$touch"
41+
v-bind:error-messages="$v.activity.description.$error == true ? $t('message.validation_alphanum') : null"
42+
>
3743
</v-text-field>
38-
<v-select v-model="defaultView" :items="viste"
39-
v-bind:label="$t('message.activity_predefined_view')" required></v-select>
44+
<v-select v-model="activity.defaultView" :items="viste"
45+
v-bind:label="$t('message.activity_predefined_view')" required
46+
@input="$v.activity.defaultView.$touch"
47+
></v-select>
4048
</v-form>
4149
</v-card>
4250
<br><br>
@@ -65,7 +73,10 @@
6573
<v-card>
6674
<div class="cardContent">
6775
<span v-bind:style="bodyUIstyleObj">Lorem ipsum dolor sit amet</span>
68-
<v-radio-group v-model="activity.bodyFont" column>
76+
<v-radio-group v-model="activity.bodyFont" column
77+
v-bind:label="$t('message.activity_predefined_view')" required
78+
@change="$v.activity.bodyFont.$touch"
79+
>
6980
<v-radio label="Roboto" value="Roboto"></v-radio>
7081
<v-radio label="Open Sans" value="opensans"></v-radio>
7182
<!--
@@ -80,23 +91,24 @@
8091
<v-card>
8192
<div class="cardContent">
8293
<span v-bind:style="codeUIstyleObj">function life() { return 42; }</span>
83-
<v-radio-group v-model="activity.codeFont" column>
94+
<v-radio-group v-model="activity.codeFont" column
95+
@change="$v.activity.codeFont.$touch"
96+
>
8497
<v-radio label="Ubuntu Mono" value="ubuntumono"></v-radio>
8598
<v-radio label="Roboto Mono" value="robotomono"></v-radio>
8699
</v-radio-group>
87100
</div>
88101
</v-card>
89102
<br><br>
90-
<!--
91-
<h3 class="text-xs-left">Lingua</h3>
103+
<h3 class="text-xs-left">{{ $t("message.activity_locale") }}</h3>
92104
<v-card>
93105
<div class="cardContent">
94-
<v-select v-model="uiLang" :items="langs" label="Lingua Interfaccia" required></v-select>
95-
<v-select v-model="blocklyLang" :items="langs" label="Lingua Blocchi" required></v-select>
106+
<v-select v-model="activity.uiLang" :items="langs" v-bind:label="$t('message.activity_locale')" required
107+
@change="$v.activity.uiLang.$touch"
108+
></v-select>
96109
</div>
97110
</v-card>
98111
<br><br>
99-
-->
100112
<h3 class="text-xs-left">{{ $t("message.activity_programing_title") }}</h3>
101113
<v-card>
102114
<div class="cardContent">
@@ -117,11 +129,16 @@
117129
-->
118130
<v-flex>
119131
<v-checkbox v-model="activity.autoRecVideo"
120-
v-bind:label="$t('message.activity_auto_rec_video')"></v-checkbox>
132+
v-bind:label="$t('message.activity_auto_rec_video')"
133+
@input="$v.activity.autoRecVideo.$touch"
134+
></v-checkbox>
121135
</v-flex>
122136
<v-flex>
123137
<v-text-field v-model="activity.maxBlocks"
124-
v-bind:label="$t('message.activity_blocks_max_blocks')"></v-text-field>
138+
v-bind:label="$t('message.activity_blocks_max_blocks')"
139+
@input="$v.activity.maxBlocks.$touch"
140+
v-bind:error-messages="$v.activity.maxBlocks.$error == true ? $t('message.validation_integer_positive') : null"
141+
></v-text-field>
125142
</v-flex>
126143
</v-layout>
127144
</div>
@@ -167,9 +184,13 @@
167184
</template>
168185
</v-app-bar>
169186
<br>
170-
<v-switch v-bind:label="$t('message.activity_lateral_menu_icon')" v-model="activity.drawerEnabled">
187+
<v-switch v-bind:label="$t('message.activity_lateral_menu_icon')" v-model="activity.drawerEnabled"
188+
@change="$v.activity.drawerEnabled.$touch"
189+
>
171190
</v-switch>
172-
<v-switch v-bind:label="$t('message.activity_name')" v-model="activity.showName"></v-switch>
191+
<v-switch v-bind:label="$t('message.activity_name')" v-model="activity.showName"
192+
@change="$v.activity.showName.$touch"
193+
></v-switch>
173194
<br>
174195
<h3> {{ $t("message.activity_toolbar_buttons") }} </h3>
175196
<v-btn @click="addButton()" outlined color="green">
@@ -302,6 +323,10 @@
302323
import Swatches from 'vue-swatches';
303324
import 'vue-swatches/dist/vue-swatches.css';
304325
326+
import {
327+
alphaNum, integer,
328+
} from 'vuelidate/lib/validators';
329+
305330
// import wsFactory from '../components/wsFactory';
306331
import sidebar from '../components/Sidebar';
307332
@@ -311,6 +336,14 @@ export default {
311336
Swatches,
312337
sidebar /* , wsFactory */
313338
},
339+
beforeRouteLeave(to, from, next) {
340+
if (this.$v.$anyDirty) {
341+
this.router_next = next;
342+
this.confirm_exit_dialog = true;
343+
} else {
344+
next();
345+
}
346+
},
314347
computed: {
315348
prefix() {
316349
if (this.activity.name != null && this.activity.name != '') return '-';
@@ -394,6 +427,8 @@ export default {
394427
snackbarText: '',
395428
b: 0,
396429
activity: {
430+
uiLang: null,
431+
defaultView: null,
397432
exec: {
398433
camera: true,
399434
log: true,
@@ -427,6 +462,10 @@ export default {
427462
},
428463
],
429464
actions: [
465+
{
466+
text: this.$i18n.t('message.activity_program_clear'),
467+
value: 'clearProgram'
468+
},
430469
{
431470
text: this.$i18n.t('message.activity_program_run'),
432471
value: 'runProgram'
@@ -476,8 +515,6 @@ export default {
476515
this.$i18n.t('message.activity_lang_english'),
477516
this.$i18n.t('message.activity_lang_french'),
478517
],
479-
uiLang: 'Italiano',
480-
blocklyLang: 'Inglese',
481518
editHistory: false,
482519
navHistory: false,
483520
experimental: true,
@@ -491,8 +528,6 @@ export default {
491528
ar: false,
492529
// drawer: null,
493530
source: null,
494-
msg: 'Welcome to Your Vue.js App',
495-
defaultView: 'blocks',
496531
viste: [
497532
{
498533
text: this.$i18n.t('message.activity_views_blocks'),
@@ -515,6 +550,26 @@ export default {
515550
unwatch: null
516551
};
517552
},
553+
validations() {
554+
return {
555+
activity: {
556+
uiLang: { },
557+
defaultView: { },
558+
drawerEnabled: { },
559+
showName: { },
560+
buttons: { },
561+
fontSize: { },
562+
capsSwitch: { },
563+
bodyFont: { },
564+
codeFont: { },
565+
viewSource: { },
566+
autoRecVideo: { },
567+
name: { required: true, alphaNum },
568+
description: { alphaNum },
569+
maxBlocks: { integer, minValue: 0 },
570+
},
571+
};
572+
},
518573
mounted() {
519574
if (this.$route.params.name) {
520575
const axios = this.$axios;
@@ -550,12 +605,13 @@ export default {
550605
axios.post(`${CB}/saveActivity`, {
551606
activity: this.activity,
552607
}).then(() => {
553-
this.snackbarText = this.$i18n.t('activity_saved');
608+
this.snackbarText = this.$i18n.t('message.activity_saved');
554609
this.snackbar = true;
555610
this.saved = true;
611+
this.$v.$reset();
556612
});
557613
} else {
558-
this.snackbarText = this.$i18n.t('activity_save_error');
614+
this.snackbarText = this.$i18n.t('message.activity_save_error');
559615
this.snackbar = true;
560616
}
561617
},

0 commit comments

Comments
 (0)