auto save on dev env

This commit is contained in:
Tykayn 2021-04-30 11:27:54 +02:00 committed by tykayn
parent 585d3a215e
commit 12a41b5022
12 changed files with 72 additions and 68 deletions

View File

@ -50,7 +50,7 @@ export class PollConfig {
expirationDate = ''; // expiracy date
voteStackId = null; // id of the vote stack to update
pollId = null; // id of the current poll when created. data given by the backend api
pollSlug = null; // id of the current poll when created. data given by the backend api
custom_url = null; // id of the current poll when created. data given by the backend api
currentPoll; // current poll selected with createPoll or getPoll of ConfigService
passwordAccess = 0;
password = '';

View File

@ -20,6 +20,7 @@ import { mockMyPolls } from '../mocks/mockmypolls';
export class ConfigService extends PollConfig {
loading = false;
apiBaseHref: any = environment.api.baseHref;
pollSlug: string;
constructor(
private http: HttpClient,

View File

@ -143,15 +143,21 @@ export class PollService implements Resolve<Poll> {
return str + '-' + this.uuidService.getUUID();
}
public async saveCurrentPoll(): Promise<void> {
const pollUrl: Subscription = await this.apiService.createPoll(this._poll.getValue());
// TODO: Maybe handle the url to update currentPoll according to backend response
if (pollUrl) {
console.log('pollUrl', pollUrl);
this.toastService.display('Le sondage a été enregistré.');
} else {
this.toastService.display('Le sondage na été correctement enregistré, veuillez ré-essayer.');
}
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 {

View File

@ -31,14 +31,14 @@
<span
>{{ urlPrefix }}
<strong>
{{ form.controls.slug.value }}
{{ form.controls.custom_url.value }}
</strong>
</span>
<app-copy-text [textToCopy]="form.controls.slug.value"></app-copy-text>
<app-copy-text [textToCopy]="form.controls.custom_url.value"></app-copy-text>
<button
mat-button
*ngIf="form.controls.slug.value"
*ngIf="form.controls.custom_url.value"
matSuffix
mat-icon-button
aria-label="Clear"

View File

@ -92,10 +92,7 @@
Tout réinitialiser
</button>
<br />
<button class="btn is-success" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
<br />
<button class="btn is-default" (click)="automaticSlug()">
<i class="fa fa-refresh"></i>

View File

@ -34,47 +34,18 @@ export class BaseConfigComponent {
) {}
askInitFormDefault(): void {
// this.initFormDefault(false);
this.toastService.display('formulaire réinitialisé');
}
public createPoll(): void {
console.log('this.form', this.form);
const newpoll = this.pollService.newPollFromForm(this.form);
console.log('newpoll', newpoll);
const router = this.router;
if (!environment.production) {
this.toastService.display('mode dev : envoi du form sans validation');
this.apiService.createPoll(newpoll).then((resp) => {
console.log('resp', resp);
router.navigate(['success']);
});
} else {
if (this.form.valid) {
console.log('Le sondage est correctement rempli, prêt à enregistrer.');
const newpoll = this.pollService.newPollFromForm(this.form);
this.apiService.createPoll(newpoll).then((resp) => {
console.log('resp', resp);
router.navigate(['success']);
this.toastService.display('sauvegarde du nouveau sondage réussie');
});
} else {
this.toastService.display('invalid form');
}
}
this.toastService.display('formulaire réinitialisé', 'info');
}
public updateSlug(): void {
const newValueFormatted = this.pollService.makecustom_url(this.poll);
this.form.patchValue({ slug: newValueFormatted });
this.form.patchValue({ custom_url: newValueFormatted });
}
/**
* set the poll custom_url from other data of the poll
*/
automaticSlug() {
this.form.patchValue({ slug: this.utilitiesService.makeUuid() });
automaticSlug(): void {
this.form.patchValue({ custom_url: this.utilitiesService.makeUuid() });
}
}

View File

@ -8,8 +8,8 @@
</h1>
</div>
<div class="column">
<button class="btn is-success" (click)="apiService.createPoll(poll)">
<!-- [disabled]="!form.valid || !form.valid"-->
<button class="btn is-success" (click)="createPoll()">
<i class="fa fa-save"></i>
Enregistrer le sondage
</button>
@ -37,11 +37,11 @@
</div>
<app-base-config [form]="form"></app-base-config>
<!-- <app-date-select-->
<!-- *ngIf="form.value.configuration && form.value.kind == 'date'"-->
<!-- [form]="form"-->
<!-- ></app-date-select>-->
<!-- <app-text-select ng-if="!form.value.isAboutDate" [form]="form"></app-text-select>-->
<app-date-select
*ngIf="form.value.configuration && form.value.kind == 'date'"
[form]="form"
></app-date-select>
<app-text-select *ngIf="!form.value.kind == 'date'" [form]="form"></app-text-select>
<button
class="btn"

View File

@ -36,9 +36,6 @@ export class FormComponent implements OnInit {
ngOnInit(): void {
this.initFormDefault();
const pollsAvailable = this.pollService.getAllAvailablePolls();
console.log('pollsAvailable', pollsAvailable);
}
initFormDefault(showDemoValues = environment.autofill): void {
@ -100,6 +97,10 @@ export class FormComponent implements OnInit {
this.setDemoValues();
this.toastService.display('default values filled for demo');
}
if (environment.autoSendNewPoll) {
this.createPoll();
}
}
/**
@ -148,4 +149,32 @@ export class FormComponent implements OnInit {
goNextStep() {
alert('todo');
}
public createPoll(): void {
console.log('this.form', this.form);
const newpoll = this.pollService.newPollFromForm(this.form);
console.log('newpoll', newpoll);
const router = this.router;
if (!environment.production) {
this.toastService.display('mode dev : envoi du form sans validation');
this.apiService.createPoll(newpoll).then((resp) => {
console.log('resp', resp);
router.navigate(['success']);
});
} else {
if (this.form.valid) {
console.log('Le sondage est correctement rempli, prêt à enregistrer.');
const newpoll = this.pollService.newPollFromForm(this.form);
this.apiService.createPoll(newpoll).then((resp) => {
console.log('resp', resp);
router.navigate(['poll', this.form.value.custom_url, 'consultation']);
this.toastService.display('sauvegarde du nouveau sondage réussie');
});
} else {
this.toastService.display('invalid form');
}
}
}
}

View File

@ -25,7 +25,7 @@ export class StepperComponent implements OnInit {
ngOnInit(): void {
this.pollFormGroup = this.fb.group({
question: [this.poll ? this.poll.title : '', [Validators.required]],
slug: [this.poll ? this.poll.slug : this.uuidService.getUUID(), [Validators.required]],
slug: [this.poll ? this.poll.custom_url : this.uuidService.getUUID(), [Validators.required]],
description: [this.poll ? this.poll.description : ''],
});

View File

@ -64,9 +64,9 @@ export class ConsultationComponent implements OnInit, OnDestroy {
this.passHash = params.get('hash');
if (this.passHash) {
this.pollService.loadPollBySlugWithPasswordHash(this.pollSlug, this.passHash);
this.pollService.loadPollBycustom_urlWithPasswordHash(this.pollSlug, this.passHash);
} else {
this.pollService.loadPollBySlug(this.pollSlug).then((resp) => {
this.pollService.loadPollBycustom_url(this.pollSlug).then((resp) => {
console.log('resp', resp);
this.fetching = false;
});
@ -96,7 +96,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
this.toastService.display('vote ajouté', 'success');
if (resp) {
this.api.getPollBySlug(this.poll.custom_url);
this.api.getPollByCustomUrl(this.poll.custom_url);
} else {
this.toastService.display('erreur à la réception du nouveau vote', 'error');
}

View File

@ -26,8 +26,8 @@
<tr *ngFor="let poll of (_user | async)?.polls">
<th>{{ poll.title }}</th>
<td>
<a routerLink="{{ '../../poll/' + poll.slug + '/consultation' }}">
{{ poll.slug }}
<a routerLink="{{ '../../poll/' + poll.custom_url + '/consultation' }}">
{{ poll.custom_url }}
</a>
</td>
</tr>

View File

@ -3,7 +3,7 @@
// The list of file replacements can be found in `angular.json`.
const backendApiUrlsInDev = {
local: '/api/v1',
local: 'http://localhost:8000/api/v1',
remote: 'http://localhost:8000/api/v1',
// remote: 'https://framadate-api.cipherbliss.com/api/v1',
};