Skip to content
Snippets Groups Projects
Commit becf5b24 authored by Camille Blanchon's avatar Camille Blanchon
Browse files

Merge branch 'redmine-issues/23374' into 'develop'

REDMINE_ISSUE-23374 | Création d’un Web Component pour l’affichage de données issues de GéoContrib dans un site web tiers

See merge request !854
parents ca666eaa 76e735a0
No related branches found
No related tags found
1 merge request!854REDMINE_ISSUE-23374 | Création d’un Web Component pour l’affichage de données issues de GéoContrib dans un site web tiers
...@@ -115,22 +115,44 @@ ...@@ -115,22 +115,44 @@
aria-hidden="true" aria-hidden="true"
/> />
</a> </a>
</div> <div
v-if="isProjectAdmin && !isSharedProject"
<button id="share-button"
v-if="isProjectAdmin && !isSharedProject && project.generate_share_link" class="ui dropdown button compact tiny-margin"
class="ui teal left labeled icon button share-button tiny-margin" data-tooltip="Partager le projet"
@click="copyLink" data-position="bottom right"
data-variation="mini"
@click="toggleShareOptions"
> >
<i <i
class="left icon share square" class="inverted grey share icon"
aria-hidden="true" aria-hidden="true"
/> />
<div
:class="['menu left transition', {'visible': showShareOptions}]"
style="z-index: 9999"
>
<div
v-if="project.generate_share_link"
class="item"
@click="copyLink"
>
Copier le lien de partage Copier le lien de partage
</button> </div>
<div
<div v-if="confirmMsg"> class="item"
<div class="ui positive tiny-margin message"> @click="copyCode"
>
Copier le code du Web Component
</div>
</div>
</div>
</div>
<Transition>
<div
v-if="confirmMsg"
class="ui positive tiny-margin message"
>
<span> <span>
Le lien a été copié dans le presse-papier Le lien a été copié dans le presse-papier
</span> </span>
...@@ -138,10 +160,10 @@ ...@@ -138,10 +160,10 @@
<i <i
class="close icon" class="close icon"
aria-hidden="true" aria-hidden="true"
@click="confirmMsg = ''" @click="confirmMsg = false"
/> />
</div> </div>
</div> </Transition>
</div> </div>
<div <div
...@@ -189,6 +211,7 @@ export default { ...@@ -189,6 +211,7 @@ export default {
return { return {
slug: this.$route.params.slug, slug: this.$route.params.slug,
confirmMsg: false, confirmMsg: false,
showShareOptions: false,
}; };
}, },
...@@ -225,6 +248,11 @@ export default { ...@@ -225,6 +248,11 @@ export default {
mounted() { mounted() {
let textarea = document.querySelector('textarea'); let textarea = document.querySelector('textarea');
new TextareaMarkdown(textarea); new TextareaMarkdown(textarea);
window.addEventListener('mousedown', this.clickOutsideDropdown);
},
destroyed() {
window.removeEventListener('mousedown', this.clickOutsideDropdown);
}, },
methods: { methods: {
...@@ -238,15 +266,50 @@ export default { ...@@ -238,15 +266,50 @@ export default {
return '?ver=' + crypto.getRandomValues(array); // Compliant for security-sensitive use cases return '?ver=' + crypto.getRandomValues(array); // Compliant for security-sensitive use cases
}, },
toggleShareOptions() {
this.confirmMsg = false;
this.showShareOptions = !this.showShareOptions;
},
clickOutsideDropdown(e) {
// If the user click outside of the dropdown, close it
if (!e.target.closest('#share-button')) {
this.showShareOptions = false;
}
},
copyLink() { copyLink() {
const sharedLink = window.location.href.replace('projet', 'projet-partage'); const sharedLink = window.location.href.replace('projet', 'projet-partage');
navigator.clipboard.writeText(sharedLink).then(()=> { navigator.clipboard.writeText(sharedLink).then(()=> {
console.log('success');
this.confirmMsg = true; this.confirmMsg = true;
}, () => { setTimeout(() => {
console.log('failed'); this.confirmMsg = false;
} }, 15000);
); }, (e) => console.error('Failed to copy link: ', e));
},
copyCode() {
// Including <script> directly within template literals cause the JavaScript parser to raise syntax errors.
// The only working workaround, but ugly, is to split and concatenate the <script> tag.
const webComponent = `
<!-- Pour modifier la police, ajoutez l'attribut "font" avec le nom de la police souhaitée (par exemple: font="'Roboto Condensed', Lato, 'Helvetica Neue'"). -->
<!-- Dans le cas où la police souhaitée ne serait pas déjà disponible dans la page affichant le web component, incluez également une balise <style> pour l'importer. -->
<style>@import url('https://fonts.googleapis.com/css?family=Roboto Condensed:400,700,400italic,700italic&subset=latin');</style>
<scr` + `ipt src="${this.configuration.VUE_APP_DJANGO_BASE}/geocontrib/static/wc/project-preview.js"></scr` + `ipt>
<project-preview
domain="${this.configuration.VUE_APP_DJANGO_BASE}"
project-slug="${this.project.slug}"
color="${this.configuration.VUE_APP_PRIMARY_COLOR}"
font="${this.configuration.VUE_APP_FONT_FAMILY}"
width=""
></project-preview>`;
navigator.clipboard.writeText(webComponent).then(()=> {
this.confirmMsg = true;
setTimeout(() => {
this.confirmMsg = false;
}, 15000);
}, (e) => console.error('Failed to copy link: ', e));
}, },
sendOfflineFeatures() { sendOfflineFeatures() {
...@@ -286,14 +349,13 @@ export default { ...@@ -286,14 +349,13 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
.project-header { .project-header {
.row .right-column { .row .right-column {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
.ui.buttons { .ui.buttons {
justify-content: flex-end; justify-content: flex-end;
a.ui.button { .ui.button {
flex-grow: 0; /* avoid stretching buttons */ flex-grow: 0; /* avoid stretching buttons */
} }
} }
...@@ -302,6 +364,36 @@ export default { ...@@ -302,6 +364,36 @@ export default {
margin: auto; margin: auto;
text-align: center; text-align: center;
} }
.ui.dropdown > .left.menu {
display: block;
overflow: hidden;
opacity: 0;
max-height: 0;
&.transition {
transition: all .5s ease;
}
&.visible {
opacity: 1;
max-height: 6em;
}
.menu {
margin-right: 0 !important;
.item {
white-space: nowrap;
}
}
}
.v-enter-active,
.v-leave-active {
transition: opacity .5s ease;
}
.v-enter-from,
.v-leave-to {
opacity: 0;
}
} }
#preview { #preview {
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment