forked from tykayn/funky-framadate-front
better mix on creation of poll
This commit is contained in:
parent
9a013f6d2c
commit
d40aa6a3ae
@ -20,6 +20,7 @@ export class Poll {
|
||||
public kind: string;
|
||||
|
||||
public description?: string;
|
||||
public password?: string;
|
||||
|
||||
public expiracy_date?: string;
|
||||
|
||||
@ -32,6 +33,7 @@ export class Poll {
|
||||
public is_archived?: boolean;
|
||||
public is_zero_knowledge?: boolean = false;
|
||||
public allow_comments?: boolean = true;
|
||||
public allowComments?: boolean = true;
|
||||
public has_several_hours?: boolean = false;
|
||||
|
||||
public allowSeveralHours?: boolean;
|
||||
@ -41,8 +43,9 @@ export class Poll {
|
||||
public max_score?: number;
|
||||
|
||||
public max_count_of_answers?: number = 150;
|
||||
public maxCountOfAnswers?: number = 150;
|
||||
|
||||
public configuration: PollConfiguration = new PollConfiguration();
|
||||
// public configuration: PollConfiguration = new PollConfiguration();
|
||||
|
||||
public comments: Comment[] = [];
|
||||
|
||||
|
@ -14,7 +14,6 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { StorageService } from './storage.service';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
import { TimeSlices } from '../../../../mocks/old-stuff/config/defaultConfigs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
@ -93,6 +92,7 @@ export class PollService implements Resolve<Poll> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async loadPollBycustom_urlWithPasswordHash(custom_url: string, hash: string): Promise<void> {
|
||||
console.log('custom_url', custom_url);
|
||||
if (custom_url) {
|
||||
@ -107,9 +107,6 @@ export class PollService implements Resolve<Poll> {
|
||||
* @param poll
|
||||
*/
|
||||
public updateCurrentPoll(poll: Poll): void {
|
||||
if (poll.kind == 'date') {
|
||||
poll.choices = this.parseDateChoices(poll.choices);
|
||||
}
|
||||
this.storageService.setChoicesForVoteStack(poll.choices);
|
||||
|
||||
this.toastService.display('sondage bien mis à jour', 'success');
|
||||
@ -120,21 +117,22 @@ export class PollService implements Resolve<Poll> {
|
||||
|
||||
/**
|
||||
* make a uniq custom_url for the current poll creation
|
||||
* @param config
|
||||
* @param poll
|
||||
*/
|
||||
makecustom_url(config: Poll): string {
|
||||
console.log('config', config);
|
||||
makecustom_url(poll: Poll): string {
|
||||
console.log('config', poll);
|
||||
let str = '';
|
||||
const creation_date = new Date(poll.creation_date);
|
||||
str =
|
||||
config.configuration.dateCreated.getFullYear() +
|
||||
creation_date.getFullYear() +
|
||||
'_' +
|
||||
(config.configuration.dateCreated.getMonth() + 1) +
|
||||
(creation_date.getMonth() + 1) +
|
||||
'_' +
|
||||
config.configuration.dateCreated.getDate() +
|
||||
creation_date.getDate() +
|
||||
'_' +
|
||||
config.owner.pseudo +
|
||||
poll.owner.pseudo +
|
||||
'_' +
|
||||
config.title;
|
||||
poll.title;
|
||||
str = str.replace(/^\s+|\s+$/g, ''); // trim
|
||||
str = str.toLowerCase();
|
||||
|
||||
@ -205,11 +203,21 @@ export class PollService implements Resolve<Poll> {
|
||||
const pollKeys = Object.keys(newpoll);
|
||||
const formFields = Object.keys(form.value);
|
||||
|
||||
for (const fieldOfForm of formFields) {
|
||||
if (pollKeys.indexOf(fieldOfForm) !== -1) {
|
||||
newpoll[fieldOfForm] = form.value[fieldOfForm];
|
||||
console.log('pollKeys, formFields', pollKeys, formFields);
|
||||
|
||||
for (const pk of pollKeys) {
|
||||
if (formFields.indexOf(pk) !== -1) {
|
||||
newpoll[pk] = form.value[pk];
|
||||
} else {
|
||||
console.log('manque pollKey', pk);
|
||||
}
|
||||
}
|
||||
newpoll.description = form.value.description;
|
||||
newpoll.max_count_of_answers = form.value.allowComments;
|
||||
newpoll.maxCountOfAnswers = form.value.maxCountOfAnswers;
|
||||
newpoll.password = form.value.password;
|
||||
newpoll.kind = form.value.kind;
|
||||
newpoll.allow_comments = form.value.allowComments;
|
||||
newpoll.dateChoices = this.storageService.dateList;
|
||||
newpoll.timeSlices = this.storageService.timeSlices;
|
||||
|
||||
@ -217,20 +225,26 @@ export class PollService implements Resolve<Poll> {
|
||||
return newpoll;
|
||||
}
|
||||
|
||||
/**
|
||||
* regrouper les jours et périodes de temps
|
||||
* @param choices
|
||||
*/
|
||||
public parseDateChoices(choices: Choice[]) {
|
||||
console.log('choices before', choices);
|
||||
return choices;
|
||||
public getAdministrationUrl(): string {
|
||||
let url = '';
|
||||
if (this._poll && this._poll.getValue) {
|
||||
const polltemp = this._poll.getValue();
|
||||
if (polltemp) {
|
||||
url = `${environment.frontDomain}#/poll/admin/${polltemp.admin_key}`;
|
||||
}
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
public getAdministrationUrl(): string {
|
||||
return `${environment.frontDomain}#/poll/admin/${this._poll.getValue().admin_key}`;
|
||||
}
|
||||
public getParticipationUrl(): string {
|
||||
let url = '';
|
||||
if (this._poll && this._poll.getValue) {
|
||||
const polltemp = this._poll.getValue();
|
||||
if (polltemp) {
|
||||
url = `${environment.frontDomain}#/poll/${polltemp.custom_url}/consultation`;
|
||||
}
|
||||
}
|
||||
// TODO handle pass access
|
||||
return `${environment.frontDomain}#/poll/${this._poll.getValue().custom_url}/consultation`;
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
@ -72,10 +72,4 @@ export class StorageService {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
parseDateChoices(datechoices) {
|
||||
const choices: Choice[] = [];
|
||||
|
||||
return choices;
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,8 @@
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
custom url:
|
||||
{{ form.value.custom_url }}
|
||||
</div>
|
||||
|
||||
<hr />
|
||||
|
@ -115,13 +115,16 @@ export class FormComponent implements OnInit {
|
||||
isAboutDate: true,
|
||||
// hasSeveralHours: true,
|
||||
kind: 'date',
|
||||
password: '',
|
||||
whoCanChangeAnswers: 'everybody',
|
||||
isProtectedByPassword: false,
|
||||
isOwnerNotifiedByEmailOnNewVote: false,
|
||||
isOwnerNotifiedByEmailOnNewComment: false,
|
||||
isMaybeAnswerAvailable: false,
|
||||
areResultsPublic: true,
|
||||
allowComments: true,
|
||||
expiresDaysDelay: 60,
|
||||
maxCountOfAnswers: 150,
|
||||
comments: [],
|
||||
choices: [
|
||||
{
|
||||
|
@ -99,7 +99,6 @@ export class ConsultationComponent implements OnInit, OnDestroy {
|
||||
if (resp) {
|
||||
const response: Promise<Poll | undefined> = this.api.getPollByCustomUrl(this.poll.custom_url);
|
||||
response.then((res: Poll | undefined) => {
|
||||
res.choices = this.pollService.parseDateChoices(res.choices);
|
||||
this.pollService._poll.next(res);
|
||||
});
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user