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 expirationDate = ''; // expiracy date
voteStackId = null; // id of the vote stack to update voteStackId = null; // id of the vote stack to update
pollId = null; // id of the current poll when created. data given by the backend api 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 currentPoll; // current poll selected with createPoll or getPoll of ConfigService
passwordAccess = 0; passwordAccess = 0;
password = ''; password = '';

View File

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

View File

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

@ -31,14 +31,14 @@
<span <span
>{{ urlPrefix }} >{{ urlPrefix }}
<strong> <strong>
{{ form.controls.slug.value }} {{ form.controls.custom_url.value }}
</strong> </strong>
</span> </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 <button
mat-button mat-button
*ngIf="form.controls.slug.value" *ngIf="form.controls.custom_url.value"
matSuffix matSuffix
mat-icon-button mat-icon-button
aria-label="Clear" aria-label="Clear"

View File

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

View File

@ -34,47 +34,18 @@ export class BaseConfigComponent {
) {} ) {}
askInitFormDefault(): void { askInitFormDefault(): void {
// this.initFormDefault(false); this.toastService.display('formulaire réinitialisé', 'info');
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');
}
}
} }
public updateSlug(): void { public updateSlug(): void {
const newValueFormatted = this.pollService.makecustom_url(this.poll); 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 * set the poll custom_url from other data of the poll
*/ */
automaticSlug() { automaticSlug(): void {
this.form.patchValue({ slug: this.utilitiesService.makeUuid() }); this.form.patchValue({ custom_url: this.utilitiesService.makeUuid() });
} }
} }

View File

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

View File

@ -36,9 +36,6 @@ export class FormComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.initFormDefault(); this.initFormDefault();
const pollsAvailable = this.pollService.getAllAvailablePolls();
console.log('pollsAvailable', pollsAvailable);
} }
initFormDefault(showDemoValues = environment.autofill): void { initFormDefault(showDemoValues = environment.autofill): void {
@ -100,6 +97,10 @@ export class FormComponent implements OnInit {
this.setDemoValues(); this.setDemoValues();
this.toastService.display('default values filled for demo'); this.toastService.display('default values filled for demo');
} }
if (environment.autoSendNewPoll) {
this.createPoll();
}
} }
/** /**
@ -148,4 +149,32 @@ export class FormComponent implements OnInit {
goNextStep() { goNextStep() {
alert('todo'); 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 { ngOnInit(): void {
this.pollFormGroup = this.fb.group({ this.pollFormGroup = this.fb.group({
question: [this.poll ? this.poll.title : '', [Validators.required]], 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 : ''], description: [this.poll ? this.poll.description : ''],
}); });

View File

@ -64,9 +64,9 @@ export class ConsultationComponent implements OnInit, OnDestroy {
this.passHash = params.get('hash'); this.passHash = params.get('hash');
if (this.passHash) { if (this.passHash) {
this.pollService.loadPollBySlugWithPasswordHash(this.pollSlug, this.passHash); this.pollService.loadPollBycustom_urlWithPasswordHash(this.pollSlug, this.passHash);
} else { } else {
this.pollService.loadPollBySlug(this.pollSlug).then((resp) => { this.pollService.loadPollBycustom_url(this.pollSlug).then((resp) => {
console.log('resp', resp); console.log('resp', resp);
this.fetching = false; this.fetching = false;
}); });
@ -96,7 +96,7 @@ export class ConsultationComponent implements OnInit, OnDestroy {
this.toastService.display('vote ajouté', 'success'); this.toastService.display('vote ajouté', 'success');
if (resp) { if (resp) {
this.api.getPollBySlug(this.poll.custom_url); this.api.getPollByCustomUrl(this.poll.custom_url);
} else { } else {
this.toastService.display('erreur à la réception du nouveau vote', 'error'); 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"> <tr *ngFor="let poll of (_user | async)?.polls">
<th>{{ poll.title }}</th> <th>{{ poll.title }}</th>
<td> <td>
<a routerLink="{{ '../../poll/' + poll.slug + '/consultation' }}"> <a routerLink="{{ '../../poll/' + poll.custom_url + '/consultation' }}">
{{ poll.slug }} {{ poll.custom_url }}
</a> </a>
</td> </td>
</tr> </tr>

View File

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