From a68cbdcc0a017e30490239ff9593c69b7b2f798f Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Tue, 21 Jan 2020 12:04:14 +0100 Subject: [PATCH] :book: add mocks from updated backend --- package.json | 1 + src/app/app.component.ts | 2 +- .../config/mocks/comment-same-text-error.json | 4 + .../config/mocks/comment-too-fast-error.json | 4 + .../mocks/config-poll-dessins-animes.json | 565 ++++++++++++++++++ src/app/config/mocks/created-comment.json | 48 ++ src/app/config/mocks/votestack-success.json | 43 ++ .../poll-display/poll-display.component.ts | 5 +- src/app/services/config.service.ts | 25 +- .../ui/navigation/navigation.component.html | 40 +- .../ui/vote-choice/vote-choice.component.ts | 2 +- src/environments/environment.ts | 14 +- 12 files changed, 714 insertions(+), 39 deletions(-) create mode 100644 src/app/config/mocks/comment-same-text-error.json create mode 100644 src/app/config/mocks/comment-too-fast-error.json create mode 100644 src/app/config/mocks/config-poll-dessins-animes.json create mode 100644 src/app/config/mocks/created-comment.json create mode 100644 src/app/config/mocks/votestack-success.json diff --git a/package.json b/package.json index 9d78a553..b0752bdc 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "start": "ng serve", "serve": "ng serve", "build": "ng build", + "build:demo": "ng build --crossOrigin=anonymous --extractCss=true --baseHref=https://framadate-api.cipherbliss.com --aot=true --progress=true --statsJson=true", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e", diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 80ecc37f..cce83e93 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -19,7 +19,7 @@ export class AppComponent { age: 42 }; menuVisible: boolean = true; - private step: string; + step: string; constructor(private translate: TranslateService, @Inject(DOCUMENT) private document, diff --git a/src/app/config/mocks/comment-same-text-error.json b/src/app/config/mocks/comment-same-text-error.json new file mode 100644 index 00000000..d68e7bab --- /dev/null +++ b/src/app/config/mocks/comment-same-text-error.json @@ -0,0 +1,4 @@ +{ + "message": "anti flood déclenché", + "details": "votre deriner commentaire a exactement le même contenu que celui ci, il n'a donc pas été créé" +} diff --git a/src/app/config/mocks/comment-too-fast-error.json b/src/app/config/mocks/comment-too-fast-error.json new file mode 100644 index 00000000..4af92db2 --- /dev/null +++ b/src/app/config/mocks/comment-too-fast-error.json @@ -0,0 +1,4 @@ +{ + "message": "anti flood déclenché", + "details": "votre deriner commentaire a été envoyé il y a moins de 5 secondes" +} diff --git a/src/app/config/mocks/config-poll-dessins-animes.json b/src/app/config/mocks/config-poll-dessins-animes.json new file mode 100644 index 00000000..983a4952 --- /dev/null +++ b/src/app/config/mocks/config-poll-dessins-animes.json @@ -0,0 +1,565 @@ +{ + "message": "your poll config v2", + "data": { + "id": 3, + "title": "dessin animé préféré", + "customUrl": null, + "description": "choisissez votre animé préféré", + "creationDate": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "expiracyDate": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "owner": { + "__initializer__": null, + "__cloner__": null, + "__isInitialized__": true, + "pseudo": "tk_TEST", + "email": "tktest@tktest.com" + }, + "kind": "text", + "allowedAnswers": [ + "yes" + ], + "modificationPolicy": "self", + "mailOnComment": null, + "mailOnVote": null, + "hideResults": null, + "showResultEvenIfPasswords": null, + "votes": {}, + "stacksOfVotes": {}, + "choices": {}, + "comments": {}, + "defaultExpiracyDaysFromNow": 60 + }, + "stacks_count": 10, + "stacks": { + "3": { + "id": 3, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "4": { + "id": 3, + "vote_id": 4, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + }, + "5": { + "id": 3, + "vote_id": 5, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + } + } + }, + "4": { + "id": 4, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "6": { + "id": 4, + "vote_id": 6, + "value": "yes", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "7": { + "id": 4, + "vote_id": 7, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + }, + "8": { + "id": 4, + "vote_id": 8, + "value": "no", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "5": { + "id": 5, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:33:26.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "9": { + "id": 5, + "vote_id": 9, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "10": { + "id": 5, + "vote_id": 10, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "11": { + "id": 5, + "vote_id": 11, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "6": { + "id": 6, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:36:58.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "12": { + "id": 6, + "vote_id": 12, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "13": { + "id": 6, + "vote_id": 13, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "14": { + "id": 6, + "vote_id": 14, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "7": { + "id": 7, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:39:12.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "15": { + "id": 7, + "vote_id": 15, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "16": { + "id": 7, + "vote_id": 16, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "17": { + "id": 7, + "vote_id": 17, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "8": { + "id": 8, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:39:13.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "18": { + "id": 8, + "vote_id": 18, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "19": { + "id": 8, + "vote_id": 19, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "20": { + "id": 8, + "vote_id": 20, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "9": { + "id": 9, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:42:19.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "21": { + "id": 9, + "vote_id": 21, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "22": { + "id": 9, + "vote_id": 22, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "23": { + "id": 9, + "vote_id": 23, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "10": { + "id": 10, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:42:32.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "24": { + "id": 10, + "vote_id": 24, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "25": { + "id": 10, + "vote_id": 25, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "26": { + "id": 10, + "vote_id": 26, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "11": { + "id": 11, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:43:46.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "27": { + "id": 11, + "vote_id": 27, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "28": { + "id": 11, + "vote_id": 28, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "29": { + "id": 11, + "vote_id": 29, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + }, + "12": { + "id": 12, + "pseudo": "voting_people_TEST", + "creation_date": { + "date": "2020-01-21 10:44:35.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "votes": { + "30": { + "id": 12, + "vote_id": 30, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "31": { + "id": 12, + "vote_id": 31, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "32": { + "id": 12, + "vote_id": 32, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + } + } + }, + "choices_count": 7, + "choices": { + "5": { + "id": 5, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Vic le viking" + }, + "6": { + "id": 6, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Boumbo petite automobile" + }, + "7": { + "id": 7, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Les mystérieuses cités d'or" + }, + "8": { + "id": 8, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Les mondes engloutis" + }, + "9": { + "id": 9, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Foot 2 rue" + }, + "10": { + "id": 10, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Le chat, la vache, et l'océan" + }, + "11": { + "id": 11, + "date": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "text": "Digimon" + } + }, + "comments": { + "3": { + "id": 3, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-20 16:58:56.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "4": { + "id": 4, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-20 16:59:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "5": { + "id": 5, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:12:02.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "6": { + "id": 6, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:12:34.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "7": { + "id": 7, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:14:20.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "8": { + "id": 8, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:15:09.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "9": { + "id": 9, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:15:10.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "10": { + "id": 10, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:15:35.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "11": { + "id": 11, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:26:58.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "12": { + "id": 12, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:27:03.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "13": { + "id": 13, + "text": "wouah trop bien framadate!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:27:10.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "14": { + "id": 14, + "text": "wouah trop bien framadate wouhouuu!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:34:04.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "15": { + "id": 15, + "text": "wouah trop bien framadate wouhouucghfdghu!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:36:33.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + }, + "16": { + "id": 16, + "text": "wouah trop bien framadate woudghdghhouucghfdghu!", + "pseudo": "tk_TEST", + "date": { + "date": "2020-01-21 10:50:43.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + } + } + }, + "comments_count": 14 +} diff --git a/src/app/config/mocks/created-comment.json b/src/app/config/mocks/created-comment.json new file mode 100644 index 00000000..d7ae4604 --- /dev/null +++ b/src/app/config/mocks/created-comment.json @@ -0,0 +1,48 @@ +{ + "message": "you created a comment", + "data": { + "your_comment": { + "id": 14, + "poll": { + "id": 3, + "title": "dessin animé préféré", + "customUrl": null, + "description": "choisissez votre animé préféré", + "creationDate": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "expiracyDate": { + "date": "2020-01-20 16:45:48.000000", + "timezone_type": 3, + "timezone": "Europe/Berlin" + }, + "owner": { + "__initializer__": null, + "__cloner__": null, + "__isInitialized__": true, + "pseudo": "tk_TEST", + "email": "tktest@tktest.com" + }, + "kind": "text", + "allowedAnswers": [ + "yes" + ], + "modificationPolicy": "self", + "mailOnComment": null, + "mailOnVote": null, + "hideResults": null, + "showResultEvenIfPasswords": null, + "votes": {}, + "stacksOfVotes": {}, + "choices": {}, + "comments": {}, + "defaultExpiracyDaysFromNow": 60 + }, + "text": "wouah trop bien framadate wouhouuu!", + "token": "5e25cb2c6e533" + }, + "poll_comments": {} + } +} diff --git a/src/app/config/mocks/votestack-success.json b/src/app/config/mocks/votestack-success.json new file mode 100644 index 00000000..b2b6c171 --- /dev/null +++ b/src/app/config/mocks/votestack-success.json @@ -0,0 +1,43 @@ +{ + "message": "you created a vote stack from an existing owner : testing_vote_people@tktest.com", + "vote_stack": { + "30": { + "id": 30, + "value": "no", + "choice_id": 5, + "text": "Vic le viking" + }, + "31": { + "id": 31, + "value": "maybe", + "choice_id": 6, + "text": "Boumbo petite automobile" + }, + "32": { + "id": 32, + "value": "yes", + "choice_id": 7, + "text": "Les mystérieuses cités d'or" + } + }, + "vote_count": 10, + "owner_modifier_token": "rc7fgzdb6D8bUdgwl7H065eYMMeqOcL31JrS11MpRs08az8ed43aZLKsFd81cr50uq23D9b1w068E57U39omaBcygfebm7m252YI430b332UZ4tkC76", + "json_you_sent": { + "pseudo": "tktest", + "email": "testing_vote_people@tktest.com", + "votes": [ + { + "choice_id": 5, + "value": "no" + }, + { + "choice_id": 6, + "value": "maybe" + }, + { + "choice_id": 7, + "value": "yes" + } + ] + } +} diff --git a/src/app/pages/poll-display/poll-display.component.ts b/src/app/pages/poll-display/poll-display.component.ts index f1a49e93..7ec97ab5 100644 --- a/src/app/pages/poll-display/poll-display.component.ts +++ b/src/app/pages/poll-display/poll-display.component.ts @@ -1,7 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {BaseComponent} from "../base-page/base.component"; import {ConfigService} from "../../services/config.service"; -import {mockPoll3} from "../../config/mocks/mock-poll3"; import {mockComments} from "../../config/mocks/mock-comments"; import {ActivatedRoute} from "@angular/router"; @@ -12,8 +11,8 @@ import {ActivatedRoute} from "@angular/router"; }) export class PollDisplayComponent extends BaseComponent implements OnInit { - private pollConfigFetched; - private comments = mockComments; + pollConfigFetched; + comments = mockComments; constructor(public config: ConfigService, public activeRoute: ActivatedRoute) { diff --git a/src/app/services/config.service.ts b/src/app/services/config.service.ts index f58b0d89..9cd73378 100644 --- a/src/app/services/config.service.ts +++ b/src/app/services/config.service.ts @@ -120,7 +120,7 @@ export class ConfigService extends PollConfig { 'Charset': 'UTF-8', 'Content-Type': 'application/json', 'Accept': 'application/json', - 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE', + 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Origin': '*' }; @@ -136,6 +136,8 @@ export class ConfigService extends PollConfig { this.customUrlIsUnique = null; this.loading = true; + // TODO + this.todo('check slug is unique'); this.http.get(`${this.baseHref}/check-slug-is-uniq`, this.makeHeaders({slug: this.customUrl}), ) @@ -198,7 +200,6 @@ export class ConfigService extends PollConfig { if (localStorage) { console.log('localStorage', localStorage) } - } @@ -207,13 +208,15 @@ export class ConfigService extends PollConfig { * @param url */ getPollByURL(url: string) { - this.http.get(`${this.baseHref}/poll/${url}`, this.makeHeaders()).subscribe( - (res: any) => { - this.myPolls = res.data; - }, (e) => { - this.handleError(e) - } - ); + + this.todo(); + // this.http.get(`${this.baseHref}/poll/${url}`, this.makeHeaders()).subscribe( + // (res: any) => { + // this.myPolls = res.data; + // }, (e) => { + // this.handleError(e) + // } + // ); } /** @@ -501,9 +504,9 @@ export class ConfigService extends PollConfig { alert('TODO'); } - todo() { + todo(message = '') { this.messageService.add({ - severity: 'info', + severity: 'info' + message, detail: "cette fonctionnalité n'est pas encore disponible. Venez en discuter sur framateam.org / Ux et design libre / Framasoft", summary: "Work in progress", }); diff --git a/src/app/ui/navigation/navigation.component.html b/src/app/ui/navigation/navigation.component.html index 081ada0d..304bcb25 100644 --- a/src/app/ui/navigation/navigation.component.html +++ b/src/app/ui/navigation/navigation.component.html @@ -1,94 +1,96 @@ - diff --git a/src/app/ui/vote-choice/vote-choice.component.ts b/src/app/ui/vote-choice/vote-choice.component.ts index 9ecc8f28..5c33102c 100644 --- a/src/app/ui/vote-choice/vote-choice.component.ts +++ b/src/app/ui/vote-choice/vote-choice.component.ts @@ -25,7 +25,7 @@ interface VoteChoice { }) export class VoteChoiceComponent { - @Input() private choice: any; + @Input() public choice: any; constructor(private el: ElementRef) { diff --git a/src/environments/environment.ts b/src/environments/environment.ts index fc436014..cc5c5ac1 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -1,12 +1,18 @@ // This file can be replaced during build by using the `fileReplacements` array. // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. // The list of file replacements can be found in `angular.json`. - +let baseURL = "http://localhost:8000/"; +const baseURLProd = "https://framadate.org/"; +const baseURLDemo = "https://framadate-api.cipherbliss.com/"; +const apiVersion = 1; +const testOnDemo = 0; +if (testOnDemo) { + baseURL = baseURLDemo; +} export const environment = { production: false, - baseHref: "https://framadate-api.cipherbliss.com/", - baseApiHref: "https://framadate-api.cipherbliss.com/api/v1" - // baseApiHref: "http://localhost:8000/api/v1" + baseHref: baseURL, + baseApiHref: baseURL + "api/v" + apiVersion }; /*