Browse Source

🎨 add font awesome

develop
Baptiste Lemoine 3 years ago
parent
commit
4296c5c9f9
  1. 1
      angular.json
  2. 1
      package.json
  3. 3
      src/app/config/PollConfig.ts
  4. 147
      src/app/services/config.service.ts
  5. 5
      yarn.lock

1
angular.json

@ -29,6 +29,7 @@
],
"styles": [
"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/primeng.min.css",
"src/styles.scss"

1
package.json

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

3
src/app/config/PollConfig.ts

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

147
src/app/services/config.service.ts

@ -1,6 +1,6 @@
import {Injectable} from '@angular/core';
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 {MessageService} from 'primeng/api';
@ -17,7 +17,7 @@ export class ConfigService extends PollConfig {
myPolls: any;// list of retrieved polls from the backend api
constructor(public http: HttpClient,
constructor(private http: HttpClient,
private messageService: MessageService) {
super();
}
@ -26,6 +26,10 @@ export class ConfigService extends PollConfig {
this[key] = val;
}
clear() {
this.messageService.clear();
}
/** ==================================
*
* poll public calls to get non authenticated info
@ -64,6 +68,24 @@ export class ConfigService extends PollConfig {
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
* @param email
@ -76,27 +98,28 @@ export class ConfigService extends PollConfig {
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.http.get(`${this.baseHref}/my-polls`,
requestOptions,
this.makeHeaders({email: this.myEmail}),
)
.subscribe(res => {
// message: 'Trouvé! Allez voir votre boite email',
this.myPolls = res;
console.log('res', res)
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) {
// TODO handle a toast message
console.error('err', err)
console.error('err', err);
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
*/
getPollByURL(url: string) {
this.http.get(`${this.baseHref}/poll/${url}`).subscribe(
this.http.get(`${this.baseHref}/poll/${url}`, this.makeHeaders()).subscribe(
(res: any) => {
this.myPolls = res.data;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -140,11 +165,13 @@ export class ConfigService extends PollConfig {
this.http
.get(`${this.baseHref}/poll/${id}`,
{params: new HttpParams().set('body', password)})
this.makeHeaders({body: password}))
.subscribe(
(res: any) => {
this.myPolls = res.data;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -156,17 +183,14 @@ export class ConfigService extends PollConfig {
getMyPolls(ownerEmail: string) {
this.http
.get(`${this.baseHref}/my-polls`,
{
headers: new HttpHeaders()
.append('Content-Type', 'application/json')
.append('Charset', 'UTF-8')
,
params: new HttpParams().set('ownerEmail', ownerEmail)
})
this.makeHeaders({ownerEmail: ownerEmail})
)
.subscribe(
(res: any) => {
this.myPolls = res.data;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -177,7 +201,7 @@ export class ConfigService extends PollConfig {
createPoll() {
console.log('sends the form');
// 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) => {
console.log('res', res);
this.createPollFromConfig(this.getPollConfig())
@ -194,13 +218,15 @@ export class ConfigService extends PollConfig {
* @param config
*/
createPollFromConfig(config: any) {
this.http.post(`${this.baseHref}/poll`, config)
this.http.post(`${this.baseHref}/poll`, this.makeHeaders({config: config}))
.subscribe((res: any) => {
// redirect to the page to administrate the new poll
alert("succès!");
this.messageService.add({severity: 'success', summary: 'Sondage Créé',});
this.selectedPoll = res;
this.pollId = res.pollId;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -210,12 +236,20 @@ export class ConfigService extends PollConfig {
* @param voteStack
*/
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) => {
alert("succès!");
this.messageService.add({
severity: 'success',
summary: 'Sondage mis à jour',
});
this.myPolls = res;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -225,12 +259,18 @@ export class ConfigService extends PollConfig {
* @param voteStack
*/
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) => {
this.messageService.add({severity: 'success', summary: 'Vote ajouté'});
alert("succès!");
this.myPolls = res;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -240,12 +280,16 @@ export class ConfigService extends PollConfig {
* @param voteStack
*/
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) => {
alert("succès!");
this.messageService.add({severity: 'success', summary: 'Vote mis à jour'});
this.myPolls = res;
}, this.handleError
}, (e) => {
this.handleError(e)
}
);
}
@ -255,10 +299,19 @@ export class ConfigService extends PollConfig {
* @param comment
*/
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) => {
alert("succès!");
}, this.handleError
this.messageService.add({
severity: 'success',
summary: 'Commentaire Créé',
detail: 'Via MessageService'
});
}, (e) => {
this.handleError(e)
}
);
}

5
yarn.lock

@ -2728,6 +2728,11 @@ follow-redirects@^1.0.0:
dependencies:
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:
version "0.1.8"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-0.1.8.tgz#d8773908e31256109952b1fdb9b3fa867d2775e1"

Loading…
Cancel
Save