Feature/refacto 1 See merge request framasoft/framadate/funky-framadate-front!33archived-develop
commit
c45137ee79
@ -0,0 +1,42 @@
|
||||
/**
|
||||
*
|
||||
* -------------------------- -------- -------- ------ ------------------------------------------------
|
||||
Name Method Scheme Host Path
|
||||
-------------------------- -------- -------- ------ ------------------------------------------------
|
||||
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
|
||||
api_get_poll_comment GET ANY ANY /poll/{id}/comments
|
||||
api_new_comment POST ANY ANY /poll/{id}/comment
|
||||
api_poll_comments_delete DELETE ANY ANY /poll/{id}/comments
|
||||
api_send_user_polls GET ANY ANY /send-polls-to-user/{email}
|
||||
homepageget_default GET ANY ANY /
|
||||
api_get_all_polls GET ANY ANY /poll/
|
||||
api_get_poll GET ANY ANY /poll/{id}
|
||||
api_update_poll PUT ANY ANY /poll/{id}/{token}
|
||||
api_new_poll POST ANY ANY /poll/
|
||||
api_test-mail-poll GET ANY ANY /poll/mail/test-mail-poll/{emailChoice}
|
||||
api_poll_delete DELETE ANY ANY /poll/{id}
|
||||
api_clean_expired_polls GET ANY ANY /poll/clean-polls
|
||||
api_check_slug_is_unique GET ANY ANY /poll/admin/{token}
|
||||
api_new_vote_stack POST ANY ANY /poll/{id}/vote
|
||||
api_update_vote_stack PATCH ANY ANY /vote-stack/{id}/token/{modifierToken}
|
||||
api_poll_votes_delete DELETE ANY ANY /poll/{id}/votes/{accessToken}
|
||||
app.swagger GET ANY ANY /doc.json
|
||||
-------------------------- -------- -------- ------ ------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* WANTED CHANGES (seraf)
|
||||
* -------------------------- -------- -------- ------ ------------------------------------------------
|
||||
Name Method Scheme Host Path
|
||||
-------------------------- -------- -------- ------ ------------------------------------------------
|
||||
api_get_poll_comment GET ANY ANY /poll/{id}/comment
|
||||
api_delete_poll_comments DELETE ANY ANY /poll/{id}/comment
|
||||
api_user_polls_send_by_email GET ANY ANY /user/{email}/polls/send-by-email
|
||||
api_get_user_polls GET ANY ANY /user/{email}/polls
|
||||
api_get_poll_slug GET ANY ANY /poll/slug/{id}/{token}
|
||||
api_clean_expired_polls GET ANY ANY /admin/clean-polls/{token}
|
||||
|
||||
api_test-mail-poll GET ANY ANY /poll/mail/test-mail-poll/{emailChoice}
|
||||
api_update_vote_stack PATCH ANY ANY /vote-stack/{id}/token/{modifierToken}
|
||||
-------------------------- -------- -------- ------ ------------------------------------------------
|
||||
*/
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* each step in the form is a component
|
||||
*/
|
||||
export const Routes = [];
|
@ -1,24 +0,0 @@
|
||||
export var graphOptions = {
|
||||
legend: { display: false },
|
||||
scales: {
|
||||
xAxes: [
|
||||
{
|
||||
gridLines: { drawBorder: false, display: false },
|
||||
display: false,
|
||||
stacked: true,
|
||||
ticks: {
|
||||
beginAtZero: true,
|
||||
maxRotation: 0,
|
||||
minRotation: 0,
|
||||
},
|
||||
},
|
||||
],
|
||||
yAxes: [
|
||||
{
|
||||
gridLines: { drawBorder: true, display: false },
|
||||
display: true,
|
||||
stacked: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { ConfigService } from '../../../services/config.service';
|
||||
|
||||
@Component({
|
||||
selector: 'framadate-base-page',
|
@ -1,6 +1,6 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { BaseComponent } from '../base-page/base.component';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { ConfigService } from '../../../services/config.service';
|
||||
|
||||
@Component({
|
||||
selector: 'framadate-page-kind',
|
@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { ConfigService } from '../../../services/config.service';
|
||||
import { BaseComponent } from '../base-page/base.component';
|
||||
|
||||
@Component({
|
@ -1 +0,0 @@
|
||||
@import '../../../assets/scss/variables';
|
@ -0,0 +1,8 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class PollAdministrationModule {}
|
@ -0,0 +1 @@
|
||||
@import '../../../../assets/scss/variables';
|
@ -1,10 +1,10 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { BaseComponent } from '../base-page/base.component';
|
||||
import { ConfigService } from '../../services/config.service';
|
||||
import { mockComments } from '../../config/mocks/mock-comments';
|
||||
import { BaseComponent } from '../../example/base-page/base.component';
|
||||
import { ConfigService } from '../../../services/config.service';
|
||||
import { mockComments } from '../../../mocks/mock-comments';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { mockPoll3 } from '../../config/mocks/mock-poll3';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { mockPoll3 } from '../../../mocks/mock-poll3';
|
||||
|
||||
@Component({
|
||||
selector: 'framadate-poll-display',
|
@ -0,0 +1,8 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { NgModule } from '@angular/core';
|
||||
|
||||
@NgModule({
|
||||
declarations: [],
|
||||
imports: [CommonModule],
|
||||
})
|
||||
export class PollParticipationModule {}
|
@ -1,11 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class PollService {
|
||||
private baseHref: string = environment.baseApiHref;
|
||||
|
||||
constructor() {}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ConfigService } from './config.service';
|
||||
|
||||
describe('ConfigService', () => {
|
||||
beforeEach(() => TestBed.configureTestingModule({}));
|
||||
|
||||
it('should be created', () => {
|
||||
const service: ConfigService = TestBed.get(ConfigService);
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,4 @@
|
||||
export enum AnswerGranularity {
|
||||
BASIC = 'BASIC',
|
||||
COMPLEX = 'COMPLEX',
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export enum AnswerType {
|
||||
YES = 'YES',
|
||||
NO = 'NO',
|
||||
MAYBE = 'MAYBE',
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
export enum PollType {
|
||||
CLASSIC = 'CLASSIC',
|
||||
DATES = 'DATES',
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export enum Theme {
|
||||
LIGHT = 'light-watermelon',
|
||||
DARK = 'dark-crystal',
|
||||
RED = 'hot-covid',
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
export interface DateOption {
|
||||
timeList: any;
|
||||
literal: string;
|
||||
date_object?: object;
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import { AnswerType } from '../enums/answer-type.enum';
|
||||
import { PollOption } from './poll-options.model';
|
||||
|
||||
export class Answer {
|
||||
constructor(public pollOption: PollOption, public type: AnswerType, public userPseudo: string) {}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
import { AnswerGranularity } from '../enums/answer-granularity.enum';
|
||||
|
||||
export class PollConfig {
|
||||
constructor(
|
||||
public allowSeveralHours = true,
|
||||
public isVisibleToAnyoneWithTheLink: boolean = true,
|
||||
public answerType: AnswerGranularity = AnswerGranularity.BASIC,
|
||||
public creationDate: Date = new Date(),
|
||||
public expirationDate?: Date,
|
||||
public canVotersModifyTheirAnswers = true,
|
||||
public isProtectedByPassword: boolean = false
|
||||
) {}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import { isValid } from 'date-fns';
|
||||
|
||||
export class PollOption {
|
||||
constructor(public label: string, public url?: string, public subOptions?: PollOption[]) {}
|
||||
|
||||
public isDatePoll(): boolean {
|
||||
return isValid(this.label);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import { PollType } from '../enums/poll-type.enum';
|
||||
import { Answer } from './answer.model';
|
||||
import { PollConfig } from './poll-config.model';
|
||||
import { PollOption } from './poll-options.model';
|
||||
import { User } from './user.model';
|
||||
|
||||
export class Poll {
|
||||
constructor(
|
||||
public id: string,
|
||||
public slug: string,
|
||||
public type: PollType,
|
||||
public title: string,
|
||||
public description: string,
|
||||
public owner: User,
|
||||
public config: PollConfig,
|
||||
public options: PollOption[] = [],
|
||||
public answers: Answer[] = []
|
||||
) {}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
import { Theme } from '../enums/theme.enum';
|
||||
|
||||
export class UIConfig {
|
||||
constructor(public isMenuVisible = true, public theme: Theme.LIGHT) {}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
import { Poll } from './poll.model';
|
||||
|
||||
export class User {
|
||||
constructor(
|
||||
public isOwner: boolean = false,
|
||||
public pseudo?: string,
|
||||
public email?: string,
|
||||
public polls?: Poll[]
|
||||
) {}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ApiService } from './api.service';
|
||||
|
||||
describe('ApiService', () => {
|
||||
let service: ApiService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(ApiService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,195 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
import { Poll } from '../models/poll.model';
|
||||
import { User } from '../models/user.model';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ApiService {
|
||||
////////////
|
||||
// CREATE //
|
||||
////////////
|
||||
public async savePoll(poll: Poll): Promise<void> {
|
||||
try {
|
||||
await axios.post(`${environment.api.baseHref}${environment.api.endpoints.poll.name}`, {
|
||||
params: { config: poll.config },
|
||||
});
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async saveVote(poll: Poll): Promise<void> {
|
||||
try {
|
||||
// TODO: add the votestack in the params
|
||||
await axios.post(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.name}/${poll.id}${environment.api.endpoints.poll.vote.name}`,
|
||||
{ params: { voteStack: {} } }
|
||||
);
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async saveComment(poll: Poll, comment: string): Promise<void> {
|
||||
try {
|
||||
// TODO: add the comment in the params
|
||||
await axios.post(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.name}/${poll.id}${environment.api.endpoints.poll.comment.name}`,
|
||||
{ params: { comment } }
|
||||
);
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
//////////
|
||||
// READ //
|
||||
//////////
|
||||
public async isSlugAvailable(slug: string): Promise<boolean> {
|
||||
try {
|
||||
// TODO: scenario should be : if we can get this slug, it exists. if not, it doesn't. It's just a GET.
|
||||
const response: AxiosResponse = await axios.get(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.slug.name}/${slug}`
|
||||
);
|
||||
return response && response.status === 404 ? true : false;
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async sendEmailToUserOfItsPollsList(email: string): Promise<Poll[]> {
|
||||
// If user is not authenticated: the list of polls is send to user's email by the backend.
|
||||
try {
|
||||
const response: AxiosResponse<Poll[]> = await axios.get<Poll[]>(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.user.polls.sendEmail.name}/${email}`
|
||||
);
|
||||
return response ? response.data : [];
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async getPollsByUserEmail(user: User): Promise<Poll[]> {
|
||||
// If user is authenticated : retrieve polls & display directly in frontend.
|
||||
// TODO: Backend should handle this case. Actually the endpoint doesn't exist in backend.
|
||||
try {
|
||||
const response: AxiosResponse<Poll[]> = await axios.get<Poll[]>(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.user.polls.name}/${user.email}`
|
||||
);
|
||||
return response ? response.data : [];
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async getPollsByUrl(url: string): Promise<Poll[]> {
|
||||
try {
|
||||
const response: AxiosResponse<Poll[]> = await axios.get<Poll[]>(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.name}/${url}`
|
||||
);
|
||||
return response ? response.data : [];
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async getPollById(id: string, password?: string): Promise<Poll[]> {
|
||||
try {
|
||||
const response: AxiosResponse<Poll[]> = await axios.get<Poll[]>(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.name}/${id}`,
|
||||
password ? { params: { password } } : {}
|
||||
);
|
||||
return response ? response.data : [];
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
////////////
|
||||
// UPDATE //
|
||||
////////////
|
||||
public async updatePoll(poll: Poll): Promise<void> {
|
||||
try {
|
||||
// TODO: implement the params when entities are finalized.
|
||||
await axios.put(`${environment.api.baseHref}${environment.api.endpoints.poll.name}/${poll.id}`, {
|
||||
params: { voteStack: {}, token: '' },
|
||||
});
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async updateVote(voteStack: any): Promise<void> {
|
||||
try {
|
||||
// TODO: implement the params when entities are finalized.
|
||||
await axios.patch(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.vote.name}/${voteStack.id}`,
|
||||
{
|
||||
params: { voteStack: {}, token: '' },
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
////////////
|
||||
// DELETE //
|
||||
////////////
|
||||
|
||||
public async deletePoll(poll: Poll): Promise<void> {
|
||||
try {
|
||||
await axios.delete(`${environment.api.baseHref}${environment.api.endpoints.poll.name}${poll.id}`, {});
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async deletePollVotes(poll: Poll): Promise<void> {
|
||||
try {
|
||||
// TODO: update endpoint in Backend
|
||||
await axios.delete(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.name}${poll.id}${environment.api.endpoints.poll.vote.name}`
|
||||
);
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||
}
|
||||
}
|
||||
|
||||
public async deletePollComments(poll: Poll): Promise<void> {
|
||||
try {
|
||||
// TODO: modify endpoint in Backend
|
||||
await axios.delete(
|
||||
`${environment.api.baseHref}${environment.api.endpoints.poll.name}${poll.id}${environment.api.endpoints.poll.comment.name}`
|
||||
);
|
||||
} catch (error) {
|
||||
this.handleError(error);
|
||||