update custom_url with title

This commit is contained in:
Tykayn 2021-05-03 14:54:32 +02:00 committed by tykayn
parent 1755f205ad
commit f1e5903d0a
6 changed files with 24 additions and 29 deletions

View File

@ -24,7 +24,7 @@ export class Poll {
public expiracy_date?: string; public expiracy_date?: string;
public creation_date?: string; public creation_date?: string = new Date().toISOString();
public creatorPseudo?: string; public creatorPseudo?: string;

View File

@ -137,6 +137,11 @@ export class PollService implements Resolve<Poll> {
poll.owner.pseudo + poll.owner.pseudo +
'_' + '_' +
poll.title; poll.title;
return this.convertTextToSlug(str) + '-' + this.uuidService.getUUID();
}
public convertTextToSlug(str: string) {
str = str.replace(/^\s+|\s+$/g, ''); // trim str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase(); str = str.toLowerCase();
@ -151,25 +156,7 @@ export class PollService implements Resolve<Poll> {
.replace(/[^a-z0-9 -]/g, '') // remove invalid chars .replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by - .replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes .replace(/-+/g, '-'); // collapse dashes
return str;
return str + '-' + this.uuidService.getUUID();
}
public async saveCurrentPoll(): Promise<Subscription> {
// .then((resp) => {
// console.log('resp', resp);
// if (pollUrl) {
// console.log('pollUrl', pollUrl);
// this.toastService.display('Le sondage a été enregistré.');
// // TODO: redirect to view
// } else {
// this.toastService.display('Le sondage na été correctement enregistré, veuillez ré-essayer.');
// }
// })
// .catch((err) => {
// console.error('err', err);
// });
return await this.apiService.createPoll(this._poll.getValue());
} }
public saveParticipation(choice: Choice, user: Owner, response: Answer): void { public saveParticipation(choice: Choice, user: Owner, response: Answer): void {

View File

@ -14,20 +14,18 @@
<!-- >--> <!-- >-->
<input <input
class="input is-block is-fullwidth" class="input"
[placeholder]="'creation.choose_title_placeholder' | translate" [placeholder]="'creation.choose_title_placeholder' | translate"
formControlName="title" formControlName="title"
id="title" id="title"
autofocus="autofocus" autofocus="autofocus"
(change)="updateSlug()" (keyup)="updateSlug()"
required="required" required="required"
#title #title
/> />
<div class="hint" *ngIf="form.controls.title.errors">
<app-erasable-input [inputModel]="form.value.title"></app-erasable-input>
<span class="button is-error" *ngIf="form.controls.title.errors">
Ce champ est requis Ce champ est requis
</span> </div>
<button <button
mat-button mat-button
*ngIf="form.value.title" *ngIf="form.value.title"

View File

@ -38,7 +38,7 @@ export class BaseConfigComponent {
} }
public updateSlug(): void { public updateSlug(): void {
const newValueFormatted = this.pollService.makecustom_url(this.poll); const newValueFormatted = this.pollService.convertTextToSlug(this.form.value.title);
this.form.patchValue({ custom_url: newValueFormatted }); this.form.patchValue({ custom_url: newValueFormatted });
} }

View File

@ -32,3 +32,7 @@
.padded { .padded {
padding: 1em; padding: 1em;
} }
.marged {
margin: 1em;
}

View File

@ -40,8 +40,6 @@ textarea {
input, input,
select { select {
display: inline-block; display: inline-block;
margin-bottom: 10px;
margin-left: 5px;
} }
.next { .next {
@ -73,3 +71,11 @@ li {
button[type='submit'] { button[type='submit'] {
margin-top: 2em; margin-top: 2em;
} }
.hint {
margin-top: 0;
margin-bottom: 1em;
padding: 1em;
background: $warning;
color: $white;
}