Merge branch 'date-convert-creation' into 'master'

Date convert creation

See merge request framasoft/framadate/funky-framadate-front!53
This commit is contained in:
ty kayn 2021-11-22 11:13:37 +00:00
commit d5e6a0330b
9 changed files with 73 additions and 40 deletions

View File

@ -1,11 +1,11 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import axios, { AxiosInstance, AxiosResponse } from 'axios'; import { AxiosInstance, AxiosResponse } from 'axios';
import { environment } from 'src/environments/environment'; import { environment } from 'src/environments/environment';
import { Answer } from '../enums/answer.enum'; import { Answer } from '../enums/answer.enum';
import { Poll } from '../models/poll.model'; import { Poll } from '../models/poll.model';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Observable, Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { ToastService } from './toast.service'; import { ToastService } from './toast.service';
import { LoaderService } from './loader.service'; import { LoaderService } from './loader.service';
import { Stack } from '../models/stack.model'; import { Stack } from '../models/stack.model';
@ -15,6 +15,7 @@ const currentApiRoutes = environment.api.version[apiVersion];
const apiBaseHref = environment.api.version[apiVersion].baseHref; const apiBaseHref = environment.api.version[apiVersion].baseHref;
const apiEndpoints = environment.api.endpoints; const apiEndpoints = environment.api.endpoints;
let axios = require('axios');
class PollDTO {} class PollDTO {}
@ -67,7 +68,7 @@ export class ApiService {
Charset: 'UTF-8', Charset: 'UTF-8',
// 'Content-Type': 'application/json', // 'Content-Type': 'application/json',
// Accept: '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', 'Content-Type': 'application/json',
// mode: 'no-cors', // mode: 'no-cors',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS', 'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
@ -82,17 +83,23 @@ export class ApiService {
} }
/** /**
* * create a new poll
* @param poll * @param poll
*/ */
public async createPoll(poll: PollDTO): Promise<Subscription> { public async createPoll(poll: PollDTO): Promise<Subscription> {
// this.loaderService.setStatus(true); // 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); console.log('apiservice createPoll config', poll);
return this.axiosInstance.post(
`${this.baseHref}${currentApiRoutes['api_new_poll']}`, return this.axiosInstance.post(`${this.baseHref}${currentApiRoutes['api_new_poll']}`, poll);
poll
// ApiService.makeHeaders()
);
} }
/** /**
@ -243,9 +250,11 @@ export class ApiService {
ApiService.handleError(error); ApiService.handleError(error);
} }
} }
public findMyPollsByEmail(email: string): Promise<any> { public findMyPollsByEmail(email: string): Promise<any> {
return this.axiosInstance.get<any>(`${this.baseHref}/poll/owner/${email}`); return this.axiosInstance.get<any>(`${this.baseHref}/poll/owner/${email}`);
} }
public async updateAnswer(slug: string, choiceLabel: string, pseudo: string, answer: Answer): Promise<string> { public async updateAnswer(slug: string, choiceLabel: string, pseudo: string, answer: Answer): Promise<string> {
try { try {
return await this.axiosInstance.patch(`${this.baseHref}/${slug}${this.answersEndpoint}`, { return await this.axiosInstance.patch(`${this.baseHref}/${slug}${this.answersEndpoint}`, {
@ -257,6 +266,7 @@ export class ApiService {
ApiService.handleError(error); ApiService.handleError(error);
} }
} }
//////////// ////////////
// DELETE // // DELETE //
@ -317,6 +327,7 @@ export class ApiService {
console.log(error.config); console.log(error.config);
// this.loaderService.setStatus(false); // this.loaderService.setStatus(false);
} }
public ousideHandleError(error) { public ousideHandleError(error) {
// this.loaderService.setStatus(true); // this.loaderService.setStatus(true);
if (error.response) { if (error.response) {

View File

@ -47,6 +47,7 @@ export class PollService implements Resolve<Poll> {
public showDateInterval = false; public showDateInterval = false;
public allowSeveralHours = false; public allowSeveralHours = false;
public richTextMode = false; public richTextMode = false;
public mode_calendar = false;
public calendar: Date[] = [new Date()]; public calendar: Date[] = [new Date()];
public disabled_dates: Date[] = []; public disabled_dates: Date[] = [];
@ -607,10 +608,10 @@ export class PollService implements Resolve<Poll> {
if (this._poll && this._poll.getValue) { if (this._poll && this._poll.getValue) {
const polltemp = this._poll.getValue(); const polltemp = this._poll.getValue();
if (polltemp) { if (polltemp) {
url = `${environment.frontDomain}#/poll/${polltemp.custom_url}/consultation`; url = `${environment.frontDomain}/#/poll/${polltemp.custom_url}/consultation`;
} }
} else { } 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 // TODO handle pass access
@ -624,10 +625,10 @@ export class PollService implements Resolve<Poll> {
if (this._poll && this._poll.getValue) { if (this._poll && this._poll.getValue) {
const polltemp = this._poll.getValue(); const polltemp = this._poll.getValue();
if (polltemp) { if (polltemp) {
url = `${environment.frontDomain}#/admin/${polltemp.admin_key}`; url = `${environment.frontDomain}/#/admin/${polltemp.admin_key}`;
} }
} else { } else {
url = `${environment.frontDomain}#/admin/${this.form.value.admin_key}`; url = `${environment.frontDomain}/#/admin/${this.form.value.admin_key}`;
} }
return url; return url;
} }
@ -679,7 +680,7 @@ export class PollService implements Resolve<Poll> {
/** /**
* convert the DateChoices to an arrray of Dates for calendar picker * convert the DateChoices to an arrray of Dates for calendar picker
*/ */
convertTextToCalendar() { convertTextToCalendar(): Date[] {
console.log('convert text to calendar', this.dateChoiceList); console.log('convert text to calendar', this.dateChoiceList);
let converted = []; let converted = [];
for (let someDateChoice of this.dateChoiceList) { for (let someDateChoice of this.dateChoiceList) {
@ -693,7 +694,7 @@ export class PollService implements Resolve<Poll> {
console.log('converted', converted); console.log('converted', converted);
this.calendar = converted; this.calendar = converted;
return; return converted;
} }
patchFormWithPoll(poll: Poll) { patchFormWithPoll(poll: Poll) {
@ -745,10 +746,21 @@ export class PollService implements Resolve<Poll> {
newpoll.allow_comments = form.value.allowComments; newpoll.allow_comments = form.value.allowComments;
// merge choices from storage // merge choices from storage
if (form.value.isAboutDate) { 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); console.log('this.calendar', this.calendar);
for (let elem of this.calendar) { for (let elem of convertedDates) {
console.log('elem', elem); console.log('elem', elem);
let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem); let converted_day = this.DateUtilitiesService.convertDateToDateChoiceObject(elem);
newpoll.dateChoices.push(converted_day); newpoll.dateChoices.push(converted_day);

View File

@ -2,6 +2,7 @@ import { Component, Input, OnInit } from '@angular/core';
import { FormGroup } from '@angular/forms'; import { FormGroup } from '@angular/forms';
import { PollService } from '../../../../../core/services/poll.service'; import { PollService } from '../../../../../core/services/poll.service';
import { ApiService } from '../../../../../core/services/api.service'; import { ApiService } from '../../../../../core/services/api.service';
import { environment } from '../../../../../../environments/environment';
@Component({ @Component({
selector: 'app-step-five', selector: 'app-step-five',
@ -12,7 +13,7 @@ export class StepFiveComponent implements OnInit {
@Input() step_max: any; @Input() step_max: any;
@Input() public form: FormGroup; @Input() public form: FormGroup;
poll: any; poll: any;
advancedDisplayEnabled = true; advancedDisplayEnabled = environment.advanced_options_display;
constructor(public pollService: PollService) { constructor(public pollService: PollService) {
this.pollService.step_current = 5; this.pollService.step_current = 5;
} }

View File

@ -2,7 +2,7 @@
<app-stepper [step_current]="3" [step_max]="pollService.step_max"></app-stepper> <app-stepper [step_current]="3" [step_max]="pollService.step_max"></app-stepper>
<app-errors-list [form]="pollService.form"></app-errors-list> <app-errors-list [form]="pollService.form"></app-errors-list>
<!-- choix spécialement pour les dates--> <!-- choix spécialement pour les dates-->
<div class="calendar" *ngIf="mode_calendar"> <div class="calendar" *ngIf="pollService.mode_calendar">
<p-calendar <p-calendar
[(ngModel)]="pollService.calendar" [(ngModel)]="pollService.calendar"
firstDayOfWeek="1" firstDayOfWeek="1"
@ -16,16 +16,18 @@
></p-calendar> ></p-calendar>
</div> </div>
<div class="text-date-list" *ngIf="!mode_calendar"> <div class="text-date-list" *ngIf="!pollService.mode_calendar">
<app-day-list <app-day-list
[form]="pollService.form" [form]="pollService.form"
[hasSeveralHours]="pollService.form.value.hasSeveralHours" [hasSeveralHours]="pollService.form.value.hasSeveralHours"
></app-day-list> ></app-day-list>
</div> </div>
<button class="button" (click)="changeDateInputMode()" [ngClass]="{ 'is-primary': !mode_calendar }"> <button class="button" (click)="changeDateInputMode()" [ngClass]="{ 'is-primary': !pollService.mode_calendar }">
<span *ngIf="mode_calendar"> <i class="fa fa-pencil"></i> Saisir les dates manuellement </span> <span *ngIf="pollService.mode_calendar"> <i class="fa fa-pencil"></i> Saisir les dates manuellement </span>
<span *ngIf="!mode_calendar"> <i class="fa fa-calendar-o"></i> Saisir les dates dans le calendrier </span> <span *ngIf="!pollService.mode_calendar">
<i class="fa fa-calendar-o"></i> Saisir les dates dans le calendrier
</span>
</button> </button>
</div> </div>
<div class="columns"> <div class="columns">
@ -88,7 +90,7 @@
type="text" type="text"
id="timeChoices_{{ id }}" id="timeChoices_{{ id }}"
/> />
<button (click)="time.timeList.splice(id, 1)" class="btn btn-warning"> <button (click)="pollService.timeList.splice(id, 1)" class="btn btn-warning">
<i class="fa fa-times" aria-hidden="true"></i> <i class="fa fa-times" aria-hidden="true"></i>
</button> </button>
</div> </div>

View File

@ -12,7 +12,6 @@ export class StepThreeComponent implements OnInit {
step_max: any; step_max: any;
@Input() @Input()
form: any; form: any;
public mode_calendar = false;
constructor(public pollService: PollService) { constructor(public pollService: PollService) {
this.pollService.step_current = 3; this.pollService.step_current = 3;
@ -25,8 +24,10 @@ export class StepThreeComponent implements OnInit {
} }
changeDateInputMode() { 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;
} }
} }

View File

@ -68,8 +68,8 @@
{{ 'SENTENCES.view-an-example' | translate }} {{ 'SENTENCES.view-an-example' | translate }}
</h2> </h2>
<p> <p>
<a href="/poll/orange-ou-citron/consultation" class="btn btn-info"> <a href="/#/poll/aujourdhui-ou-demain/consultation/simple" class="btn btn-info">
<i class="fa fa-biking"></i> Orange ou citron? <i class="fa fa-biking"></i> Aujourd'hui ou demain ?
</a> </a>
</p> </p>
<p> <p>

View File

@ -1,15 +1,18 @@
export const backendApiUrlsInDev = { export const backendApiUrlsInDev = {
// local: 'http://tktest.lan/api/v1', // local: 'http://tktest.lan/api/v1',
// remote: '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', // 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', // remote: 'https://framadate-api.cipherbliss.com/api/v1',
}; };
export const apiV1 = { 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: '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_new_poll: '/poll/',
api_get_poll: '/poll/{id}', api_get_poll: '/poll/{id}',
api_new_vote_stack: '/vote-stack', api_new_vote_stack: '/vote-stack',

View File

@ -1,18 +1,21 @@
const productionBaseUrl = 'https://framadate-api.cipherbliss.com'; // set this to your production domain
const apiVersion = 'v1';
const backendApiUrlsInDev = { const backendApiUrlsInDev = {
local: '/api/v1', local: `/api/${apiVersion}`,
remote: 'https://framadate-api.cipherbliss.com/api/v1', remote: `${productionBaseUrl}/api/${apiVersion}`,
}; };
const apiV1 = { const apiV1 = {
baseHref: 'https://framadate-api.cipherbliss.com/api/v1', baseHref: `${productionBaseUrl}/api/${apiVersion}`,
api_new_poll: '/poll/', api_new_poll: '/poll/',
api_get_poll: '/poll/{id}', api_get_poll: '/poll/{id}',
api_new_vote_stack: '/vote-stack', 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', 'app.swagger': '/api/doc.json',
}; };
export const environment = { export const environment = {
frontDomain: 'https://framadate-api.cipherbliss.com', frontDomain: productionBaseUrl,
production: true, production: true,
display_routes: false, display_routes: false,
showDemoWarning: false, showDemoWarning: false,

View File

@ -15,8 +15,8 @@ export const environment = {
advanced_options_display: false, advanced_options_display: false,
autofill_participation: false, autofill_participation: false,
showDemoWarning: false, showDemoWarning: false,
autoSendNewPoll: false, autoSendNewPoll: true,
showStepperShortcuts: false, showStepperShortcuts: true,
interval_days_default: 7, interval_days_default: 7,
expiresDaysDelay: 60, expiresDaysDelay: 60,
maxCountOfAnswers: 300, maxCountOfAnswers: 300,