Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

display import modal #3

Merged
merged 8 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"exportModalIncludeRelated": "Include related documents",
"exportModalIncludeChildren": "Include children of this page",
"exportModalIncludeRelatedSettings": "Related Documents Settings",
"exportModalNoRelatedTypes": "No Related Types"
"exportModalNoRelatedTypes": "No Related Types",
"import": "Import",
"importDocuments": "Import Documents",
"importModalDescription": "Importing content requires a zip file. See our <a href=\"https://v3.docs.apostrophecms.org/\" target=\"_blank\">guide to importing content</a> in Apostrophe."
}
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {

init(self) {
self.apos.asset.iconMap['apos-import-export-download-icon'] = 'Download';
self.apos.asset.iconMap['apos-import-export-upload-icon'] = 'Upload';
},

apiRoutes(self) {
Expand Down
26 changes: 26 additions & 0 deletions modules/@apostrophecms/import-export-page/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
improve: '@apostrophecms/page',

utilityOperations (self) {
if (self.options.import === false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the ticket, the option name is shareDocsDisableImport. Not sure it's a good one since he module is called import-export but we might check.

Copy link
Contributor Author

@ETLaurent ETLaurent Aug 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's why Anthony has changed it to export.
I did the same with import so we can disable the export and not the import, and vice versa.
We could still change the name later I think.

return {};
}

return {
add: {
import: {
label: 'aposImportExport:import',
modalOptions: {
modal: 'AposImportModal'
},
messages: {
progress: 'Importing {{ type }}...'
},
requestOptions: {
extension: 'zip'
}
}
}
};
}
};
23 changes: 23 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,29 @@ module.exports = {

cascades: [ 'batchOperations' ],

utilityOperations (self) {
if (self.options.import === false) {
return {};
}

return {
add: {
import: {
label: 'aposImportExport:import',
modalOptions: {
modal: 'AposImportModal'
},
messages: {
progress: 'Importing {{ type }}...'
},
requestOptions: {
extension: 'zip'
}
}
}
};
},

batchOperations(self) {
if (self.options.export === false) {
return;
Expand Down
151 changes: 151 additions & 0 deletions ui/apos/components/AposImportModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
<template>
<AposModal
class="apos-import"
:modal="modal"
@esc="cancel"
@no-modal="$emit('safe-close')"
@inactive="modal.active = false"
@show-modal="modal.showModal = true"
@ready="ready"
>
<template #main>
<AposModalBody>
<template #bodyMain>
<h2 class="apos-import__heading">
{{ $t('aposImportExport:importDocuments') }}
</h2>
<!-- eslint-disable vue/no-v-html -->
<p
class="apos-import__description"
v-html="$t('aposImportExport:importModalDescription')"
/>
<!-- eslint-enable vue/no-v-html -->
<AposFile
class="apos-import__file"
allowed-extensions=".zip"
@upload-file="uploadImportFile"
@update="updateImportFile"
/>
<div class="apos-import__btns">
<AposButton
ref="cancelButton"
class="apos-import__btn"
label="apostrophe:cancel"
@click="cancel"
/>
<AposButton
class="apos-import__btn"
icon="apos-import-export-upload-icon"
label="aposImportExport:import"
type="primary"
:disabled="!selectedFile"
@click="runImport"
/>
</div>
</template>
</AposModalBody>
</template>
</AposModal>
</template>

<script>
export default {
emits: [ 'safe-close' ],
data () {
return {
modal: {
active: false,
type: 'overlay',
showModal: false,
disableHeader: true
},
selectedFile: null
};
},
mounted() {
this.modal.active = true;
},
methods: {
ready() {
this.$refs.cancelButton.$el.querySelector('button').focus();
},
uploadImportFile (file) {
this.selectedFile = file || null;
},
updateImportFile () {
this.selectedFile = null;
},
cancel () {
this.modal.active = false;
this.modal.showModal = false;
},
async runImport () {
// TODO: implement

this.modal.showModal = 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;

&__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: space-between;
margin-top: 10px;
width: 100%;
}

&__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: left;
}

.apos-modal__body-main {
display: flex;
flex-direction: column;
align-items: baseline;
}
}

</style>