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 {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'
})
export class ConfigService extends PollConfig {
myEmail: string;
myPolls: any;// list of retrieved polls from the backend api
constructor() {
constructor(public http: HttpClient) {
super();
}
@ -19,9 +23,15 @@ export class ConfigService extends PollConfig {
this[key] = val;
}
sendForm() {
createPoll() {
// todo
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 = '';
description = '';
myName = '';
visibility = 'link_only';
// 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
timeList: DateOption[] = timeOfDay; // ranges of time expressed as strings
answers: any = [{

View File

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

View File

@ -1,55 +1,60 @@
<section class="creation">
<h1>
{{"creation.title"|translate}}
</h1>
<p
class="description"
i18n
>
{{"config.title"|translate}}
</p>
<div class="btn-next">
<a
[routerLink]="'/home'"
>
<h1>
{{"creation.title"|translate}}
</h1>
<p
class="description"
i18n
>
{{"config.title"|translate}}
</p>
<div class="btn-next">
<a
[routerLink]="'/home'"
>
<span
class="text"
i18n
>
class="text"
i18n
>
{{"config.letsgo"|translate}}
</span>
<span class="icon right">
<span class="icon right">
>
</span>
</a>
</div>
</a>
</div>
</section>
<section class="recuperation">
<h1>
{{"config.find_my_polls"|translate}}
</h1>
<form
action="https://framadate.org/find_polls.php"
method="post"
>
<label
class="description"
for="email"
i18n
>
{{"config.find_helper"|translate}} :
</label>
<input
type="email"
name="mail"
id="email"
autofocus="autofocus"
/>
<input
type="submit"
class="btn btn-block"
i18n-value="'config.find_button'|translate"
/>
</form>
<h1>
{{"config.find_my_polls"|translate}}
</h1>
<form
(ngSubmit)="findMyPollsByEmail(emailToFind.value)"
>
<label
class="description"
for="email"
i18n
>
{{"config.find_helper"|translate}} :
</label>
<input
#emailToFind
type="email"
name="mail"
id="email"
autofocus="autofocus"
/>
<input
type="submit"
class="btn btn-block"
i18n-value="'config.find_button'|translate"
/>
</form>
</section>
<section class="list-my-polls">
<ul class="poll-list" *ngFor="let poll of config.myPolls">
<li> poll</li>
</ul>
</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 {ConfigService} from "../../config.service";
import {PollServiceService} from "../../services/poll-service.service";
@Component({
selector: 'framadate-create-or-retrieve',
templateUrl: './create-or-retrieve.component.html',
styleUrls: ['./create-or-retrieve.component.scss']
selector: 'framadate-create-or-retrieve',
templateUrl: './create-or-retrieve.component.html',
styleUrls: ['./create-or-retrieve.component.scss']
})
export class CreateOrRetrieveComponent extends BaseComponent implements OnInit {
constructor(public config: ConfigService) {
constructor(public config: ConfigService, public pollService: PollServiceService) {
super(config);
}
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 = {
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`.
export const environment = {
production: false
production: false,
baseApiHref: "http://127.0.0.1:8000/api/v1/"
};
/*