date accessor

This commit is contained in:
Baptiste Lemoine 2020-01-24 11:15:38 +01:00
parent 460e236d60
commit 22736f709e
4 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import {defaultAnswers} from "./defaultConfigs";
export interface DateOption { export interface DateOption {
timeList: any; timeList: any;
literal: string; literal: string;
date_object?: object;
} }
const baseConfigValues = { const baseConfigValues = {

View File

@ -8,14 +8,17 @@ export const timeOfDay = [{
export const defaultDates = [ export const defaultDates = [
{ {
literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}`, literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}`,
date_object: new Date(),
timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}] timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}]
}, },
{ {
literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 1}`, literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 1}`,
date_object: new Date(),
timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}] timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}]
}, },
{ {
literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 2}`, literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 2}`,
date_object: new Date(),
timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}] timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}]
} }
]; ];
@ -24,6 +27,7 @@ export const defaultAnswers = [{
text: 'réponse de démo 1', text: 'réponse de démo 1',
url: 'https://mastodon.cipherbliss.com/system/media_attachments/files/001/439/118/original/6fcf149bd902841b.png?1579471574', url: 'https://mastodon.cipherbliss.com/system/media_attachments/files/001/439/118/original/6fcf149bd902841b.png?1579471574',
literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}`, literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}`,
date_object: new Date(),
timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}] timeList: [{literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'}]
}, },
{ {
@ -31,10 +35,12 @@ export const defaultAnswers = [{
text: 'réponse 2', text: 'réponse 2',
url: 'https://mastodon.cipherbliss.com/system/media_attachments/files/001/439/118/original/6fcf149bd902841b.png?1579471574', url: 'https://mastodon.cipherbliss.com/system/media_attachments/files/001/439/118/original/6fcf149bd902841b.png?1579471574',
literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 1}`, literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 1}`,
date_object: new Date(),
}, },
{ {
id: 2, id: 2,
text: 'la réponse D', text: 'la réponse D',
url: 'https://mastodon.cipherbliss.com/system/media_attachments/files/001/439/118/original/6fcf149bd902841b.png?1579471574', url: 'https://mastodon.cipherbliss.com/system/media_attachments/files/001/439/118/original/6fcf149bd902841b.png?1579471574',
literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 2}`, literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 2}`,
date_object: new Date(),
}]; }];

View File

@ -154,7 +154,7 @@
class="date-choice" class="date-choice"
> >
<input <input
[(ngModel)]="choice.literal" [(ngModel)]="choice.date_object"
name="dateChoices_{{id}}" name="dateChoices_{{id}}"
id="dateChoices_{{id}}" id="dateChoices_{{id}}"
useValueAsDate useValueAsDate
@ -181,7 +181,7 @@
class="time-choice" class="time-choice"
> >
<input <input
[(ngModel)]="time.literal" [(ngModel)]="time.date_object"
name="dateTime_{{id}}_Choices_{{idTime}}" name="dateTime_{{id}}_Choices_{{idTime}}"
id="dateTime_{{id}}_Choices_{{idTime}}" id="dateTime_{{id}}_Choices_{{idTime}}"
useValueAsDate useValueAsDate

View File

@ -43,7 +43,10 @@ export class DatesComponent extends BaseComponent implements OnInit {
} }
addDate() { addDate() {
this.config.dateList.push({literal: '', timeList: []}); this.config.dateList.push({
literal: '',
date_object: new Date(),
timeList: []});
let selector = '[ng-reflect-name="dateChoices_' + (this.config.dateList.length - 1) + '"]'; let selector = '[ng-reflect-name="dateChoices_' + (this.config.dateList.length - 1) + '"]';
this.cd.detectChanges(); this.cd.detectChanges();
const elem = this.document.querySelector(selector); const elem = this.document.querySelector(selector);