start backend calls

This commit is contained in:
Baptiste Lemoine 2019-12-03 17:20:57 +01:00
parent 157a8d63c5
commit f223b760ff
27 changed files with 205 additions and 92 deletions

View File

@ -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"
},

View File

@ -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({

View File

@ -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))
}
}

View File

@ -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',

View File

@ -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',

View File

@ -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';

View File

@ -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',

View File

@ -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);
}
}

View File

@ -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';

View File

@ -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',

View File

@ -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({

View File

@ -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',

View File

@ -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',

View File

@ -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({

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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',

View File

@ -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
);
}
}

View File

@ -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();
});
});

View File

@ -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)
)
}
}

View File

@ -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) {
}
}

View File

@ -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',

View File

@ -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"
};
/*

View File

@ -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"