Skip to content

Commit

Permalink
Merge pull request #197 from coroot/agent_installation_fix1
Browse files Browse the repository at this point in the history
ui: fix the `copy to clipboard` button
  • Loading branch information
apetruhin committed Apr 17, 2024
2 parents 5254b38 + b9a0b57 commit e01f91a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions front/src/components/Code.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="code">
<div ref="code" class="code">
<v-btn icon small dark class="copy" @click="copy" :disabled="disabled">
<v-icon small>{{ icon }}</v-icon>
</v-btn>
Expand Down Expand Up @@ -29,11 +29,20 @@ export default {
methods: {
copy() {
navigator.clipboard.writeText(this.$refs.body.innerText.trim());
this.copied = true;
setTimeout(() => {
this.copied = false;
}, 1000);
const textarea = document.createElement('textarea');
this.$refs.code.appendChild(textarea);
textarea.value = this.$refs.body.innerText.trim();
textarea.focus();
textarea.select();
try {
document.execCommand('copy');
this.copied = true;
setTimeout(() => {
this.copied = false;
}, 3000);
} finally {
this.$refs.code.removeChild(textarea);
}
},
},
};
Expand Down
3 changes: 2 additions & 1 deletion front/src/views/AgentInstallation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ export default {
components: { Code },
data() {
const local = ['127.0.0.1', 'localhost'].some((v) => location.origin.includes(v));
return {
dialog: false,
tab: null,
coroot_url: '',
coroot_url: !local ? location.origin : '',
scrape_interval: '15s',
valid: false,
};
Expand Down

0 comments on commit e01f91a

Please sign in to comment.