🎨 add font awesome

This commit is contained in:
Baptiste Lemoine 2020-01-15 15:55:15 +01:00
parent ded5e71e73
commit 4296c5c9f9
5 changed files with 109 additions and 48 deletions

View File

@ -29,6 +29,7 @@
], ],
"styles": [ "styles": [
"node_modules/primeicons/primeicons.css", "node_modules/primeicons/primeicons.css",
"node_modules/font-awesome/css/font-awesome.css",
"node_modules/primeng/resources/themes/nova-light/theme.css", "node_modules/primeng/resources/themes/nova-light/theme.css",
"node_modules/primeng/resources/primeng.min.css", "node_modules/primeng/resources/primeng.min.css",
"src/styles.scss" "src/styles.scss"

View File

@ -26,6 +26,7 @@
"@ngx-translate/core": "^11.0.1", "@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0", "@ngx-translate/http-loader": "^4.0.0",
"chart.js": "^2.8.0", "chart.js": "^2.8.0",
"font-awesome": "^4.7.0",
"ngx-markdown": "^8.2.1", "ngx-markdown": "^8.2.1",
"ngx-toaster": "^1.0.1", "ngx-toaster": "^1.0.1",
"primeicons": "^2.0.0", "primeicons": "^2.0.0",

View File

@ -71,5 +71,6 @@ export class PollConfig {
answers: any = defaultAnswers; answers: any = defaultAnswers;
constructor() {
}
} }

View File

@ -1,6 +1,6 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {PollConfig} from '../config/PollConfig'; import {PollConfig} from '../config/PollConfig';
import {HttpClient, HttpHeaders, HttpParams} from "@angular/common/http"; import {HttpClient, HttpHeaders} from "@angular/common/http";
import {environment} from "../../environments/environment"; import {environment} from "../../environments/environment";
import {MessageService} from 'primeng/api'; import {MessageService} from 'primeng/api';
@ -17,7 +17,7 @@ export class ConfigService extends PollConfig {
myPolls: any;// list of retrieved polls from the backend api myPolls: any;// list of retrieved polls from the backend api
constructor(public http: HttpClient, constructor(private http: HttpClient,
private messageService: MessageService) { private messageService: MessageService) {
super(); super();
} }
@ -26,6 +26,10 @@ export class ConfigService extends PollConfig {
this[key] = val; this[key] = val;
} }
clear() {
this.messageService.clear();
}
/** ================================== /** ==================================
* *
* poll public calls to get non authenticated info * poll public calls to get non authenticated info
@ -64,6 +68,24 @@ export class ConfigService extends PollConfig {
return jsonConfig return jsonConfig
} }
makeHeaders(bodyContent?: any) {
const headerDict = {
'Charset': 'UTF-8',
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
'Access-Control-Allow-Origin': '*'
};
const requestOptions = {
headers: new HttpHeaders(headerDict),
body: bodyContent
};
return requestOptions;
}
/** /**
* search in localstorage, fallback asking the backend to send an email to the owner if it exists * search in localstorage, fallback asking the backend to send an email to the owner if it exists
* @param email * @param email
@ -76,27 +98,28 @@ export class ConfigService extends PollConfig {
this.myEmail = email; this.myEmail = email;
const headerDict = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
'Access-Control-Allow-Origin': environment.baseApiHref
};
const requestOptions = {
headers: new HttpHeaders(headerDict),
email: this.myEmail
};
this.loading = true; this.loading = true;
this.http.get(`${this.baseHref}/my-polls`, this.http.get(`${this.baseHref}/my-polls`,
requestOptions, this.makeHeaders({email: this.myEmail}),
) )
.subscribe(res => { .subscribe(res => {
// message: 'Trouvé! Allez voir votre boite email', // message: 'Trouvé! Allez voir votre boite email',
this.myPolls = res; this.myPolls = res;
console.log('res', res)
this.loading = false; this.loading = false;
}, this.handleError this.messageService.add({
severity: 'success',
summary: 'Service Message',
detail: 'Via MessageService'
});
}, (e) => {
this.messageService.add(
{
severity: 'warning',
summary: "Erreur lors de l'appel "
});
}
) )
} }
@ -107,9 +130,9 @@ export class ConfigService extends PollConfig {
*/ */
handleError(err: any) { handleError(err: any) {
// TODO handle a toast message // TODO handle a toast message
console.error('err', err) console.error('err', err);
this.loading = false; this.loading = false;
this.messageService.add({severity: 'success', summary: 'Service Message', detail: 'Via MessageService'}); this.messageService.add({severity: 'warning', summary: "Erreur lors de l'appel "});
} }
@ -120,14 +143,16 @@ export class ConfigService extends PollConfig {
/** /**
* * get one poll by its slug name
* @param url * @param url
*/ */
getPollByURL(url: string) { getPollByURL(url: string) {
this.http.get(`${this.baseHref}/poll/${url}`).subscribe( this.http.get(`${this.baseHref}/poll/${url}`, this.makeHeaders()).subscribe(
(res: any) => { (res: any) => {
this.myPolls = res.data; this.myPolls = res.data;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -140,11 +165,13 @@ export class ConfigService extends PollConfig {
this.http this.http
.get(`${this.baseHref}/poll/${id}`, .get(`${this.baseHref}/poll/${id}`,
{params: new HttpParams().set('body', password)}) this.makeHeaders({body: password}))
.subscribe( .subscribe(
(res: any) => { (res: any) => {
this.myPolls = res.data; this.myPolls = res.data;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -156,17 +183,14 @@ export class ConfigService extends PollConfig {
getMyPolls(ownerEmail: string) { getMyPolls(ownerEmail: string) {
this.http this.http
.get(`${this.baseHref}/my-polls`, .get(`${this.baseHref}/my-polls`,
{ this.makeHeaders({ownerEmail: ownerEmail})
headers: new HttpHeaders() )
.append('Content-Type', 'application/json')
.append('Charset', 'UTF-8')
,
params: new HttpParams().set('ownerEmail', ownerEmail)
})
.subscribe( .subscribe(
(res: any) => { (res: any) => {
this.myPolls = res.data; this.myPolls = res.data;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -177,7 +201,7 @@ export class ConfigService extends PollConfig {
createPoll() { createPoll() {
console.log('sends the form'); console.log('sends the form');
// alert('envoi de formulaire pour création de sondage en XHR à faire'); // alert('envoi de formulaire pour création de sondage en XHR à faire');
this.http.get(`${this.baseHref}/`) this.http.get(`${this.baseHref}/`, this.makeHeaders())
.subscribe((res) => { .subscribe((res) => {
console.log('res', res); console.log('res', res);
this.createPollFromConfig(this.getPollConfig()) this.createPollFromConfig(this.getPollConfig())
@ -194,13 +218,15 @@ export class ConfigService extends PollConfig {
* @param config * @param config
*/ */
createPollFromConfig(config: any) { createPollFromConfig(config: any) {
this.http.post(`${this.baseHref}/poll`, config) this.http.post(`${this.baseHref}/poll`, this.makeHeaders({config: config}))
.subscribe((res: any) => { .subscribe((res: any) => {
// redirect to the page to administrate the new poll // redirect to the page to administrate the new poll
alert("succès!"); this.messageService.add({severity: 'success', summary: 'Sondage Créé',});
this.selectedPoll = res; this.selectedPoll = res;
this.pollId = res.pollId; this.pollId = res.pollId;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -210,12 +236,20 @@ export class ConfigService extends PollConfig {
* @param voteStack * @param voteStack
*/ */
updatePoll(voteStack: any) { updatePoll(voteStack: any) {
this.http.put(`${this.baseHref}/poll/${this.pollId}`, voteStack) this.http.put(
`${this.baseHref}/poll/${this.pollId}`,
voteStack,
this.makeHeaders()
)
.subscribe((res: any) => { .subscribe((res: any) => {
this.messageService.add({
alert("succès!"); severity: 'success',
summary: 'Sondage mis à jour',
});
this.myPolls = res; this.myPolls = res;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -225,12 +259,18 @@ export class ConfigService extends PollConfig {
* @param voteStack * @param voteStack
*/ */
addVote(voteStack: any) { addVote(voteStack: any) {
this.http.post(`${this.baseHref}/poll/${this.pollId}/vote`, voteStack) this.http.post(
`${this.baseHref}/poll/${this.pollId}/vote`,
voteStack,
this.makeHeaders())
.subscribe((res: any) => { .subscribe((res: any) => {
this.messageService.add({severity: 'success', summary: 'Vote ajouté'});
alert("succès!"); alert("succès!");
this.myPolls = res; this.myPolls = res;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -240,12 +280,16 @@ export class ConfigService extends PollConfig {
* @param voteStack * @param voteStack
*/ */
updateVote(voteStack: any) { updateVote(voteStack: any) {
this.http.put(`${this.baseHref}/poll/${this.pollId}/vote`, voteStack) this.http.put(
`${this.baseHref}/poll/${this.pollId}/vote`,
voteStack,
this.makeHeaders())
.subscribe((res: any) => { .subscribe((res: any) => {
this.messageService.add({severity: 'success', summary: 'Vote mis à jour'});
alert("succès!");
this.myPolls = res; this.myPolls = res;
}, this.handleError }, (e) => {
this.handleError(e)
}
); );
} }
@ -255,10 +299,19 @@ export class ConfigService extends PollConfig {
* @param comment * @param comment
*/ */
addComment(comment: any) { addComment(comment: any) {
this.http.post(`${this.baseHref}/poll/${this.pollId}/comment`, comment) this.http.post(
`${this.baseHref}/poll/${this.pollId}/comment`,
comment,
this.makeHeaders())
.subscribe((res: any) => { .subscribe((res: any) => {
alert("succès!"); this.messageService.add({
}, this.handleError severity: 'success',
summary: 'Commentaire Créé',
detail: 'Via MessageService'
});
}, (e) => {
this.handleError(e)
}
); );
} }

View File

@ -2728,6 +2728,11 @@ follow-redirects@^1.0.0:
dependencies: dependencies:
debug "^3.0.0" debug "^3.0.0"
font-awesome@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/font-awesome/-/font-awesome-4.7.0.tgz#8fa8cf0411a1a31afd07b06d2902bb9fc815a133"
integrity sha1-j6jPBBGhoxr9B7BtKQK7n8gVoTM=
for-in@^0.1.3: for-in@^0.1.3:
version "0.1.8" version "0.1.8"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1" resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"