|
|
|
@ -30,6 +30,48 @@ export class ConfigService extends PollConfig {
|
|
|
|
|
this.messageService.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* generate unique id to have a default url for future poll
|
|
|
|
|
*/
|
|
|
|
|
makeUuid() {
|
|
|
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
|
|
|
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
|
|
|
|
return v.toString(16);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
makeSlug(str?: string) {
|
|
|
|
|
if (!str) {
|
|
|
|
|
str = this.creationDate.getFullYear() + '_' + (this.creationDate.getMonth() + 1) + '_' + this.creationDate.getDate() + '_' + this.myName + '_' + this.title;
|
|
|
|
|
}
|
|
|
|
|
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
|
|
|
|
str = str.toLowerCase();
|
|
|
|
|
|
|
|
|
|
// remove accents, swap ñ for n, etc
|
|
|
|
|
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
|
|
|
|
|
var to = "aaaaeeeeiiiioooouuuunc------";
|
|
|
|
|
for (var i = 0, l = from.length; i < l; i++) {
|
|
|
|
|
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
|
|
|
|
|
.replace(/\s+/g, '-') // collapse whitespace and replace by -
|
|
|
|
|
.replace(/-+/g, '-'); // collapse dashes
|
|
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* add some days to a date, to compute intervals
|
|
|
|
|
* @param days
|
|
|
|
|
* @param date
|
|
|
|
|
*/
|
|
|
|
|
addDaysToDate(days: number, date: Date) {
|
|
|
|
|
date = new Date(date.valueOf());
|
|
|
|
|
date.setDate(date.getDate() + days);
|
|
|
|
|
return date;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/** ==================================
|
|
|
|
|
*
|
|
|
|
|
* poll public calls to get non authenticated info
|
|
|
|
@ -86,6 +128,22 @@ export class ConfigService extends PollConfig {
|
|
|
|
|
return requestOptions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
checkIfSlugIsUniqueInDatabase(slug: string) {
|
|
|
|
|
this.customUrlIsUnique = null;
|
|
|
|
|
|
|
|
|
|
this.loading = true;
|
|
|
|
|
this.http.get(`${this.baseHref}/check-slug-is-uniq`,
|
|
|
|
|
this.makeHeaders({slug: this.customUrl}),
|
|
|
|
|
)
|
|
|
|
|
.subscribe((res: any) => {
|
|
|
|
|
|
|
|
|
|
this.customUrlIsUnique = res.data.isUnique;
|
|
|
|
|
this.loading = false;
|
|
|
|
|
},
|
|
|
|
|
(e) => this.handleError(e))
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* search in localstorage, fallback asking the backend to send an email to the owner if it exists
|
|
|
|
|
* @param email
|
|
|
|
@ -105,9 +163,9 @@ export class ConfigService extends PollConfig {
|
|
|
|
|
)
|
|
|
|
|
.subscribe(res => {
|
|
|
|
|
// message: 'Trouvé! Allez voir votre boite email',
|
|
|
|
|
this.myPolls = res;
|
|
|
|
|
console.log('res', res)
|
|
|
|
|
this.loading = false;
|
|
|
|
|
this.myPolls = res;
|
|
|
|
|
console.log('res', res);
|
|
|
|
|
this.loading = false;
|
|
|
|
|
this.messageService.add({
|
|
|
|
|
severity: 'success',
|
|
|
|
|
summary: 'Service Message',
|
|
|
|
|