From f5b4dcb85e8e2c0cf4db35aa8227ff10885d396b Mon Sep 17 00:00:00 2001 From: Hugh Wells Date: Thu, 30 Jul 2020 16:02:00 +0100 Subject: [PATCH 1/8] WIP: basic (non-working) implementation of some of the hard limit stuff --- src/helpers/date.js | 73 +++++++++++++++++++++++++++++++++++ src/views/Assessment/Edit.vue | 72 ++++++++++++++++++++-------------- src/views/Assessments.vue | 19 +++++++++ 3 files changed, 136 insertions(+), 28 deletions(-) create mode 100644 src/helpers/date.js diff --git a/src/helpers/date.js b/src/helpers/date.js new file mode 100644 index 0000000..12d2d24 --- /dev/null +++ b/src/helpers/date.js @@ -0,0 +1,73 @@ +const isDate = (date) => date instanceof Date; + +const isDateInFuture = (date) => { + // @TODO #388 update to full datetime instead of hardcoding time + if (!(date instanceof Date)) { + throw 'Supplied date must be a Date object'; + } + + const today = new Date(); + + date = new Date( + date.getFullYear(), + date.getMonth(), + date.getDate(), + 13, + 0, + 0 + ); + + return date > today; +}; + +const formatDate = (date, type) => { + if (!(date instanceof Date)) { + throw 'Supplied date must be a Date object'; + } + + if (type && type === 'time') { + return date.toLocaleString('en-GB', { hour: 'numeric', minute: 'numeric', hour12: true }).toLowerCase(); + } + + const month = date.toLocaleString('en-GB', { month: 'long' }); + + if (type && type === 'month') { + return `${month} ${date.getFullYear()}`; + } + + return `${date.getDate()} ${month} ${date.getFullYear()}`; +}; + +const parseEstimatedDate = (value) => { + if (value instanceof Date) { + return value; + } + + if (typeof value != 'string') { + return; + } + const parts = value.split('-'); + + const [year, month, day] = [...parts, 1]; + const date = new Date(Date.UTC(year, month - 1, day)); + + return date; +}; + +const validateYear = (val) => { + val = parseInt(val); + + if (isNaN(val) || val.toString().length !== 4) { + return null; + } + + return val; +}; + +export { + isDate, + isDateInFuture, + formatDate, + parseEstimatedDate, + validateYear +}; diff --git a/src/views/Assessment/Edit.vue b/src/views/Assessment/Edit.vue index 96f50f4..6725258 100644 --- a/src/views/Assessment/Edit.vue +++ b/src/views/Assessment/Edit.vue @@ -52,45 +52,50 @@ -

- Download the template on this page to complete your assessment. -

+
+

+ Download the template on this page to complete your assessment. +

-

- Come back to this page to upload your finished assessment. -

+

+ Come back to this page to upload your finished assessment. +

-
-

- Download self assessment template -

+
+

+ Download self assessment template +

- -
+ +
- + - + +
From 4b37969a0514700195f03d6d261d0bb013311099 Mon Sep 17 00:00:00 2001 From: Hugh Wells Date: Fri, 31 Jul 2020 11:24:37 +0100 Subject: [PATCH 4/8] Add logic to hide form and display warning when hard limit exceeded --- src/views/Assessment/Edit.vue | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/views/Assessment/Edit.vue b/src/views/Assessment/Edit.vue index 14f707e..09c711f 100644 --- a/src/views/Assessment/Edit.vue +++ b/src/views/Assessment/Edit.vue @@ -89,6 +89,10 @@ Save and continue + @@ -96,17 +100,18 @@