add api version config in env

This commit is contained in:
tykayn 2020-11-09 12:44:24 +01:00
parent 1745762ba3
commit 1167b692ea
8 changed files with 59 additions and 25 deletions

View File

@ -6,7 +6,7 @@
<span class="app-title title is-2"> <span class="app-title title is-2">
{{ appTitle }} {{ appTitle }}
</span> </span>
<span class="dev-env button bg-success" *ngIf="!env.production"> <span class="dev-env button has-background-success" *ngIf="!env.production">
<i> <i>
(dev) (dev)
</i> </i>
@ -19,7 +19,7 @@
aria-label="menu" aria-label="menu"
aria-expanded="false" aria-expanded="false"
data-target="navbarBasicExample" data-target="navbarBasicExample"
[ngClass]="{ 'bg-primary': mobileMenuVisible }" [ngClass]="{ 'has-background-primary': mobileMenuVisible }"
(click)="mobileMenuVisible = !mobileMenuVisible" (click)="mobileMenuVisible = !mobileMenuVisible"
> >
<span aria-hidden="true"></span> <span aria-hidden="true"></span>

View File

@ -6,22 +6,28 @@ import { Answer } from '../enums/answer.enum';
import { Poll } from '../models/poll.model'; import { Poll } from '../models/poll.model';
import { HttpHeaders } from '@angular/common/http'; import { HttpHeaders } from '@angular/common/http';
const apiVersion = environment.api.versionToUse;
const currentApiRoutes = environment.api.version[apiVersion];
const apiBaseHref = environment.api.version[apiVersion].baseHref;
const apiEndpoints = environment.api.endpoints;
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ApiService { export class ApiService {
private axiosInstance: AxiosInstance; private axiosInstance: AxiosInstance;
private readonly pollsEndpoint = environment.api.endpoints.polls.name; private readonly pollsEndpoint = apiEndpoints.polls.name;
private readonly answersEndpoint = environment.api.endpoints.polls.answers.name; private readonly answersEndpoint = apiEndpoints.polls.answers.name;
private readonly commentsEndpoint = environment.api.endpoints.polls.comments.name; private readonly commentsEndpoint = apiEndpoints.polls.comments.name;
private readonly slugsEndpoint = environment.api.endpoints.polls.slugs.name; private readonly slugsEndpoint = apiEndpoints.polls.slugs.name;
private readonly usersEndpoint = environment.api.endpoints.users.name; private readonly usersEndpoint = apiEndpoints.users.name;
private readonly usersPollsEndpoint = environment.api.endpoints.users.polls.name; private readonly usersPollsEndpoint = apiEndpoints.users.polls.name;
private readonly usersPollsSendEmailEndpoint = environment.api.endpoints.users.polls.sendEmail.name; private readonly usersPollsSendEmailEndpoint = apiEndpoints.users.polls.sendEmail.name;
constructor() { constructor() {
this.axiosInstance = axios.create({ baseURL: environment.api.baseHref }); this.axiosInstance = axios.create({ baseURL: apiBaseHref });
this.axiosInstance.defaults.timeout = 2500; this.axiosInstance.defaults.timeout = 2500;
this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json'; this.axiosInstance.defaults.headers.post['Content-Type'] = 'application/json';
} }
@ -31,7 +37,8 @@ export class ApiService {
////////////////////// //////////////////////
public async createPoll(poll: Poll): Promise<string> { public async createPoll(poll: Poll): Promise<string> {
try { try {
return await this.axiosInstance.post(`${this.pollsEndpoint}`, poll); console.log('currentApiRoutes', currentApiRoutes);
return await this.axiosInstance.post(`${apiBaseHref}${currentApiRoutes['api_new_poll']}`, poll);
} catch (error) { } catch (error) {
ApiService.handleError(error); ApiService.handleError(error);
} }

View File

@ -99,6 +99,7 @@ export class PollService implements Resolve<Poll> {
const pollUrl: string = await this.apiService.createPoll(this._poll.getValue()); const pollUrl: string = await this.apiService.createPoll(this._poll.getValue());
// TODO: Maybe handle the url to update currentPoll according to backend response // TODO: Maybe handle the url to update currentPoll according to backend response
if (pollUrl) { if (pollUrl) {
console.log('pollUrl', pollUrl);
this.toastService.display('Le sondage a été enregistré.'); this.toastService.display('Le sondage a été enregistré.');
} else { } else {
this.toastService.display('Le sondage na été correctement enregistré, veuillez ré-essayer.'); this.toastService.display('Le sondage na été correctement enregistré, veuillez ré-essayer.');

View File

@ -20,8 +20,13 @@
<div class="well"> <div class="well">
{{ poll.slug }} {{ poll.slug }}
</div> </div>
<div class="bg-danger" *ngIf="!form.valid"> <div class="has-background-danger" *ngIf="!form.valid">
le formulaire est invalide le formulaire est invalide
<pre>
{{ form.errors | json }}
</pre
>
</div> </div>
<div class="dates-list"> <div class="dates-list">
<div class="title"> <div class="title">

View File

@ -75,4 +75,12 @@
.example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) { .example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) {
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
} }
.ng-touched.ng-invalid {
border-left: $danger 3px solid;
padding-left: 1em;
}
.ng-touched.ng-valid {
border-left: $success 3px solid;
padding-left: 1em;
}
} }

View File

@ -54,14 +54,15 @@ export class FormComponent implements OnInit {
public createPoll(): void { public createPoll(): void {
console.log('this.form', this.form); console.log('this.form', this.form);
if (this.form.valid && this.form.valid) { this.apiService.createPoll(this.pollService.newPollFromForm(this.form));
console.log('Le sondage est correctement rempli, prêt à enregistrer.'); // if (this.form.valid) {
const newpoll = this.pollService.newPollFromForm(this.form); // console.log('Le sondage est correctement rempli, prêt à enregistrer.');
// TODO : save the poll // const newpoll = this.pollService.newPollFromForm(this.form);
this.apiService.createPoll(newpoll); // // TODO : save the poll
} else { // this.apiService.createPoll(newpoll);
this.toastService.display('invalid form'); // } else {
} // this.toastService.display('invalid form');
// }
} }
public updateSlug(): void { public updateSlug(): void {
@ -78,6 +79,7 @@ export class FormComponent implements OnInit {
if (optionalLabel) { if (optionalLabel) {
newControlGroup.patchValue({ newControlGroup.patchValue({
label: optionalLabel, label: optionalLabel,
imageUrl: 'mon url',
}); });
} }
this.choices.push(newControlGroup); this.choices.push(newControlGroup);
@ -164,7 +166,7 @@ export class FormComponent implements OnInit {
description: 'répondez SVP <3 ! *-* ', description: 'répondez SVP <3 ! *-* ',
slug: this.uuidService.getUUID(), slug: this.uuidService.getUUID(),
creatorPseudo: 'Chuck Norris', creatorPseudo: 'Chuck Norris',
creatorEmail: '', creatorEmail: 'chucknorris@example.com',
isAboutDate: true, isAboutDate: true,
whoModifiesAnswers: 'everybody', whoModifiesAnswers: 'everybody',
whoCanChangeAnswers: 'everybody', whoCanChangeAnswers: 'everybody',
@ -188,7 +190,6 @@ export class FormComponent implements OnInit {
this.dateUtilities.parseInputDateToDateObject(this.startDateInterval), this.dateUtilities.parseInputDateToDateObject(this.startDateInterval),
this.dateUtilities.parseInputDateToDateObject(this.endDateInterval) this.dateUtilities.parseInputDateToDateObject(this.endDateInterval)
); );
this.toastService.display('intervalle de ' + this.intervalDays + ' jours');
this.cd.detectChanges(); this.cd.detectChanges();
} }

View File

@ -6,6 +6,13 @@ const backendApiUrlsInDev = {
local: '/api/v1', local: '/api/v1',
remote: 'https://framadate-api.cipherbliss.com/api/v1', remote: 'https://framadate-api.cipherbliss.com/api/v1',
}; };
const apiV1 = {
baseHref: 'https://framadate-api.cipherbliss.com/api/v1',
api_new_poll: '/poll/new',
api_get_poll: '/poll/{id}',
'api_test-mail-poll': '/api/v1/poll/mail/test-mail-poll/{emailChoice}',
'app.swagger': '/api/doc.json',
};
export const environment = { export const environment = {
production: false, production: false,
@ -13,10 +20,14 @@ export const environment = {
appVersion: '2.0.0', appVersion: '2.0.0',
appLogo: 'assets/img/logo.png', appLogo: 'assets/img/logo.png',
api: { api: {
versionToUse: 'apiV1',
version: {
apiV1,
},
baseHref: backendApiUrlsInDev.local, baseHref: backendApiUrlsInDev.local,
endpoints: { endpoints: {
polls: { polls: {
name: '/polls', name: '/poll',
choices: { choices: {
name: '/choices', name: '/choices',
}, },

View File

@ -1,7 +1,7 @@
@charset "UTF-8"; @charset "UTF-8";
// colors from styleguide https://app.zeplin.io/project/5d4d83d68866d6522ff2ff10/styleguide/colors?cid=5d502bb032e23e3516af8154 // colors from styleguide https://app.zeplin.io/project/5d4d83d68866d6522ff2ff10/styleguide/colors?cid=5d502bb032e23e3516af8154
$camo: #839546; $green: #64d16e;
$black: #000000; $black: #000000;
$ugly-purple: #b24eb7; $ugly-purple: #b24eb7;
$lavender-pink: #e9bdeb; $lavender-pink: #e9bdeb;
@ -27,7 +27,7 @@ $primary: $ugly-purple;
$secondary_color: $lavender-pink; $secondary_color: $lavender-pink;
$font_color: $black; $font_color: $black;
$logo_color: $dark-lavender; $logo_color: $dark-lavender;
$logo_color_2: $camo; $logo_color_2: $green;
$legend_color: $dark-lavender; $legend_color: $dark-lavender;
$legend_color_2: $dusty-orange; $legend_color_2: $dusty-orange;
$choice_select_border_color: $cool-grey; $choice_select_border_color: $cool-grey;
@ -38,6 +38,7 @@ $clicked-color: $wisteria;
$mini-button-color: $pale-purple; $mini-button-color: $pale-purple;
$warning: $dusty-orange; $warning: $dusty-orange;
$danger: $red; $danger: $red;
$success: $green;
// FONT // FONT
$default_font: 'pt_sans'; $default_font: 'pt_sans';