@anglr/datetime 5.0.0-beta.20221020044622 → 5.0.0-beta.20221020100553
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +7 -1
- package/es2015/src/legacy/picker/components/dayPicker/dayPicker.component.js +2 -1
- package/es2015/src/legacy/picker/components/dayPicker/dayPicker.component.js.map +1 -1
- package/es2015/src/legacy/picker/components/monthPicker/monthPicker.component.js +2 -1
- package/es2015/src/legacy/picker/components/monthPicker/monthPicker.component.js.map +1 -1
- package/es2015/src/legacy/picker/components/yearPicker/yearPicker.component.js +2 -1
- package/es2015/src/legacy/picker/components/yearPicker/yearPicker.component.js.map +1 -1
- package/es2015/src/legacy/picker/misc/datetimePicker.interface.js.map +1 -1
- package/es2015/src/misc/types.js.map +1 -1
- package/es2015/src/misc/utils.js.map +1 -1
- package/es2015/src/misc/validators.js.map +1 -1
- package/es2015/src/modules/dateTime/directives/dateTime/dateTime.directive.js +12 -0
- package/es2015/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/components/dateTimePeriodPickerBase.js +87 -0
- package/es2015/src/modules/dateTimePicker/components/dateTimePeriodPickerBase.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js +100 -14
- package/es2015/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.js +120 -29
- package/es2015/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.js +69 -15
- package/es2015/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.interface.js.map +1 -1
- package/es2015/src/modules/dateTimePicker/interfaces/dateTimePicker/dateTimePicker.interface.js.map +1 -1
- package/es2020/src/legacy/picker/components/dayPicker/dayPicker.component.js +2 -1
- package/es2020/src/legacy/picker/components/dayPicker/dayPicker.component.js.map +1 -1
- package/es2020/src/legacy/picker/components/monthPicker/monthPicker.component.js +2 -1
- package/es2020/src/legacy/picker/components/monthPicker/monthPicker.component.js.map +1 -1
- package/es2020/src/legacy/picker/components/yearPicker/yearPicker.component.js +2 -1
- package/es2020/src/legacy/picker/components/yearPicker/yearPicker.component.js.map +1 -1
- package/es2020/src/legacy/picker/misc/datetimePicker.interface.js.map +1 -1
- package/es2020/src/misc/types.js.map +1 -1
- package/es2020/src/misc/utils.js.map +1 -1
- package/es2020/src/misc/validators.js.map +1 -1
- package/es2020/src/modules/dateTime/directives/dateTime/dateTime.directive.js +12 -0
- package/es2020/src/modules/dateTime/directives/dateTime/dateTime.directive.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/components/dateTimePeriodPickerBase.js +84 -0
- package/es2020/src/modules/dateTimePicker/components/dateTimePeriodPickerBase.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js +97 -13
- package/es2020/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.js +118 -28
- package/es2020/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.js +65 -11
- package/es2020/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.interface.js.map +1 -1
- package/es2020/src/modules/dateTimePicker/interfaces/dateTimePicker/dateTimePicker.interface.js.map +1 -1
- package/package.json +1 -1
- package/src/legacy/picker/components/dayPicker/dayPicker.component.d.ts.map +1 -1
- package/src/legacy/picker/components/monthPicker/monthPicker.component.d.ts.map +1 -1
- package/src/legacy/picker/components/yearPicker/yearPicker.component.d.ts.map +1 -1
- package/src/legacy/picker/misc/datetimePicker.interface.d.ts +4 -0
- package/src/legacy/picker/misc/datetimePicker.interface.d.ts.map +1 -1
- package/src/misc/types.d.ts +2 -2
- package/src/misc/types.d.ts.map +1 -1
- package/src/misc/utils.d.ts +2 -2
- package/src/misc/utils.d.ts.map +1 -1
- package/src/misc/validators.d.ts +5 -5
- package/src/misc/validators.d.ts.map +1 -1
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts +9 -1
- package/src/modules/dateTime/directives/dateTime/dateTime.directive.d.ts.map +1 -1
- package/src/modules/dateTimePicker/components/dateTimePeriodPickerBase.d.ts +48 -5
- package/src/modules/dateTimePicker/components/dateTimePeriodPickerBase.d.ts.map +1 -1
- package/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.d.ts +26 -6
- package/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.d.ts.map +1 -1
- package/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.d.ts +33 -11
- package/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.d.ts.map +1 -1
- package/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.html +5 -5
- package/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.d.ts +21 -6
- package/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.directive.d.ts.map +1 -1
- package/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.interface.d.ts +8 -0
- package/src/modules/dateTimePicker/directives/dateTimePicker/dateTimePicker.interface.d.ts.map +1 -1
- package/src/modules/dateTimePicker/interfaces/dateTimePicker/dateTimePicker.interface.d.ts +2 -1
- package/src/modules/dateTimePicker/interfaces/dateTimePicker/dateTimePicker.interface.d.ts.map +1 -1
- package/styles/components/_date-time-picker.scss +129 -0
- package/version.bak +1 -1
- package/src/modules/dateTimePicker/components/dayPicker/dayPicker.component.css +0 -27
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","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AI,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI;YAC7B,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,IAAI;SAC9B,CAAC;KACL;IAED,uBAAuB;IACvB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;QACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACnF;IAED,kBAAkB;IAClB,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,EACxD;QACI,+CAA+C;QAC/C,IAAG,OAAO,CAAC,YAAY,CAAC,EACxB;YACI,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC5E;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;KACrC;IAED,IAAG,cAAc,IAAI,mBAAmB,CAAC,aAAa,EACtD;QACI,KAAK,CAAC,aAAa,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAkB,KAAc;IAE3D,OAAO,UAAU,CAAC,KAAK,CAAC;QACjB,MAAM,CAAgB,MAAM,CAAC,IAAI,KAAK;QACtC,MAAM,CAAgB,IAAI,CAAC,IAAI,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAQ,KAAqD;IAE/F,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;QACI,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;KAC7F;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport {DateApi, DateApiObject} from '../services';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from './types';\n\n/**\n * Parses date time input output value\n * @param value - Value to be parsed\n * @param dateApi - Date api used for obtaining result\n * @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function parseDateTime<TDate = unknown>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): DateTimeObjectValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //format is specified\n if(isPresent(dateTimeFormat))\n {\n //string format required, but format string was not provided\n if(dateTimeFormat == DateTimeValueFormat.FormattedString && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n //requirested format is different\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: requested datetime format is not range, but value is range!');\n }\n\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n ];\n }\n\n //value should be date instance, or number, or string, but it is not\n if(dateTimeFormat != DateTimeValueFormat.DateInstance &&\n dateTimeFormat != DateTimeValueFormat.FormattedString &&\n dateTimeFormat != DateTimeValueFormat.UnixTimestamp)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n}\n\n/**\n * Formats value into specified format of date time\n * @param value - Value that should be converted to input output date time value\n * @param dateTimeFormat - Date time format type\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null): DateTimeInputOutputValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //value is range\n if(Array.isArray(value))\n {\n //range is expected\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is array of values, but format is not range!');\n }\n\n return {\n from: value[0]?.value ?? null,\n to: value[1]?.value ?? null,\n };\n }\n\n //range is not expected\n if(dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is not array of values, but format is range!');\n }\n\n //string date time\n if(dateTimeFormat == DateTimeValueFormat.FormattedString)\n {\n //string format is missing for string date time\n if(isBlank(stringFormat))\n {\n throw new Error('DateTime: missing string format for string date time!');\n }\n\n return value.format(stringFormat);\n }\n\n if(dateTimeFormat == DateTimeValueFormat.UnixTimestamp)\n {\n value.unixTimestamp();\n }\n\n return value.value;\n}\n\n/**\n * Tests whether value is `DateTimeValue`\n * @param value - Value that is tested\n */\nexport function isDateTimeValue<TDate = unknown>(value: unknown): value is DateTimeValue<TDate>\n{\n return isJsObject(value) &&\n nameof<DateTimeValue>('from') in value &&\n nameof<DateTimeValue>('to') in value;\n}\n\n/**\n * Gets single date time value, use in places where ranged date time can not be used\n * @param value - Value to be examined\n */\nexport function getSingleDateTimeValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null):
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/misc/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,SAAS,EA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AC,EAAE,KAAK,IAAI,IAAI;SAC9B,CAAC;KACL;IAED,uBAAuB;IACvB,IAAG,cAAc,IAAI,mBAAmB,CAAC,oBAAoB,EAC7D;QACI,MAAM,IAAI,KAAK,CAAC,8DAA8D,CAAC,CAAC;KACnF;IAED,kBAAkB;IAClB,IAAG,cAAc,IAAI,mBAAmB,CAAC,eAAe,EACxD;QACI,+CAA+C;QAC/C,IAAG,OAAO,CAAC,YAAY,CAAC,EACxB;YACI,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;SAC5E;QAED,OAAO,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;KACrC;IAED,IAAG,cAAc,IAAI,mBAAmB,CAAC,aAAa,EACtD;QACI,KAAK,CAAC,aAAa,EAAE,CAAC;KACzB;IAED,OAAO,KAAK,CAAC,KAAK,CAAC;AACvB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAkB,KAAc;IAE3D,OAAO,UAAU,CAAC,KAAK,CAAC;QACjB,MAAM,CAAgB,MAAM,CAAC,IAAI,KAAK;QACtC,MAAM,CAAgB,IAAI,CAAC,IAAI,KAAK,CAAC;AAChD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAQ,KAAqD;IAE/F,IAAG,eAAe,CAAC,KAAK,CAAC,EACzB;QACI,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;KAC7F;IAED,OAAO,KAAK,CAAC;AACjB,CAAC","sourcesContent":["import {isBlank, isJsObject, isPresent, isString, nameof} from '@jscrpt/common';\n\nimport {DateTimeValue} from '../interfaces';\nimport {DateApi, DateApiObject, DateValue} from '../services';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue, DateTimeObjectValue} from './types';\n\n/**\n * Parses date time input output value\n * @param value - Value to be parsed\n * @param dateApi - Date api used for obtaining result\n * @param dateTimeFormat - Date time format type, optional, if not specified autodetection of format will be used\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function parseDateTime<TDate = unknown>(value: DateTimeInputOutputValue<TDate>|undefined|null,\n dateApi: DateApi<TDate>,\n dateTimeFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): DateTimeObjectValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //format is specified\n if(isPresent(dateTimeFormat))\n {\n //string format required, but format string was not provided\n if(dateTimeFormat == DateTimeValueFormat.FormattedString && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n //requirested format is different\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: requested datetime format is not range, but value is range!');\n }\n\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n ];\n }\n\n //value should be date instance, or number, or string, but it is not\n if(dateTimeFormat != DateTimeValueFormat.DateInstance &&\n dateTimeFormat != DateTimeValueFormat.FormattedString &&\n dateTimeFormat != DateTimeValueFormat.UnixTimestamp)\n {\n throw new Error('DateTime: unable to get date time value, should be date instance, or string, or number!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n }\n\n //value is range\n if(isDateTimeValue(value))\n {\n return [\n isBlank(value.from) ? null : parseDateTime(value.from, dateApi, DateTimeValueFormat.DateInstance, null) as DateApiObject<TDate>,\n isBlank(value.to) ? null : parseDateTime(value.to, dateApi, DateTimeValueFormat.DateInstance , null) as DateApiObject<TDate>,\n ];\n }\n\n //string format, but format string was not provided\n if(isString(value) && isBlank(stringFormat))\n {\n throw new Error('DateTime: unable to parse string date, because format is missing!');\n }\n\n //value is string, instance of date or unix timestamp\n return dateApi.getValue(value, stringFormat ?? undefined);\n}\n\n/**\n * Formats value into specified format of date time\n * @param value - Value that should be converted to input output date time value\n * @param dateTimeFormat - Date time format type\n * @param stringFormat - String format for parsing string dates, required only for string dates\n */\nexport function formatDateTime<TDate = unknown>(value: DateTimeObjectValue<TDate>|undefined|null,\n dateTimeFormat: DateTimeValueFormat,\n stringFormat: string|undefined|null): DateTimeInputOutputValue<TDate>|undefined|null\n{\n if(isBlank(value))\n {\n return value;\n }\n\n //value is range\n if(Array.isArray(value))\n {\n //range is expected\n if(dateTimeFormat != DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is array of values, but format is not range!');\n }\n\n return {\n from: value[0]?.value ?? null,\n to: value[1]?.value ?? null,\n };\n }\n\n //range is not expected\n if(dateTimeFormat == DateTimeValueFormat.RangeOfDateInstances)\n {\n throw new Error('DateTime: value is not array of values, but format is range!');\n }\n\n //string date time\n if(dateTimeFormat == DateTimeValueFormat.FormattedString)\n {\n //string format is missing for string date time\n if(isBlank(stringFormat))\n {\n throw new Error('DateTime: missing string format for string date time!');\n }\n\n return value.format(stringFormat);\n }\n\n if(dateTimeFormat == DateTimeValueFormat.UnixTimestamp)\n {\n value.unixTimestamp();\n }\n\n return value.value;\n}\n\n/**\n * Tests whether value is `DateTimeValue`\n * @param value - Value that is tested\n */\nexport function isDateTimeValue<TDate = unknown>(value: unknown): value is DateTimeValue<TDate>\n{\n return isJsObject(value) &&\n nameof<DateTimeValue>('from') in value &&\n nameof<DateTimeValue>('to') in value;\n}\n\n/**\n * Gets single date time value, use in places where ranged date time can not be used\n * @param value - Value to be examined\n */\nexport function getSingleDateTimeValue<TDate>(value: DateTimeInputOutputValue<TDate>|undefined|null): DateValue|TDate|null|undefined\n{\n if(isDateTimeValue(value))\n {\n throw new Error('DateTime: Unable to apply ranged date time input as value restriction!');\n }\n\n return value;\n}"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/misc/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,qBA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AAK;iBAC/B,CAAC;aACL;YAED,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import {AbstractControl, ValidationErrors, ValidatorFn} from '@angular/forms';\nimport {ModelPropertyMetadata, ValidatorFnFactory} from '@anglr/common/forms';\nimport {isBlank, isNumber, isString} from '@jscrpt/common';\n\nimport {DateApi} from '../services';\nimport {DateTimeValueObject} from '../interfaces/dateTime/datetime.interface';\nimport {getSingleDateTimeValue, parseDateTime} from './utils';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue} from './types';\nimport {DateTimeBase} from '../modules/dateTime/directives/dateTimeBase';\nimport {DATE_API} from './tokens';\n\n//TODO: add decorators for min and max date time\n\n/**\n * Validations arguments for date time validators for model based forms\n */\nexport interface DateTimeValidationArgs<TDate = unknown>\n{\n /**\n * Format of validated value\n */\n valueFormat?: DateTimeValueFormat|null;\n\n /**\n * Format of string value\n */\n stringFormat?: string|null;\n\n /**\n * Max allowed value\n */\n maxValue?: string|number|TDate|Date|DateTimeBase<TDate>;\n\n /**\n * Min allowed value\n */\n minValue?: string|number|TDate|Date|DateTimeBase<TDate>;\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime\n * @param dateApi - Date api used for parsing date time\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value))\n {\n return null;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n if(!Array.isArray(parsedValue))\n {\n if(!parsedValue.isValid())\n {\n return {\n 'datetime': stringFormat\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Factory function that creates validator function factory\n * @param args - Static arguments for date time validator\n */\nexport function dateTimeModelValidatorFactory<TDate = unknown>(args: DateTimeValidationArgs<TDate>): ValidatorFnFactory<DateTimeValidationArgs<TDate>>\n{\n return new ValidatorFnFactory<DateTimeValidationArgs<TDate>>(args =>\n {\n const dateApi = args.injector?.get(DATE_API, null);\n\n if(!dateApi)\n {\n throw new Error('DateTime: missing DateApi! Please provide one.');\n }\n\n return datetimeValidator(dateApi, args.valueFormat, args.stringFormat);\n }, args);\n}\n\n/**\n * Sets date time validator, with default formats\n */\nexport function DateTime(): PropertyDecorator\n/**\n * Sets date time validator, with default string format\n * @param valueFormat - Format of validated value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat): PropertyDecorator\n/**\n * Sets date time validator, with default value format\n * @param stringFormat - Format of string value\n */\nexport function DateTime(stringFormat: string|null): PropertyDecorator\n/**\n * Sets date time validator\n * @param valueFormat - Format of validated value\n * @param stringFormat - Format of string value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat, stringFormat: string): PropertyDecorator\n/**\n * Sets date time validator to property on which is used\n */\nexport function DateTime(valueFormatOrStringFormat?: DateTimeValueFormat|string|null, stringFormat?: string|undefined|null): PropertyDecorator\n{\n let valueFormat: DateTimeValueFormat|undefined|null;\n\n if(isNumber(valueFormatOrStringFormat))\n {\n valueFormat = valueFormatOrStringFormat;\n }\n\n if(isString(valueFormatOrStringFormat))\n {\n stringFormat = valueFormatOrStringFormat;\n }\n\n return ModelPropertyMetadata(\n {\n validators: [dateTimeModelValidatorFactory(\n {\n stringFormat,\n valueFormat,\n })]\n });\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime max value\n * @param dateApi - Date api used for parsing date time\n * @param maxValue - Maximal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMaxValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n maxValue: string|number|TDate|Date|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(maxValue))\n {\n return null;\n }\n\n if(maxValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(maxValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n maxValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const maxDateTime = dateApi.getValue(maxValue as string|number|TDate, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isBefore(maxDateTime.value))\n {\n return {\n 'datetimemax': maxDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime min value\n * @param dateApi - Date api used for parsing date time\n * @param minValue - Minimal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMinValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n minValue: string|number|TDate|Date|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(minValue))\n {\n return null;\n }\n\n if(minValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(minValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n minValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const minDateTime = dateApi.getValue(minValue as string|number|TDate, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isAfter(minDateTime.value))\n {\n return {\n 'datetimemin': minDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Validations functions for datetime\n */\nexport class Validators\n{\n /**\n * Creates validator function that validates control if its value is valid datetime value\n * @param datetime - Object storing information about datetime value\n */\n public static datetime<TDate = any>(datetime: DateTimeValueObject<TDate>): ValidatorFn\n {\n return (): ValidationErrors|null =>\n {\n if(!datetime.valid)\n {\n return {\n 'datetime': true\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of minimal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static minDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.minValue &&\n dateApi.getValue(control.value).isBefore(datetime.minValue))\n {\n return {\n 'minDatetime': datetime.minValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of maximal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static maxDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.maxValue &&\n dateApi.getValue(control.value).isAfter(datetime.maxValue))\n {\n return {\n 'maxDatetime': datetime.maxValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n}"]}
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../../../src/misc/validators.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,qBAAqB,EAAE,kBAAkB,EAAC,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AAI3D,OAAO,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import {ModelPropertyMetadata, ValidatorFnFactory} from '@anglr/common/forms';\nimport {isBlank, isNumber, isString} from '@jscrpt/common';\n\nimport {DateApi, DateValue} from '../services';\nimport {DateTimeValueObject} from '../interfaces/dateTime/datetime.interface';\nimport {getSingleDateTimeValue, parseDateTime} from './utils';\nimport {DateTimeValueFormat} from './enums';\nimport {DateTimeInputOutputValue} from './types';\nimport {DateTimeBase} from '../modules/dateTime/directives/dateTimeBase';\nimport {DATE_API} from './tokens';\n\n//TODO: add decorators for min and max date time\n\n/**\n * Validations arguments for date time validators for model based forms\n */\nexport interface DateTimeValidationArgs<TDate = unknown>\n{\n /**\n * Format of validated value\n */\n valueFormat?: DateTimeValueFormat|null;\n\n /**\n * Format of string value\n */\n stringFormat?: string|null;\n\n /**\n * Max allowed value\n */\n maxValue?: DateValue|TDate|DateTimeBase<TDate>;\n\n /**\n * Min allowed value\n */\n minValue?: DateValue|TDate|DateTimeBase<TDate>;\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime\n * @param dateApi - Date api used for parsing date time\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value))\n {\n return null;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n if(!Array.isArray(parsedValue))\n {\n if(!parsedValue.isValid())\n {\n return {\n 'datetime': stringFormat\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Factory function that creates validator function factory\n * @param args - Static arguments for date time validator\n */\nexport function dateTimeModelValidatorFactory<TDate = unknown>(args: DateTimeValidationArgs<TDate>): ValidatorFnFactory<DateTimeValidationArgs<TDate>>\n{\n return new ValidatorFnFactory<DateTimeValidationArgs<TDate>>(args =>\n {\n const dateApi = args.injector?.get(DATE_API, null);\n\n if(!dateApi)\n {\n throw new Error('DateTime: missing DateApi! Please provide one.');\n }\n\n return datetimeValidator(dateApi, args.valueFormat, args.stringFormat);\n }, args);\n}\n\n/**\n * Sets date time validator, with default formats\n */\nexport function DateTime(): PropertyDecorator\n/**\n * Sets date time validator, with default string format\n * @param valueFormat - Format of validated value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat): PropertyDecorator\n/**\n * Sets date time validator, with default value format\n * @param stringFormat - Format of string value\n */\nexport function DateTime(stringFormat: string|null): PropertyDecorator\n/**\n * Sets date time validator\n * @param valueFormat - Format of validated value\n * @param stringFormat - Format of string value\n */\nexport function DateTime(valueFormat: DateTimeValueFormat, stringFormat: string): PropertyDecorator\n/**\n * Sets date time validator to property on which is used\n */\nexport function DateTime(valueFormatOrStringFormat?: DateTimeValueFormat|string|null, stringFormat?: string|undefined|null): PropertyDecorator\n{\n let valueFormat: DateTimeValueFormat|undefined|null;\n\n if(isNumber(valueFormatOrStringFormat))\n {\n valueFormat = valueFormatOrStringFormat;\n }\n\n if(isString(valueFormatOrStringFormat))\n {\n stringFormat = valueFormatOrStringFormat;\n }\n\n return ModelPropertyMetadata(\n {\n validators: [dateTimeModelValidatorFactory(\n {\n stringFormat,\n valueFormat,\n })]\n });\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime max value\n * @param dateApi - Date api used for parsing date time\n * @param maxValue - Maximal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMaxValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n maxValue: DateValue|TDate|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(maxValue))\n {\n return null;\n }\n\n if(maxValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(maxValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n maxValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const maxDateTime = dateApi.getValue(maxValue, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isBefore(maxDateTime.value))\n {\n return {\n 'datetimemax': maxDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Date time validator factory function, creates validator for checking validity of datetime min value\n * @param dateApi - Date api used for parsing date time\n * @param minValue - Minimal date time value that should be used for validation against\n * @param valueFormat - Optional required format\n * @param stringFormat - Optional string format of value\n */\nexport function datetimeMinValidator<TDate = unknown>(dateApi: DateApi<TDate>,\n minValue: DateValue|TDate|DateTimeBase<TDate>|undefined|null,\n valueFormat: DateTimeValueFormat|undefined|null,\n stringFormat: string|undefined|null,): ValidatorFn\n{\n return (control: AbstractControl<DateTimeInputOutputValue<TDate>>): ValidationErrors|null =>\n {\n if(isBlank(control.value) || isBlank(minValue))\n {\n return null;\n }\n\n if(minValue instanceof DateTimeBase<TDate>)\n {\n const value = getSingleDateTimeValue(minValue.value);\n\n //no validation\n if(isBlank(value))\n {\n return null;\n }\n\n minValue = value;\n }\n\n const parsedValue = parseDateTime(control.value, dateApi, valueFormat, stringFormat);\n\n if(!parsedValue)\n {\n return null;\n }\n\n const minDateTime = dateApi.getValue(minValue, stringFormat ?? undefined);\n\n if(!Array.isArray(parsedValue))\n {\n if(parsedValue.isValid() && !parsedValue.isAfter(minDateTime.value))\n {\n return {\n 'datetimemin': minDateTime.value\n };\n }\n }\n else\n {\n //TODO: support for ranges\n }\n\n return null;\n };\n}\n\n/**\n * Validations functions for datetime\n */\nexport class Validators\n{\n /**\n * Creates validator function that validates control if its value is valid datetime value\n * @param datetime - Object storing information about datetime value\n */\n public static datetime<TDate = any>(datetime: DateTimeValueObject<TDate>): ValidatorFn\n {\n return (): ValidationErrors|null =>\n {\n if(!datetime.valid)\n {\n return {\n 'datetime': true\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of minimal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static minDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.minValue &&\n dateApi.getValue(control.value).isBefore(datetime.minValue))\n {\n return {\n 'minDatetime': datetime.minValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n\n /**\n * Creates validator function that validates control if its value is withing range of maximal datetime value\n * @param datetime - Object storing information about datetime value\n * @param dateApi - Date api object\n */\n public static maxDatetime<TDate = any>(datetime: DateTimeValueObject<TDate>, dateApi: DateApi<TDate>): ValidatorFn\n {\n return (control: AbstractControl): ValidationErrors|null =>\n {\n if(!!control.value &&\n datetime.valid &&\n datetime.maxValue &&\n dateApi.getValue(control.value).isAfter(datetime.maxValue))\n {\n return {\n 'maxDatetime': datetime.maxValue,\n 'actualValue': control.value\n };\n }\n\n return null;\n };\n }\n}"]}
|
|
@@ -161,6 +161,7 @@ export class DateTimeDirective {
|
|
|
161
161
|
minDateSet(value) {
|
|
162
162
|
this.ɵMinDateTime = value;
|
|
163
163
|
this.minDateTimeChangesSubject.next();
|
|
164
|
+
this.onMinDateTimeChange();
|
|
164
165
|
}
|
|
165
166
|
/**
|
|
166
167
|
* Sets max date time and notifies about changes
|
|
@@ -169,6 +170,7 @@ export class DateTimeDirective {
|
|
|
169
170
|
maxDateSet(value) {
|
|
170
171
|
this.ɵMaxDateTime = value;
|
|
171
172
|
this.maxDateTimeChangesSubject.next();
|
|
173
|
+
this.onMaxDateTimeChange();
|
|
172
174
|
}
|
|
173
175
|
/**
|
|
174
176
|
* Sets min or max date time value
|
|
@@ -184,6 +186,16 @@ export class DateTimeDirective {
|
|
|
184
186
|
setter(null);
|
|
185
187
|
}
|
|
186
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Called whenever max date time restriction changes
|
|
191
|
+
*/
|
|
192
|
+
onMaxDateTimeChange() {
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Called whenever min date time restriction changes
|
|
196
|
+
*/
|
|
197
|
+
onMinDateTimeChange() {
|
|
198
|
+
}
|
|
187
199
|
}
|
|
188
200
|
DateTimeDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimeDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
189
201
|
DateTimeDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.2.6", type: DateTimeDirective, selector: "[dateTime]", inputs: { valueFormat: "valueFormat", format: "format", customFormat: "customFormat", maxDateTime: "maxDateTime", minDateTime: "minDateTime" }, ngImport: i0 });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateTime.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/dateTime/directives/dateTime/dateTime.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAY,MAAM,eAAe,CAAC;AAClE,OAAO,EAAU,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAC,MAAM,gBAAgB,CAAC;AACpE,OAAO,EAAa,OAAO,EAAe,MAAM,MAAM,CAAC;AAGvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAE,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAElE,OAAO,EAAC,sBAAsB,EAAC,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;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;IAED,uEAAuE;IAEvE;;;OAGG;IAEO,UAAU,CAAC,KAA2B;QAE5C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED;;;OAGG;IAEO,UAAU,CAAC,KAA2B;QAE5C,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACO,cAAc,CAAC,KAA+B,EAAE,MAAqC;QAE3F,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAE5D,IAAG,GAAG,CAAC,OAAO,EAAE,EAChB;YACI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACrB;aAED;YACI,MAAM,CAAC,IAAI,CAAC,CAAC;SAChB;IACL,CAAC;;8GAnRQ,iBAAiB;kGAAjB,iBAAiB;;IAgPzB,QAAQ;;;;mDAKR;;IAMA,QAAQ;;;;mDAKR;2FAhQQ,iBAAiB;kBAJ7B,SAAS;mBACV;oBACI,QAAQ,EAAE,YAAY;iBACzB;8BA+Ec,WAAW;sBADrB,KAAK;gBAqBK,MAAM;sBADhB,KAAK;gBAeC,YAAY;sBADlB,KAAK;gBAOK,WAAW;sBADrB,KAAK;gBAsDK,WAAW;sBADrB,KAAK;gBAuEI,UAAU,MAWV,UAAU","sourcesContent":["import {Directive, inject, Input, OnDestroy} from '@angular/core';\nimport {Action1, BindThis, isBlank, isString} from '@jscrpt/common';\nimport {Observable, Subject, Subscription} from 'rxjs';\n\nimport {FormatProvider} from '../../../../interfaces';\nimport {DateTimeValueFormat} from '../../../../misc/enums';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateTimeInputOutputValue} from '../../../../misc/types';\nimport {getSingleDateTimeValue} from '../../../../misc/utils';\nimport {DateApi, DateValue} from '../../../../services';\nimport {DateTimeBase} from '../dateTimeBase';\n\n/**\n * Directive that holds shared data for date time, like formats, restrictions\n */\n@Directive(\n{\n selector: '[dateTime]'\n})\nexport class DateTimeDirective<TDate = unknown> implements OnDestroy\n{\n //######################### protected properties #########################\n\n /**\n * Subject used for emitting changes in max date time value\n */\n protected maxDateTimeChangesSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subject used for emitting changes in min date time value\n */\n protected minDateTimeChangesSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subscription for max date instance value changes\n */\n protected maxDateInstanceChange: Subscription|undefined|null;\n\n /**\n * Subscription for min date instance value changes\n */\n protected minDateInstanceChange: Subscription|undefined|null;\n\n /**\n * Max allowed value of date time\n */\n protected ɵMaxDateTime: TDate|undefined|null;\n\n /**\n * Min allowed value of date time\n */\n protected ɵMinDateTime: TDate|undefined|null;\n\n /**\n * Date time value format which is being worked with in this date time\n */\n protected ɵValueFormat: DateTimeValueFormat = DateTimeValueFormat.DateInstance;\n\n /**\n * Format of string representation of date\n */\n protected ɵFormat: keyof FormatProvider = 'date';\n\n /**\n * Date api instance, used for date time manipulation\n */\n protected dateApi: DateApi<TDate> = inject(DATE_API);\n\n /**\n * Provider for available formats\n */\n protected formatProvider: FormatProvider = inject(FORMAT_PROVIDER);\n\n //######################### public properties #########################\n\n /**\n * Occurs when there are changes in max date time value\n */\n public get maxDateTimeChanges(): Observable<void>\n {\n return this.maxDateTimeChangesSubject.asObservable();\n }\n\n /**\n * Occurs when there are changes in min date time value\n */\n public get minDateTimeChanges(): Observable<void>\n {\n return this.minDateTimeChangesSubject.asObservable();\n }\n\n //######################### public properties - inputs #########################\n\n /**\n * Gets or sets date time value format which is being worked with in this date time\n */\n @Input()\n public get valueFormat(): DateTimeValueFormat\n {\n return this.ɵValueFormat;\n }\n public set valueFormat(value: DateTimeValueFormat)\n {\n if(isString(value))\n {\n this.ɵValueFormat = DateTimeValueFormat[value] as unknown as DateTimeValueFormat;\n\n return;\n }\n\n this.ɵValueFormat = value;\n }\n\n /**\n * Gets or sets format of string representation of date\n */\n @Input()\n public get format(): keyof FormatProvider\n {\n return this.ɵFormat;\n }\n public set format(value: keyof FormatProvider)\n {\n this.ɵFormat = value;\n this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);\n }\n\n /**\n * Custom format string representation of date\n */\n @Input()\n public customFormat: string = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);\n\n /**\n * Gets or sets max allowed date for date time\n */\n @Input()\n public get maxDateTime(): TDate|undefined|null\n {\n return this.ɵMaxDateTime;\n }\n public set maxDateTime(value: TDate|undefined|null)\n {\n this.maxDateInstanceChange?.unsubscribe();\n this.maxDateInstanceChange = null;\n\n if(isBlank(value))\n {\n this.maxDateSet(value);\n\n return;\n }\n\n let val: DateTimeInputOutputValue<TDate> = value;\n\n if(value instanceof DateTimeBase<TDate>)\n {\n this.maxDateInstanceChange = value.valueChange.subscribe(() =>\n {\n const val = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(val))\n {\n this.maxDateSet(null);\n\n return;\n }\n\n this.setMinMaxValue(val, this.maxDateSet);\n });\n\n const v = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(v))\n {\n this.maxDateSet(null);\n\n return;\n }\n\n val = v;\n }\n \n this.setMinMaxValue(val, this.maxDateSet);\n }\n\n /**\n * Gets or sets min allowed date for date time\n */\n @Input()\n public get minDateTime(): TDate|undefined|null\n {\n return this.ɵMinDateTime;\n }\n public set minDateTime(value: TDate|undefined|null)\n {\n this.minDateInstanceChange?.unsubscribe();\n this.minDateInstanceChange = null;\n\n if(isBlank(value))\n {\n this.minDateSet(value);\n\n return;\n }\n\n let val: DateTimeInputOutputValue<TDate> = value;\n\n if(value instanceof DateTimeBase<TDate>)\n {\n this.minDateInstanceChange = value.valueChange.subscribe(() =>\n {\n const val = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(val))\n {\n this.minDateSet(null);\n\n return;\n }\n\n this.setMinMaxValue(val, this.minDateSet);\n });\n\n const v = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(v))\n {\n this.minDateSet(null);\n\n return;\n }\n\n val = v;\n }\n\n this.setMinMaxValue(val, this.minDateSet);\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.maxDateInstanceChange?.unsubscribe();\n this.maxDateInstanceChange = null;\n\n this.minDateInstanceChange?.unsubscribe();\n this.minDateInstanceChange = null;\n }\n\n //######################### protected methods #########################\n\n /**\n * Sets min date time and notifies about changes\n * @param value - Value to be set\n */\n @BindThis\n protected minDateSet(value: TDate|undefined|null): void\n {\n this.ɵMinDateTime = value;\n this.minDateTimeChangesSubject.next();\n }\n\n /**\n * Sets max date time and notifies about changes\n * @param value - Value to be set\n */\n @BindThis\n protected maxDateSet(value: TDate|undefined|null): void\n {\n this.ɵMaxDateTime = value;\n this.maxDateTimeChangesSubject.next();\n }\n\n /**\n * Sets min or max date time value\n * @param value - Value to be set\n * @param setter - Action used for setting value\n */\n protected setMinMaxValue(value: string|number|TDate|Date, setter: Action1<TDate|undefined|null>): void\n {\n const val = this.dateApi.getValue(value, this.customFormat);\n\n if(val.isValid())\n {\n setter(val.value);\n }\n else\n {\n setter(null);\n }\n }\n\n //######################### ng language server #########################\n \n /**\n * Custom input type for `valueFormat` input\n */\n public static ngAcceptInputType_valueFormat: keyof typeof DateTimeValueFormat|DateTimeValueFormat;\n\n /**\n * Custom input type for `maxDateTime` input\n */\n public static ngAcceptInputType_maxDateTime: DateValue|DateTimeBase;\n\n /**\n * Custom input type for `minDateTime` input\n */\n public static ngAcceptInputType_minDateTime: DateValue|DateTimeBase;\n}"]}
|
|
1
|
+
{"version":3,"file":"dateTime.directive.js","sourceRoot":"","sources":["../../../../../../src/modules/dateTime/directives/dateTime/dateTime.directive.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EA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2FAlQQ,iBAAiB;kBAJ7B,SAAS;mBACV;oBACI,QAAQ,EAAE,YAAY;iBACzB;8BA+Ec,WAAW;sBADrB,KAAK;gBAqBK,MAAM;sBADhB,KAAK;gBAeC,YAAY;sBADlB,KAAK;gBAOK,WAAW;sBADrB,KAAK;gBAsDK,WAAW;sBADrB,KAAK;gBAuEI,UAAU,MAYV,UAAU","sourcesContent":["import {Directive, inject, Input, OnDestroy} from '@angular/core';\nimport {Action1, BindThis, isBlank, isString} from '@jscrpt/common';\nimport {Observable, Subject, Subscription} from 'rxjs';\n\nimport {FormatProvider} from '../../../../interfaces';\nimport {DateTimeValueFormat} from '../../../../misc/enums';\nimport {DATE_API, FORMAT_PROVIDER} from '../../../../misc/tokens';\nimport {DateTimeInputOutputValue} from '../../../../misc/types';\nimport {getSingleDateTimeValue} from '../../../../misc/utils';\nimport {DateApi, DateValue} from '../../../../services';\nimport {DateTimeBase} from '../dateTimeBase';\n\n/**\n * Directive that holds shared data for date time, like formats, restrictions\n */\n@Directive(\n{\n selector: '[dateTime]'\n})\nexport class DateTimeDirective<TDate = unknown> implements OnDestroy\n{\n //######################### protected properties #########################\n\n /**\n * Subject used for emitting changes in max date time value\n */\n protected maxDateTimeChangesSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subject used for emitting changes in min date time value\n */\n protected minDateTimeChangesSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subscription for max date instance value changes\n */\n protected maxDateInstanceChange: Subscription|undefined|null;\n\n /**\n * Subscription for min date instance value changes\n */\n protected minDateInstanceChange: Subscription|undefined|null;\n\n /**\n * Max allowed value of date time\n */\n protected ɵMaxDateTime: TDate|undefined|null;\n\n /**\n * Min allowed value of date time\n */\n protected ɵMinDateTime: TDate|undefined|null;\n\n /**\n * Date time value format which is being worked with in this date time\n */\n protected ɵValueFormat: DateTimeValueFormat = DateTimeValueFormat.DateInstance;\n\n /**\n * Format of string representation of date\n */\n protected ɵFormat: keyof FormatProvider = 'date';\n\n /**\n * Date api instance, used for date time manipulation\n */\n protected dateApi: DateApi<TDate> = inject(DATE_API);\n\n /**\n * Provider for available formats\n */\n protected formatProvider: FormatProvider = inject(FORMAT_PROVIDER);\n\n //######################### public properties #########################\n\n /**\n * Occurs when there are changes in max date time value\n */\n public get maxDateTimeChanges(): Observable<void>\n {\n return this.maxDateTimeChangesSubject.asObservable();\n }\n\n /**\n * Occurs when there are changes in min date time value\n */\n public get minDateTimeChanges(): Observable<void>\n {\n return this.minDateTimeChangesSubject.asObservable();\n }\n\n //######################### public properties - inputs #########################\n\n /**\n * Gets or sets date time value format which is being worked with in this date time\n */\n @Input()\n public get valueFormat(): DateTimeValueFormat\n {\n return this.ɵValueFormat;\n }\n public set valueFormat(value: DateTimeValueFormat)\n {\n if(isString(value))\n {\n this.ɵValueFormat = DateTimeValueFormat[value] as unknown as DateTimeValueFormat;\n\n return;\n }\n\n this.ɵValueFormat = value;\n }\n\n /**\n * Gets or sets format of string representation of date\n */\n @Input()\n public get format(): keyof FormatProvider\n {\n return this.ɵFormat;\n }\n public set format(value: keyof FormatProvider)\n {\n this.ɵFormat = value;\n this.customFormat = this.dateApi.getFormat(this.formatProvider[value]);\n }\n\n /**\n * Custom format string representation of date\n */\n @Input()\n public customFormat: string = this.dateApi.getFormat(this.formatProvider[this.ɵFormat]);\n\n /**\n * Gets or sets max allowed date for date time\n */\n @Input()\n public get maxDateTime(): TDate|undefined|null\n {\n return this.ɵMaxDateTime;\n }\n public set maxDateTime(value: TDate|undefined|null)\n {\n this.maxDateInstanceChange?.unsubscribe();\n this.maxDateInstanceChange = null;\n\n if(isBlank(value))\n {\n this.maxDateSet(value);\n\n return;\n }\n\n let val: DateTimeInputOutputValue<TDate> = value;\n\n if(value instanceof DateTimeBase<TDate>)\n {\n this.maxDateInstanceChange = value.valueChange.subscribe(() =>\n {\n const val = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(val))\n {\n this.maxDateSet(null);\n\n return;\n }\n\n this.setMinMaxValue(val, this.maxDateSet);\n });\n\n const v = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(v))\n {\n this.maxDateSet(null);\n\n return;\n }\n\n val = v;\n }\n \n this.setMinMaxValue(val, this.maxDateSet);\n }\n\n /**\n * Gets or sets min allowed date for date time\n */\n @Input()\n public get minDateTime(): TDate|undefined|null\n {\n return this.ɵMinDateTime;\n }\n public set minDateTime(value: TDate|undefined|null)\n {\n this.minDateInstanceChange?.unsubscribe();\n this.minDateInstanceChange = null;\n\n if(isBlank(value))\n {\n this.minDateSet(value);\n\n return;\n }\n\n let val: DateTimeInputOutputValue<TDate> = value;\n\n if(value instanceof DateTimeBase<TDate>)\n {\n this.minDateInstanceChange = value.valueChange.subscribe(() =>\n {\n const val = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(val))\n {\n this.minDateSet(null);\n\n return;\n }\n\n this.setMinMaxValue(val, this.minDateSet);\n });\n\n const v = getSingleDateTimeValue<TDate>(value.value);\n\n if(isBlank(v))\n {\n this.minDateSet(null);\n\n return;\n }\n\n val = v;\n }\n\n this.setMinMaxValue(val, this.minDateSet);\n }\n\n //######################### public methods - implementation of OnDestroy #########################\n \n /**\n * Called when component is destroyed\n */\n public ngOnDestroy(): void\n {\n this.maxDateInstanceChange?.unsubscribe();\n this.maxDateInstanceChange = null;\n\n this.minDateInstanceChange?.unsubscribe();\n this.minDateInstanceChange = null;\n }\n\n //######################### protected methods #########################\n\n /**\n * Sets min date time and notifies about changes\n * @param value - Value to be set\n */\n @BindThis\n protected minDateSet(value: TDate|undefined|null): void\n {\n this.ɵMinDateTime = value;\n this.minDateTimeChangesSubject.next();\n this.onMinDateTimeChange();\n }\n\n /**\n * Sets max date time and notifies about changes\n * @param value - Value to be set\n */\n @BindThis\n protected maxDateSet(value: TDate|undefined|null): void\n {\n this.ɵMaxDateTime = value;\n this.maxDateTimeChangesSubject.next();\n this.onMaxDateTimeChange();\n }\n\n /**\n * Sets min or max date time value\n * @param value - Value to be set\n * @param setter - Action used for setting value\n */\n protected setMinMaxValue(value: DateValue|TDate, setter: Action1<TDate|undefined|null>): void\n {\n const val = this.dateApi.getValue(value, this.customFormat);\n\n if(val.isValid())\n {\n setter(val.value);\n }\n else\n {\n setter(null);\n }\n }\n\n /**\n * Called whenever max date time restriction changes\n */\n protected onMaxDateTimeChange(): void\n {\n }\n\n /**\n * Called whenever min date time restriction changes\n */\n protected onMinDateTimeChange(): void\n {\n }\n\n //######################### ng language server #########################\n \n /**\n * Custom input type for `valueFormat` input\n */\n public static ngAcceptInputType_valueFormat: keyof typeof DateTimeValueFormat|DateTimeValueFormat;\n\n /**\n * Custom input type for `maxDateTime` input\n */\n public static ngAcceptInputType_maxDateTime: DateValue|DateTimeBase;\n\n /**\n * Custom input type for `minDateTime` input\n */\n public static ngAcceptInputType_minDateTime: DateValue|DateTimeBase;\n}"]}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import { ChangeDetectorRef, inject } from '@angular/core';
|
|
1
2
|
import { Subject } from 'rxjs';
|
|
3
|
+
import { DATE_API } from '../../../misc/tokens';
|
|
2
4
|
/**
|
|
3
5
|
* Base abstract class for each date time period picker
|
|
4
6
|
*/
|
|
5
7
|
export class DateTimePeriodPickerBase {
|
|
6
8
|
constructor() {
|
|
7
9
|
//######################### protected properties #########################
|
|
10
|
+
/**
|
|
11
|
+
* Array of period data to be displayed
|
|
12
|
+
*/
|
|
13
|
+
this.periodData = [];
|
|
8
14
|
/**
|
|
9
15
|
* Subject used for emitting of value changes
|
|
10
16
|
*/
|
|
@@ -17,6 +23,14 @@ export class DateTimePeriodPickerBase {
|
|
|
17
23
|
* Subject used for scaling down
|
|
18
24
|
*/
|
|
19
25
|
this.scaleDownSubject = new Subject();
|
|
26
|
+
/**
|
|
27
|
+
* Change detector instance
|
|
28
|
+
*/
|
|
29
|
+
this.changeDetector = inject(ChangeDetectorRef);
|
|
30
|
+
/**
|
|
31
|
+
* Instance of date api for manipulation with date time
|
|
32
|
+
*/
|
|
33
|
+
this.dateApi = inject(DATE_API);
|
|
20
34
|
/**
|
|
21
35
|
* @inheritdoc
|
|
22
36
|
*/
|
|
@@ -26,6 +40,45 @@ export class DateTimePeriodPickerBase {
|
|
|
26
40
|
*/
|
|
27
41
|
this.canScaleDown = false;
|
|
28
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* @inheritdoc
|
|
45
|
+
*/
|
|
46
|
+
get display() {
|
|
47
|
+
return this.displayDate?.value;
|
|
48
|
+
}
|
|
49
|
+
set display(value) {
|
|
50
|
+
if (!value) {
|
|
51
|
+
this.displayDate = null;
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.displayDate = this.dateApi.getValue(value);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @inheritdoc
|
|
58
|
+
*/
|
|
59
|
+
get maxDate() {
|
|
60
|
+
return this.maxDateObj?.value;
|
|
61
|
+
}
|
|
62
|
+
set maxDate(value) {
|
|
63
|
+
if (!value) {
|
|
64
|
+
this.maxDateObj = null;
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.maxDateObj = this.dateApi.getValue(value);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @inheritdoc
|
|
71
|
+
*/
|
|
72
|
+
get minDate() {
|
|
73
|
+
return this.minDateObj?.value;
|
|
74
|
+
}
|
|
75
|
+
set minDate(value) {
|
|
76
|
+
if (!value) {
|
|
77
|
+
this.minDateObj = null;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this.minDateObj = this.dateApi.getValue(value);
|
|
81
|
+
}
|
|
29
82
|
/**
|
|
30
83
|
* @inheritdoc
|
|
31
84
|
*/
|
|
@@ -44,5 +97,36 @@ export class DateTimePeriodPickerBase {
|
|
|
44
97
|
get scaleDown() {
|
|
45
98
|
return this.scaleDownSubject.asObservable();
|
|
46
99
|
}
|
|
100
|
+
//######################### public methods - implementation of invalidatable #########################
|
|
101
|
+
/**
|
|
102
|
+
* @inheritdoc
|
|
103
|
+
*/
|
|
104
|
+
invalidateVisuals() {
|
|
105
|
+
this.onRender();
|
|
106
|
+
this.changeDetector.detectChanges();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Updates minimal and maximal value for picker
|
|
110
|
+
*/
|
|
111
|
+
updateMinMax() {
|
|
112
|
+
if (!this.periodData.length) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
//no min, no max
|
|
116
|
+
if (!this.minDateObj && !this.maxDateObj) {
|
|
117
|
+
this.periodData.forEach(itm => itm.disabled = false);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
let restAfter = false;
|
|
121
|
+
for (const period of this.periodData) {
|
|
122
|
+
if (this.minDateObj && this.minDateObj.isAfter(period.dateObj.value) && !this.isSamePeriod(this.minDateObj, period.dateObj.value)) {
|
|
123
|
+
period.disabled = true;
|
|
124
|
+
}
|
|
125
|
+
if (restAfter || (this.maxDateObj && this.maxDateObj.isBefore(period.dateObj.value) && !this.isSamePeriod(this.maxDateObj, period.dateObj.value))) {
|
|
126
|
+
restAfter = true;
|
|
127
|
+
period.disabled = true;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
47
131
|
}
|
|
48
132
|
//# sourceMappingURL=dateTimePeriodPickerBase.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateTimePeriodPickerBase.js","sourceRoot":"","sources":["../../../../../src/modules/dateTimePicker/components/dateTimePeriodPickerBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,OAAO,EAAC,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"dateTimePeriodPickerBase.js","sourceRoot":"","sources":["../../../../../src/modules/dateTimePicker/components/dateTimePeriodPickerBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,MAAM,EAAC,MAAM,eAAe,CAAC;AACxD,OAAO,EAAa,OAAO,EAAC,MAAM,MAAM,CAAC;AAGzC,OAAO,EAAC,QAAQ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,OAAO,CAAC,KAAK,CAAC,EAChI;gBACI,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;aAC1B;YAED,IAAG,SAAS,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAChJ;gBACI,SAAS,GAAG,IAAI,CAAC;gBACjB,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC;aAC1B;SACJ;IACL,CAAC;CACJ","sourcesContent":["import {ChangeDetectorRef, inject} from '@angular/core';\nimport {Observable, Subject} from 'rxjs';\n\nimport {PeriodData} from '../../../legacy/picker/interfaces';\nimport {DATE_API} from '../../../misc/tokens';\nimport {DateTimeObjectValue} from '../../../misc/types';\nimport {DateApi, DateApiObject} from '../../../services';\nimport {DateTimePicker} from '../interfaces';\n\n/**\n * Base abstract class for each date time period picker\n */\nexport abstract class DateTimePeriodPickerBase<TPeriod extends PeriodData<TDate>, TDate = unknown, TOptions = unknown> implements DateTimePicker<TDate, TOptions>\n{\n //######################### protected properties #########################\n\n /**\n * Array of period data to be displayed\n */\n protected periodData: TPeriod[] = [];\n\n /**\n * Subject used for emitting of value changes\n */\n protected valueChangeSubject: Subject<void> = new Subject<void>();\n\n /**\n * Subject used for scaling up\n */\n protected scaleUpSubject: Subject<TDate> = new Subject<TDate>();\n\n /**\n * Subject used for scaling down\n */\n protected scaleDownSubject: Subject<TDate> = new Subject<TDate>();\n\n /**\n * Date api instance for displayed date\n */\n protected displayDate: DateApiObject<TDate>|undefined|null;\n\n /**\n * Date api instance for max date\n */\n protected maxDateObj: DateApiObject<TDate>|undefined|null;\n\n /**\n * Date api instance for min date\n */\n protected minDateObj: DateApiObject<TDate>|undefined|null;\n\n /**\n * Change detector instance\n */\n protected changeDetector: ChangeDetectorRef = inject(ChangeDetectorRef);\n\n /**\n * Instance of date api for manipulation with date time\n */\n protected dateApi: DateApi<TDate> = inject(DATE_API);\n\n //######################### public properties - implementation of DateTimePicker #########################\n\n /**\n * @inheritdoc\n */\n public value: DateTimeObjectValue<TDate>|undefined|null;\n\n /**\n * @inheritdoc\n */\n public options: TOptions|undefined|null;\n\n /**\n * @inheritdoc\n */\n public get display(): TDate|undefined|null\n {\n return this.displayDate?.value;\n }\n public set display(value: TDate|undefined|null)\n {\n if(!value)\n {\n this.displayDate = null;\n\n return;\n }\n\n this.displayDate = this.dateApi.getValue(value);\n }\n\n /**\n * @inheritdoc\n */\n public get maxDate(): TDate|undefined|null\n {\n return this.maxDateObj?.value;\n }\n public set maxDate(value: TDate|undefined|null)\n {\n if(!value)\n {\n this.maxDateObj = null;\n\n return;\n }\n\n this.maxDateObj = this.dateApi.getValue(value);\n }\n\n /**\n * @inheritdoc\n */\n public get minDate(): TDate|undefined|null\n {\n return this.minDateObj?.value;\n }\n public set minDate(value: TDate|undefined|null)\n {\n if(!value)\n {\n this.minDateObj = null;\n\n return;\n }\n\n this.minDateObj = this.dateApi.getValue(value);\n }\n\n /**\n * @inheritdoc\n */\n public canScaleUp: boolean = false;\n\n /**\n * @inheritdoc\n */\n public canScaleDown: boolean = false;\n\n /**\n * @inheritdoc\n */\n public get valueChange(): Observable<void>\n {\n return this.valueChangeSubject.asObservable();\n }\n\n /**\n * @inheritdoc\n */\n public get scaleUp(): Observable<TDate>\n {\n return this.scaleUpSubject.asObservable();\n }\n\n /**\n * @inheritdoc\n */\n public get scaleDown(): Observable<TDate>\n {\n return this.scaleDownSubject.asObservable();\n }\n\n //######################### public methods - implementation of invalidatable #########################\n\n /**\n * @inheritdoc\n */\n public invalidateVisuals(): void\n {\n this.onRender();\n\n this.changeDetector.detectChanges();\n }\n\n //######################### protected methods #########################\n\n /**\n * Method that is being called to render changes\n */\n protected abstract onRender(): void;\n\n /**\n * Tests whether provided value is in same period target value\n * @param val - Tested value\n * @param target - Target value to be tested against\n */\n protected abstract isSamePeriod(val: DateApiObject<TDate>, target: TDate): boolean;\n\n /**\n * Updates minimal and maximal value for picker\n */\n protected updateMinMax(): void\n {\n if(!this.periodData.length)\n {\n return;\n }\n\n //no min, no max\n if(!this.minDateObj && !this.maxDateObj)\n {\n this.periodData.forEach(itm => itm.disabled = false);\n\n return;\n }\n\n let restAfter = false;\n\n for(const period of this.periodData)\n {\n if(this.minDateObj && this.minDateObj.isAfter(period.dateObj.value) && !this.isSamePeriod(this.minDateObj, period.dateObj.value))\n {\n period.disabled = true;\n }\n\n if(restAfter || (this.maxDateObj && this.maxDateObj.isBefore(period.dateObj.value) && !this.isSamePeriod(this.maxDateObj, period.dateObj.value)))\n {\n restAfter = true;\n period.disabled = true;\n }\n }\n }\n}"]}
|
package/es2020/src/modules/dateTimePicker/components/dateTimePicker/dateTimePicker.component.js
CHANGED
|
@@ -5,9 +5,11 @@ import { Subscription } from 'rxjs';
|
|
|
5
5
|
import { DATE_TIME_PICKER_OPTIONS } from '../../misc/tokens';
|
|
6
6
|
import { DayPickerSAComponent } from '../dayPicker/dayPicker.component';
|
|
7
7
|
import { formatDateTime, parseDateTime } from '../../../../misc/utils';
|
|
8
|
-
import { DateTimeValueFormat } from '../../../../misc/enums';
|
|
9
8
|
import { DateTimeDirective } from '../../../dateTime/directives';
|
|
9
|
+
import { DateValueProvider } from '../../../../services';
|
|
10
10
|
import * as i0 from "@angular/core";
|
|
11
|
+
import * as i1 from "../../../../services";
|
|
12
|
+
//TODO: use mixin for set internal
|
|
11
13
|
/**
|
|
12
14
|
* Text to be displayed when configuration, options are corrupted
|
|
13
15
|
*/
|
|
@@ -26,9 +28,10 @@ const defaultOptions = {
|
|
|
26
28
|
*/
|
|
27
29
|
export class DateTimePickerComponent extends DateTimeDirective {
|
|
28
30
|
//######################### constructor #########################
|
|
29
|
-
constructor(position, options) {
|
|
31
|
+
constructor(position, valueProvider, options) {
|
|
30
32
|
super();
|
|
31
33
|
this.position = position;
|
|
34
|
+
this.valueProvider = valueProvider;
|
|
32
35
|
//######################### public properties - outputs #########################
|
|
33
36
|
/**
|
|
34
37
|
* @inheritdoc
|
|
@@ -44,6 +47,18 @@ export class DateTimePickerComponent extends DateTimeDirective {
|
|
|
44
47
|
throw new Error(CORRUPTED_CONFIG_TEXT);
|
|
45
48
|
}
|
|
46
49
|
}
|
|
50
|
+
//######################### public properties - inputs #########################
|
|
51
|
+
/**
|
|
52
|
+
* @inheritdoc
|
|
53
|
+
*/
|
|
54
|
+
get value() {
|
|
55
|
+
return this.ɵValue;
|
|
56
|
+
}
|
|
57
|
+
set value(value) {
|
|
58
|
+
//accepts all available formats
|
|
59
|
+
this.setInternalValue(value);
|
|
60
|
+
this.ɵValue = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);
|
|
61
|
+
}
|
|
47
62
|
/**
|
|
48
63
|
* Options for date time picker
|
|
49
64
|
*/
|
|
@@ -56,18 +71,47 @@ export class DateTimePickerComponent extends DateTimeDirective {
|
|
|
56
71
|
this.ɵOptions.periodsDefinition = value.periodsDefinition;
|
|
57
72
|
}
|
|
58
73
|
}
|
|
74
|
+
//######################### public methods - implementation of OnInit #########################
|
|
75
|
+
/**
|
|
76
|
+
* Initialize component
|
|
77
|
+
*/
|
|
78
|
+
ngOnInit() {
|
|
79
|
+
//empty value show now
|
|
80
|
+
if (isBlank(this.value)) {
|
|
81
|
+
const now = this.dateApi.now();
|
|
82
|
+
this.showPicker(this.displayedPeriodType, now.value);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const val = (Array.isArray(this.internalValue) ? this.internalValue[0] : this.internalValue) ?? this.dateApi.now();
|
|
86
|
+
this.showPicker(this.displayedPeriodType, val.value);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
59
89
|
//######################### public methods - implementation of OnChanges #########################
|
|
60
90
|
/**
|
|
61
91
|
* Called when input value changes
|
|
62
92
|
*/
|
|
63
93
|
ngOnChanges(changes) {
|
|
94
|
+
if (!this.component) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const component = this.component.instance;
|
|
98
|
+
let invalidate = false;
|
|
99
|
+
if (nameof('maxDateTime') in changes) {
|
|
100
|
+
component.maxDate = this.maxDateTime;
|
|
101
|
+
invalidate = true;
|
|
102
|
+
}
|
|
103
|
+
if (nameof('minDateTime') in changes) {
|
|
104
|
+
component.minDate = this.minDateTime;
|
|
105
|
+
invalidate = true;
|
|
106
|
+
}
|
|
64
107
|
if (nameof('value') in changes) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
108
|
+
const val = (Array.isArray(this.internalValue) ? this.internalValue[0] : this.internalValue) ?? this.dateApi.now();
|
|
109
|
+
component.display = val.isValid() ? val.value : this.dateApi.now().value;
|
|
110
|
+
component.value = this.internalValue;
|
|
111
|
+
invalidate = true;
|
|
112
|
+
}
|
|
113
|
+
if (this.component && invalidate) {
|
|
114
|
+
this.component.instance.invalidateVisuals();
|
|
71
115
|
}
|
|
72
116
|
}
|
|
73
117
|
//######################### public methods - implementation of OnDestroy #########################
|
|
@@ -82,6 +126,38 @@ export class DateTimePickerComponent extends DateTimeDirective {
|
|
|
82
126
|
this.periodChangesSubscription = null;
|
|
83
127
|
}
|
|
84
128
|
//######################### protected methods #########################
|
|
129
|
+
/**
|
|
130
|
+
* Sets internal value and fix lowest time difference
|
|
131
|
+
* @param value - Value to be set
|
|
132
|
+
*/
|
|
133
|
+
setInternalValue(value) {
|
|
134
|
+
this.internalValue = parseDateTime(value, this.dateApi, null, this.customFormat);
|
|
135
|
+
if (isBlank(this.internalValue)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
//ranged value
|
|
139
|
+
if (Array.isArray(this.internalValue)) {
|
|
140
|
+
const [from, to] = this.internalValue;
|
|
141
|
+
if (from) {
|
|
142
|
+
const val = this.valueProvider.getValue(from.value, this.customFormat).from;
|
|
143
|
+
if (val) {
|
|
144
|
+
this.internalValue[0] = this.dateApi.getValue(val, this.customFormat);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (to) {
|
|
148
|
+
const val = this.valueProvider.getValue(to.value, this.customFormat).to;
|
|
149
|
+
if (val) {
|
|
150
|
+
this.internalValue[1] = this.dateApi.getValue(val, this.customFormat);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
const val = this.valueProvider.getValue(this.internalValue.value, this.customFormat).from;
|
|
156
|
+
if (val) {
|
|
157
|
+
this.internalValue = this.dateApi.getValue(val, this.customFormat);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
85
161
|
/**
|
|
86
162
|
* Shows picker
|
|
87
163
|
* @param type - Type of period that should be displayed
|
|
@@ -102,7 +178,13 @@ export class DateTimePickerComponent extends DateTimeDirective {
|
|
|
102
178
|
if (!component) {
|
|
103
179
|
return;
|
|
104
180
|
}
|
|
105
|
-
|
|
181
|
+
if (!Array.isArray(component.value)) {
|
|
182
|
+
this.setInternalValue(component.value?.value);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
//TODO: handle ranges
|
|
186
|
+
}
|
|
187
|
+
this.value = formatDateTime(this.internalValue, this.valueFormat, this.customFormat);
|
|
106
188
|
this.valueChange.emit();
|
|
107
189
|
}));
|
|
108
190
|
this.periodChangesSubscription.add(this.component.instance.scaleUp.subscribe(date => this.showPicker(this.getUpperType(), date)));
|
|
@@ -113,8 +195,10 @@ export class DateTimePickerComponent extends DateTimeDirective {
|
|
|
113
195
|
component.canScaleUp = false;
|
|
114
196
|
component.display = displayDate;
|
|
115
197
|
// component.options
|
|
116
|
-
|
|
117
|
-
component.
|
|
198
|
+
component.maxDate = this.maxDateTime;
|
|
199
|
+
component.minDate = this.minDateTime;
|
|
200
|
+
component.value = this.internalValue;
|
|
201
|
+
component.invalidateVisuals();
|
|
118
202
|
}
|
|
119
203
|
/**
|
|
120
204
|
* Gets type that is above current period picker
|
|
@@ -149,7 +233,7 @@ export class DateTimePickerComponent extends DateTimeDirective {
|
|
|
149
233
|
return this.displayedPeriodType;
|
|
150
234
|
}
|
|
151
235
|
}
|
|
152
|
-
DateTimePickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimePickerComponent, deps: [{ token: POSITION }, { token: DATE_TIME_PICKER_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component });
|
|
236
|
+
DateTimePickerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimePickerComponent, deps: [{ token: POSITION }, { token: i1.DateValueProvider }, { token: DATE_TIME_PICKER_OPTIONS, optional: true }], target: i0.ɵɵFactoryTarget.Component });
|
|
153
237
|
DateTimePickerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.6", type: DateTimePickerComponent, selector: "date-time-picker", inputs: { value: "value", options: "options" }, outputs: { valueChange: "valueChange" }, viewQueries: [{ propertyName: "pickerContainer", first: true, predicate: ["container"], descendants: true, read: ViewContainerRef, static: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: "<ng-container #container></ng-container>", changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
154
238
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImport: i0, type: DateTimePickerComponent, decorators: [{
|
|
155
239
|
type: Component,
|
|
@@ -157,7 +241,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.6", ngImpor
|
|
|
157
241
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
158
242
|
type: Inject,
|
|
159
243
|
args: [POSITION]
|
|
160
|
-
}] }, { type: undefined, decorators: [{
|
|
244
|
+
}] }, { type: i1.DateValueProvider }, { type: undefined, decorators: [{
|
|
161
245
|
type: Inject,
|
|
162
246
|
args: [DATE_TIME_PICKER_OPTIONS]
|
|
163
247
|
}, {
|