Skip to content

Fix #22: when trying to load a new program, if there are unsaved edits, ask for saving then proceed #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 58 additions & 4 deletions src/components/Blockly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@
</v-card-title>
<v-list>
<v-list-tile v-for="program in programList" :key="program.el" avatar @click="">
<v-list-tile-title ripple @click="loadProgram(program.name)">
<v-list-tile-title ripple @click="
checkAction(loadProgram, program.name)">
{{ program.name }}
</v-list-tile-title>
<v-btn v-if="program.default != 'True'" flat icon color="grey darken-1" ripple @click="deleteProgramDlg(program.name)">
Expand Down Expand Up @@ -184,6 +185,25 @@
</v-card>
</v-dialog>
<!-- -->
<v-dialog v-model="saveWorkspace" max-width="500">
<v-card>
<v-card-title class="headline">
Salvare workspace
</v-card-title>
<v-card-actions>
<v-card-text>
La workspace non è vuota, vuoi salvare il tuo programma?
</v-card-text>
<v-btn color="red darken-1" flat="flat" @click="saveWorkspace = false, clearWorkspace = true, checkAction(callBack, generalParameter)">
No
</v-btn>
<v-btn color="green darken-1" flat="flat" @click="saveWorkspace = false, salva = true">
Si
</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
<!-- -->
<v-dialog v-model="del" max-width="500">
<v-card>
<v-card-title class="headline">
Expand Down Expand Up @@ -304,6 +324,11 @@ export default {
defaultProgramName: '',
overwrite: 0,
overwriteDialog: false,
saveWorkspace: false,
clearWorkspace: false,
generalParameter: '',
callBack: '',
programCode: '',
}),
computed: {
statusText: function() {
Expand Down Expand Up @@ -395,6 +420,30 @@ export default {

return { name: name, dom_code: dom_code, code: code, default: isDefault };
},
checkAction(functionToCall, parameter) {
if(this.clearWorkspace){
let workspace = this.workspace
workspace.clear()
this.clearWorkspace = false
}
let data = this.getProgramData()
let code = data.code
if (code == '' || code == this.programCode){
if(parameter != null){
console.log("ho il parametro")
functionToCall(parameter)
}
else{
console.log("non ho il parametro")
functionToCall()
}
}
else{
this.callBack = functionToCall
this.generalParameter = parameter
this.$data.saveWorkspace = true
}
},
exportProgram() {
let data = JSON.stringify(this.getProgramData())
const blob = new Blob([data], { type: 'text/json' })
Expand Down Expand Up @@ -473,11 +522,16 @@ export default {
this.$data.isDefault = ''
this.$data.overwrite = 0
console.log("salvato")
this.programCode = data.code
if(this.callBack != ''){
this.callBack(this.generalParameter)
this.callBack = ''
}
}
}.bind(this))
} else {
this.unvalidName = true
}
}
},
loadProgramList() {
let axios = this.$axios
Expand All @@ -502,11 +556,11 @@ export default {
}
})
.then(function(data) {
console.log(data)
workspace.clear();
var xml = Blockly.Xml.textToDom(data.data.dom_code);
this.programCode = data.data.code;
Blockly.Xml.domToWorkspace(xml, workspace);
this.$data.isDefault = data.data.default
this.$data.isDefault = data.data.default;
}.bind(this))
},
deleteProgramDlg(program) {
Expand Down