Skip to content

Commit 83fd36a

Browse files
committed
Save, Preload in editor and dynamic route matching for /activity/edit/:name
1 parent 3b0c74b commit 83fd36a

File tree

2 files changed

+68
-50
lines changed

2 files changed

+68
-50
lines changed

src/components/ActivityEditor.vue

Lines changed: 67 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -335,59 +335,76 @@ export default {
335335
};
336336
},
337337
mounted() {
338-
this.restoreDefaults();
338+
339+
if (this.$route.params.name) {
340+
let axios = this.$axios
341+
let CB = this.CB
342+
console.log("Loading activity", this.$route.params.name)
343+
axios.get(CB + '/loadActivity', {
344+
params: {
345+
name: this.$route.params.name
346+
}
347+
})
348+
.then(function(response) {
349+
console.log(response)
350+
this.activity = response.data
351+
}.bind(this))
352+
} else {
353+
this.restoreDefaults();
354+
}
355+
356+
},
357+
methods: {
358+
save: function() {
359+
console.log(JSON.stringify(this.activity))
360+
if (this.activity.name) {
361+
let axios = this.$axios
362+
let CB = this.CB
363+
axios.post(CB + '/saveActivity', {
364+
activity: this.activity
365+
})
366+
.then(function(data) {
367+
this.snackbarText = "Attività salvata";
368+
this.snackbar = true;
369+
}.bind(this))
370+
} else {
371+
this.snackbarText = "Salvataggio non riuscito: inserisci un nome all'attività!";
372+
this.snackbar = true;
373+
}
374+
},
375+
toggleSidebar: function() {
376+
let currentStatus = this.$store.getters.drawerStatus
377+
this.$store.commit('toggleDrawer', !currentStatus)
339378
},
340-
methods: {
341-
save: function() {
342-
console.log(JSON.stringify(this.activity))
343-
if (this.activity.name) {
344-
let axios = this.$axios
345-
let CB = this.CB
346-
axios.post(CB + '/saveActivity', {
347-
activity: this.activity
348-
})
349-
.then(function(data) {
350-
this.snackbarText = "Attività salvata";
351-
this.snackbar = true;
352-
}.bind(this))
353-
} else {
354-
this.snackbarText = "Salvataggio non riuscito: inserisci un nome all'attività!";
355-
this.snackbar = true;
379+
addButton: function() {
380+
this.activity.buttons.push({
381+
label: '',
382+
})
383+
},
384+
removeButton: function(index) {
385+
this.activity.buttons.splice(index, 1)
386+
},
387+
removeAll: function() {
388+
this.activity.buttons = []
389+
},
390+
restoreDefaults: function() {
391+
this.activity.buttons = [{
392+
label: 'Esegui Roba',
393+
icon: 'play_arrow',
394+
colorBtn: 'green',
395+
colorText: 'white--text',
396+
action: 'run'
397+
},
398+
{
399+
label: 'Codice',
400+
icon: 'code',
401+
colorBtn: 'blue',
402+
colorText: 'white--text',
403+
action: 'showcode'
356404
}
357-
},
358-
toggleSidebar: function() {
359-
let currentStatus = this.$store.getters.drawerStatus
360-
this.$store.commit('toggleDrawer', !currentStatus)
361-
},
362-
addButton: function() {
363-
this.activity.buttons.push({
364-
label: '',
365-
})
366-
},
367-
removeButton: function(index) {
368-
this.activity.buttons.splice(index, 1)
369-
},
370-
removeAll: function() {
371-
this.activity.buttons = []
372-
},
373-
restoreDefaults: function() {
374-
this.activity.buttons = [{
375-
label: 'Esegui Roba',
376-
icon: 'play_arrow',
377-
colorBtn: 'green',
378-
colorText: 'white--text',
379-
action: 'run'
380-
},
381-
{
382-
label: 'Codice',
383-
icon: 'code',
384-
colorBtn: 'blue',
385-
colorText: 'white--text',
386-
action: 'showcode'
387-
}
388-
]
389-
}
405+
]
390406
}
407+
}
391408
};
392409
393410
</script>

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const routes = [
7171
//{ path: '/ar', component: arexample, meta: {title: 'CoderBot'} },
7272
{ path: '/activity/new', component: activityEditor, meta: {title: 'CoderBot - Nuova Attività'}},
7373
{ path: '/activity/open', component: activityList, meta: {title: 'CoderBot - Apri Attività'}},
74+
{ path: '/activity/edit/:name', component: activityEditor, meta: {title: 'CoderBot - Modifica Attività'}}
7475
];
7576

7677

0 commit comments

Comments
 (0)