From 7e30a4a3d460f3011696002b09e188fb8f97204d Mon Sep 17 00:00:00 2001 From: Farhan Tariq Date: Wed, 21 Oct 2020 06:11:45 +0500 Subject: [PATCH] Subfolder functionality (#1194) * Added functionality for sub-folders * Edit Request name only. Drag and drop to move requests * Refactor * Move requests between folder or collections * Functionality to save request in multiple folders * Unnecessary Lang Co-authored-by: Liyas Thomas --- components/collections/add-folder.vue | 15 +- components/collections/collection.vue | 50 +++-- components/collections/edit-folder.vue | 2 +- components/collections/edit-request.vue | 80 ++----- components/collections/folder.vue | 75 +++++-- .../collections/import-export-collections.vue | 94 +++----- components/collections/index.vue | 35 +-- components/collections/request.vue | 34 ++- components/collections/save-request-as.vue | 107 +++++---- components/ui/autocomplete.vue | 8 +- store/postwoman.js | 207 +++++++++--------- 11 files changed, 362 insertions(+), 345 deletions(-) diff --git a/components/collections/add-folder.vue b/components/collections/add-folder.vue index d81823319..28aca4a0d 100644 --- a/components/collections/add-folder.vue +++ b/components/collections/add-folder.vue @@ -21,7 +21,7 @@ type="text" v-model="name" :placeholder="$t('my_new_folder')" - @keyup.enter="addNewFolder" + @keyup.enter="addFolder" /> @@ -33,7 +33,7 @@ - @@ -45,14 +45,13 @@ diff --git a/components/collections/import-export-collections.vue b/components/collections/import-export-collections.vue index dbba1f8f2..cbab58714 100644 --- a/components/collections/import-export-collections.vue +++ b/components/collections/import-export-collections.vue @@ -117,7 +117,7 @@ export default { // Do nothing } } else if (collections.info && collections.info.schema.includes("v2.1.0")) { - collections = this.parsePostmanCollection(collections) + collections = [this.parsePostmanCollection(collections)] } else { return this.failedImport() } @@ -141,8 +141,7 @@ export default { } else if (collections.info && collections.info.schema.includes("v2.1.0")) { //replace the variables, postman uses {{var}}, Hoppscotch uses <> collections = JSON.parse(content.replaceAll(/{{([a-z]+)}}/gi, "<<$1>>")) - collections.item = this.flattenPostmanFolders(collections) - collections = this.parsePostmanCollection(collections) + collections = [this.parsePostmanCollection(collections)] } else { return this.failedImport() } @@ -192,36 +191,31 @@ export default { icon: "error", }) }, - parsePostmanCollection(collection, folders = true) { - let postwomanCollection = folders - ? [ - { - name: "", - folders: [], - requests: [], - }, - ] - : { - name: "", - requests: [], - } - if (folders) { - //pick up collection name even when all children are folders - postwomanCollection[0].name = collection.info ? collection.info.name : "" - } - for (let collectionItem of collection.item) { - if (collectionItem.request) { - if (postwomanCollection[0]) { - postwomanCollection[0].name = collection.info ? collection.info.name : "" - postwomanCollection[0].requests.push(this.parsePostmanRequest(collectionItem)) + parsePostmanCollection(collection) { + let postwomanCollection = + { + name: "", + folders: [], + requests: [], + } + + postwomanCollection.name = collection.info ? collection.info.name : collection.name + + if (collection.item && collection.item.length > 0) { + for (let collectionItem of collection.item) { + if (collectionItem.request) { + if (postwomanCollection.hasOwnProperty('folders')) { + postwomanCollection.name = collection.info ? collection.info.name : collection.name + postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem)) + } else { + postwomanCollection.name = collection.name ? collection.name : "" + postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem)) + } + } else if (this.hasFolder(collectionItem)) { + postwomanCollection.folders.push(this.parsePostmanCollection(collectionItem)) } else { - postwomanCollection.name = collection.name ? collection.name : "" postwomanCollection.requests.push(this.parsePostmanRequest(collectionItem)) } - } else if (collectionItem.item) { - if (collectionItem.item[0]) { - postwomanCollection[0].folders.push(this.parsePostmanCollection(collectionItem, false)) - } } } return postwomanCollection @@ -300,46 +294,8 @@ export default { } return pwRequest }, - flattenPostmanFolders(collection) { - let items = [] - - for (let collectionItem of collection.item) { - if (this.hasFolder(collectionItem)) { - let newFolderItems = [] - for (let folderItem of collectionItem.item) { - if (this.isSubFolder(folderItem)) { - newFolderItems = newFolderItems.concat(this.flattenPostmanItem(folderItem)) - } else { - newFolderItems.push(folderItem) - } - } - collectionItem.item = newFolderItems - } - items.push(collectionItem) - } - return items - }, hasFolder(item) { - return Object.prototype.hasOwnProperty.call(item, "item") - }, - isSubFolder(item) { - return ( - Object.prototype.hasOwnProperty.call(item, "_postman_isSubFolder") && - item._postman_isSubFolder - ) - }, - flattenPostmanItem(subFolder, subFolderGlue = " -- ") { - delete subFolder._postman_isSubFolder - let flattenedItems = [] - for (let subFolderItem of subFolder.item) { - subFolderItem.name = subFolder.name + subFolderGlue + subFolderItem.name - if (this.isSubFolder(subFolderItem)) { - flattenedItems = flattenedItems.concat(this.flattenPostmanItem(subFolderItem)) - } else { - flattenedItems.push(subFolderItem) - } - } - return flattenedItems + return item.hasOwnProperty('item') }, }, } diff --git a/components/collections/index.vue b/components/collections/index.vue index aca710adc..9406983e5 100644 --- a/components/collections/index.vue +++ b/components/collections/index.vue @@ -14,30 +14,29 @@ TODO:
  • -
    +