From e4ca0270655223fb85885f2241b1ff6d8681fd43 Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Thu, 5 Sep 2019 11:25:14 -0400 Subject: [PATCH] Validate CLIN PoP against configurable contract start and end dates --- config/base.ini | 2 + js/components/clin_fields.js | 63 +++++++++++++++++++++++++------ templates/task_orders/step_3.html | 12 ++---- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/config/base.ini b/config/base.ini index 1d4461b8..c034cc7a 100644 --- a/config/base.ini +++ b/config/base.ini @@ -2,6 +2,8 @@ CAC_URL = http://localhost:8000/login-redirect CA_CHAIN = ssl/server-certs/ca-chain.pem CLASSIFIED = false +CONTRACT_START_DATE = 2019-09-14 +CONTRACT_END_DATE = 2022-09-14 COOKIE_SECRET = some-secret-please-replace DISABLE_CRL_CHECK = false CRL_FAIL_OPEN = false diff --git a/js/components/clin_fields.js b/js/components/clin_fields.js index acf45d09..72da4b71 100644 --- a/js/components/clin_fields.js +++ b/js/components/clin_fields.js @@ -1,3 +1,5 @@ +import * as R from 'ramda' + import DateSelector from './date_selector' import { emitEvent } from '../lib/emitters' import Modal from '../mixins/modal' @@ -9,6 +11,12 @@ const END_DATE = 'end_date' const POP = 'period_of_performance' const NUMBER = 'number' +const fs = require('fs') +const ini = require('ini') +const config = ini.parse(fs.readFileSync('./config/base.ini', 'utf-8')) +const CONTRACT_START_DATE = new Date(config.default.CONTRACT_START_DATE) +const CONTRACT_END_DATE = new Date(config.default.CONTRACT_END_DATE) + export default { name: 'clin-fields', @@ -44,7 +52,6 @@ export default { ? new Date(this.initialEndDate) : undefined const popValidation = !this.initialStartDate ? false : start < end - const showPopValidation = !this.initialStartDate ? false : !popValidation const clinNumber = !!this.initialClinNumber ? this.initialClinNumber : undefined @@ -54,9 +61,22 @@ export default { startDate: start, endDate: end, popValid: popValidation, - showPopError: showPopValidation, clinNumber: clinNumber, - showClin: true, + popErrors: [], + validations: [ + { + func: this.popDateOrder, + message: 'PoP start date must be before end date.', + }, + { + func: this.popStartsAfterContract, + message: `PoP start date must be on or after ${CONTRACT_START_DATE}.`, + }, + { + func: this.popEndsBeforeContract, + message: `PoP end date must be before or on ${CONTRACT_END_DATE}.`, + }, + ], } }, @@ -74,20 +94,41 @@ export default { methods: { checkPopValid: function() { - return this.startDate < this.endDate + return ( + this.popDateOrder() && + this.popStartsAfterContract() && + this.popEndsBeforeContract() + ) }, validatePop: function() { - if (!!this.startDate && !!this.endDate) { - // only want to update popValid and showPopError if both dates are filled in - this.popValid = this.checkPopValid() - this.showPopError = !this.popValid - } - + this.popValid = this.checkPopValid() emitEvent('field-change', this, { name: 'clins-' + this.clinIndex + '-' + POP, - valid: this.checkPopValid(), + valid: this.popValid, }) + + this.popErrors = R.pipe( + R.map(validation => + !validation.func() ? validation.message : undefined + ), + R.filter(Boolean) + )(this.validations) + }, + + popStartsAfterContract: function() { + return this.startDate >= CONTRACT_START_DATE + }, + + popEndsBeforeContract: function() { + return this.endDate <= CONTRACT_END_DATE + }, + + popDateOrder: function() { + if (!!this.startDate && !!this.endDate) { + return this.startDate < this.endDate + } + return true }, handleFieldChange: function(event) { diff --git a/templates/task_orders/step_3.html b/templates/task_orders/step_3.html index 1d86a672..3b2bfe0b 100644 --- a/templates/task_orders/step_3.html +++ b/templates/task_orders/step_3.html @@ -314,15 +314,9 @@ {% endif %}
-

- -

+
+
+