From cf4e9f45634b0eb8fa52bf77c52373876ce5eaef Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Wed, 15 Jan 2020 11:40:39 +0100 Subject: [PATCH] :zap: fix some deps --- package.json | 1 + src/app/app.module.ts | 5 +++-- src/app/config/Routes.ts | 3 ++- .../create-or-retrieve.component.html | 17 ++++++++++++----- .../create-or-retrieve.component.ts | 6 ++++++ src/app/poll-graphic/poll-graphic.component.ts | 8 ++++---- src/app/services/config.service.ts | 13 +++++++++++-- src/app/services/poll.service.ts | 11 +---------- src/environments/environment.prod.ts | 2 +- src/environments/environment.ts | 3 ++- 10 files changed, 43 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index 6301943b..a372d3b2 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "scripts": { "ng": "ng", "start": "ng serve", + "serve": "ng serve", "build": "ng build", "test": "ng test", "lint": "ng lint", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1c51d044..88d468e0 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,6 +1,5 @@ import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; - import {AppRoutingModule} from './app-routing.module'; import {AppComponent} from './app.component'; import {BaseComponent} from './pages/base-page/base.component'; @@ -42,6 +41,8 @@ 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"; +import {ConfigService} from "./services/config.service"; +import {PollService} from "./services/poll.service"; export class MyMissingTranslationHandler implements MissingTranslationHandler { handle(params: MissingTranslationHandlerParams) { @@ -104,7 +105,7 @@ export function HttpLoaderFactory(http: HttpClient) { FormsModule, RouterModule.forRoot(Routes) ], - providers: [TranslateService], + providers: [TranslateService, ConfigService, PollService], bootstrap: [AppComponent] }) export class AppModule { diff --git a/src/app/config/Routes.ts b/src/app/config/Routes.ts index 52360ff5..c9fcf5c7 100644 --- a/src/app/config/Routes.ts +++ b/src/app/config/Routes.ts @@ -17,7 +17,7 @@ import {VoteChoiceComponent} from "../vote-choice/vote-choice.component"; */ export const Routes = [ - {path: '', component: CreateOrRetrieveComponent}, + {path: '', redirectTo: 'step/creation', pathMatch: 'full'}, {path: 'home', component: HomeComponent}, {path: 'base', component: BaseComponent}, {path: 'step/base', component: BaseComponent}, @@ -32,5 +32,6 @@ export const Routes = {path: 'step/end', component: EndConfirmationComponent}, {path: 'graphic/:poll', component: PollGraphicComponent}, {path: 'votechoice', component: VoteChoiceComponent}, + {path: '**', redirectTo: '/home', pathMatch: 'full'}, ] ; 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 20c0b141..8212aba4 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 @@ -40,16 +40,17 @@ {{"config.find_helper"|translate}} : @@ -57,4 +58,10 @@ +
+ +
+
+ Aucun sondage. +
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 00536fbf..469f80ab 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 @@ -10,6 +10,8 @@ import {PollService} from "../../services/poll.service"; }) export class CreateOrRetrieveComponent extends BaseComponent implements OnInit { + loadedMyPolls: boolean = false; + constructor(public config: ConfigService, public pollService: PollService) { super(config); @@ -20,7 +22,11 @@ export class CreateOrRetrieveComponent extends BaseComponent implements OnInit { } findMyPollsByEmail(email: string) { + if (!email) { + return + } this.config.findPollsByEmail(email); + this.loadedMyPolls = true; } } diff --git a/src/app/poll-graphic/poll-graphic.component.ts b/src/app/poll-graphic/poll-graphic.component.ts index f3ba0682..1356e25a 100644 --- a/src/app/poll-graphic/poll-graphic.component.ts +++ b/src/app/poll-graphic/poll-graphic.component.ts @@ -1,5 +1,6 @@ -import {Component, OnInit} from "@angular/core"; +import {Component, Inject, OnInit} from "@angular/core"; import {Chart} from "chart.js"; +import {DOCUMENT} from '@angular/common'; @Component({ selector: "framadate-poll-graphic", @@ -8,7 +9,6 @@ import {Chart} from "chart.js"; }) export class PollGraphicComponent implements OnInit { isColorblind: boolean = false; - lineChart: Chart; pollData: any; yesList: number[] = []; maybeList: number[] = []; @@ -16,7 +16,7 @@ export class PollGraphicComponent implements OnInit { nbPoll: number = 0; dateList: string[] = []; - constructor() { + constructor(@Inject(DOCUMENT) private document: any,) { } ngOnInit() { @@ -76,7 +76,7 @@ export class PollGraphicComponent implements OnInit { this.formatDataAnswers(toto); this.isColorblind = false; - this.pollData = new Chart(document.getElementById("graph"), { + this.pollData = new Chart(this.document.getElementById("graph"), { type: "horizontalBar", data: { labels: ["jeudi"], diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index 483ceaa4..56de8d53 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -12,6 +12,7 @@ import {environment} from "../../environments/environment"; }) export class ConfigService extends PollConfig { myEmail: string; + loading: boolean = false; baseHref: any = environment.baseApiHref; myPolls: any;// list of retrieved polls from the backend api @@ -77,16 +78,23 @@ export class ConfigService extends PollConfig { const headerDict = { 'Content-Type': 'application/json', 'Accept': 'application/json', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE', + 'Access-Control-Allow-Origin': environment.baseApiHref }; const requestOptions = { headers: new HttpHeaders(headerDict), + email: this.myEmail }; - this.http.get(`${this.baseHref}/my-polls`) + this.loading = true; + this.http.get(`${this.baseHref}/my-polls`, + requestOptions, + ) .subscribe(res => { // message: 'Trouvé! Allez voir votre boite email', this.myPolls = res; + this.loading = false; }, this.handleError ) } @@ -99,6 +107,7 @@ export class ConfigService extends PollConfig { handleError(err: any) { // TODO handle a toast message console.error('err', err) + this.loading = false; } @@ -126,7 +135,7 @@ export class ConfigService extends PollConfig { * @param id */ getPollById(id: string, password: string) { - // http://127.0.0.1:8000/ + this.http .get(`${this.baseHref}/poll/${id}`, {params: new HttpParams().set('body', password)}) diff --git a/src/app/services/poll.service.ts b/src/app/services/poll.service.ts index b30b45a6..33f190d2 100644 --- a/src/app/services/poll.service.ts +++ b/src/app/services/poll.service.ts @@ -1,13 +1,6 @@ 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' }) @@ -15,9 +8,7 @@ export class PollService { private baseHref: string = environment.baseApiHref; - constructor(private configService: ConfigService, - private document: Document, - private http: HttpClient) { + constructor() { } diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 0a1bc680..8ccf98f9 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,4 +1,4 @@ export const environment = { production: true, - baseApiHref : 'http://127.0.0.1:8000/api/v1/' + baseApiHref: 'http://127.0.0.1:8000/api/v1/' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4d63b3f5..0ab15255 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,7 +4,8 @@ export const environment = { production: false, - baseApiHref: "http://localhost:8000/api/v1" + baseApiHref: "https://framadate-api.cipherbliss.com/api/v1" + // baseApiHref: "http://localhost:8000/api/v1" }; /*