diff --git a/src/app/core/services/api.service.ts b/src/app/core/services/api.service.ts index 4b72865d..a38f0d19 100644 --- a/src/app/core/services/api.service.ts +++ b/src/app/core/services/api.service.ts @@ -1,11 +1,11 @@ import { Injectable } from '@angular/core'; -import axios, { AxiosInstance, AxiosResponse } from 'axios'; +import { AxiosInstance, AxiosResponse } from 'axios'; import { environment } from 'src/environments/environment'; import { Answer } from '../enums/answer.enum'; import { Poll } from '../models/poll.model'; import { HttpClient } from '@angular/common/http'; -import { Observable, Subscription } from 'rxjs'; +import { Subscription } from 'rxjs'; import { ToastService } from './toast.service'; import { LoaderService } from './loader.service'; import { Stack } from '../models/stack.model'; @@ -15,6 +15,7 @@ const currentApiRoutes = environment.api.version[apiVersion]; const apiBaseHref = environment.api.version[apiVersion].baseHref; const apiEndpoints = environment.api.endpoints; +let axios = require('axios'); class PollDTO {} @@ -67,7 +68,7 @@ export class ApiService { Charset: 'UTF-8', // 'Content-Type': 'application/json', // Accept: 'application/json', - 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Origin': '^https?://(localhost|127.0.0.1)(:[0-9]+)?$', 'Content-Type': 'application/json', // mode: 'no-cors', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', @@ -82,17 +83,23 @@ export class ApiService { } /** - * + * create a new poll * @param poll */ public async createPoll(poll: PollDTO): Promise { // this.loaderService.setStatus(true); + + let axiosConf = { + method: 'post', + url: `${this.baseHref}${currentApiRoutes['api_new_poll']}`, + headers: { + 'Content-Type': 'application/json', + }, + data: JSON.stringify(poll), + }; console.log('apiservice createPoll config', poll); - return this.axiosInstance.post( - `${this.baseHref}${currentApiRoutes['api_new_poll']}`, - poll - // ApiService.makeHeaders() - ); + + return this.axiosInstance.post(`${this.baseHref}${currentApiRoutes['api_new_poll']}`, poll); } /** @@ -243,9 +250,11 @@ export class ApiService { ApiService.handleError(error); } } + public findMyPollsByEmail(email: string): Promise { return this.axiosInstance.get(`${this.baseHref}/poll/owner/${email}`); } + public async updateAnswer(slug: string, choiceLabel: string, pseudo: string, answer: Answer): Promise { try { return await this.axiosInstance.patch(`${this.baseHref}/${slug}${this.answersEndpoint}`, { @@ -257,6 +266,7 @@ export class ApiService { ApiService.handleError(error); } } + //////////// // DELETE // @@ -317,6 +327,7 @@ export class ApiService { console.log(error.config); // this.loaderService.setStatus(false); } + public ousideHandleError(error) { // this.loaderService.setStatus(true); if (error.response) { diff --git a/src/app/core/services/poll.service.ts b/src/app/core/services/poll.service.ts index ed9ba9ab..5680ec7f 100644 --- a/src/app/core/services/poll.service.ts +++ b/src/app/core/services/poll.service.ts @@ -47,6 +47,7 @@ export class PollService implements Resolve { public showDateInterval = false; public allowSeveralHours = false; public richTextMode = false; + public mode_calendar = false; public calendar: Date[] = [new Date()]; public disabled_dates: Date[] = []; @@ -607,10 +608,10 @@ export class PollService implements Resolve { if (this._poll && this._poll.getValue) { const polltemp = this._poll.getValue(); if (polltemp) { - url = `${environment.frontDomain}#/poll/${polltemp.custom_url}/consultation`; + url = `${environment.frontDomain}/#/poll/${polltemp.custom_url}/consultation`; } } else { - url = `${environment.frontDomain}#/poll/${this.form.value.custom_url}/consultation`; + url = `${environment.frontDomain}/#/poll/${this.form.value.custom_url}/consultation`; } // TODO handle pass access @@ -624,10 +625,10 @@ export class PollService implements Resolve { if (this._poll && this._poll.getValue) { const polltemp = this._poll.getValue(); if (polltemp) { - url = `${environment.frontDomain}#/admin/${polltemp.admin_key}`; + url = `${environment.frontDomain}/#/admin/${polltemp.admin_key}`; } } else { - url = `${environment.frontDomain}#/admin/${this.form.value.admin_key}`; + url = `${environment.frontDomain}/#/admin/${this.form.value.admin_key}`; } return url; } @@ -679,7 +680,7 @@ export class PollService implements Resolve { /** * convert the DateChoices to an arrray of Dates for calendar picker */ - convertTextToCalendar() { + convertTextToCalendar(): Date[] { console.log('convert text to calendar', this.dateChoiceList); let converted = []; for (let someDateChoice of this.dateChoiceList) { @@ -693,7 +694,7 @@ export class PollService implements Resolve { console.log('converted', converted); this.calendar = converted; - return; + return converted; } patchFormWithPoll(poll: Poll) { @@ -745,10 +746,21 @@ export class PollService implements Resolve { newpoll.allow_comments = form.value.allowComments; // merge choices from storage if (form.value.isAboutDate) { - // convert calendar picker dates + // first we convert calendar picker dates. + // we want a list of date object, and we want the kind of dates who was lastly edited by the user + // depending on the manual or datepicker mode, we need to get a converted list of dates + let convertedDates = []; + if (this.mode_calendar) { + // mode calendar date picker, we take the list of date objects in calendar property + convertedDates = this.calendar; + } else { + // mode text, we convert to calendar list, and take that list + convertedDates = this.convertTextToCalendar(); + } + console.log('this.calendar', this.calendar); - for (let elem of this.calendar) { + for (let elem of convertedDates) { console.log('elem', elem); let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem); newpoll.dateChoices.push(converted_day); diff --git a/src/app/features/administration/form/steps/step-five/step-five.component.ts b/src/app/features/administration/form/steps/step-five/step-five.component.ts index 67ea01ee..fdfaa132 100644 --- a/src/app/features/administration/form/steps/step-five/step-five.component.ts +++ b/src/app/features/administration/form/steps/step-five/step-five.component.ts @@ -2,6 +2,7 @@ import { Component, Input, OnInit } from '@angular/core'; import { FormGroup } from '@angular/forms'; import { PollService } from '../../../../../core/services/poll.service'; import { ApiService } from '../../../../../core/services/api.service'; +import { environment } from '../../../../../../environments/environment'; @Component({ selector: 'app-step-five', @@ -12,7 +13,7 @@ export class StepFiveComponent implements OnInit { @Input() step_max: any; @Input() public form: FormGroup; poll: any; - advancedDisplayEnabled = true; + advancedDisplayEnabled = environment.advanced_options_display; constructor(public pollService: PollService) { this.pollService.step_current = 5; } diff --git a/src/app/features/administration/form/steps/step-three/step-three.component.html b/src/app/features/administration/form/steps/step-three/step-three.component.html index 4ccb5947..c16264f4 100644 --- a/src/app/features/administration/form/steps/step-three/step-three.component.html +++ b/src/app/features/administration/form/steps/step-three/step-three.component.html @@ -2,7 +2,7 @@ -
+
-
+
-
@@ -88,7 +90,7 @@ type="text" id="timeChoices_{{ id }}" /> -
diff --git a/src/app/features/administration/form/steps/step-three/step-three.component.ts b/src/app/features/administration/form/steps/step-three/step-three.component.ts index 516af21a..aa5c04e5 100644 --- a/src/app/features/administration/form/steps/step-three/step-three.component.ts +++ b/src/app/features/administration/form/steps/step-three/step-three.component.ts @@ -12,7 +12,6 @@ export class StepThreeComponent implements OnInit { step_max: any; @Input() form: any; - public mode_calendar = false; constructor(public pollService: PollService) { this.pollService.step_current = 3; @@ -25,8 +24,10 @@ export class StepThreeComponent implements OnInit { } changeDateInputMode() { - this.mode_calendar ? this.pollService.convertCalendarToText() : this.pollService.convertTextToCalendar(); + this.pollService.mode_calendar + ? this.pollService.convertCalendarToText() + : this.pollService.convertTextToCalendar(); - this.mode_calendar = !this.mode_calendar; + this.pollService.mode_calendar = !this.pollService.mode_calendar; } } diff --git a/src/app/features/shared/components/ui/static-pages/about/about.component.html b/src/app/features/shared/components/ui/static-pages/about/about.component.html index fd9657b7..9fe684ad 100644 --- a/src/app/features/shared/components/ui/static-pages/about/about.component.html +++ b/src/app/features/shared/components/ui/static-pages/about/about.component.html @@ -68,8 +68,8 @@ {{ 'SENTENCES.view-an-example' | translate }}

- - Orange ou citron? + + Aujourd'hui ou demain ?

diff --git a/src/environments/endpoints.ts b/src/environments/endpoints.ts index 01f50335..775786bf 100644 --- a/src/environments/endpoints.ts +++ b/src/environments/endpoints.ts @@ -1,15 +1,18 @@ export const backendApiUrlsInDev = { // local: 'http://tktest.lan/api/v1', // remote: 'http://tktest.lan/api/v1', - local: 'http://localhost:8000/api/v1', + // local: 'http://localhost:8000/api/v1', + local: 'http://www.tk.lan/index.php/api/v1', // local: 'https://framadate-api.cipherbliss.com/api/v1', - remote: 'http://localhost:8000/api/v1', + // remote: 'http://localhost:8000/api/v1', + remote: 'http://www.tk.lan/index.php/api/v1', // remote: 'https://framadate-api.cipherbliss.com/api/v1', }; export const apiV1 = { - baseHref: 'http://localhost:8000/api/v1', + // baseHref: 'http://localhost:8000/api/v1', // local "symfony serve" live server + baseHref: 'http://www.tk.lan/index.php/api/v1', // local apache2 server // baseHref: 'http://tktest.lan/api/v1', - // baseHref: 'https://framadate-api.cipherbliss.com/api/v1', + // baseHref: 'https://framadate-api.cipherbliss.com/api/v1', // demo preprod api_new_poll: '/poll/', api_get_poll: '/poll/{id}', api_new_vote_stack: '/vote-stack', diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index 123d0beb..6fc4397a 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,18 +1,21 @@ +const productionBaseUrl = 'https://framadate-api.cipherbliss.com'; // set this to your production domain +const apiVersion = 'v1'; + const backendApiUrlsInDev = { - local: '/api/v1', - remote: 'https://framadate-api.cipherbliss.com/api/v1', + local: `/api/${apiVersion}`, + remote: `${productionBaseUrl}/api/${apiVersion}`, }; const apiV1 = { - baseHref: 'https://framadate-api.cipherbliss.com/api/v1', + baseHref: `${productionBaseUrl}/api/${apiVersion}`, api_new_poll: '/poll/', api_get_poll: '/poll/{id}', api_new_vote_stack: '/vote-stack', - 'api_test-mail-poll': '/api/v1/poll/mail/test-mail-poll/{emailChoice}', + 'api_test-mail-poll': `/api/${apiVersion}/poll/mail/test-mail-poll/{emailChoice}`, 'app.swagger': '/api/doc.json', }; export const environment = { - frontDomain: 'https://framadate-api.cipherbliss.com', + frontDomain: productionBaseUrl, production: true, display_routes: false, showDemoWarning: false, diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 52f93886..e92c29de 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -15,8 +15,8 @@ export const environment = { advanced_options_display: false, autofill_participation: false, showDemoWarning: false, - autoSendNewPoll: false, - showStepperShortcuts: false, + autoSendNewPoll: true, + showStepperShortcuts: true, interval_days_default: 7, expiresDaysDelay: 60, maxCountOfAnswers: 300,