Skip to content

Commit

Permalink
display import modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ETLaurent committed Aug 9, 2023
1 parent 5fe2d20 commit a3d640c
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 0 deletions.
5 changes: 5 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"import": "Import",
"importType": "Import {{ type }}",
"importModalDescriptionStart": "Importing content requires a zip file. See our",
"importModalDescriptionLink": "guide to importing content",
"importModalDescriptionEnd": "in Apostrophe.",
"export": "Export",
"exporting": "Exporting",
"exportModalDescription": "You've selected {{ count }} {{ type }} for export"
Expand Down
29 changes: 29 additions & 0 deletions modules/@apostrophecms/import-export-piece-type/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ module.exports = {

cascades: [ 'batchOperations' ],

utilityOperations (self) {
return self.options.import !== false
? {
add: {
import: {
label: 'aposImportExport:import',
modalOptions: {
title: 'aposImportExport:importType',
descriptionStart: 'aposImportExport:importModalDescriptionStart',
descriptionLink: 'aposImportExport:importModalDescriptionLink',
descriptionEnd: 'aposImportExport:importModalDescriptionEnd',
confirmationButton: 'aposImportExport:importType',

// TODO: rename AposImportPiecesModal to AposImportModal since pages can be imported, not only pieces
modal: 'AposImportPiecesModal'
},
messages: {
progress: 'Importing {{ type }}...'
},
requestOptions: {
extension: 'zip'
}
}
}
}
: {};
},

batchOperations(self) {
if (self.options.export === false) {
return;
Expand All @@ -15,6 +43,7 @@ module.exports = {
messages: {
progress: 'aposImportExport:exporting'
},
// TODO: rename AposExportPiecesModal to AposExportModal since pages can be exported, not only pieces
modal: 'AposExportPiecesModal'
}
},
Expand Down
212 changes: 212 additions & 0 deletions ui/apos/components/AposImportPiecesModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
<template>
<AposModal
class="apos-import"
:modal="modal"
@show-modal="modal.showModal = true"
>
<template #main>
<AposModalBody>
<template #bodyMain>
<AposLogoIcon
class="apos-import__logo"
/>
<h2
v-if="title"
class="apos-import__heading"
>
{{ $t(title, { type: $t(labels.plural) }) }}
</h2>
<p class="apos-import__description">
{{ $t(descriptionStart) }}
<a
href="https://v3.docs.apostrophecms.org/"
target="_blank"
>{{ $t(descriptionLink) }}</a>
{{ $t(descriptionEnd) }}
</p>
<AposFile
class="apos-import__file"
allowed-extensions=".zip"
@upload-file="uploadImportFile"
@update="updateImportFile"
/>
<div class="apos-import__btns">
<AposButton
class="apos-import__btn"
label="apostrophe:cancel"
@click="cancel"
/>
<AposButton
class="apos-import__btn"
:label="$t(confirmationButton, { type: $t(labels.plural) })"
:type="'primary'"
:disabled="!selectedFile"
@click="runImport"
/>
</div>
</template>
</AposModalBody>
</template>
</AposModal>
</template>

<script>
export default {
props: {
action: {
type: String,
required: true
},
moduleAction: {
type: String,
required: true
},
title: {
type: String,
required: true
},
descriptionStart: {
type: String,
required: true
},
descriptionLink: {
type: String,
required: true
},
descriptionEnd: {
type: String,
required: true
},
confirmationButton: {
type: String,
required: true
},
labels: {
type: Object,
required: true
},
messages: {
type: Object,
default: null
}
},
data () {
return {
modal: {
title: '',
active: false,
type: 'overlay',
showModal: false,
disableHeader: true
},
selectedFile: null
};
},
mounted() {
this.modal.active = true;
},
methods: {
uploadImportFile (file) {
this.selectedFile = file || null;
},
updateImportFile () {
this.selectedFile = null;
},
cancel () {
this.modal.active = false;
},
async runImport () {
// try {
// const formData = new FormData();
// formData.append('file', this.selectedFile);
// if (this.messages) {
// Object.entries(this.messages).forEach(([ stage, message ]) => {
// formData.append(stage, message);
// });
// }
// this.selectedFile = null;
// await apos.http.post(`${this.moduleAction}/${this.action}`, {
// body: formData
// });
// } catch (error) {
// apos.notify('Import failed.', {
// type: 'danger',
// dismiss: true
// });
// }
this.modal.active = false;
}
}
};
</script>

<style scoped lang='scss'>
.apos-import {
z-index: $z-index-modal;
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-items: center;
justify-content: center;
&__logo {
height: 35px;
margin-bottom: $spacing-double;
}
&__heading {
@include type-title;
line-height: var(--a-line-tall);
margin: 0;
}
&__description {
@include type-base;
max-width: 370px;
line-height: var(--a-line-tallest);
}
&__file {
min-width: 370px;
}
&__btns {
display: flex;
justify-content: center;
margin-top: 10px;
}
&__btn {
& + & {
margin-left: $spacing-double;
}
}
}
::v-deep {
.apos-modal__inner {
top: auto;
right: auto;
bottom: auto;
left: auto;
max-width: 700px;
height: auto;
text-align: center;
}
.apos-modal__body-main {
display: flex;
flex-direction: column;
align-items: center;
}
}
</style>

0 comments on commit a3d640c

Please sign in to comment.