123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- <template>
- <div class="flex flex-col" :class="[{ 'bg-primaryLight': dragging }]">
- <div
- class="flex items-center group"
- @dragover.prevent
- @drop.prevent="dropEvent"
- @dragover="dragging = true"
- @drop="dragging = false"
- @dragleave="dragging = false"
- @dragend="dragging = false"
- >
- <span
- class="cursor-pointer flex px-4 justify-center items-center"
- @click="toggleShowChildren()"
- >
- <SmartIcon
- class="svg-icons"
- :class="{ 'text-green-500': isSelected }"
- :name="getCollectionIcon"
- />
- </span>
- <span
- class="
- cursor-pointer
- flex flex-1
- min-w-0
- py-2
- pr-2
- transition
- group-hover:text-secondaryDark
- "
- @click="toggleShowChildren()"
- >
- <span class="truncate">
- {{ folder.name ? folder.name : folder.title }}
- </span>
- </span>
- <div class="flex">
- <ButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- svg="folder-plus"
- :title="$t('folder.new')"
- class="hidden group-hover:inline-flex"
- @click.native="$emit('add-folder', { folder, path: folderPath })"
- />
- <span>
- <tippy
- ref="options"
- interactive
- trigger="click"
- theme="popover"
- arrow
- >
- <template #trigger>
- <ButtonSecondary
- v-tippy="{ theme: 'tooltip' }"
- :title="$t('action.more')"
- svg="more-vertical"
- />
- </template>
- <SmartItem
- svg="folder-plus"
- :label="$t('folder.new')"
- @click.native="
- () => {
- $emit('add-folder', { folder, path: folderPath })
- $refs.options.tippy().hide()
- }
- "
- />
- <SmartItem
- svg="edit"
- :label="$t('action.edit')"
- @click.native="
- () => {
- $emit('edit-folder', {
- folder,
- folderIndex,
- collectionIndex,
- folderPath,
- })
- $refs.options.tippy().hide()
- }
- "
- />
- <SmartItem
- svg="trash-2"
- color="red"
- :label="$t('action.delete')"
- @click.native="
- () => {
- confirmRemove = true
- $refs.options.tippy().hide()
- }
- "
- />
- </tippy>
- </span>
- </div>
- </div>
- <div v-if="showChildren || isFiltered" class="flex">
- <div
- class="
- flex
- w-1
- transform
- transition
- cursor-nsResize
- ml-5.5
- bg-dividerLight
- hover:scale-x-125 hover:bg-dividerDark
- "
- @click="toggleShowChildren()"
- ></div>
- <div class="flex flex-col flex-1 truncate">
- <CollectionsMyFolder
- v-for="(subFolder, subFolderIndex) in folder.folders"
- :key="`subFolder-${subFolderIndex}`"
- :folder="subFolder"
- :folder-index="subFolderIndex"
- :collection-index="collectionIndex"
- :doc="doc"
- :save-request="saveRequest"
- :collections-type="collectionsType"
- :folder-path="`${folderPath}/${subFolderIndex}`"
- :picked="picked"
- @add-folder="$emit('add-folder', $event)"
- @edit-folder="$emit('edit-folder', $event)"
- @edit-request="$emit('edit-request', $event)"
- @duplicate-request="$emit('duplicate-request', $event)"
- @update-team-collections="$emit('update-team-collections')"
- @select="$emit('select', $event)"
- @remove-request="removeRequest"
- />
- <CollectionsMyRequest
- v-for="(request, index) in folder.requests"
- :key="`request-${index}`"
- :request="request"
- :collection-index="collectionIndex"
- :folder-index="folderIndex"
- :folder-name="folder.name"
- :folder-path="folderPath"
- :request-index="index"
- :doc="doc"
- :picked="picked"
- :save-request="saveRequest"
- :collections-type="collectionsType"
- @edit-request="$emit('edit-request', $event)"
- @duplicate-request="$emit('duplicate-request', $event)"
- @select="$emit('select', $event)"
- @remove-request="removeRequest"
- />
- <div
- v-if="
- folder.folders &&
- folder.folders.length === 0 &&
- folder.requests &&
- folder.requests.length === 0
- "
- class="
- flex flex-col
- text-secondaryLight
- p-4
- items-center
- justify-center
- "
- >
- <img
- :src="`/images/states/${$colorMode.value}/pack.svg`"
- loading="lazy"
- class="
- flex-col
- mb-4
- object-contain object-center
- h-16
- w-16
- inline-flex
- "
- :alt="$t('empty.folder')"
- />
- <span class="text-center">
- {{ $t("empty.folder") }}
- </span>
- </div>
- </div>
- </div>
- <SmartConfirmModal
- :show="confirmRemove"
- :title="$t('confirm.remove_folder')"
- @hide-modal="confirmRemove = false"
- @resolve="removeFolder"
- />
- </div>
- </template>
- <script>
- import { defineComponent } from "@nuxtjs/composition-api"
- import {
- removeRESTFolder,
- removeRESTRequest,
- moveRESTRequest,
- } from "~/newstore/collections"
- export default defineComponent({
- name: "Folder",
- props: {
- folder: { type: Object, default: () => {} },
- folderIndex: { type: Number, default: null },
- collectionIndex: { type: Number, default: null },
- folderPath: { type: String, default: null },
- doc: Boolean,
- saveRequest: Boolean,
- isFiltered: Boolean,
- collectionsType: { type: Object, default: () => {} },
- picked: { type: Object, default: () => {} },
- },
- data() {
- return {
- showChildren: false,
- dragging: false,
- confirmRemove: false,
- prevCursor: "",
- cursor: "",
- }
- },
- computed: {
- isSelected() {
- return (
- this.picked &&
- this.picked.pickedType === "my-folder" &&
- this.picked.folderPath === this.folderPath
- )
- },
- getCollectionIcon() {
- if (this.isSelected) return "check-circle"
- else if (!this.showChildren && !this.isFiltered) return "folder"
- else if (this.showChildren || this.isFiltered) return "folder-minus"
- else return "folder"
- },
- },
- methods: {
- toggleShowChildren() {
- if (this.$props.saveRequest)
- this.$emit("select", {
- picked: {
- pickedType: "my-folder",
- collectionIndex: this.collectionIndex,
- folderName: this.folder.name,
- folderPath: this.folderPath,
- },
- })
- this.showChildren = !this.showChildren
- },
- removeFolder() {
- // TODO: Bubble it up ?
- // Cancel pick if picked folder was deleted
- if (
- this.picked &&
- this.picked.pickedType === "my-folder" &&
- this.picked.folderPath === this.folderPath
- ) {
- this.$emit("select", { picked: null })
- }
- removeRESTFolder(this.folderPath)
- this.$toast.success(this.$t("state.deleted"), {
- icon: "delete",
- })
- },
- dropEvent({ dataTransfer }) {
- this.dragging = !this.dragging
- const folderPath = dataTransfer.getData("folderPath")
- const requestIndex = dataTransfer.getData("requestIndex")
- moveRESTRequest(folderPath, requestIndex, this.folderPath)
- },
- removeRequest({ requestIndex }) {
- // TODO: Bubble it up to root ?
- // Cancel pick if the picked item is being deleted
- if (
- this.picked &&
- this.picked.pickedType === "my-request" &&
- this.picked.folderPath === this.folderPath &&
- this.picked.requestIndex === requestIndex
- ) {
- this.$emit("select", { picked: null })
- }
- removeRESTRequest(this.folderPath, requestIndex)
- },
- },
- })
- </script>
|