From 49b79395644d792ac633a0df5d15da07e0c460a3 Mon Sep 17 00:00:00 2001 From: Baptiste Lemoine Date: Wed, 19 Feb 2020 12:26:44 +0100 Subject: [PATCH] :zap: add some types interfaces in the config --- src/app/config/PollConfig.ts | 9 +-- src/app/config/defaultConfigs.ts | 78 ++++++++++++------------ src/app/pages/dates/dates.component.html | 4 ++ src/app/pages/dates/dates.component.ts | 4 +- 4 files changed, 51 insertions(+), 44 deletions(-) diff --git a/src/app/config/PollConfig.ts b/src/app/config/PollConfig.ts index d78524f6..84197284 100644 --- a/src/app/config/PollConfig.ts +++ b/src/app/config/PollConfig.ts @@ -2,7 +2,7 @@ * une option de date dans les sondages spéciaux */ import {environment} from "../../environments/environment"; -import {defaultAnswers, otherDefaultDates, otherTimeOfDay} from "./defaultConfigs"; +import {DateChoice, defaultAnswers, otherDefaultDates, PollAnswer} from "./defaultConfigs"; export interface DateOption { timeList: any; @@ -18,6 +18,7 @@ const baseConfigValues = { myEmail: "", }; + /** * configuration of the poll, add new fields at will */ @@ -56,13 +57,13 @@ export class PollConfig { urlAdmin = environment.baseHref + '/#/admin/d65es45fd45sdf45sd345f312sdf31sgfd345'; adminKey = ''; // key to change config of the poll owner_modifier_token = ''; // key to change a vote stack - canModifyAnswers = true;// bool for the frontend selector + canModifyAnswers: boolean = true;// bool for the frontend selector whoModifiesAnswers = "everybody";// everybody, self, nobody (= just admin) whoCanChangeAnswers = 'everybody';// everybody, self, nobody (= just admin) dateList: any = otherDefaultDates; // sets of days as strings, config to set identical time for days in a special days poll - timeList: any = otherTimeOfDay; // ranges of time expressed as strings + timeList: DateChoice[] = otherDefaultDates; // ranges of time expressed as strings - answers: any = defaultAnswers; + answers: PollAnswer[] = defaultAnswers; resetConfig() { const self = this; diff --git a/src/app/config/defaultConfigs.ts b/src/app/config/defaultConfigs.ts index 2ba2f10f..d37749af 100644 --- a/src/app/config/defaultConfigs.ts +++ b/src/app/config/defaultConfigs.ts @@ -1,78 +1,80 @@ -export const basicSlicesOfDay = [ +export interface DateChoice { + literal: string, + timeList: TimeSlices[], + date_object: Date +} + +export interface TimeSlices { + literal: string +} + +export interface PollAnswer { + id: number, + text: string, + url: string, + literal: string, + date_object: Date, + timeList: TimeSlices[] +} + +export const basicSlicesOfDay: TimeSlices[] = [ {literal: 'matin'}, {literal: 'midi'}, {literal: 'soir'} ]; -export const otherSlicesOfDay = [ +export const otherSlicesOfDay: TimeSlices[] = [ {literal: 'aux aurores'}, {literal: 'au petit dej'}, {literal: 'au deuxième petit dej des hobbits'} ]; -export const defaultTimeOfDay = Array.from([{ - timeList: [...basicSlicesOfDay], - literal: 'matin' -}, - {timeList: [...basicSlicesOfDay], literal: 'midi'}, - {timeList: [...basicSlicesOfDay], literal: 'après-midi'}, - {timeList: [...basicSlicesOfDay], literal: 'soirée'}]); -export const otherTimeOfDay = Array.from([{ - timeList: [ - {literal: 'aux aurores'}, - {literal: 'au petit dej'}, - {literal: 'au deuxième petit dej des hobbits'} - ], - literal: 'matin' -}, - { - timeList: [ - {literal: 'matin'}, - {literal: 'midi'}, - {literal: 'soir'} - ], literal: 'midi' - }, - {timeList: [...otherSlicesOfDay], literal: 'après-midi'}, - {timeList: [...basicSlicesOfDay], literal: 'soirée'}]); -export const defaultDates = [ +export const defaultTimeOfDay: TimeSlices[] = (() => { + return [...basicSlicesOfDay] +})(); + +export const otherTimeOfDay: TimeSlices[] = (() => { + return [...otherSlicesOfDay] +})(); +export const defaultDates: DateChoice[] = [ { literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}`, date_object: new Date(), - timeList: [...otherSlicesOfDay] + timeList: defaultTimeOfDay }, { literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 1}`, date_object: new Date(), - timeList: [...basicSlicesOfDay] + timeList: defaultTimeOfDay }, { literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 2}`, date_object: new Date(), - timeList: [...otherSlicesOfDay] + timeList: defaultTimeOfDay } ]; -export const otherDefaultDates = [ +export const otherDefaultDates: DateChoice[] = [ { literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate()}`, date_object: new Date(), - timeList: [...otherSlicesOfDay] + timeList: otherTimeOfDay }, { literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 1}`, date_object: new Date(), - timeList: [...basicSlicesOfDay] + timeList: defaultTimeOfDay }, { literal: `${new Date().getFullYear()}-${new Date().getMonth()}-${new Date().getDate() + 2}`, date_object: new Date(), - timeList: [...otherSlicesOfDay] + timeList: otherTimeOfDay } ]; -export const defaultAnswers = [{ +export const defaultAnswers: PollAnswer[] = [{ id: 0, text: 'réponse de démo 1', 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()}`, date_object: new Date(), - timeList: Array.from(otherSlicesOfDay) + timeList: otherSlicesOfDay }, { id: 1, @@ -80,7 +82,7 @@ export const defaultAnswers = [{ 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}`, date_object: new Date(), - timeList: Array.from(basicSlicesOfDay) + timeList: basicSlicesOfDay }, { id: 2, @@ -88,5 +90,5 @@ export const defaultAnswers = [{ 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}`, date_object: new Date(), - timeList: Array.from(otherSlicesOfDay) + timeList: otherSlicesOfDay }]; diff --git a/src/app/pages/dates/dates.component.html b/src/app/pages/dates/dates.component.html index 90c8258c..7b00ee46 100644 --- a/src/app/pages/dates/dates.component.html +++ b/src/app/pages/dates/dates.component.html @@ -183,6 +183,10 @@ *ngIf=" 'true' === config.allowSeveralHours" class="several-times" > +
+                    choice.timeList :
+                        {{choice.timeList|json}}
+                    

Several hours