-
-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathConsoleBrowser.vue
More file actions
144 lines (124 loc) · 3.36 KB
/
ConsoleBrowser.vue
File metadata and controls
144 lines (124 loc) · 3.36 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
<template>
<div class="console">
<console-command
v-if="!readonly && flipLayout"
v-model="currentCommand"
:disabled="!klippyConnected"
:autofocus="fullscreen"
@send="sendCommand"
/>
<v-card
flat
class="console-wrapper"
>
<app-auto-scroll-container
ref="consoleScroller"
class="console-scroller"
:class="{
'console-scroller-fullscreen': fullscreen
}"
:reversed="flipLayout"
v-on="$listeners"
>
<console-item
v-for="item in orderedItems"
:key="item.id"
:value="item"
class="console-item"
@click="handleEntryClick"
/>
</app-auto-scroll-container>
</v-card>
<console-command
v-if="!readonly && !flipLayout"
v-model="currentCommand"
:disabled="!klippyConnected"
:autofocus="fullscreen"
@send="sendCommand"
/>
</div>
</template>
<script lang="ts">
import { Component, Prop, Mixins, Ref } from 'vue-property-decorator'
import StateMixin from '@/mixins/state'
import ConsoleCommand from './ConsoleCommand.vue'
import ConsoleItem from './ConsoleItem.vue'
import { SocketActions } from '@/api/socketActions'
import type { ConsoleEntry } from '@/store/console/types'
import type { UpdateResponse } from '@/store/version/types'
import type AppAutoScrollContainer from '@/components/ui/AppAutoScrollContainer.vue'
@Component({
components: {
ConsoleCommand,
ConsoleItem
}
})
export default class ConsoleBrowser extends Mixins(StateMixin) {
@Prop({ type: [Array], default: () => [] })
readonly items!: ConsoleEntry[] | UpdateResponse[]
@Prop({ type: Boolean })
readonly fullscreen?: boolean
@Prop({ type: Boolean })
readonly readonly?: boolean
@Prop({ type: String })
readonly search?: string
@Ref('consoleScroller')
readonly consoleScrollerElement!: AppAutoScrollContainer
get currentCommand (): string {
return this.$typedState.console.consoleCommand
}
set currentCommand (val: string) {
this.$typedCommit('console/setConsoleCommand', val)
}
get flipLayout (): boolean {
return this.$typedState.config.uiSettings.general.flipConsoleLayout
}
get orderedItems () {
const search = this.search?.toLowerCase()
const items = search
? this.items
.filter(item => item.message.toLowerCase().includes(search))
: [...this.items]
return this.flipLayout
? items.reverse()
: items
}
scrollToLatest () {
this.consoleScrollerElement.scrollToLatest(true)
}
sendCommand (command?: string) {
if (command) {
// If clients detect M112 input from the console, we should invoke the emergency_stop endpoint
if (command.trim().toLowerCase() === 'm112') {
SocketActions.printerEmergencyStop()
}
this.sendGcode(command)
this.currentCommand = ''
}
}
handleEntryClick (command: string) {
this.currentCommand = command
}
}
</script>
<style lang="scss" scoped>
.console-item {
white-space: pre-wrap;
}
.console-wrapper {
font-family: monospace;
font-size: 1rem; // 15 px
font-weight: 100 !important;
padding-left: 4px;
}
.console-scroller {
height: 300px;
}
.console-scroller-fullscreen {
height: calc(100vh - 308px);
height: calc(100svh - 308px);
}
.v-input {
flex: 0 0 auto;
}
</style>