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

@ -20,7 +20,7 @@
<li> <li>
config: config:
<pre> <pre>
{{config|json}} {{config.answers|json}}
</pre> </pre>
</li> </li>
</ul> </ul>
@ -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

@ -30,8 +30,7 @@
{{"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"
@ -41,6 +40,7 @@
{{"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"
@ -53,3 +53,8 @@
/> />
</form> </form>
</section> </section>
<section class="list-my-polls">
<ul class="poll-list" *ngFor="let poll of config.myPolls">
<li> poll</li>
</ul>
</section>

View File

@ -1,6 +1,7 @@
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',
@ -9,11 +10,15 @@ import {ConfigService} from "../../config.service";
}) })
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/"
}; };
/* /*