organise calls, add headers

This commit is contained in:
Baptiste Lemoine 2019-12-04 12:45:50 +01:00
parent f223b760ff
commit cb6636f155
5 changed files with 192 additions and 441 deletions

View File

@ -58,6 +58,8 @@ export class PollConfig {
visibility = 'link_only'; // visible to anyone with the link:
voteChoices = 'only_yes'; // possible answers to a vote choice: only "yes", "yes, maybe, no"
expirationDate = ''; // expiracy date
pollId = null; // id of the current poll when created. data given by the backend api
selectedPoll = null; // current poll selected with createPoll or getPoll of ConfigService
passwordAccess = 0;
password = '';
customUrl = '';

View File

@ -17,48 +17,9 @@
<li>
type de formulaire: {{config.pollType}}
</li>
<li>
config:
<pre>
{{config.answers|json}}
</pre>
</li>
</ul>
</div>
<span i18n>
Choix cornélien syncronisé:
</span>
<!-- todo: factoriser les boutons-->
<button
(click)="config.set('pollType' , 'classic')"
[class.active]="config.pollType == 'classic'"
[disabled]="!formIsValid"
class="btn btn--primary next"
>
<span i18n>
sondage classique
</span>
<span *ngIf="config.pollType == 'classic'">
[x]
</span>
</button>
<button
(click)="selectOption('pollType' ,'dates')"
[class.active]="config.pollType == 'dates'"
[disabled]="!formIsValid"
class="btn btn--primary next"
>
<span i18n>
sondage spécial date
</span>
<span *ngIf="config.pollType == 'dates'">
[x]
</span>
</button>
<button
class="btn btn--primary"
i18n
@ -66,3 +27,17 @@
>
Envoyer le formulaire
</button>
<button
class="btn btn--primary"
i18n
(click)="config.getPollById(1, 'example password')"
>
get poll 1
</button>
<button
class="btn btn--primary"
i18n
(click)="config.getMyPolls( 'tktest@tktest.com')"
>
get my polls
</button>

View File

@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
import {PollConfig} from '../config/PollConfig';
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http";
import {environment} from "../../environments/environment";
@ -24,55 +24,14 @@ export class ConfigService extends PollConfig {
this[key] = val;
}
createPoll() {
console.log('sends the form');
// alert('envoi de formulaire pour création de sondage en XHR à faire');
this.http.get(`${this.baseHref}/`)
.subscribe((res) => {
console.log('res', res);
this.createPollFromConfig(this.getPollConfig())
},
this.handleError
)
;
}
createPollFromConfig(config: any) {
this.http.post(`${this.baseHref}/poll`, config)
.subscribe((res: any) => {
// redirect to the page to administrate the new poll
alert("succès!");
this.myPolls = res;
}, this.handleError
);
}
findPollsByEmail(email: string) {
this.findLocalStorageData();
// If no key is found in the localstorage, ask the backend to send an email to the user
this.myEmail = email;
const headers = new HttpHeaders('Content-Type:application/json');
const headerDict = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};
const requestOptions = {
headers: new HttpHeaders(headerDict),
};
this.http.get(`${this.baseHref}/my-polls`)
.subscribe(res => {
// message: 'Trouvé! Allez voir votre boite email',
this.myPolls = res;
}, this.handleError
)
}
/** ==================================
*
* poll public calls to get non authenticated info
*
* ==================================/
/**
* convert current poll config to a payload to send to the backend API
*/
getPollConfig() {
const jsonConfig = {
method: 'POST',
@ -103,7 +62,42 @@ export class ConfigService extends PollConfig {
return jsonConfig
}
/**
* search in localstorage, fallback asking the backend to send an email to the owner if it exists
* @param email
*/
findPollsByEmail(email: string) {
this.findLocalStorageData();
// If no key is found in the localstorage, ask the backend to send an email to the user
this.myEmail = email;
const headerDict = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};
const requestOptions = {
headers: new HttpHeaders(headerDict),
};
this.http.get(`${this.baseHref}/my-polls`)
.subscribe(res => {
// message: 'Trouvé! Allez voir votre boite email',
this.myPolls = res;
}, this.handleError
)
}
/**
* display error message depending on the response of the backend
* @param err
*/
handleError(err: any) {
// TODO handle a toast message
console.error('err', err)
}
@ -127,16 +121,139 @@ export class ConfigService extends PollConfig {
}
/**
*
* GET
* api/v1/poll/{id}
* @param id
*/
getPollById(id: string) {
// http://127.0.0.1:8000/api/v1/poll/1
this.http.get(`${this.baseHref}/poll/${id}`).subscribe(
(res: any) => {
this.myPolls = res.data;
}, this.handleError
);
getPollById(id: string, password: string) {
// http://127.0.0.1:8000/
this.http
.get(`${this.baseHref}/poll/${id}`,
{params: new HttpParams().set('body', password)})
.subscribe(
(res: any) => {
this.myPolls = res.data;
}, this.handleError
);
}
/**
* GET
* api/v1/my-polls
* @param ownerEmail
*/
getMyPolls(ownerEmail: string) {
this.http
.get(`${this.baseHref}/my-polls`,
{
headers: new HttpHeaders()
.append('Content-Type', 'application/json')
.append('Charset', 'UTF-8')
,
params: new HttpParams().set('ownerEmail', ownerEmail)
})
.subscribe(
(res: any) => {
this.myPolls = res.data;
}, this.handleError
);
}
/**
* action of the form
*/
createPoll() {
console.log('sends the form');
// alert('envoi de formulaire pour création de sondage en XHR à faire');
this.http.get(`${this.baseHref}/`)
.subscribe((res) => {
console.log('res', res);
this.createPollFromConfig(this.getPollConfig())
},
this.handleError
)
;
}
/**
* POST
* /api/v1/poll/{id}/poll
* @param config
*/
createPollFromConfig(config: any) {
this.http.post(`${this.baseHref}/poll`, config)
.subscribe((res: any) => {
// redirect to the page to administrate the new poll
alert("succès!");
this.selectedPoll = res;
this.pollId = res.pollId;
}, this.handleError
);
}
/**
* UPDATE
* /api/v1/poll/{id}/vote
* @param voteStack
*/
updatePoll(voteStack: any) {
this.http.put(`${this.baseHref}/poll/${this.pollId}`, voteStack)
.subscribe((res: any) => {
alert("succès!");
this.myPolls = res;
}, this.handleError
);
}
/**
* POST
* /api/v1/poll/{id}/vote
* @param voteStack
*/
addVote(voteStack: any) {
this.http.post(`${this.baseHref}/poll/${this.pollId}/vote`, voteStack)
.subscribe((res: any) => {
alert("succès!");
this.myPolls = res;
}, this.handleError
);
}
/**
* UPDATE
* /api/v1/poll/{id}/vote
* @param voteStack
*/
updateVote(voteStack: any) {
this.http.put(`${this.baseHref}/poll/${this.pollId}/vote`, voteStack)
.subscribe((res: any) => {
alert("succès!");
this.myPolls = res;
}, this.handleError
);
}
/**
* POST
* /api/v1/poll/{id}/comment
* @param comment
*/
addComment(comment: any) {
this.http.post(`${this.baseHref}/poll/${this.pollId}/comment`, comment)
.subscribe((res: any) => {
alert("succès!");
}, this.handleError
);
}
/**
* administrator calls
*/
}

View File

@ -4,7 +4,7 @@
export const environment = {
production: false,
baseApiHref: "http://127.0.0.1:8000/api/v1"
baseApiHref: "http://localhost:8000/api/v1"
};
/*

View File

@ -1,343 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="demo" datatype="html">
<source>
Ceci est une démo
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.html</context>
<context context-type="linenumber">7</context>
</context-group>
<note priority="1" from="description">introduction header saying just demo </note>
<note priority="1" from="meaning">demo title</note>
</trans-unit>
<trans-unit id="plural_example" datatype="html">
<source>
Updated <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/>
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.html</context>
<context context-type="linenumber">10</context>
</context-group>
</trans-unit>
<trans-unit id="5a134dee893586d02bffc9611056b9cadf9abfad" datatype="html">
<source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago} }</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.html</context>
<context context-type="linenumber">11</context>
</context-group>
</trans-unit>
<trans-unit id="c279d3eb8220c1a0b77adb0a520b3e81f086d046" datatype="html">
<source>placeholder à traduire</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.html</context>
<context context-type="linenumber">13</context>
</context-group>
</trans-unit>
<trans-unit id="confirm" datatype="html">
<source>C&apos;est parfait!</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/base-page/base.component.html</context>
<context context-type="linenumber">2</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/kind/kind.component.html</context>
<context context-type="linenumber">4</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/visibility/visibility.component.html</context>
<context context-type="linenumber">14</context>
</context-group>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/resume/resume.component.html</context>
<context context-type="linenumber">10</context>
</context-group>
</trans-unit>
<trans-unit id="8dfa2af2946c94200a9c49226ac8221ddec0834d" datatype="html">
<source>
Config spécialement pour les dates
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/dates/dates.component.html</context>
<context context-type="linenumber">1</context>
</context-group>
</trans-unit>
<trans-unit id="05c94bdaeec38467e5d8ec67ef06ae02bc2721fd" datatype="html">
<source>
Je souhaite mettre des créneaux horaires
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/dates/dates.component.html</context>
<context context-type="linenumber">16</context>
</context-group>
</trans-unit>
<trans-unit id="3da20d71c6eacf0bf933e2ebefcc8581b77fcd07" datatype="html">
<source>
pour chaque journée
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/dates/dates.component.html</context>
<context context-type="linenumber">20</context>
</context-group>
</trans-unit>
<trans-unit id="0bd3bae4b21407cbd1ab7f12f2516aba84ee8cd5" datatype="html">
<source>
Ajouter une plage de dates
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/dates/dates.component.html</context>
<context context-type="linenumber">30</context>
</context-group>
</trans-unit>
<trans-unit id="d5ac5c6775ece9a7d33e5dc3519806c6edfb87bc" datatype="html">
<source>
choix de Dates
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/dates/dates.component.html</context>
<context context-type="linenumber">35</context>
</context-group>
</trans-unit>
<trans-unit id="6387b579b9b1bdb74c3dfd9d63387adb40076376" datatype="html">
<source>
infos de debug
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/debugger/debugger.component.html</context>
<context context-type="linenumber">4</context>
</context-group>
</trans-unit>
<trans-unit id="ddacf8feec398fe7fcda34b82a7aa4d71e10e755" datatype="html">
<source>
Choix cornélien syncronisé:
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/debugger/debugger.component.html</context>
<context context-type="linenumber">27</context>
</context-group>
</trans-unit>
<trans-unit id="d146b7d3598f0f99412cb115c4c9b9dc6724a3db" datatype="html">
<source>
sondage classique
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/debugger/debugger.component.html</context>
<context context-type="linenumber">37</context>
</context-group>
</trans-unit>
<trans-unit id="9e1841dca6f43cec422f009746b78fa72021aed3" datatype="html">
<source>
sondage spécial date
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/debugger/debugger.component.html</context>
<context context-type="linenumber">51</context>
</context-group>
</trans-unit>
<trans-unit id="9dffbece2b62a762cc013cd9a092a45386644395" datatype="html">
<source>
Envoyer le formulaire
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/debugger/debugger.component.html</context>
<context context-type="linenumber">64</context>
</context-group>
</trans-unit>
<trans-unit id="a2e46fcfdbcd6457dd6dda15896ff772a4cccb59" datatype="html">
<source>
Visibilité des réponses
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/visibility/visibility.component.html</context>
<context context-type="linenumber">1</context>
</context-group>
</trans-unit>
<trans-unit id="f3fa123ec08a0f55d20203474e459cb166171530" datatype="html">
<source>
Votes
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/visibility/visibility.component.html</context>
<context context-type="linenumber">4</context>
</context-group>
</trans-unit>
<trans-unit id="07056464cc8e77270490824db1c119774a9605d8" datatype="html">
<source>
Archivage
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/visibility/visibility.component.html</context>
<context context-type="linenumber">7</context>
</context-group>
</trans-unit>
<trans-unit id="e89a47f338845c2bc853956b810455622ea70d18" datatype="html">
<source>
Accès au sondage
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/visibility/visibility.component.html</context>
<context context-type="linenumber">11</context>
</context-group>
</trans-unit>
<trans-unit id="575c777901e66582920b91544ddfc3f1cff6dfdd" datatype="html">
<source>
Résumé avant validation
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/resume/resume.component.html</context>
<context context-type="linenumber">1</context>
</context-group>
</trans-unit>
<trans-unit id="e73989397fa8b6b2a516ec090b7653d7ca8a9f2d" datatype="html">
<source>
Images
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/pictures/pictures.component.html</context>
<context context-type="linenumber">2</context>
</context-group>
</trans-unit>
<trans-unit id="f6d82bb9d11a1a8fbfbc8dd54388b068db42fd4a" datatype="html">
<source>
Choisir les propositions
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/answers/answers.component.html</context>
<context context-type="linenumber">2</context>
</context-group>
</trans-unit>
<trans-unit id="aa15ed6f3664a52d0532b4caccc5e3862eceaff6" datatype="html">
<source>
vous pouvez utiliser la syntaxe markdown
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/answers/answers.component.html</context>
<context context-type="linenumber">6</context>
</context-group>
</trans-unit>
<trans-unit id="8c8496fbdf12a4a3ef88119cd37deca10bf6c661" datatype="html">
<source>
Et c&apos;est tout pour nous!
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/end-confirmation/end-confirmation.component.html</context>
<context context-type="linenumber">1</context>
</context-group>
</trans-unit>
<trans-unit id="c434b3773c35a5d55a1f5648433e7521e4424aea" datatype="html">
<source>Coté administrateur-ice-eux</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/end-confirmation/end-confirmation.component.html</context>
<context context-type="linenumber">4</context>
</context-group>
</trans-unit>
<trans-unit id="d0225bc631b962e0c6696ebc3e26cc90ecf15387" datatype="html">
<source>Coté sondés</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/end-confirmation/end-confirmation.component.html</context>
<context context-type="linenumber">5</context>
</context-group>
</trans-unit>
<trans-unit id="585c8fc362784c1de91b02f0e69e08c6993f9dd2" datatype="html">
<source>recevoir les liens par e-mail</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/end-confirmation/end-confirmation.component.html</context>
<context context-type="linenumber">6</context>
</context-group>
</trans-unit>
<trans-unit id="f74e29e3e6b015dc4163c3d43002088d0e1da5dc" datatype="html">
<source>
Créer un sondage
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/create-or-retrieve/create-or-retrieve.component.html</context>
<context context-type="linenumber">2</context>
</context-group>
</trans-unit>
<trans-unit id="36ab2505621b4451317833191d6a4c2d7c214b3c" datatype="html">
<source>
Planifiez des rendez-vous avec vos amis ou votre famille ou créez un sondage avec du texte, des images ou des
liens… un sondage quoi !
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/create-or-retrieve/create-or-retrieve.component.html</context>
<context context-type="linenumber">8</context>
</context-group>
</trans-unit>
<trans-unit id="c3781d8c21f3eba04fe803a3fe0a4560401491d5" datatype="html">
<source>
C&apos;est parti
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/create-or-retrieve/create-or-retrieve.component.html</context>
<context context-type="linenumber">19</context>
</context-group>
</trans-unit>
<trans-unit id="9e1fa5a7ae3c13a9fa4a657d94085e239066377a" datatype="html">
<source>
Où sont mes sondages ?
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/create-or-retrieve/create-or-retrieve.component.html</context>
<context context-type="linenumber">29</context>
</context-group>
</trans-unit>
<trans-unit id="b291d9e84fc9afe337b3450266847c430523bcc5" datatype="html">
<source>
Je cherche les sondages qui correspondent à mon mail :
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/create-or-retrieve/create-or-retrieve.component.html</context>
<context context-type="linenumber">40</context>
</context-group>
</trans-unit>
<trans-unit id="9606f1c734851ad834d5f9eca4fbc79fad2cf406" datatype="html">
<source>
Pour commencer
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/home/home.component.html</context>
<context context-type="linenumber">4</context>
</context-group>
</trans-unit>
<trans-unit id="e40f615c5bada8d5458ede5b03812bdb8074d7d7" datatype="html">
<source>
Je veux créer un sondage
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/home/home.component.html</context>
<context context-type="linenumber">10</context>
</context-group>
</trans-unit>
<trans-unit id="99eef0ca99f5a0e0aee806ffdefb5ca1ca318b07" datatype="html">
<source>
Dont le titre sera
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/home/home.component.html</context>
<context context-type="linenumber">34</context>
</context-group>
</trans-unit>
<trans-unit id="77100ae0f206a821d33d9582dd2962f379eaeac7" datatype="html">
<source>
et la description serait
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/home/home.component.html</context>
<context context-type="linenumber">64</context>
</context-group>
</trans-unit>
<trans-unit id="114007b6744088dc57d792702b19f91f68f7926e" datatype="html">
<source>
Continuer
</source>
<context-group purpose="location">
<context context-type="sourcefile">src/app/pages/home/home.component.html</context>
<context context-type="linenumber">82</context>
</context-group>
</trans-unit>
</body>
</file>
</xliff>