|
20 | 20 | <v-card :key="i" data-test="device-card"> |
21 | 21 | <v-list-item |
22 | 22 | @click="openDialog(item.uid)" |
| 23 | + @keydown="openTerminalMacro(item)" |
23 | 24 | :key="i" |
24 | 25 | class="ma-0 pa-0 card" |
25 | 26 | data-test="device-list-item" |
|
39 | 40 | <CopyWarning |
40 | 41 | ref="copyRef" |
41 | 42 | :copied-item="'Device SSHID'" |
| 43 | + :bypass="shouldOpenTerminalHelper()" |
42 | 44 | :macro="sshidAddress(item)" |
43 | 45 | > |
44 | 46 | <template #default="{ copyText }"> |
45 | 47 | <span |
46 | 48 | v-bind="props" |
47 | 49 | tabindex="0" |
48 | 50 | class="hover-text" |
49 | | - @click.stop="copyText(sshidAddress(item))" |
50 | | - @keydown.enter.stop="copyText(sshidAddress(item))" |
| 51 | + @click.stop="handleSshidClick(item, copyText)" |
| 52 | + @keypress.enter.stop="handleSshidClick(item, copyText)" |
51 | 53 | data-test="copy-id-button" |
52 | 54 | > |
53 | 55 | {{ sshidAddress(item) }} |
54 | 56 | </span> |
55 | 57 | </template> |
56 | 58 | </CopyWarning> |
57 | | - |
58 | 59 | </template> |
59 | 60 | <span>Copy ID</span> |
60 | 61 | </v-tooltip> |
|
85 | 86 | </v-card> |
86 | 87 | </v-col> |
87 | 88 | </v-list> |
88 | | - |
| 89 | + <TerminalHelper |
| 90 | + v-if="showTerminalHelper" |
| 91 | + v-model="showTerminalHelper" |
| 92 | + :sshid="selectedSshid" |
| 93 | + :user-id="userId" |
| 94 | + :show-checkbox="true" |
| 95 | + /> |
89 | 96 | <TerminalDialog |
90 | 97 | v-model="showDialog" |
91 | 98 | :deviceUid="selectedDeviceUid" |
|
96 | 103 | <script setup lang="ts"> |
97 | 104 | import { ref, onMounted, computed, watch } from "vue"; |
98 | 105 | import { VList } from "vuetify/components"; |
| 106 | +import { useMagicKeys } from "@vueuse/core"; |
99 | 107 | import TerminalDialog from "../Terminal/TerminalDialog.vue"; |
| 108 | +import TerminalHelper from "../Terminal/TerminalHelper.vue"; |
| 109 | +import CopyWarning from "@/components/User/CopyWarning.vue"; |
100 | 110 | import { useStore } from "@/store"; |
101 | 111 | import { displayOnlyTenCharacters } from "@/utils/string"; |
102 | 112 | import showTag from "@/utils/tag"; |
103 | 113 | import DeviceIcon from "../Devices/DeviceIcon.vue"; |
104 | 114 | import handleError from "@/utils/handleError"; |
105 | 115 | import { IDevice } from "@/interfaces/IDevice"; |
106 | 116 | import useSnackbar from "@/helpers/snackbar"; |
107 | | -import CopyWarning from "@/components/User/CopyWarning.vue"; |
108 | 117 |
|
109 | 118 | interface Device { |
110 | 119 | online: boolean |
111 | 120 | } |
112 | 121 |
|
113 | 122 | const store = useStore(); |
114 | 123 | const snackbar = useSnackbar(); |
115 | | -const copyRef = ref<InstanceType<typeof CopyWarning> | null>(null); |
116 | 124 | const loading = ref(false); |
117 | 125 | const itemsPerPage = ref(10); |
118 | 126 | const page = ref(); |
119 | 127 | const rootEl = ref<VList>(); |
120 | 128 | const selectedDeviceUid = ref(""); |
121 | 129 | const showDialog = ref(false); |
| 130 | +const showTerminalHelper = ref(false); |
| 131 | +const selectedSshid = ref(""); |
| 132 | +const userId = computed(() => store.getters["auth/id"]); |
122 | 133 |
|
123 | 134 | defineExpose({ rootEl }); |
124 | 135 |
|
@@ -187,6 +198,43 @@ watch(itemsPerPage, async () => { |
187 | 198 | }); |
188 | 199 |
|
189 | 200 | const sshidAddress = (item: IDevice) => `${item.namespace}.${item.name}@${window.location.hostname}`; |
| 201 | +
|
| 202 | +const openTerminalHelper = (item: IDevice) => { |
| 203 | + selectedSshid.value = sshidAddress(item); |
| 204 | + showTerminalHelper.value = true; |
| 205 | +}; |
| 206 | +
|
| 207 | +const shouldOpenTerminalHelper = () => { |
| 208 | + try { |
| 209 | + const dispensedUsers = JSON.parse(localStorage.getItem("dispenseTerminalHelper") || "[]"); |
| 210 | + return !dispensedUsers.includes(userId.value); |
| 211 | + } catch { |
| 212 | + return true; |
| 213 | + } |
| 214 | +}; |
| 215 | +
|
| 216 | +const handleSshidClick = (item: IDevice, copyFn: (text: string) => void) => { |
| 217 | + if (shouldOpenTerminalHelper()) { |
| 218 | + openTerminalHelper(item); |
| 219 | + return; |
| 220 | + } |
| 221 | + copyFn(sshidAddress(item)); |
| 222 | +}; |
| 223 | +
|
| 224 | +const openTerminalMacro = (value: IDevice) => { |
| 225 | + let executed = false; |
| 226 | +
|
| 227 | + return useMagicKeys({ |
| 228 | + passive: false, |
| 229 | + onEventFired(e) { |
| 230 | + if (!executed && value && e.ctrlKey && e.key === "c" && e.type === "keydown") { |
| 231 | + executed = true; |
| 232 | + openTerminalHelper(value); |
| 233 | + e.preventDefault(); |
| 234 | + } |
| 235 | + }, |
| 236 | + }); |
| 237 | +}; |
190 | 238 | </script> |
191 | 239 |
|
192 | 240 | <style scoped> |
|
0 commit comments