From: Jane Sandberg Date: Sat, 30 Mar 2019 01:00:43 +0000 (-0700) Subject: LP1816475: Reservations grid now respects the pickup library's tz X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=4ec86b6a644dc947c6b5f46d5b3babf99459a76e;p=working%2FEvergreen.git LP1816475: Reservations grid now respects the pickup library's tz Signed-off-by: Jane Sandberg --- diff --git a/Open-ILS/src/eg2/src/app/core/format.service.ts b/Open-ILS/src/eg2/src/app/core/format.service.ts index c764e61422..f236769220 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -137,14 +137,47 @@ export class FormatService { /** * Create an IDL-friendly display version of a human-readable date */ - idlFormatDate(original: string): string { - return Moment(original, 'MMM DD YYYY', 'America/Los_Angeles').format('YYYY-MM-DD'); - } + idlFormatDate(date: string): string { return this.momentizeDateString(date).format('YYYY-MM-DD'); } + /** * Create an IDL-friendly display version of a human-readable datetime */ - idlFormatDatetime(original: string): string { - return Moment(original, 'MMM DD YYYY HH:mm', 'America/Los_Angeles').toISOString() + idlFormatDatetime(datetime: string): string { return this.momentizeDateTimeString(datetime).toISOString(); } + + momentizeDateString(date: string): Moment { + const parseableFormat = this.makeFormatParseable(this.dateFormat); + if (parseableFormat.length) {return Moment(date, parseableFormat, 'Asia/Tokyo')}; + return Moment(date, 'Asia/Tokyo'); + } + + momentizeDateTimeString(datetime: string): Moment { + const parseableFormat = this.makeFormatParseable(this.dateTimeFormat); + if (parseableFormat.length) {return Moment(datetime, parseableFormat, 'Asia/Tokyo')}; + return Moment(datetime, 'Asia/Tokyo'); + } + + /** + * Takes a dateFormate or dateTimeFormat string (which uses Angular syntax) and transforms + * it into a format string that MomentJs can use to parse input human-readable strings + * (https://momentjs.com/docs/#/parsing/string-format/) + * + * Returns a blank string if it can't do this transformation. + */ + private makeFormatParseable(original: string): string { + const specialFormats = ['short', 'medium', 'long', 'full', + 'shortDate', 'mediumDate', 'longDate', 'fullDate', + 'shortTime', 'mediumTime', 'longTime', 'fullTime']; + if (!original || specialFormats.includes(original)) { return ''; }; + return original + .replace(/a+/, 'a') // MomentJs can handle all sorts of meridian strings + .replace('d', 'D') // MomentJs capitalizes day of month + .replace('EEEEEE', '') // MomentJs does not handle short day of week + .replace('EEEEE', '') // MomentJs does not handle narrow day of week + .replace('EEEE', 'dddd') // MomentJs has different syntax for long day of week + .replace(/E{1,3}/, 'ddd') // MomentJs has different syntax for abbreviated day of week + .replace('L', 'M') // MomentJs does not differentiate between month and month standalone + .replace('W', '') // MomentJs uses W for something else + .replace('y', 'Y'); // MomentJs capitalizes year } } diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html index ee006604b5..08ff81d2fc 100644 --- a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.html @@ -1,17 +1,10 @@ -
diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts index e9101cdd40..d46aed8988 100644 --- a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts @@ -22,7 +22,7 @@ export class DateTimeSelectComponent implements OnInit { @Output() onChangeAsIso = new EventEmitter(); - dateTime: any; // Used internally on internal input + stringVersion: any; // Used internally on internal input timeModel: NgbTimeStruct; dateModel: NgbDateStruct; @@ -59,21 +59,21 @@ export class DateTimeSelectComponent implements OnInit { } modelChanged(event) { - let newDate: any; + let newDate: Moment; - if (event) { - newDate = Moment(new Date(this.dateTime)); + if (event) { // if the change came from the input field + newDate = this.format.momentizeDateTimeString(this.stringVersion); } else { - newDate = new Date(this.dateModel.year, this.dateModel.month, this.dateModel.day, - this.timeModel.hour, this.timeModel.minute, this.timeModel.second); + newDate = Moment(new Date(this.dateModel.year, (this.dateModel.month - 1), this.dateModel.day, + this.timeModel.hour, this.timeModel.minute, this.timeModel.second)); } if (newDate && !isNaN(newDate)) { console.log('newDate'); // Set component view value - this.dateTime = this.format.transform({value: newDate, datatype: 'string', datePlusTime: true}); + this.stringVersion = this.format.transform({value: newDate, datatype: 'timestamp', datePlusTime: true}); // Update form passed in view value - this.onChangeAsIso.emit(Moment(newDate).toISOString); + this.onChangeAsIso.emit(newDate.toISOString()); } } 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 2331740573..beaf6a76cb 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 @@ -47,6 +47,8 @@ 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 f78ead37bb..fdb880ab17 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 @@ -86,6 +86,9 @@ export class FmRecordEditorComponent mode: 'create' | 'update' | 'view' = 'create'; recId: any; + // Show datetime fields in this particular timezone + timezone: string; + // IDL record we are editing // TODO: allow this to be update in real time by the caller? record: IdlObject; @@ -111,7 +114,7 @@ export class FmRecordEditorComponent @Input() requiredFieldsList: string[] = []; @Input() requiredFields: string; // comma-separated string version - // list of timezone fields that should display with a timepicker + // list of timestamp fields that should display with a timepicker @Input() datetimeFieldsList: string[] = []; @Input() datetimeFields: string; // comma-separated string version @@ -525,4 +528,3 @@ export class FmRecordEditorComponent } } - diff --git a/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.html b/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.html index 7b48afa97c..5d4aebf87d 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.html +++ b/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.html @@ -8,8 +8,8 @@ - - + + @@ -20,17 +20,18 @@ - - + + - + + diff --git a/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.ts b/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.ts index 6ab727f296..af5b88e89a 100644 --- a/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/booking/reservations-grid.component.ts @@ -15,6 +15,7 @@ import {ToastService} from '@eg/share/toast/toast.service'; import {Router, ActivatedRoute, ParamMap} from '@angular/router'; import {NetService} from '@eg/core/net.service'; import {NoTimezoneSetComponent} from './no-timezone-set.component'; +import {OrgService} from '@eg/core/org.service'; import {PatronService} from '@eg/staff/share/patron.service'; import * as Moment from 'moment-timezone'; @@ -59,13 +60,14 @@ export class ReservationsGridComponent implements OnInit { returnNotAppropriate: (rows: IdlObject[]) => boolean; constructor( + private auth: AuthService, + private format: FormatService, + private pcrud: PcrudService, private route: ActivatedRoute, private router: Router, private toast: ToastService, - private pcrud: PcrudService, - private auth: AuthService, - private format: FormatService, private net: NetService, + private org: OrgService, private patronService: PatronService ) { @@ -108,7 +110,9 @@ export class ReservationsGridComponent implements OnInit { flesh_fields: {'bresv' : [ 'usr', 'capture_staff', 'target_resource', 'target_resource_type', 'current_resource', 'request_lib', 'pickup_lib' ], 'au': ['card'] } - }); + }).pipe(tap((row) => { + this.org.settings('lib.timezone', row['pickup_lib']()).then((tz) => {row['timezone'] = tz['lib.timezone']}); + })); }; this.editDialog.mode = 'update'; @@ -187,6 +191,7 @@ export class ReservationsGridComponent implements OnInit { showEditDialog(idlThing: IdlObject) { this.editDialog.recId = idlThing.id(); + this.editDialog.timezone = idlThing['timezone']; return this.editDialog.open({size: 'lg'}).then( ok => { this.toast.success('Reservation successfully updated'); // TODO: needs i18n, pluralization