123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <template>
- <div>
- <div
- class="
- bg-primary
- border-b border-dividerLight
- flex flex-1
- top-lowerSecondaryStickyFold
- pl-4
- z-10
- sticky
- items-center
- justify-between
- "
- >
- <label class="font-semibold text-secondaryLight">
- {{ $t("response.body") }}
- </label>
- <div class="flex">
- <ButtonSecondary
- v-if="response.body"
- ref="downloadResponse"
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('action.download_file')"
- :svg="downloadIcon"
- @click.native="downloadResponse"
- />
- <ButtonSecondary
- v-if="response.body"
- ref="copyResponse"
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('action.copy')"
- :svg="copyIcon"
- @click.native="copyResponse"
- />
- </div>
- </div>
- <div class="relative">
- <SmartAceEditor
- :value="responseBodyText"
- :lang="'xml'"
- :options="{
- maxLines: Infinity,
- minLines: 16,
- autoScrollEditorIntoView: true,
- readOnly: true,
- showPrintMargin: false,
- useWorker: false,
- }"
- styles="border-b border-dividerLight"
- />
- </div>
- </div>
- </template>
- <script>
- import { defineComponent } from "@nuxtjs/composition-api"
- import TextContentRendererMixin from "./mixins/TextContentRendererMixin"
- import { copyToClipboard } from "~/helpers/utils/clipboard"
- export default defineComponent({
- mixins: [TextContentRendererMixin],
- props: {
- response: { type: Object, default: () => {} },
- },
- data() {
- return {
- copyIcon: "copy",
- downloadIcon: "download",
- }
- },
- computed: {
- responseType() {
- return (
- this.response.headers.find(
- (h) => h.key.toLowerCase() === "content-type"
- ).value || ""
- )
- .split(";")[0]
- .toLowerCase()
- },
- },
- methods: {
- downloadResponse() {
- const dataToWrite = this.responseBodyText
- const file = new Blob([dataToWrite], { type: this.responseType })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- // TODO get uri from meta
- a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}`
- document.body.appendChild(a)
- a.click()
- this.downloadIcon = "check"
- this.$toast.success(this.$t("state.download_started"), {
- icon: "downloading",
- })
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- this.downloadIcon = "download"
- }, 1000)
- },
- copyResponse() {
- copyToClipboard(this.responseBodyText)
- this.copyIcon = "check"
- this.$toast.success(this.$t("state.copied_to_clipboard"), {
- icon: "content_paste",
- })
- setTimeout(() => (this.copyIcon = "copy"), 1000)
- },
- },
- })
- </script>
|