diff --git a/src/app/config/PollConfig.ts b/src/app/config/PollConfig.ts index c34bb98a..db150ad1 100644 --- a/src/app/config/PollConfig.ts +++ b/src/app/config/PollConfig.ts @@ -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 = ''; diff --git a/src/app/debugger/debugger.component.html b/src/app/debugger/debugger.component.html index c9e8a4f6..b7f72cfe 100644 --- a/src/app/debugger/debugger.component.html +++ b/src/app/debugger/debugger.component.html @@ -17,48 +17,9 @@
  • type de formulaire: {{config.pollType}}
  • -
  • - config: -
    -				{{config.answers|json}}
    -			
    -
  • - - Choix cornélien syncronisé: - - - - - + + diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index be6d0fcc..483ceaa4 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -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 + */ + } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index b2a49141..4d63b3f5 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,7 @@ export const environment = { production: false, - baseApiHref: "http://127.0.0.1:8000/api/v1" + baseApiHref: "http://localhost:8000/api/v1" }; /* diff --git a/src/locale/messages.xlf b/src/locale/messages.xlf deleted file mode 100644 index ba35cf85..00000000 --- a/src/locale/messages.xlf +++ /dev/null @@ -1,343 +0,0 @@ - - - - - - - Ceci est une démo - - - src/app/app.component.html - 7 - - introduction header saying just demo - demo title - - - - Updated - - - src/app/app.component.html - 10 - - - - {VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other { minutes ago} } - - src/app/app.component.html - 11 - - - - placeholder à traduire - - src/app/app.component.html - 13 - - - - C'est parfait! - - src/app/pages/base-page/base.component.html - 2 - - - src/app/pages/kind/kind.component.html - 4 - - - src/app/pages/visibility/visibility.component.html - 14 - - - src/app/pages/resume/resume.component.html - 10 - - - - - Config spécialement pour les dates - - - src/app/pages/dates/dates.component.html - 1 - - - - - Je souhaite mettre des créneaux horaires - - - src/app/pages/dates/dates.component.html - 16 - - - - - pour chaque journée - - - src/app/pages/dates/dates.component.html - 20 - - - - - Ajouter une plage de dates - - - src/app/pages/dates/dates.component.html - 30 - - - - - choix de Dates - - - src/app/pages/dates/dates.component.html - 35 - - - - - infos de debug - - - src/app/debugger/debugger.component.html - 4 - - - - - Choix cornélien syncronisé: - - - src/app/debugger/debugger.component.html - 27 - - - - - sondage classique - - - src/app/debugger/debugger.component.html - 37 - - - - - sondage spécial date - - - src/app/debugger/debugger.component.html - 51 - - - - - Envoyer le formulaire - - - src/app/debugger/debugger.component.html - 64 - - - - - Visibilité des réponses - - - src/app/pages/visibility/visibility.component.html - 1 - - - - - Votes - - - src/app/pages/visibility/visibility.component.html - 4 - - - - - Archivage - - - src/app/pages/visibility/visibility.component.html - 7 - - - - - Accès au sondage - - - src/app/pages/visibility/visibility.component.html - 11 - - - - - Résumé avant validation - - - src/app/pages/resume/resume.component.html - 1 - - - - - Images - - - src/app/pages/pictures/pictures.component.html - 2 - - - - - Choisir les propositions - - - src/app/pages/answers/answers.component.html - 2 - - - - - vous pouvez utiliser la syntaxe markdown - - - src/app/pages/answers/answers.component.html - 6 - - - - - Et c'est tout pour nous! - - - src/app/pages/end-confirmation/end-confirmation.component.html - 1 - - - - Coté administrateur-ice-eux - - src/app/pages/end-confirmation/end-confirmation.component.html - 4 - - - - Coté sondés - - src/app/pages/end-confirmation/end-confirmation.component.html - 5 - - - - recevoir les liens par e-mail - - src/app/pages/end-confirmation/end-confirmation.component.html - 6 - - - - - Créer un sondage - - - src/app/pages/create-or-retrieve/create-or-retrieve.component.html - 2 - - - - - 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 ! - - - src/app/pages/create-or-retrieve/create-or-retrieve.component.html - 8 - - - - - C'est parti - - - src/app/pages/create-or-retrieve/create-or-retrieve.component.html - 19 - - - - - Où sont mes sondages ? - - - src/app/pages/create-or-retrieve/create-or-retrieve.component.html - 29 - - - - - Je cherche les sondages qui correspondent à mon mail : - - - src/app/pages/create-or-retrieve/create-or-retrieve.component.html - 40 - - - - - Pour commencer - - - src/app/pages/home/home.component.html - 4 - - - - - Je veux créer un sondage - - - src/app/pages/home/home.component.html - 10 - - - - - Dont le titre sera - - - src/app/pages/home/home.component.html - 34 - - - - - et la description serait - - - src/app/pages/home/home.component.html - 64 - - - - - Continuer - - - src/app/pages/home/home.component.html - 82 - - - - -