forked from tykayn/funky-framadate-front
assign datechoices from storage at creation of poll
This commit is contained in:
parent
6e61e49235
commit
e86e7af5e1
@ -2,6 +2,7 @@ import { Choice, ChoiceGroup } from './choice.model';
|
|||||||
import { Comment } from './comment.model';
|
import { Comment } from './comment.model';
|
||||||
import { Owner } from './owner.model';
|
import { Owner } from './owner.model';
|
||||||
import { DateChoice, TimeSlices } from './dateChoice.model';
|
import { DateChoice, TimeSlices } from './dateChoice.model';
|
||||||
|
import { defaultTimeOfDay } from '../../../../mocks/old-stuff/config/defaultConfigs';
|
||||||
|
|
||||||
export class Poll {
|
export class Poll {
|
||||||
public id = 0;
|
public id = 0;
|
||||||
@ -53,13 +54,13 @@ export class Poll {
|
|||||||
|
|
||||||
public stacks = [];
|
public stacks = [];
|
||||||
|
|
||||||
public allowed_answers = [];
|
public allowed_answers = ['yes'];
|
||||||
|
|
||||||
public modification_policy = 'everybody';
|
public modification_policy = 'everybody';
|
||||||
|
|
||||||
public dateChoices: DateChoice[] = [];
|
public dateChoices: DateChoice[] = [];
|
||||||
// sets of dateChoices as strings, config to set identical time for dateChoices in a special dateChoices poll
|
// sets of dateChoices as strings, config to set identical time for dateChoices in a special dateChoices poll
|
||||||
public timeSlices: TimeSlices[] = []; // ranges of time expressed as strings
|
public timeSlices: TimeSlices[] = Object.create(defaultTimeOfDay); // ranges of time expressed as strings
|
||||||
|
|
||||||
constructor(public owner: Owner = new Owner(), public title = 'mon titre', public custom_url: string = '') {}
|
constructor(public owner: Owner = new Owner(), public title = 'mon titre', public custom_url: string = '') {}
|
||||||
}
|
}
|
||||||
|
@ -96,10 +96,12 @@ export class DateUtilitiesService {
|
|||||||
*/
|
*/
|
||||||
makeDefaultDateChoices(): DateChoice[] {
|
makeDefaultDateChoices(): DateChoice[] {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
const ladate = this.addDaysToDate(1, today);
|
const ladate = this.addDaysToDate(0, today);
|
||||||
const ladate2 = this.addDaysToDate(2, today);
|
const ladate2 = this.addDaysToDate(1, today);
|
||||||
const ladate3 = this.addDaysToDate(3, today);
|
const ladate3 = this.addDaysToDate(2, today);
|
||||||
const ladate4 = this.addDaysToDate(4, today);
|
const ladate4 = this.addDaysToDate(3, today);
|
||||||
|
const ladate5 = this.addDaysToDate(4, today);
|
||||||
|
const ladate6 = this.addDaysToDate(5, today);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
@ -122,6 +124,16 @@ export class DateUtilitiesService {
|
|||||||
timeSlices: Object.create(defaultTimeOfDay),
|
timeSlices: Object.create(defaultTimeOfDay),
|
||||||
date_object: ladate4,
|
date_object: ladate4,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
literal: this.formateDateToInputStringNg(ladate5),
|
||||||
|
timeSlices: Object.create(defaultTimeOfDay),
|
||||||
|
date_object: ladate5,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
literal: this.formateDateToInputStringNg(ladate6),
|
||||||
|
timeSlices: Object.create(defaultTimeOfDay),
|
||||||
|
date_object: ladate6,
|
||||||
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,14 +198,23 @@ export class PollService implements Resolve<Poll> {
|
|||||||
const formFields = Object.keys(form.value);
|
const formFields = Object.keys(form.value);
|
||||||
|
|
||||||
console.log('pollKeys, formFields', pollKeys, formFields);
|
console.log('pollKeys, formFields', pollKeys, formFields);
|
||||||
|
newpoll.allowed_answers = ['yes'];
|
||||||
|
|
||||||
for (const pk of pollKeys) {
|
for (const pk of pollKeys) {
|
||||||
if (formFields.indexOf(pk) !== -1) {
|
if (formFields.indexOf(pk) !== -1) {
|
||||||
newpoll[pk] = form.value[pk];
|
const field = form.value[pk];
|
||||||
|
newpoll[pk] = field;
|
||||||
} else {
|
} else {
|
||||||
console.log('manque pollKey', pk);
|
console.log('manque pollKey', pk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (form.value.isMaybeAnswerAvailable) {
|
||||||
|
newpoll.allowed_answers.push('maybe');
|
||||||
|
}
|
||||||
|
if (form.value.isNoAnswerAvailable) {
|
||||||
|
newpoll.allowed_answers.push('no');
|
||||||
|
}
|
||||||
newpoll.description = form.value.description;
|
newpoll.description = form.value.description;
|
||||||
newpoll.has_several_hours = form.value.hasSeveralHours;
|
newpoll.has_several_hours = form.value.hasSeveralHours;
|
||||||
newpoll.hasSeveralHours = form.value.hasSeveralHours;
|
newpoll.hasSeveralHours = form.value.hasSeveralHours;
|
||||||
@ -215,9 +224,11 @@ export class PollService implements Resolve<Poll> {
|
|||||||
newpoll.kind = form.value.kind;
|
newpoll.kind = form.value.kind;
|
||||||
newpoll.allow_comments = form.value.allowComments;
|
newpoll.allow_comments = form.value.allowComments;
|
||||||
// merge choices from storage
|
// merge choices from storage
|
||||||
newpoll.choices = this.storageService.choices;
|
newpoll.choices = Object.assign([], this.storageService.choices);
|
||||||
newpoll.dateChoices = this.storageService.dateChoices;
|
newpoll.dateChoices = Object.assign([], this.storageService.dateChoices);
|
||||||
newpoll.timeSlices = this.storageService.timeSlices;
|
newpoll.timeSlices = Object.assign([], this.storageService.timeSlices);
|
||||||
|
|
||||||
|
console.log('this.storageService.timeSlices', this.storageService.timeSlices, newpoll.timeSlices);
|
||||||
|
|
||||||
return newpoll;
|
return newpoll;
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ export class FormComponent implements OnInit, AfterViewInit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// take back values from pollservice
|
// take back values from pollservice
|
||||||
this.form.patchValue(this.pollService.poll);
|
// this.form.patchValue(this.pollService.poll);
|
||||||
this.setDefaultFormValues();
|
this.setDefaultFormValues();
|
||||||
|
|
||||||
if (showDemoValues) {
|
if (showDemoValues) {
|
||||||
@ -136,6 +136,7 @@ export class FormComponent implements OnInit, AfterViewInit {
|
|||||||
startDateInterval: dateStart,
|
startDateInterval: dateStart,
|
||||||
endDateInterval: dateEnd,
|
endDateInterval: dateEnd,
|
||||||
});
|
});
|
||||||
|
this.automaticSlug();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,6 +156,8 @@ export class FormComponent implements OnInit, AfterViewInit {
|
|||||||
description: 'répondez SVP <3 ! *-*',
|
description: 'répondez SVP <3 ! *-*',
|
||||||
creatorPseudo: 'Chuck Norris',
|
creatorPseudo: 'Chuck Norris',
|
||||||
creatorEmail: 'chucknorris@example.com',
|
creatorEmail: 'chucknorris@example.com',
|
||||||
|
dateStart,
|
||||||
|
dateEnd,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +133,6 @@ mat-checkbox {
|
|||||||
|
|
||||||
.cdk-drag {
|
.cdk-drag {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
//border-left: 3px white solid;
|
|
||||||
&:hover {
|
&:hover {
|
||||||
background: #fefefe;
|
background: #fefefe;
|
||||||
}
|
}
|
||||||
@ -208,7 +207,7 @@ mat-checkbox {
|
|||||||
}
|
}
|
||||||
.ng-pristine,
|
.ng-pristine,
|
||||||
.ng-dirty {
|
.ng-dirty {
|
||||||
border-left: $white 3px solid;
|
border-left: blue 3px solid;
|
||||||
padding-left: 1em;
|
padding-left: 1em;
|
||||||
}
|
}
|
||||||
.ng-touched.ng-invalid {
|
.ng-touched.ng-invalid {
|
||||||
|
Loading…
Reference in New Issue
Block a user