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

feat(Detail): added PagePreview component #51

Merged
merged 2 commits into from
Jan 12, 2024
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
16 changes: 16 additions & 0 deletions packages/@mapomodule/uikit/components/Detail/Detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@
>{{ $t("mapo.delete") }}</v-btn
>
</slot>
<!-- Use this to override the Preview Page button. -->
<slot name="button.preview" v-bind="slotBindings">
<!-- The Preview Page button. Needs a preview field from model. Declare it in the props. -->
<PagePreview
v-if="previewUrl"
:pageUrl="previewUrl"
/>
</slot>
</div>
</slot>
<!-- Use this to add content on the top of the sidebar fields (or under sidebar buttons). -->
Expand Down Expand Up @@ -281,6 +289,11 @@ export default {
return ["auto", "force", "disable"].indexOf(value) !== -1;
},
},
// The name of the field that contains the url of the page preview. [optional]
previewField: {
type: String,
required: false,
},
// This forces the detail page to be readonly.
readonly: Boolean
},
Expand Down Expand Up @@ -491,6 +504,9 @@ export default {
hasDiff() {
return !!(this.modelDiff && Object.keys(this.modelDiff).length > 0);
},
previewUrl() {
return this.previewField ? this.model[this.previewField] : null;
},
},
async mounted() {
if (this.identifier && this.identifier !== "new") {
Expand Down
58 changes: 58 additions & 0 deletions packages/@mapomodule/uikit/components/PagePreview.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<template>
<v-dialog v-model="dialog" width="90vw">
<template v-slot:activator="{ on, attrs }">
<v-btn tile block @click="openPreview(true)" color="primary" class="mb-2">
{{ $t("mapo.showPreview") }}</v-btn
>
</template>
<v-card class="iframe-card">
<iframe :src="computedUrl" class="iframe-preview"></iframe>
</v-card>
</v-dialog>
</template>

<style lang="scss" scoped>
.iframe-card {
height: 90vh;
min-height: 90vh;
}
.iframe-preview {
width: 100%;
height: 100%;
border: none;
}
</style>

<script>
export default {
name: "PagePreview",
props: {
pageUrl: {
type: String,
reruired: true,
},
},
data() {
return {
dialog: false,
};
},
methods: {
openPreview() {
this.dialog = true;
},
},
computed: {
checkifUrlIsAbsolute() {
return this.pageUrl.startsWith("http");
},
computedUrl() {
if (this.checkifUrlIsAbsolute) {
return this.pageUrl;
} else {
return `/${this.pageUrl}`;
}
},
},
};
</script>
1 change: 1 addition & 0 deletions packages/@mapomodule/uikit/translations/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default {
altTag: "Alt Tag",
titleTag: "Title Tag",
linkedModels: "Linked Models",
showPreview: "Show preview",
searchLocation: "Search location",
latitude: "Latitude",
longitude: "Longitude",
Expand Down
1 change: 1 addition & 0 deletions packages/@mapomodule/uikit/translations/it-IT.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default {
altTag: "Alt Tag",
titleTag: "Title Tag",
linkedModels: "Modelli collegati",
showPreview: "Mostra anteprima",
searchLocation: "Cerca luogo",
latitude: "Latitudine",
longitude: "Longitudine",
Expand Down
Loading