From 026c7cfda2476e7a77cecfaff28c151e835b7a10 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Tue, 19 Nov 2019 11:19:21 +0100 Subject: [PATCH] :zap: start call backend service to retrieve my polls by email --- src/app/config.service.ts | 16 +++- src/app/config/PollConfig.ts | 8 +- src/app/debugger/debugger.component.html | 48 +++++----- .../create-or-retrieve.component.html | 95 ++++++++++--------- .../create-or-retrieve.component.ts | 17 ++-- src/app/services/poll-service.service.spec.ts | 12 +++ src/app/services/poll-service.service.ts | 32 +++++++ src/environments/environment.prod.ts | 3 +- src/environments/environment.ts | 3 +- 9 files changed, 152 insertions(+), 82 deletions(-) create mode 100644 src/app/services/poll-service.service.spec.ts create mode 100644 src/app/services/poll-service.service.ts diff --git a/src/app/config.service.ts b/src/app/config.service.ts index 8cb4ebdf..39d1dcaf 100644 --- a/src/app/config.service.ts +++ b/src/app/config.service.ts @@ -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)) } } diff --git a/src/app/config/PollConfig.ts b/src/app/config/PollConfig.ts index 4a19e91b..a6f89d77 100644 --- a/src/app/config/PollConfig.ts +++ b/src/app/config/PollConfig.ts @@ -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 = [{ diff --git a/src/app/debugger/debugger.component.html b/src/app/debugger/debugger.component.html index 1af1e473..c9e8a4f6 100644 --- a/src/app/debugger/debugger.component.html +++ b/src/app/debugger/debugger.component.html @@ -1,29 +1,29 @@
- -

- infos de debug -

- + +

+ infos de debug +

+ {{"config.demo"|translate}} -
-
@@ -62,7 +62,7 @@ diff --git a/src/app/pages/create-or-retrieve/create-or-retrieve.component.html b/src/app/pages/create-or-retrieve/create-or-retrieve.component.html index 50753eca..20c0b141 100644 --- a/src/app/pages/create-or-retrieve/create-or-retrieve.component.html +++ b/src/app/pages/create-or-retrieve/create-or-retrieve.component.html @@ -1,55 +1,60 @@
-

- {{"creation.title"|translate}} -

-

- {{"config.title"|translate}} -

-
-

- {{"config.find_my_polls"|translate}} -

-
- - - -
+

+ {{"config.find_my_polls"|translate}} +

+
+ + + +
+
+
+
    +
  • poll
  • +
diff --git a/src/app/pages/create-or-retrieve/create-or-retrieve.component.ts b/src/app/pages/create-or-retrieve/create-or-retrieve.component.ts index 81dfb0ba..12ee44f1 100644 --- a/src/app/pages/create-or-retrieve/create-or-retrieve.component.ts +++ b/src/app/pages/create-or-retrieve/create-or-retrieve.component.ts @@ -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); + } } diff --git a/src/app/services/poll-service.service.spec.ts b/src/app/services/poll-service.service.spec.ts new file mode 100644 index 00000000..c9b6bcec --- /dev/null +++ b/src/app/services/poll-service.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/services/poll-service.service.ts b/src/app/services/poll-service.service.ts new file mode 100644 index 00000000..0bf09ae0 --- /dev/null +++ b/src/app/services/poll-service.service.ts @@ -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) + ) + } +} diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 3612073b..0a1bc680 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,3 +1,4 @@ export const environment = { - production: true + production: true, + baseApiHref : 'http://127.0.0.1:8000/api/v1/' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 7b4f817a..918f5d2b 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -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/" }; /*