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 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<Subscription> {
// 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<any> {
return this.axiosInstance.get<any>(`${this.baseHref}/poll/owner/${email}`);
}
public async updateAnswer(slug: string, choiceLabel: string, pseudo: string, answer: Answer): Promise<string> {
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) {

View File

@ -47,6 +47,7 @@ export class PollService implements Resolve<Poll> {
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<Poll> {
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<Poll> {
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<Poll> {
/**
* 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<Poll> {
console.log('converted', converted);
this.calendar = converted;
return;
return converted;
}
patchFormWithPoll(poll: Poll) {
@ -745,10 +746,21 @@ export class PollService implements Resolve<Poll> {
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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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