-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
235 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "custom", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"lit": "2.0.0-rc.3", | ||
"typescript": "4.3.2", | ||
"vite": "2.5.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2020", "dom"], | ||
"moduleResolution": "node", | ||
"experimentalDecorators": true | ||
}, | ||
"include": ["webcomponents/**/*.ts"], | ||
"files": ["webcomponents/window.d.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {defineConfig} from 'vite'; | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
server: { | ||
port: 3001, | ||
https: true, | ||
open: 'webcomponents/index.js', | ||
}, | ||
build: { | ||
lib: { | ||
entry: 'webcomponents/index.ts', | ||
formats: ['es'], | ||
}, | ||
sourcemap: true, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
import {customElement, state} from 'lit/decorators.js'; | ||
import {LitElement, html} from 'lit'; | ||
|
||
@customElement('proj-feedback') | ||
export class ProjFeedback extends LitElement { | ||
@state() | ||
private show_modal = true; | ||
@state() | ||
private permalink: string; | ||
private email: string; | ||
private email_optional: string; | ||
private feedback_text: string; | ||
private url_: string; | ||
private subscriptions_ = []; | ||
|
||
connectedCallback(): void { | ||
super.connectedCallback(); | ||
this.subscriptions_.push( | ||
window.gmf.config.getConfig().subscribe({ | ||
next: (configuration) => { | ||
this.url_ = configuration.sitnFeedbackUrl; | ||
}, | ||
}) | ||
); | ||
} | ||
|
||
render() { | ||
return html`<div class="modal-header"> | ||
<h4 class="modal-title" id="myModalLabel">Signaler un problème</h4> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
${this.show_modal | ||
? html`<div class="modal-body"> | ||
Votre email (optionnel):<br /> | ||
<input | ||
input="text" | ||
placeholder="[email protected]" | ||
name="email" | ||
class="form-control" | ||
.value="${this.email}" | ||
/> | ||
<br /> | ||
Inclure un membre du SITN (optionnel) :<br /> | ||
<input | ||
type="text" | ||
placeholder="[email protected]" | ||
name="email_optional" | ||
class="form-control" | ||
.value="${this.email_optional}" | ||
/> | ||
<br /> | ||
Votre description du problème concernant la carte :<br /> | ||
<textarea | ||
rows="4" | ||
cols="40" | ||
class="form-control" | ||
.value="${this.feedback_text}" | ||
maxlength="1000" | ||
placeholder="Taille maximale: 1000 caractères" | ||
> | ||
</textarea> | ||
<br /> | ||
L'URL ci-dessous sera envoyée au SITN: | ||
<input | ||
type="text" | ||
name="permalink" | ||
class="form-control" | ||
value="${window.location.href}" | ||
.value="${this.permalink}" | ||
readonly="True" | ||
/> | ||
<br /> | ||
Pour contacter le SITN directement: | ||
<a href="mailto:[email protected]?subject=Problème Géoportail">[email protected]</a> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="submit" class="btn btn-primary" @click="${this.feedbackSubmit}">Envoyer</button> | ||
</div>` | ||
: html`<div class="sitn-loader"> | ||
<div class="fas fa-spinner fa-spin"></div> | ||
<p>En cours d'envoi...</p> | ||
</div>`}`; | ||
} | ||
|
||
private feedbackSubmit() { | ||
if ( | ||
(this.email && this.email.indexOf('@') === -1) || | ||
(this.email_optional && this.email_optional.indexOf('@') === -1) | ||
) { | ||
alert("Une adresse email n'est pas valide"); | ||
return; | ||
} | ||
|
||
if (!this.feedback_text) { | ||
alert('Veuillez saisir une descritption du problème.'); | ||
return; | ||
} | ||
|
||
if (this.feedback_text.length > 1000) { | ||
alert('Votre texte est trop long (max 1000 caractères).'); | ||
return; | ||
} | ||
this.show_modal = false; | ||
|
||
let url = new URL(this.url_); | ||
let params = new URLSearchParams(url.search.slice(1)); | ||
let formdata = new FormData(); | ||
formdata.set('permalink', this.permalink.toString()); | ||
formdata.set('ua', navigator.userAgent); | ||
formdata.set('email', this.email); | ||
formdata.set('email_optional', this.email_optional); | ||
formdata.set('feedback', this.feedback_text); | ||
|
||
fetch(this.url_, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8', | ||
}, | ||
body: formdata, | ||
}).then( | ||
() => { | ||
this.show_modal = false; | ||
alert( | ||
[ | ||
'Merci! Votre demande est bien partie.', | ||
'\n\n', | ||
'Suivant votre demande, une personne du SITN ', | ||
'prendra bientôt contact avec vous.', | ||
].join('') | ||
); | ||
}, | ||
() => { | ||
alert('Une erreur est survenue. Merci de contacter le SITN ([email protected])'); | ||
} | ||
); | ||
} | ||
|
||
// Disable shadow DOM | ||
protected createRenderRoot(): LitElement { | ||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './feedback.ts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
interface Window { | ||
gmf: any; | ||
} |