start call backend service to retrieve my polls by email

This commit is contained in:
Baptiste Lemoine 2019-11-19 11:19:21 +01:00
parent 933c32798c
commit 026c7cfda2
9 changed files with 152 additions and 82 deletions

View File

@ -1,5 +1,7 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {PollConfig} from './config/PollConfig'; import {PollConfig} from './config/PollConfig';
import {HttpClient} from "@angular/common/http";
import {environment} from "../environments/environment";
/** /**
@ -9,9 +11,11 @@ import {PollConfig} from './config/PollConfig';
providedIn: 'root' providedIn: 'root'
}) })
export class ConfigService extends PollConfig { export class ConfigService extends PollConfig {
myEmail: string;
myPolls: any;// list of retrieved polls from the backend api
constructor() { constructor(public http: HttpClient) {
super(); super();
} }
@ -19,9 +23,15 @@ export class ConfigService extends PollConfig {
this[key] = val; this[key] = val;
} }
sendForm() { createPoll() {
// todo // todo
console.log('sends the form'); console.log('sends the form');
alert('envoi de formulaire en XHR à faire'); alert('envoi de formulaire pour création de sondage en XHR à faire');
const payload = this;
this.http.post(`${environment.baseApiHref}/poll`, payload)
.subscribe(res => {
console.log('res', res)
},
err => console.error('err', err))
} }
} }

View File

@ -38,9 +38,13 @@ export class PollConfig {
title = ''; title = '';
description = ''; description = '';
myName = ''; myName = '';
visibility = 'link_only';
// date specific poll // date specific poll
allowSeveralHours = 'true'; allowSeveralHours = 'false';
// access
visibility = 'link_only'; // visible to anyone with the link:
password = '';
whoCanChangeAnswers = 'everybody';// everybody, self, nobody (= just admin)
dateList: DateOption[] = defaultDates; // sets of days as strings, config to set identical time for days in a special days poll dateList: DateOption[] = defaultDates; // sets of days as strings, config to set identical time for days in a special days poll
timeList: DateOption[] = timeOfDay; // ranges of time expressed as strings timeList: DateOption[] = timeOfDay; // ranges of time expressed as strings
answers: any = [{ answers: any = [{

View File

@ -1,29 +1,29 @@
<div class="well debug"> <div class="well debug">
<strong> <strong>
<h2 i18n> <h2 i18n>
infos de debug infos de debug
</h2> </h2>
<span class="demo"> <span class="demo">
{{"config.demo"|translate}} {{"config.demo"|translate}}
</span> </span>
</strong> </strong>
<ul> <ul>
<li> <li>
étape actuelle {{config.step}} / {{config.stepMax}} étape actuelle {{config.step}} / {{config.stepMax}}
</li> </li>
<li> <li>
formulaire valide : {{formIsValid}} formulaire valide : {{formIsValid}}
</li> </li>
<li> <li>
type de formulaire: {{config.pollType}} type de formulaire: {{config.pollType}}
</li> </li>
<li> <li>
config: config:
<pre> <pre>
{{config|json}} {{config.answers|json}}
</pre> </pre>
</li> </li>
</ul> </ul>
</div> </div>
<span i18n> <span i18n>
@ -62,7 +62,7 @@
<button <button
class="btn btn--primary" class="btn btn--primary"
i18n i18n
(click)="config.sendForm()" (click)="config.createPoll()"
> >
Envoyer le formulaire Envoyer le formulaire
</button> </button>

View File

@ -1,55 +1,60 @@
<section class="creation"> <section class="creation">
<h1> <h1>
{{"creation.title"|translate}} {{"creation.title"|translate}}
</h1> </h1>
<p <p
class="description" class="description"
i18n i18n
> >
{{"config.title"|translate}} {{"config.title"|translate}}
</p> </p>
<div class="btn-next"> <div class="btn-next">
<a <a
[routerLink]="'/home'" [routerLink]="'/home'"
> >
<span <span
class="text" class="text"
i18n i18n
> >
{{"config.letsgo"|translate}} {{"config.letsgo"|translate}}
</span> </span>
<span class="icon right"> <span class="icon right">
> >
</span> </span>
</a> </a>
</div> </div>
</section> </section>
<section class="recuperation"> <section class="recuperation">
<h1> <h1>
{{"config.find_my_polls"|translate}} {{"config.find_my_polls"|translate}}
</h1> </h1>
<form <form
action="https://framadate.org/find_polls.php" (ngSubmit)="findMyPollsByEmail(emailToFind.value)"
method="post" >
> <label
<label class="description"
class="description" for="email"
for="email" i18n
i18n >
> {{"config.find_helper"|translate}} :
{{"config.find_helper"|translate}} : </label>
</label> <input
<input #emailToFind
type="email" type="email"
name="mail" name="mail"
id="email" id="email"
autofocus="autofocus" autofocus="autofocus"
/> />
<input <input
type="submit" type="submit"
class="btn btn-block" class="btn btn-block"
i18n-value="'config.find_button'|translate" i18n-value="'config.find_button'|translate"
/> />
</form> </form>
</section>
<section class="list-my-polls">
<ul class="poll-list" *ngFor="let poll of config.myPolls">
<li> poll</li>
</ul>
</section> </section>

View File

@ -1,19 +1,24 @@
import { Component, OnInit } from '@angular/core'; import {Component, OnInit} from '@angular/core';
import {BaseComponent} from "../base-page/base.component"; import {BaseComponent} from "../base-page/base.component";
import {ConfigService} from "../../config.service"; import {ConfigService} from "../../config.service";
import {PollServiceService} from "../../services/poll-service.service";
@Component({ @Component({
selector: 'framadate-create-or-retrieve', selector: 'framadate-create-or-retrieve',
templateUrl: './create-or-retrieve.component.html', templateUrl: './create-or-retrieve.component.html',
styleUrls: ['./create-or-retrieve.component.scss'] styleUrls: ['./create-or-retrieve.component.scss']
}) })
export class CreateOrRetrieveComponent extends BaseComponent implements OnInit { export class CreateOrRetrieveComponent extends BaseComponent implements OnInit {
constructor(public config: ConfigService) { constructor(public config: ConfigService, public pollService: PollServiceService) {
super(config); super(config);
} }
ngOnInit() { ngOnInit() {
} }
findMyPollsByEmail(email: string) {
this.pollService.findPollsByEmail(email);
}
} }

View File

@ -0,0 +1,12 @@
import { TestBed } from '@angular/core/testing';
import { PollServiceService } from './poll-service.service';
describe('PollServiceService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: PollServiceService = TestBed.get(PollServiceService);
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,32 @@
import {Injectable} from '@angular/core';
import {ConfigService} from "../config.service";
import {HttpClient} from "@angular/common/http";
import {environment} from "../../environments/environment";
class JsonResponse {
message: string;
data: string;
}
@Injectable({
providedIn: 'root'
})
export class PollServiceService {
private baseHref: string = environment.baseApiHref;
constructor(private configService: ConfigService,
private http: HttpClient) {
}
findPollsByEmail(email: string) {
// TODO check if the person has a key to retrieve her polls
// If no key is found in the localstorage, ask the backend to send an email to the user
this.configService.myEmail = email;
this.http.get(this.baseHref + '/').subscribe(res => {
this.configService.myPolls = res;
}, err => console.error('err', err)
)
}
}

View File

@ -1,3 +1,4 @@
export const environment = { export const environment = {
production: true production: true,
baseApiHref : 'http://127.0.0.1:8000/api/v1/'
}; };

View File

@ -3,7 +3,8 @@
// The list of file replacements can be found in `angular.json`. // The list of file replacements can be found in `angular.json`.
export const environment = { export const environment = {
production: false production: false,
baseApiHref: "http://127.0.0.1:8000/api/v1/"
}; };
/* /*