start backend calls

develop
Baptiste Lemoine 3 years ago
parent 157a8d63c5
commit f223b760ff
  1. 2
      package.json
  2. 2
      src/app/app.module.ts
  3. 37
      src/app/config.service.ts
  4. 2
      src/app/debugger/debugger.component.ts
  5. 2
      src/app/pages/admin/admin.component.ts
  6. 2
      src/app/pages/answers/answers.component.ts
  7. 2
      src/app/pages/base-page/base.component.ts
  8. 10
      src/app/pages/create-or-retrieve/create-or-retrieve.component.ts
  9. 2
      src/app/pages/dates/dates.component.ts
  10. 2
      src/app/pages/end-confirmation/end-confirmation.component.ts
  11. 2
      src/app/pages/home/home.component.ts
  12. 2
      src/app/pages/kind/kind.component.ts
  13. 2
      src/app/pages/password/password.component.ts
  14. 2
      src/app/pages/pictures/pictures.component.ts
  15. 2
      src/app/pages/resume/resume.component.ts
  16. 2
      src/app/pages/visibility/visibility.component.ts
  17. 2
      src/app/pages/voting-choice/voting-choice.component.ts
  18. 2
      src/app/pages/voting-graph/voting-graph.component.ts
  19. 2
      src/app/pages/voting-summary/voting-summary.component.ts
  20. 142
      src/app/services/config.service.ts
  21. 4
      src/app/services/poll-service.service.spec.ts
  22. 32
      src/app/services/poll-service.service.ts
  23. 24
      src/app/services/poll.service.ts
  24. 0
      src/app/services/progression.service.spec.ts
  25. 2
      src/app/ui/navigation/navigation.component.ts
  26. 2
      src/environments/environment.ts
  27. 10
      yarn.lock

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading…
Cancel
Save