ImportExport.vue (hoppscotch-2.0.0) | : | ImportExport.vue (hoppscotch-2.1.0) | ||
---|---|---|---|---|
<template> | <template> | |||
<SmartModal | <SmartModal | |||
v-if="show" | v-if="show" | |||
:title="`${$t('modal.import_export')} ${$t('modal.collections')}`" | :title="`${$t('modal.import_export')} ${$t('modal.collections')}`" | |||
max-width="sm:max-w-md" | ||||
@close="hideModal" | @close="hideModal" | |||
> | > | |||
<template #actions> | <template #actions> | |||
<ButtonSecondary | <ButtonSecondary | |||
v-if="mode == 'import_from_my_collections'" | v-if="mode == 'import_from_my_collections'" | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title="$t('action.go_back')" | :title="$t('action.go_back')" | |||
class="rounded" | class="rounded" | |||
icon="arrow_back" | svg="arrow-left" | |||
@click.native=" | @click.native=" | |||
mode = 'import_export' | () => { | |||
mySelectedCollectionID = undefined | mode = 'import_export' | |||
mySelectedCollectionID = undefined | ||||
} | ||||
" | " | |||
/> | /> | |||
<span> | <span> | |||
<tippy | <tippy | |||
v-if=" | v-if=" | |||
mode == 'import_export' && collectionsType.type == 'my-collections' | mode == 'import_export' && collectionsType.type == 'my-collections' | |||
" | " | |||
ref="options" | ref="options" | |||
interactive | interactive | |||
trigger="click" | trigger="click" | |||
theme="popover" | theme="popover" | |||
arrow | arrow | |||
> | > | |||
<template #trigger> | <template #trigger> | |||
<ButtonSecondary | <ButtonSecondary | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title="$t('action.more')" | :title="$t('action.more')" | |||
class="rounded" | class="rounded" | |||
icon="more_vert" | svg="more-vertical" | |||
/> | /> | |||
</template> | </template> | |||
<SmartItem | <SmartItem | |||
icon="assignment_returned" | icon="assignment_returned" | |||
:label="$t('import.from_gist')" | :label="$t('import.from_gist')" | |||
@click.native=" | @click.native=" | |||
readCollectionGist | () => { | |||
$refs.options.tippy().hide() | readCollectionGist | |||
$refs.options.tippy().hide() | ||||
} | ||||
" | " | |||
/> | /> | |||
<span | <span | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title=" | :title=" | |||
!currentUser | !currentUser | |||
? $t('export.require_github') | ? $t('export.require_github') | |||
: currentUser.provider !== 'github.com' | : currentUser.provider !== 'github.com' | |||
? $t('export.require_github') | ? $t('export.require_github') | |||
: null | : null | |||
skipping to change at line 67 | skipping to change at line 72 | |||
:disabled=" | :disabled=" | |||
!currentUser | !currentUser | |||
? true | ? true | |||
: currentUser.provider !== 'github.com' | : currentUser.provider !== 'github.com' | |||
? true | ? true | |||
: false | : false | |||
" | " | |||
icon="assignment_turned_in" | icon="assignment_turned_in" | |||
:label="$t('export.create_secret_gist')" | :label="$t('export.create_secret_gist')" | |||
@click.native=" | @click.native=" | |||
createCollectionGist() | () => { | |||
$refs.options.tippy().hide() | createCollectionGist() | |||
$refs.options.tippy().hide() | ||||
} | ||||
" | " | |||
/> | /> | |||
</span> | </span> | |||
</tippy> | </tippy> | |||
</span> | </span> | |||
</template> | </template> | |||
<template #body> | <template #body> | |||
<div v-if="mode == 'import_export'" class="flex flex-col space-y-2"> | <div v-if="mode == 'import_export'" class="flex flex-col space-y-2"> | |||
<SmartItem | <SmartItem | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title="$t('action.replace_current')" | :title="$t('action.replace_current')" | |||
icon="folder_special" | svg="file" | |||
:label="$t('action.replace_json')" | :label="$t('action.replace_json')" | |||
@click.native="openDialogChooseFileToReplaceWith" | @click.native="openDialogChooseFileToReplaceWith" | |||
/> | /> | |||
<input | <input | |||
ref="inputChooseFileToReplaceWith" | ref="inputChooseFileToReplaceWith" | |||
class="input" | class="input" | |||
type="file" | type="file" | |||
style="display: none" | style="display: none" | |||
accept="application/json" | accept="application/json" | |||
@change="replaceWithJSON" | @change="replaceWithJSON" | |||
/> | /> | |||
<SmartItem | <SmartItem | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title="$t('action.preserve_current')" | :title="$t('action.preserve_current')" | |||
icon="create_new_folder" | svg="folder-plus" | |||
:label="$t('import.json')" | :label="$t('import.json')" | |||
@click.native="openDialogChooseFileToImportFrom" | @click.native="openDialogChooseFileToImportFrom" | |||
/> | /> | |||
<input | <input | |||
ref="inputChooseFileToImportFrom" | ref="inputChooseFileToImportFrom" | |||
class="input" | class="input" | |||
type="file" | type="file" | |||
style="display: none" | style="display: none" | |||
accept="application/json" | accept="application/json" | |||
@change="importFromJSON" | @change="importFromJSON" | |||
/> | /> | |||
<SmartItem | <SmartItem | |||
v-if="collectionsType.type == 'team-collections'" | v-if="collectionsType.type == 'team-collections'" | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title="$t('action.preserve_current')" | :title="$t('action.preserve_current')" | |||
icon="folder_shared" | svg="user" | |||
:label="$t('import.from_my_collections')" | :label="$t('import.from_my_collections')" | |||
@click.native="mode = 'import_from_my_collections'" | @click.native="mode = 'import_from_my_collections'" | |||
/> | /> | |||
<SmartItem | <SmartItem | |||
v-tippy="{ theme: 'tooltip' }" | v-tippy="{ theme: 'tooltip' }" | |||
:title="$t('action.download_file')" | :title="$t('action.download_file')" | |||
icon="drive_file_move" | svg="download" | |||
:label="$t('export.as_json')" | :label="$t('export.as_json')" | |||
@click.native="exportJSON" | @click.native="exportJSON" | |||
/> | /> | |||
</div> | </div> | |||
<div | <div | |||
v-if="mode == 'import_from_my_collections'" | v-if="mode == 'import_from_my_collections'" | |||
class="flex flex-col px-2" | class="flex flex-col px-2" | |||
> | > | |||
<div class="select-wrapper"> | <div class="select-wrapper"> | |||
<select | <select | |||
type="text" | type="text" | |||
autocomplete="off" | ||||
class="select" | class="select" | |||
autofocus | autofocus | |||
@change=" | @change=" | |||
($event) => { | ($event) => { | |||
mySelectedCollectionID = $event.target.value | mySelectedCollectionID = $event.target.value | |||
} | } | |||
" | " | |||
> | > | |||
<option | <option | |||
:key="undefined" | :key="undefined" | |||
skipping to change at line 163 | skipping to change at line 171 | |||
</option> | </option> | |||
</select> | </select> | |||
</div> | </div> | |||
</div> | </div> | |||
</template> | </template> | |||
<template #footer> | <template #footer> | |||
<div v-if="mode == 'import_from_my_collections'"> | <div v-if="mode == 'import_from_my_collections'"> | |||
<span> | <span> | |||
<ButtonPrimary | <ButtonPrimary | |||
:disabled="mySelectedCollectionID == undefined" | :disabled="mySelectedCollectionID == undefined" | |||
icon="create_new_folder" | svg="folder-plus" | |||
:label="$t('import.title')" | :label="$t('import.title')" | |||
@click.native="importFromMyCollections" | @click.native="importFromMyCollections" | |||
/> | /> | |||
</span> | </span> | |||
</div> | </div> | |||
</template> | </template> | |||
</SmartModal> | </SmartModal> | |||
</template> | </template> | |||
<script> | <script> | |||
skipping to change at line 407 | skipping to change at line 415 | |||
return this.collectionJson | return this.collectionJson | |||
}, | }, | |||
exportJSON() { | exportJSON() { | |||
this.getJSONCollection() | this.getJSONCollection() | |||
const dataToWrite = this.collectionJson | const dataToWrite = this.collectionJson | |||
const file = new Blob([dataToWrite], { type: "application/json" }) | const file = new Blob([dataToWrite], { type: "application/json" }) | |||
const a = document.createElement("a") | const a = document.createElement("a") | |||
const url = URL.createObjectURL(file) | const url = URL.createObjectURL(file) | |||
a.href = url | a.href = url | |||
// TODO get uri from meta | // TODO get uri from meta | |||
a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}` | a.download = `${url.split("/").pop().split("#")[0].split("?")[0]}.json` | |||
document.body.appendChild(a) | document.body.appendChild(a) | |||
a.click() | a.click() | |||
this.$toast.success(this.$t("state.download_started"), { | this.$toast.success(this.$t("state.download_started"), { | |||
icon: "downloading", | icon: "downloading", | |||
}) | }) | |||
setTimeout(() => { | setTimeout(() => { | |||
document.body.removeChild(a) | document.body.removeChild(a) | |||
URL.revokeObjectURL(url) | URL.revokeObjectURL(url) | |||
}, 1000) | }, 1000) | |||
}, | }, | |||
End of changes. 13 change blocks. | ||||
14 lines changed or deleted | 22 lines changed or added |