123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- <template>
- <div class="flex flex-col" :class="[{ 'bg-primaryLight': dragging }]">
- <div
- class="flex items-stretch group"
- @dragover.prevent
- @drop.prevent="dropEvent"
- @dragover="dragging = true"
- @drop="dragging = false"
- @dragleave="dragging = false"
- @dragend="dragging = false"
- @contextmenu.prevent="options.tippy().show()"
- >
- <span
- class="flex items-center justify-center px-4 cursor-pointer"
- @click="toggleShowChildren()"
- >
- <SmartIcon
- class="svg-icons"
- :class="{ 'text-accent': isSelected }"
- :name="getCollectionIcon"
- />
- </span>
- <span
- class="flex flex-1 min-w-0 py-2 pr-2 cursor-pointer transition group-hover:text-secondaryDark"
- @click="toggleShowChildren()"
- >
- <span class="truncate" :class="{ 'text-accent': isSelected }">
- {{ collection.name }}
- </span>
- </span>
- <div class="flex">
- <ButtonSecondary
- v-if="doc && !selected"
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('import.title')"
- svg="circle"
- color="green"
- @click.native="$emit('select-collection')"
- />
- <ButtonSecondary
- v-if="doc && selected"
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('action.remove')"
- svg="check-circle"
- color="green"
- @click.native="$emit('unselect-collection')"
- />
- <ButtonSecondary
- v-if="!doc"
- v-tippy="{ theme: 'tooltip' }"
- svg="file-plus"
- :title="$t('request.new')"
- class="hidden group-hover:inline-flex"
- @click.native="
- $emit('add-request', {
- path: `${collectionIndex}`,
- })
- "
- />
- <ButtonSecondary
- v-if="!doc"
- v-tippy="{ theme: 'tooltip' }"
- svg="folder-plus"
- :title="$t('folder.new')"
- class="hidden group-hover:inline-flex"
- @click.native="
- $emit('add-folder', {
- folder: collection,
- path: `${collectionIndex}`,
- })
- "
- />
- <span>
- <tippy
- ref="options"
- interactive
- trigger="click"
- theme="popover"
- arrow
- :on-shown="() => tippyActions.focus()"
- >
- <template #trigger>
- <ButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('action.more')"
- svg="more-vertical"
- />
- </template>
- <div
- ref="tippyActions"
- class="flex flex-col focus:outline-none"
- tabindex="0"
- role="menu"
- @keyup.r="requestAction.$el.click()"
- @keyup.n="folderAction.$el.click()"
- @keyup.e="edit.$el.click()"
- @keyup.delete="deleteAction.$el.click()"
- @keyup.x="exportAction.$el.click()"
- @keyup.escape="options.tippy().hide()"
- >
- <SmartItem
- ref="requestAction"
- svg="file-plus"
- :label="$t('request.new')"
- :shortcut="['R']"
- @click.native="
- () => {
- $emit('add-request', {
- path: `${collectionIndex}`,
- })
- options.tippy().hide()
- }
- "
- />
- <SmartItem
- ref="folderAction"
- svg="folder-plus"
- :label="$t('folder.new')"
- :shortcut="['N']"
- @click.native="
- () => {
- $emit('add-folder', {
- folder: collection,
- path: `${collectionIndex}`,
- })
- options.tippy().hide()
- }
- "
- />
- <SmartItem
- ref="edit"
- svg="edit"
- :label="$t('action.edit')"
- :shortcut="['E']"
- @click.native="
- () => {
- $emit('edit-collection')
- options.tippy().hide()
- }
- "
- />
- <SmartItem
- ref="exportAction"
- svg="download"
- :label="$t('export.title')"
- :shortcut="['X']"
- @click.native="
- () => {
- exportCollection()
- options.tippy().hide()
- }
- "
- />
- <SmartItem
- ref="deleteAction"
- svg="trash-2"
- :label="$t('action.delete')"
- :shortcut="['⌫']"
- @click.native="
- () => {
- removeCollection()
- options.tippy().hide()
- }
- "
- />
- </div>
- </tippy>
- </span>
- </div>
- </div>
- <div v-if="showChildren || isFiltered" class="flex">
- <div
- class="bg-dividerLight cursor-nsResize flex ml-5.5 transform transition w-1 hover:bg-dividerDark hover:scale-x-125"
- @click="toggleShowChildren()"
- ></div>
- <div class="flex flex-col flex-1 truncate">
- <CollectionsMyFolder
- v-for="(folder, index) in collection.folders"
- :key="`folder-${index}`"
- :folder="folder"
- :folder-index="index"
- :folder-path="`${collectionIndex}/${index}`"
- :collection-index="collectionIndex"
- :doc="doc"
- :save-request="saveRequest"
- :collections-type="collectionsType"
- :is-filtered="isFiltered"
- :picked="picked"
- @add-request="$emit('add-request', $event)"
- @add-folder="$emit('add-folder', $event)"
- @edit-folder="$emit('edit-folder', $event)"
- @edit-request="$emit('edit-request', $event)"
- @duplicate-request="$emit('duplicate-request', $event)"
- @select="$emit('select', $event)"
- @remove-request="$emit('remove-request', $event)"
- @remove-folder="$emit('remove-folder', $event)"
- />
- <CollectionsMyRequest
- v-for="(request, index) in collection.requests"
- :key="`request-${index}`"
- :request="request"
- :collection-index="collectionIndex"
- :folder-index="-1"
- :folder-name="collection.name"
- :folder-path="`${collectionIndex}`"
- :request-index="index"
- :doc="doc"
- :save-request="saveRequest"
- :collections-type="collectionsType"
- :picked="picked"
- @edit-request="$emit('edit-request', $event)"
- @duplicate-request="$emit('duplicate-request', $event)"
- @select="$emit('select', $event)"
- @remove-request="$emit('remove-request', $event)"
- />
- <div
- v-if="
- (collection.folders == undefined ||
- collection.folders.length === 0) &&
- (collection.requests == undefined ||
- collection.requests.length === 0)
- "
- class="flex flex-col items-center justify-center p-4 text-secondaryLight"
- >
- <img
- :src="`/images/states/${$colorMode.value}/pack.svg`"
- loading="lazy"
- class="inline-flex flex-col object-contain object-center w-16 h-16 mb-4"
- :alt="`${$t('empty.collection')}`"
- />
- <span class="text-center">
- {{ $t("empty.collection") }}
- </span>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script lang="ts">
- import { defineComponent, ref } from "@nuxtjs/composition-api"
- import { moveRESTRequest } from "~/newstore/collections"
- export default defineComponent({
- props: {
- collectionIndex: { type: Number, default: null },
- collection: { type: Object, default: () => {} },
- doc: Boolean,
- isFiltered: Boolean,
- selected: Boolean,
- saveRequest: Boolean,
- collectionsType: { type: Object, default: () => {} },
- picked: { type: Object, default: () => {} },
- },
- setup() {
- return {
- tippyActions: ref<any | null>(null),
- options: ref<any | null>(null),
- requestAction: ref<any | null>(null),
- folderAction: ref<any | null>(null),
- edit: ref<any | null>(null),
- deleteAction: ref<any | null>(null),
- exportAction: ref<any | null>(null),
- }
- },
- data() {
- return {
- showChildren: false,
- dragging: false,
- selectedFolder: {},
- prevCursor: "",
- cursor: "",
- pageNo: 0,
- }
- },
- computed: {
- isSelected(): boolean {
- return (
- this.picked &&
- this.picked.pickedType === "my-collection" &&
- this.picked.collectionIndex === this.collectionIndex
- )
- },
- getCollectionIcon() {
- if (this.isSelected) return "check-circle"
- else if (!this.showChildren && !this.isFiltered) return "folder"
- else if (this.showChildren || this.isFiltered) return "folder-open"
- else return "folder"
- },
- },
- methods: {
- exportCollection() {
- const collectionJSON = JSON.stringify(this.collection)
- const file = new Blob([collectionJSON], { type: "application/json" })
- const a = document.createElement("a")
- const url = URL.createObjectURL(file)
- a.href = url
- a.download = `${this.collection.name}.json`
- document.body.appendChild(a)
- a.click()
- this.$toast.success(this.$t("state.download_started").toString())
- setTimeout(() => {
- document.body.removeChild(a)
- URL.revokeObjectURL(url)
- }, 1000)
- },
- toggleShowChildren() {
- if (this.$props.saveRequest)
- this.$emit("select", {
- picked: {
- pickedType: "my-collection",
- collectionIndex: this.collectionIndex,
- },
- })
- this.$emit("expand-collection", this.collection.id)
- this.showChildren = !this.showChildren
- },
- removeCollection() {
- this.$emit("remove-collection", {
- collectionIndex: this.collectionIndex,
- collectionID: this.collection.id,
- })
- },
- dropEvent({ dataTransfer }: any) {
- this.dragging = !this.dragging
- const folderPath = dataTransfer.getData("folderPath")
- const requestIndex = dataTransfer.getData("requestIndex")
- moveRESTRequest(folderPath, requestIndex, `${this.collectionIndex}`)
- },
- },
- })
- </script>
|