diff --git a/package.json b/package.json index 5cb7f424..6301943b 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "@ngx-translate/http-loader": "^4.0.0", "chart.js": "^2.8.0", "ngx-markdown": "^8.2.1", + "ngx-toaster": "^1.0.1", "rxjs": "~6.4.0", + "rxjs-compat": "^6.5.3", "tslib": "^1.10.0", "zone.js": "~0.9.1" }, diff --git a/src/app/app.module.ts b/src/app/app.module.ts index d448b962..1c51d044 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -41,6 +41,7 @@ import {PollGraphicComponent} from './poll-graphic/poll-graphic.component'; import {AdminComponent} from './pages/admin/admin.component'; import {SelectorComponent} from './ui/selector/selector.component'; +import {BrowserAnimationsModule} from "@angular/platform-browser/animations"; export class MyMissingTranslationHandler implements MissingTranslationHandler { handle(params: MissingTranslationHandlerParams) { @@ -84,6 +85,7 @@ export function HttpLoaderFactory(http: HttpClient) { imports: [ CommonModule, BrowserModule, + BrowserAnimationsModule, AppRoutingModule, MarkdownModule.forRoot(), TranslateModule.forRoot({ diff --git a/src/app/config.service.ts b/src/app/config.service.ts deleted file mode 100644 index 39d1dcaf..00000000 --- a/src/app/config.service.ts +++ /dev/null @@ -1,37 +0,0 @@ -import {Injectable} from '@angular/core'; -import {PollConfig} from './config/PollConfig'; -import {HttpClient} from "@angular/common/http"; -import {environment} from "../environments/environment"; - - -/** - * le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée - */ -@Injectable({ - providedIn: 'root' -}) -export class ConfigService extends PollConfig { - myEmail: string; - myPolls: any;// list of retrieved polls from the backend api - - - constructor(public http: HttpClient) { - super(); - } - - set(key, val) { - this[key] = val; - } - - createPoll() { - // todo - console.log('sends the form'); - 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/debugger/debugger.component.ts b/src/app/debugger/debugger.component.ts index 6b08ea6b..2dac8523 100644 --- a/src/app/debugger/debugger.component.ts +++ b/src/app/debugger/debugger.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {ConfigService} from '../config.service'; +import {ConfigService} from '../services/config.service'; @Component({ selector: 'framadate-debugger', diff --git a/src/app/pages/admin/admin.component.ts b/src/app/pages/admin/admin.component.ts index 13ec96e6..316fac84 100644 --- a/src/app/pages/admin/admin.component.ts +++ b/src/app/pages/admin/admin.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; @Component({ selector: 'framadate-admin', templateUrl: './admin.component.html', diff --git a/src/app/pages/answers/answers.component.ts b/src/app/pages/answers/answers.component.ts index cf8b169a..1b5906fd 100644 --- a/src/app/pages/answers/answers.component.ts +++ b/src/app/pages/answers/answers.component.ts @@ -1,6 +1,6 @@ import {AfterViewInit, ChangeDetectorRef, Component, Inject, OnInit} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; import {DOCUMENT} from '@angular/common'; diff --git a/src/app/pages/base-page/base.component.ts b/src/app/pages/base-page/base.component.ts index 660f90b9..4dd4c6a7 100644 --- a/src/app/pages/base-page/base.component.ts +++ b/src/app/pages/base-page/base.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; @Component({ selector: 'framadate-base-page', 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 12ee44f1..00536fbf 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,7 +1,7 @@ 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"; +import {ConfigService} from "../../services/config.service"; +import {PollService} from "../../services/poll.service"; @Component({ selector: 'framadate-create-or-retrieve', @@ -10,15 +10,17 @@ import {PollServiceService} from "../../services/poll-service.service"; }) export class CreateOrRetrieveComponent extends BaseComponent implements OnInit { - constructor(public config: ConfigService, public pollService: PollServiceService) { + constructor(public config: ConfigService, + public pollService: PollService) { super(config); } ngOnInit() { + this.findMyPollsByEmail('tktest@tktest.com') } findMyPollsByEmail(email: string) { - this.pollService.findPollsByEmail(email); + this.config.findPollsByEmail(email); } } diff --git a/src/app/pages/dates/dates.component.ts b/src/app/pages/dates/dates.component.ts index 7e0d8f6a..b75b7a35 100644 --- a/src/app/pages/dates/dates.component.ts +++ b/src/app/pages/dates/dates.component.ts @@ -1,5 +1,5 @@ import {ChangeDetectorRef, Component, Inject, OnInit} from '@angular/core'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; import {BaseComponent} from '../base-page/base.component'; import {DOCUMENT} from '@angular/common'; diff --git a/src/app/pages/end-confirmation/end-confirmation.component.ts b/src/app/pages/end-confirmation/end-confirmation.component.ts index 2d0752b5..3c16cbd7 100644 --- a/src/app/pages/end-confirmation/end-confirmation.component.ts +++ b/src/app/pages/end-confirmation/end-confirmation.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import {BaseComponent} from "../base-page/base.component"; -import {ConfigService} from "../../config.service"; +import {ConfigService} from "../../services/config.service"; @Component({ selector: 'framadate-end-confirmation', diff --git a/src/app/pages/home/home.component.ts b/src/app/pages/home/home.component.ts index 597b65bb..2397d5f5 100644 --- a/src/app/pages/home/home.component.ts +++ b/src/app/pages/home/home.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {ConfigService} from "../../config.service"; +import {ConfigService} from "../../services/config.service"; import {BaseComponent} from "../base-page/base.component"; @Component({ diff --git a/src/app/pages/kind/kind.component.ts b/src/app/pages/kind/kind.component.ts index 2724c701..52a03bb5 100644 --- a/src/app/pages/kind/kind.component.ts +++ b/src/app/pages/kind/kind.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; @Component({ selector: 'framadate-page-kind', diff --git a/src/app/pages/password/password.component.ts b/src/app/pages/password/password.component.ts index 4bbb1ef1..f6947854 100644 --- a/src/app/pages/password/password.component.ts +++ b/src/app/pages/password/password.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import {BaseComponent} from "../base-page/base.component"; -import {ConfigService} from "../../config.service"; +import {ConfigService} from "../../services/config.service"; @Component({ selector: 'framadate-password', diff --git a/src/app/pages/pictures/pictures.component.ts b/src/app/pages/pictures/pictures.component.ts index 624e95a2..ee04cf1f 100644 --- a/src/app/pages/pictures/pictures.component.ts +++ b/src/app/pages/pictures/pictures.component.ts @@ -1,5 +1,5 @@ import {Component, OnInit} from '@angular/core'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; import {BaseComponent} from '../base-page/base.component'; @Component({ diff --git a/src/app/pages/resume/resume.component.ts b/src/app/pages/resume/resume.component.ts index 027fe685..aad88b0e 100644 --- a/src/app/pages/resume/resume.component.ts +++ b/src/app/pages/resume/resume.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; @Component({ selector: 'framadate-resume', diff --git a/src/app/pages/visibility/visibility.component.ts b/src/app/pages/visibility/visibility.component.ts index 6dd86867..cfa20022 100644 --- a/src/app/pages/visibility/visibility.component.ts +++ b/src/app/pages/visibility/visibility.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {BaseComponent} from '../base-page/base.component'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; @Component({ selector: 'framadate-visibility', diff --git a/src/app/pages/voting-choice/voting-choice.component.ts b/src/app/pages/voting-choice/voting-choice.component.ts index 898f8eac..a1bc67f3 100644 --- a/src/app/pages/voting-choice/voting-choice.component.ts +++ b/src/app/pages/voting-choice/voting-choice.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import {BaseComponent} from "../base-page/base.component"; -import {ConfigService} from "../../config.service"; +import {ConfigService} from "../../services/config.service"; @Component({ selector: 'framadate-voting-choice', diff --git a/src/app/pages/voting-graph/voting-graph.component.ts b/src/app/pages/voting-graph/voting-graph.component.ts index 725bd1f1..fb2ae6f1 100644 --- a/src/app/pages/voting-graph/voting-graph.component.ts +++ b/src/app/pages/voting-graph/voting-graph.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import {BaseComponent} from "../base-page/base.component"; -import {ConfigService} from "../../config.service"; +import {ConfigService} from "../../services/config.service"; @Component({ selector: 'framadate-voting-graph', diff --git a/src/app/pages/voting-summary/voting-summary.component.ts b/src/app/pages/voting-summary/voting-summary.component.ts index 7c10d7ad..09b4435f 100644 --- a/src/app/pages/voting-summary/voting-summary.component.ts +++ b/src/app/pages/voting-summary/voting-summary.component.ts @@ -1,6 +1,6 @@ import { Component, OnInit } from '@angular/core'; import {BaseComponent} from "../base-page/base.component"; -import {ConfigService} from "../../config.service"; +import {ConfigService} from "../../services/config.service"; @Component({ selector: 'framadate-voting-summary', diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts new file mode 100644 index 00000000..be6d0fcc --- /dev/null +++ b/src/app/services/config.service.ts @@ -0,0 +1,142 @@ +import {Injectable} from '@angular/core'; +import {PollConfig} from '../config/PollConfig'; +import {HttpClient, HttpHeaders} from "@angular/common/http"; +import {environment} from "../../environments/environment"; + + +/** + * le service transverse à chaque page qui permet de syncroniser la configuration de sondage souhaitée + */ +@Injectable({ + providedIn: 'root' +}) +export class ConfigService extends PollConfig { + myEmail: string; + baseHref: any = environment.baseApiHref; + myPolls: any;// list of retrieved polls from the backend api + + + constructor(public http: HttpClient) { + super(); + } + + set(key, val) { + 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 + ) + } + + getPollConfig() { + const jsonConfig = { + method: 'POST', + data: { + + owner: { + email: this.myEmail, + pseudo: this.myName, + }, + title: this.title, + description: this.description, + type: this.pollType, + visibility: this.visibility, + voteChoices: this.voteChoices, + allowSeveralHours: this.allowSeveralHours, + expirationDate: this.expirationDate, + passwordAccess: this.passwordAccess, + password: this.password, + customUrl: this.customUrl, + canModifyAnswers: this.canModifyAnswers, + whoModifiesAnswers: this.whoModifiesAnswers, + dateList: this.dateList, + timeList: this.timeList, + answers: this.answers, + } + }; + console.log('jsonConfig', jsonConfig); + return jsonConfig + } + + handleError(err: any) { + console.error('err', err) + } + + + findLocalStorageData() { + // TODO check if the person has a key to retrieve her polls + + } + + + /** + * + * @param url + */ + getPollByURL(url: string) { + this.http.get(`${this.baseHref}/poll/${url}`).subscribe( + (res: any) => { + this.myPolls = res.data; + }, this.handleError + ); + } + + /** + * + * @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 + ); + } + +} diff --git a/src/app/services/poll-service.service.spec.ts b/src/app/services/poll-service.service.spec.ts index c9b6bcec..c47006ba 100644 --- a/src/app/services/poll-service.service.spec.ts +++ b/src/app/services/poll-service.service.spec.ts @@ -1,12 +1,12 @@ import { TestBed } from '@angular/core/testing'; -import { PollServiceService } from './poll-service.service'; +import { PollService } from './poll.service'; describe('PollServiceService', () => { beforeEach(() => TestBed.configureTestingModule({})); it('should be created', () => { - const service: PollServiceService = TestBed.get(PollServiceService); + const service: PollService = TestBed.get(PollService); expect(service).toBeTruthy(); }); }); diff --git a/src/app/services/poll-service.service.ts b/src/app/services/poll-service.service.ts deleted file mode 100644 index 0bf09ae0..00000000 --- a/src/app/services/poll-service.service.ts +++ /dev/null @@ -1,32 +0,0 @@ -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/app/services/poll.service.ts b/src/app/services/poll.service.ts new file mode 100644 index 00000000..b30b45a6 --- /dev/null +++ b/src/app/services/poll.service.ts @@ -0,0 +1,24 @@ +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 PollService { + + private baseHref: string = environment.baseApiHref; + + constructor(private configService: ConfigService, + private document: Document, + private http: HttpClient) { + } + + +} diff --git a/src/app/progression.service.spec.ts b/src/app/services/progression.service.spec.ts similarity index 100% rename from src/app/progression.service.spec.ts rename to src/app/services/progression.service.spec.ts diff --git a/src/app/ui/navigation/navigation.component.ts b/src/app/ui/navigation/navigation.component.ts index 52bd53d7..d0fbd588 100644 --- a/src/app/ui/navigation/navigation.component.ts +++ b/src/app/ui/navigation/navigation.component.ts @@ -1,6 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {BaseComponent} from '../../pages/base-page/base.component'; -import {ConfigService} from '../../config.service'; +import {ConfigService} from '../../services/config.service'; @Component({ selector: 'framadate-navigation', diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 918f5d2b..b2a49141 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://127.0.0.1:8000/api/v1" }; /* diff --git a/yarn.lock b/yarn.lock index 3ea57eea..8334bfae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4521,6 +4521,11 @@ ngx-markdown@^8.2.1: prismjs "^1.16.0" tslib "^1.9.0" +ngx-toaster@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/ngx-toaster/-/ngx-toaster-1.0.1.tgz#ee54f83bcbe3da26210097baac08445952899515" + integrity sha1-7lT4O8vj2iYhAJe6rAhEWVKJlRU= + nice-try@^1.0.4: version "1.0.5" resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" @@ -5707,6 +5712,11 @@ run-queue@^1.0.0, run-queue@^1.0.3: dependencies: aproba "^1.1.1" +rxjs-compat@^6.5.3: + version "6.5.3" + resolved "https://registry.yarnpkg.com/rxjs-compat/-/rxjs-compat-6.5.3.tgz#18440949b2678bf87a78a754009676b2c49183dc" + integrity sha512-BIJX2yovz3TBpjJoAZyls2QYuU6ZiCaZ+U96SmxQpuSP/qDUfiXPKOVLbThBB2WZijNHkdTTJXKRwvv5Y48H7g== + rxjs@6.4.0, rxjs@~6.4.0: version "6.4.0" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.4.0.tgz#f3bb0fe7bda7fb69deac0c16f17b50b0b8790504"