From d6d7e64335747438f21896e14126ddc9971be35d Mon Sep 17 00:00:00 2001 From: Mike Risher Date: Thu, 21 Jan 2021 20:17:11 +0000 Subject: [PATCH] LP1879517 survey start and end dates WIP Signed-off-by: Mike Risher --- .../admin/local/survey/survey-edit.component.html | 35 +++++++++- .../admin/local/survey/survey-edit.component.ts | 74 +++++++++++++++++++++- 2 files changed, 107 insertions(+), 2 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.html index 86f2f20d81..0963dcb6f9 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.html @@ -10,13 +10,46 @@ End Survey Now - + + + + + + + + + + +
+ End date must be after start date. +
+
+ diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.ts index 73b3a7bca6..1dd28fabbf 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.ts @@ -7,6 +7,8 @@ import {NetService} from '@eg/core/net.service'; import {AuthService} from '@eg/core/auth.service'; import {IdlObject, IdlService } from '@eg/core/idl.service'; import {NgbTabset, NgbTabChangeEvent} from '@ng-bootstrap/ng-bootstrap'; +import * as moment from 'moment-timezone'; +import {FormatService} from '@eg/core/format.service'; @Component({ templateUrl: './survey-edit.component.html' @@ -19,8 +21,11 @@ export class SurveyEditComponent implements OnInit { newAnswerArray: object[]; newQuestionText: string; surveyTab: string; + illegalEndDate: boolean = false; + startDate: any; + endDate: any; - @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; + @ViewChild('editDialog', { static: false }) editDialog: FmRecordEditorComponent; @ViewChild('createAnswerString', { static: true }) createAnswerString: StringComponent; @@ -62,6 +67,7 @@ export class SurveyEditComponent implements OnInit { private route: ActivatedRoute, private toast: ToastService, private idl: IdlService, + private format: FormatService, ) { } @@ -79,6 +85,10 @@ export class SurveyEditComponent implements OnInit { ).subscribe(res => { this.surveyObj = res; this.buildLocalArray(res); + this.startDate = this.surveyObj.start_date(); + this.endDate = this.surveyObj.end_date(); + // this.editDialog.fields['start_date'] = this.startDate; + // this.editDialog.fields['end_date'] = this.endDate; return res; }); } @@ -303,5 +313,67 @@ export class SurveyEditComponent implements OnInit { } return false; } + + setEndDate(event): any { + console.log("set end") + // this.checkForValidDates(); + // console.log(this.editDialog) + this.editDialog.fields['end_date'] = event; + this.checkForValidDates(); + } + + setStartDate(event): any { + console.log("set start") + // this.checkForValidDates(); + // console.log(this.editDialog) + this.editDialog.fields['start_date'] = event; + this.checkForValidDates(); + } + + areDatesValid = (): boolean => { + console.log("** are dates valid?" + this.illegalEndDate) + return this.illegalEndDate; + } + + checkForValidDates(): any { + console.log("** check") + console.log(this.editDialog) + // console.log(this.editDialog['fmEditForm']) + console.log(this.editDialog.fields['start_date']); + console.log(this.editDialog.fields['end_date']) + // console.log(typeof this.editDialog.fields['start_date']); + const d1:any = new Date(this.editDialog.fields['start_date']); + const d2:any = new Date(this.editDialog.fields['end_date']); + // console.log("** check2") + // console.log(d1); + // console.log(d2); + // console.log(d1 - d2); + if (d1-d2 >= 0) { + console.log("illegal date") + this.illegalEndDate = true; + // console.log(this.editDialog['fmEditForm']) + // this.editDialog.fmEditForm.setErrors({'invalid': true}) + } else { + this.illegalEndDate = false; + } + // console.log("start / end dates:") + // console.log(this.editDialog.fields['start_date']) + // console.log(typeof this.editDialog.fields['start_date']) + // console.log(this.editDialog.fields['end_date']) + // console.log(typeof this.editDialog.fields['end_date']) + } + + momentizeIsoString(isoString: string, timezone: string): moment.Moment { + if (!isoString) { + return null; + } + // console.log("@@@ momentize") + // console.log(isoString) + // console.log(timezone) + // console.log(this.format.momentizeIsoString(isoString, timezone)) + return this.format.momentizeIsoString(isoString, timezone); + } + + } -- 2.11.0