UNPKG

hslayers-ng

Version:
1 lines 4.6 kB
{"version":3,"file":"hslayers-ng-common-dimensions.mjs","sources":["../../../projects/hslayers/common/dimensions/dimension.ts","../../../projects/hslayers/common/dimensions/hslayers-ng-common-dimensions.ts"],"sourcesContent":["import dayjs from 'dayjs';\n\nexport class HsDimensionDescriptor {\n public type: string;\n public value: any;\n public modelValue: any;\n public label: string;\n public values?: Array<any>;\n public format: string;\n public modelTimeValue: {hour: any; minute: any};\n\n //Original dimension object can be shared between multiple layers.\n constructor(\n public name: string,\n public originalDimension: any,\n ) {\n this.type = this.originalDimension.type;\n this.value = this.originalDimension.value ?? this.originalDimension.default;\n this.modelValue =\n this.originalDimension.value ?? this.originalDimension.default;\n // Duck-type check if the passed value is an instance of Date.\n if (typeof this.value?.getMonth == 'function') {\n if (this.type == 'datetime') {\n this.modelValue = {\n year: this.value.getFullYear(),\n month: this.value.getMonth() + 1,\n day: this.value.getDate(),\n };\n this.modelTimeValue = {\n hour: this.value.getHours(),\n minute: this.value.getMinutes(),\n };\n }\n if (this.type == 'date') {\n this.modelValue = {\n year: this.value.getFullYear(),\n month: this.value.getMonth() + 1,\n day: this.value.getDate(),\n };\n }\n }\n this.label = this.originalDimension.label;\n this.values = this.originalDimension.values;\n this.format = this.originalDimension.format;\n }\n\n /* This is needed because ng-bootstrap datepicker sets value to\n object {year:.., month: .., day: ..} but we need vanillaJs Date\n in dimension.value attribute instead. Use the complex value only\n for picker through modelValue */\n postProcessDimensionValue(): void {\n if (this.modelValue.year && this.modelValue.month) {\n this.originalDimension.value = new Date(\n this.modelValue.year,\n this.modelValue.month - 1,\n this.modelValue.day,\n this.modelTimeValue?.hour,\n this.modelTimeValue?.minute,\n );\n } else {\n this.originalDimension.value = this.modelValue;\n }\n if (['datetime', 'date'].includes(this.type) && this.format) {\n this.originalDimension.value = dayjs(this.originalDimension.value).format(\n this.format,\n );\n }\n this.value = this.originalDimension.value;\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './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