Skip to content

Commit

Permalink
Add copy to clipboard button in Diagnostics page. (#2717)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com>
  • Loading branch information
ildyria and d7415 authored Nov 25, 2024
1 parent 98d012d commit 598150c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ import DiagnosticsService from "@/services/diagnostics-service";
const configs = ref<string[] | undefined>(undefined);
const emits = defineEmits<{
loaded: [data: string[]];
}>();
function load() {
DiagnosticsService.config().then((response) => {
configs.value = response.data;
emits("loaded", response.data);
});
}
Expand Down
5 changes: 5 additions & 0 deletions resources/js/components/diagnostics/ErrorsDiagnostics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import DiagnosticsService from "@/services/diagnostics-service";
const errors = ref<App.Http.Resources.Diagnostics.ErrorLine[] | undefined>(undefined);
const emits = defineEmits<{
loaded: [data: App.Http.Resources.Diagnostics.ErrorLine[]];
}>();
function load() {
DiagnosticsService.errors().then((response) => {
errors.value = response.data;
emits("loaded", response.data);
});
}
Expand Down
4 changes: 4 additions & 0 deletions resources/js/components/diagnostics/InfoDiagnostics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import Panel from "primevue/panel";
import DiagnosticsService from "@/services/diagnostics-service";
const infos = ref<string[] | undefined>(undefined);
const emits = defineEmits<{
loaded: [data: string[]];
}>();
function load() {
DiagnosticsService.info().then((response) => {
infos.value = response.data;
emits("loaded", response.data);
});
}
Expand Down
55 changes: 48 additions & 7 deletions resources/js/views/Diagnostics.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
<Toolbar class="w-full border-0 h-14">
<template #start>
<Button @click="togglableStore.toggleLeftMenu" icon="pi pi-bars" class="mr-2 border-none" severity="secondary" text />
<!-- <router-link :to="{ name: 'gallery' }">
<Button icon="pi pi-angle-left" class="mr-2" severity="secondary" text />
</router-link> -->
</template>

<template #center>
{{ $t("lychee.DIAGNOSTICS") }}
</template>

<template #end> </template>
<template #end>
<Button :disabled="!canCopy" text aria-label="Copy" icon="pi pi-copy" v-tooltip="'Copy diagnostics to clipboard'" @click="copy" />
</template>
</Toolbar>
<ErrorsDiagnotics />
<InfoDiagnostics v-if="user?.id" />
<ErrorsDiagnotics @loaded="loadError" />
<InfoDiagnostics v-if="user?.id" @loaded="loadInfo" />
<SpaceDiagnostics v-if="user?.id" />
<ConfigurationsDiagnostics v-if="user?.id" />
<ConfigurationsDiagnostics v-if="user?.id" @loaded="loadConfig" />
</template>
<script setup lang="ts">
import { ref, computed } from "vue";
import Toolbar from "primevue/toolbar";
import Button from "primevue/button";
import ConfigurationsDiagnostics from "@/components/diagnostics/ConfigurationsDiagnostics.vue";
Expand All @@ -28,9 +28,50 @@ import SpaceDiagnostics from "@/components/diagnostics/SpaceDiagnostics.vue";
import { useAuthStore } from "@/stores/Auth";
import { storeToRefs } from "pinia";
import { useTogglablesStateStore } from "@/stores/ModalsState";
import { useToast } from "primevue/usetoast";
const authStore = useAuthStore();
const { user } = storeToRefs(authStore);
authStore.getUser();
const togglableStore = useTogglablesStateStore();
const toast = useToast();
const errorLoaded = ref<App.Http.Resources.Diagnostics.ErrorLine[] | undefined>(undefined);
const infoLoaded = ref<string[] | undefined>(undefined);
const configurationLoaded = ref<string[] | undefined>(undefined);
const canCopy = computed(() => errorLoaded.value !== undefined && infoLoaded.value !== undefined && configurationLoaded.value !== undefined);
function loadError(val: App.Http.Resources.Diagnostics.ErrorLine[]) {
errorLoaded.value = val;
}
function loadInfo(val: string[]) {
infoLoaded.value = val;
}
function loadConfig(val: string[]) {
configurationLoaded.value = val;
}
function copy() {
if (!canCopy) {
return;
}
console.log(errorLoaded.value);
const errorText = errorLoaded.value
?.filter((errorLine) => errorLine.type !== undefined)
.map((errorLines) => `${errorLines.type.padEnd(7)}: ${errorLines.line}`)
.join("\n");
const infoText = infoLoaded.value?.join("\n");
const configurationText = configurationLoaded.value?.join("\n");
const toClipBoard = `Errors:\n${"-".repeat(20)}\n${errorText}\n\n\nInfo:\n${"-".repeat(20)}\n${infoText}\n\n\nConfig:\n${"-".repeat(20)}\n${configurationText}`;
navigator.clipboard
.writeText(toClipBoard)
.then(() => toast.add({ severity: "info", summary: "Info", detail: "Diagnostic copied to clipboard", life: 3000 }));
}
</script>
2 changes: 1 addition & 1 deletion resources/js/views/Error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</template>
</template>
<script setup lang="ts">
import { type Ref, ref } from "vue";
import { ref } from "vue";
import Divider from "primevue/divider";
import Message from "primevue/message";
import Panel from "primevue/panel";
Expand Down

0 comments on commit 598150c

Please sign in to comment.