From 6405470aa430c316b2b0f1c7e1865b18efeb87e1 Mon Sep 17 00:00:00 2001 From: Mike Risher Date: Thu, 18 Feb 2021 00:23:32 +0000 Subject: [PATCH] LP1879517 Survey Start and End Dates Error Change the surveys interface so that an error is raised when putting the end date before the start date. Also, list start date before end date so they're less likely to be mixed up. Signed-off-by: Mike Risher Changes to be committed: modified: Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html modified: Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts modified: Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.html modified: Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey-edit.component.ts modified: Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.html modified: Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.ts --- .../app/share/fm-editor/fm-editor.component.html | 2 +- .../src/app/share/fm-editor/fm-editor.component.ts | 15 ++++++++ .../admin/local/survey/survey-edit.component.html | 26 ++++++++++++- .../admin/local/survey/survey-edit.component.ts | 27 +++++++++++++ .../staff/admin/local/survey/survey.component.html | 23 ++++++++++- .../staff/admin/local/survey/survey.component.ts | 44 ++++++++++++++++++---- 6 files changed, 127 insertions(+), 10 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html index af9f5f0197..3919a2f7e6 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.html @@ -203,7 +203,7 @@ diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index 4ac2e2eac9..ac6874ae7e 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -77,6 +77,10 @@ export interface FmFieldOptions { // from the default set of form inputs. customTemplate?: CustomFieldTemplate; + // This will disable the save button if any field has this set to false. It + // can be used along with a customTemplate to show an error message for non-valid input + isDataValid?: boolean; + // help text to display via a popover helpText?: StringComponent; } @@ -630,6 +634,17 @@ export class FmRecordEditorComponent ); } + fieldIsInvalid() { + let inv = false; + for (const f in this.fieldOptions) { + if (this.fieldOptions[f].isDataValid === false) { + inv = true; + break; + } + } + return inv; + } + remove() { this.confirmDel.open().subscribe(confirmed => { if (!confirmed) { return; } 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..11389b4f3e 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,37 @@ 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..13287b3e57 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 @@ -19,6 +19,9 @@ export class SurveyEditComponent implements OnInit { newAnswerArray: object[]; newQuestionText: string; surveyTab: string; + illegalEndDate = false; + startDate: string; + endDate: string; @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; @@ -79,6 +82,9 @@ 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.checkForValidDates(); return res; }); } @@ -303,5 +309,26 @@ export class SurveyEditComponent implements OnInit { } return false; } + + setEndDate(event): any { + this.endDate = event; + this.checkForValidDates(); + } + + setStartDate(event): any { + this.startDate = event; + this.checkForValidDates(); + } + + checkForValidDates(): any { + const d1: any = new Date(this.startDate); + const d2: any = new Date(this.endDate); + if (d1 - d2 >= 0) { + this.illegalEndDate = true; + } else { + this.illegalEndDate = false; + } + } + } diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.html index 394d837c16..8f070b8a29 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.html @@ -14,12 +14,33 @@ + + + + + + + + +
+ End date must be after start date. +
+
+ diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.ts index c51af574fb..a0f147a634 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/survey/survey.component.ts @@ -3,7 +3,7 @@ import {Component, OnInit, Input, ViewChild} from '@angular/core'; import {GridComponent} from '@eg/share/grid/grid.component'; import {GridDataSource} from '@eg/share/grid/grid'; import {Router} from '@angular/router'; -import {IdlObject} from '@eg/core/idl.service'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; import {StringComponent} from '@eg/share/string/string.component'; @@ -18,6 +18,9 @@ import {AuthService} from '@eg/core/auth.service'; export class SurveyComponent implements OnInit { gridDataSource: GridDataSource; + illegalEndDate: boolean; + startDate: string; + endDate: string; @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent; @ViewChild('grid', { static: true }) grid: GridComponent; @@ -31,15 +34,14 @@ export class SurveyComponent implements OnInit { @ViewChild('endSurveySuccessString', { static: true }) endSurveySuccessString: StringComponent; @Input() sortField: string; - @Input() idlClass = 'asv'; - @Input() dialogSize: 'sm' | 'lg' = 'lg'; constructor( private auth: AuthService, private net: NetService, private pcrud: PcrudService, private toast: ToastService, - private router: Router + private router: Router, + private idl: IdlService, ) { this.gridDataSource = new GridDataSource(); } @@ -49,10 +51,10 @@ export class SurveyComponent implements OnInit { const orderBy: any = {}; if (sort.length) { // Sort specified from grid - orderBy[this.idlClass] = sort[0].name + ' ' + sort[0].dir; + orderBy['asv'] = sort[0].name + ' ' + sort[0].dir; } else if (this.sortField) { // Default sort field - orderBy[this.idlClass] = this.sortField; + orderBy['asv'] = this.sortField; } const searchOps = { @@ -121,7 +123,14 @@ export class SurveyComponent implements OnInit { createNew = () => { this.editDialog.mode = 'create'; this.editDialog.datetimeFields = 'start_date,end_date'; - this.editDialog.open({size: this.dialogSize}).subscribe( + const today = new Date(); + const d1 = new Date(today); + const d2 = new Date(today); + d1.setDate(today.getDate() + 1); // default start is in 1 day + d2.setDate(today.getDate() + 30); // default end is in 30 days + this.startDate = d1.toISOString(); + this.endDate = d2.toISOString(); + this.editDialog.open({size: 'lg'}).subscribe( ok => { this.createString.current() .then(str => this.toast.success(str)); @@ -135,4 +144,25 @@ export class SurveyComponent implements OnInit { } ); } + + setEndDate(event): any { + this.endDate = event; + this.checkForValidDates(); + } + + setStartDate(event): any { + this.startDate = event; + this.checkForValidDates(); + } + + checkForValidDates(): any { + const d1: any = new Date(this.startDate); + const d2: any = new Date(this.endDate); + if (d1 - d2 >= 0) { + this.illegalEndDate = true; + } else { + this.illegalEndDate = false; + } + } + } -- 2.11.0