forked from mirte-robot/mirte-web-interface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlButtons.vue
More file actions
155 lines (129 loc) · 4.76 KB
/
Copy pathControlButtons.vue
File metadata and controls
155 lines (129 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<template>
<div>
<button :disabled="isUndoDisabled" class="btn btn-outline-light mr-2"
v-b-tooltip.hover
:title="$t('programming.undo')"
@click="control('undo')"
>
<i class="fas fa-undo"></i>
</button>
<button :disabled="isRedoDisabled" class="btn btn-outline-light mr-2"
v-b-tooltip.hover
:title="$t('programming.redo')"
@click="control('redo')"
>
<i class="fa fa-redo"></i>
</button>
<span class="nav-spacer"></span>
<span v-b-tooltip.hover :title="$t('programming.start')" style="display: inline-block;">
<button :disabled="!isPlayEnabled" class="btn btn-outline-light mx-2"
@click="control('play')">
<i class="fas fa-play"></i>
</button>
</span>
<!--
<span v-b-tooltip.hover :title="$t('programming.pause')" style="display: inline-block;">
<button :disabled="isPauseDisabled"
@click="control('pause')" class="btn btn-outline-light mr-2">
<i class="fa fa-pause"></i>
</button>
</span>
<span v-b-tooltip.hover :title="$t('programming.step')" style="display: inline-block;">
<button :disabled="isStepDisabled" class="btn btn-outline-light mr-2"
@click="control('step')">
<i class="fa fa-step-forward"></i>
</button>
</span>
-->
<span v-b-tooltip.hover :title="$t('programming.stop')" style="display: inline-block;">
<button :disabled="!isStopEnabled" class="btn btn-outline-light mr-2"
@click="control('stop')">
<i class="fa fa-stop"></i>
</button>
</span>
<span class="nav-spacer"></span>
<button href="#" class="btn btn-outline-light mx-2"
v-b-tooltip.hover
:title="$t('programming.save')"
@click="download"
>
<i class="fa fa-save"></i>
</button>
<button class="btn btn-outline-light mr-2"
v-b-tooltip.hover
:title="$t('programming.open')"
@click="openFileWindow"
>
<i class="fa fa-folder-open"></i>
<input ref="file_input" @change="upload" type="file" name="name" style="display: none;" />
</button>
</div>
</template>
<script>
import EventBus from '../event-bus';
export default {
methods: {
control(command) {
EventBus.$emit('control', command);
},
openFileWindow(){
this.$refs.file_input.value = null;
if (this.$parent.language == 'blockly') {
this.$refs.file_input.accept = ".xml";
} else {
this.$refs.file_input.accept = ".py";
}
this.$refs.file_input.click()
},
upload(){
var fr=new FileReader();
fr.onload = () => {
if (this.$parent.language == 'blockly') {
this.$store.dispatch('setBlockly', fr.result)
} else {
this.$store.dispatch('setCode', fr.result)
}
}
if(this.$refs.file_input.files.length > 0){
fr.readAsText(this.$refs.file_input.files[0]);
}
},
download(){
if (this.$parent.language == 'blockly') {
var text = localStorage.getItem("blockly");
var filename = "mirte.xml";
} else {
var text = this.$store.getters.getCode;
var filename = "mirte.py";
}
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
},
},
computed: {
isUndoDisabled: function(){
return false; // TODO: determine strategy
},
isRedoDisabled: function(){
return false; // TODO: determine strategy
},
isPlayEnabled: function(){
return this.$store.getters.getExecution == "ready";
},
isPauseDisabled: function(){
return this.$store.getters.getExecution != "running" || this.$store.getters.getExecution == "disconnected";
},
isStepDisabled: function(){
return this.$store.getters.getExecution != "paused" || this.$store.getters.getExecution == "disconnected";
},
isStopEnabled: function(){
return this.$store.getters.getExecution == "running";
}
}
}
</script>