|
| 1 | +import $, { type dxElementWrapper } from '@js/core/renderer'; |
| 2 | +import { setHeight, setWidth } from '@js/core/utils/size'; |
| 3 | + |
| 4 | +import CurrentTimeShader from './current_time_shader'; |
| 5 | + |
| 6 | +const DATE_TIME_SHADER_ALL_DAY_CLASS = 'dx-scheduler-date-time-shader-all-day'; |
| 7 | +const DATE_TIME_SHADER_TOP_CLASS = 'dx-scheduler-date-time-shader-top'; |
| 8 | +const DATE_TIME_SHADER_BOTTOM_CLASS = 'dx-scheduler-date-time-shader-bottom'; |
| 9 | + |
| 10 | +class VerticalCurrentTimeShader extends CurrentTimeShader { |
| 11 | + _$topShader!: dxElementWrapper; |
| 12 | + |
| 13 | + _$bottomShader!: dxElementWrapper; |
| 14 | + |
| 15 | + _$allDayIndicator!: dxElementWrapper; |
| 16 | + |
| 17 | + renderShader(): void { |
| 18 | + let shaderHeight = this.getShaderHeight(); |
| 19 | + const maxHeight = this.getShaderMaxHeight(); |
| 20 | + const isSolidShader = shaderHeight > maxHeight; |
| 21 | + |
| 22 | + if (shaderHeight > maxHeight) { |
| 23 | + shaderHeight = maxHeight; |
| 24 | + } |
| 25 | + |
| 26 | + setHeight(this._$shader, shaderHeight); |
| 27 | + const groupCount = this._workSpace._getGroupCount() || 1; |
| 28 | + |
| 29 | + if (this._workSpace.isGroupedByDate()) { |
| 30 | + this.renderGroupedByDateShaderParts(groupCount, shaderHeight, maxHeight, isSolidShader); |
| 31 | + } else { |
| 32 | + this.renderShaderParts(groupCount, shaderHeight, maxHeight, isSolidShader); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + private renderShaderParts( |
| 37 | + groupCount: number, |
| 38 | + shaderHeight: number, |
| 39 | + maxHeight: number, |
| 40 | + isSolidShader: boolean, |
| 41 | + ): void { |
| 42 | + for (let i = 0; i < groupCount; i += 1) { |
| 43 | + const shaderWidth = this.getShaderWidth(); |
| 44 | + this.renderTopShader(this._$shader, shaderHeight, shaderWidth, i); |
| 45 | + |
| 46 | + if (!isSolidShader) { |
| 47 | + this.renderBottomShader(this._$shader, maxHeight, shaderHeight, shaderWidth, i); |
| 48 | + } |
| 49 | + |
| 50 | + this.renderAllDayShader(shaderWidth, i); |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + private renderGroupedByDateShaderParts( |
| 55 | + groupCount: number, |
| 56 | + shaderHeight: number, |
| 57 | + maxHeight: number, |
| 58 | + isSolidShader: boolean, |
| 59 | + ): void { |
| 60 | + const shaderWidth = this.getShaderWidth(); |
| 61 | + const bottomShaderWidth = shaderHeight < 0 |
| 62 | + ? shaderWidth |
| 63 | + : shaderWidth - this._workSpace.getCellWidth(); |
| 64 | + const normalizedShaderHeight = Math.max(shaderHeight, 0); |
| 65 | + |
| 66 | + this.renderTopShader(this._$shader, normalizedShaderHeight, shaderWidth * groupCount, 0); |
| 67 | + |
| 68 | + if (!isSolidShader) { |
| 69 | + this.renderBottomShader( |
| 70 | + this._$shader, |
| 71 | + maxHeight, |
| 72 | + normalizedShaderHeight, |
| 73 | + bottomShaderWidth * groupCount + this._workSpace.getCellWidth(), |
| 74 | + 0, |
| 75 | + ); |
| 76 | + } |
| 77 | + |
| 78 | + this.renderAllDayShader(shaderWidth * groupCount, 0); |
| 79 | + } |
| 80 | + |
| 81 | + private renderTopShader( |
| 82 | + $shader: dxElementWrapper, |
| 83 | + height: number, |
| 84 | + width: number, |
| 85 | + i: number, |
| 86 | + ): void { |
| 87 | + this._$topShader = $('<div>').addClass(DATE_TIME_SHADER_TOP_CLASS); |
| 88 | + if (width) { |
| 89 | + setWidth(this._$topShader, width); |
| 90 | + } |
| 91 | + if (height) { |
| 92 | + setHeight(this._$topShader, height); |
| 93 | + } |
| 94 | + |
| 95 | + this._$topShader.css('marginTop', this.getShaderTopOffset(i)); |
| 96 | + this._$topShader.css('left', this.getShaderOffset(i, width)); |
| 97 | + |
| 98 | + $shader.append(this._$topShader); |
| 99 | + } |
| 100 | + |
| 101 | + private renderBottomShader( |
| 102 | + $shader: dxElementWrapper, |
| 103 | + maxHeight: number, |
| 104 | + height: number, |
| 105 | + width: number, |
| 106 | + i: number, |
| 107 | + ): void { |
| 108 | + this._$bottomShader = $('<div>').addClass(DATE_TIME_SHADER_BOTTOM_CLASS); |
| 109 | + |
| 110 | + const shaderWidth = height < 0 ? width : width - this._workSpace.getCellWidth(); |
| 111 | + const shaderHeight = height < 0 ? maxHeight : maxHeight - height; |
| 112 | + |
| 113 | + setWidth(this._$bottomShader, shaderWidth); |
| 114 | + setHeight(this._$bottomShader, shaderHeight); |
| 115 | + |
| 116 | + this._$bottomShader.css('left', this.getShaderOffset(i, width - this._workSpace.getCellWidth())); |
| 117 | + |
| 118 | + $shader.append(this._$bottomShader); |
| 119 | + } |
| 120 | + |
| 121 | + private renderAllDayShader(shaderWidth: number, i: number): void { |
| 122 | + if (this._workSpace.option('showAllDayPanel')) { |
| 123 | + this._$allDayIndicator = $('<div>').addClass(DATE_TIME_SHADER_ALL_DAY_CLASS); |
| 124 | + setHeight(this._$allDayIndicator, this._workSpace.getAllDayHeight()); |
| 125 | + setWidth(this._$allDayIndicator, shaderWidth); |
| 126 | + this._$allDayIndicator.css('left', this.getShaderOffset(i, shaderWidth)); |
| 127 | + |
| 128 | + this._workSpace._$allDayPanel.prepend(this._$allDayIndicator); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + private getShaderOffset(i: number, width: number): number { |
| 133 | + return this._workSpace.getGroupedStrategy().getShaderOffset(i, width) as number; |
| 134 | + } |
| 135 | + |
| 136 | + private getShaderTopOffset(i: number): number { |
| 137 | + return this._workSpace.getGroupedStrategy().getShaderTopOffset(i) as number; |
| 138 | + } |
| 139 | + |
| 140 | + private getShaderHeight(): number { |
| 141 | + return this._workSpace.getGroupedStrategy().getShaderHeight() as number; |
| 142 | + } |
| 143 | + |
| 144 | + private getShaderMaxHeight(): number { |
| 145 | + return this._workSpace.getGroupedStrategy().getShaderMaxHeight() as number; |
| 146 | + } |
| 147 | + |
| 148 | + private getShaderWidth(): number { |
| 149 | + return this._workSpace.getGroupedStrategy().getShaderWidth() as number; |
| 150 | + } |
| 151 | + |
| 152 | + clean(): void { |
| 153 | + super.clean(); |
| 154 | + |
| 155 | + if (this._workSpace?._$allDayPanel) { |
| 156 | + this._workSpace._$allDayPanel.find(`.${DATE_TIME_SHADER_ALL_DAY_CLASS}`).remove(); |
| 157 | + } |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +export default VerticalCurrentTimeShader; |
0 commit comments