Skip to content

Commit

Permalink
Scheduler(T1202735):
Browse files Browse the repository at this point in the history
Fix current time indicator related issues.
  • Loading branch information
Ilya Vinogradov committed Dec 8, 2023
1 parent 450cdaa commit bdca72a
Show file tree
Hide file tree
Showing 19 changed files with 573 additions and 107 deletions.
50 changes: 50 additions & 0 deletions packages/devextreme/js/__internal/core/utils/math.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { shiftIntegerByModule } from '@ts/core/utils/math';
import each from 'jest-each';

describe('Math utils tests', () => {
describe('shiftIntegerByModule', () => {
each`
value | module | expectedResult
${0} | ${2} | ${0}
${2} | ${2} | ${0}
${2} | ${4} | ${2}
${2} | ${1000} | ${2}
${4} | ${2} | ${0}
${5} | ${2} | ${1}
${6} | ${2} | ${0}
${1e10} | ${10} | ${0}
${1e10 + 3} | ${10} | ${3}
${-9} | ${3} | ${0}
${-1} | ${6} | ${5}
${-3} | ${9} | ${6}
${-5} | ${9} | ${4}
${-1e10} | ${10} | ${0}
${-1e10 + 3} | ${10} | ${3}
`
.it('should return correct result', ({
value,
module,
expectedResult,
}) => {
const result = shiftIntegerByModule(value, module);

expect(result).toEqual(expectedResult);
});

it('should throw error if value isn\'t integer', () => {
expect(() => shiftIntegerByModule(1.5, 3)).toThrow();
});

it('should throw error if module value isn\'t integer', () => {
expect(() => shiftIntegerByModule(2, 2.5)).toThrow();
});

it('should throw error if module value equals zero', () => {
expect(() => shiftIntegerByModule(2, 0)).toThrow();
});

it('should throw error if module value less than zero', () => {
expect(() => shiftIntegerByModule(2, -2)).toThrow();
});
});
});
31 changes: 31 additions & 0 deletions packages/devextreme/js/__internal/core/utils/math.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const shiftIntegerByModule = (
integerValue: number,
moduleValue: number,
): number => {
if (!Number.isInteger(integerValue)) {
throw Error(`Passed integer value ${integerValue} is not an integer.`);
}

if (!Number.isInteger(moduleValue)) {
throw Error(`Passed module value ${moduleValue} is not an integer.`);
}

if (moduleValue <= 0) {
throw Error(`Passed module value ${moduleValue} must be > 0.`);
}

const normalizedInteger = integerValue % moduleValue;

switch (true) {
// NOTE: In some cases we can have -0 or +0 values.
// So this is why we handle zero as separate case here.
case normalizedInteger === 0:
return 0;
case normalizedInteger > 0:
return normalizedInteger;
case normalizedInteger < 0:
return moduleValue + normalizedInteger;
default:
throw Error(`Unexpected division (${integerValue} % ${moduleValue}) occurred.`);
}
};
2 changes: 1 addition & 1 deletion packages/devextreme/js/__internal/scheduler/m_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1671,7 +1671,7 @@ class Scheduler extends Widget<any> {
this._workSpaceRecalculation = new Deferred();
this._waitAsyncTemplate(() => {
triggerResizeEvent(this._workSpace.$element());
this._workSpace._refreshDateTimeIndication();
this._workSpace.renderCurrentDateTimeLineAndShader();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,21 +368,6 @@ class SchedulerTimeline extends SchedulerWorkSpace {

_setHorizontalGroupHeaderCellsHeight() { return noop(); }

_setCurrentTimeCells() {
const timePanelCells = this._getTimePanelCells();
const currentTimeCellIndices = this._getCurrentTimePanelCellIndices();
currentTimeCellIndices.forEach((timePanelCellIndex) => {
timePanelCells.eq(timePanelCellIndex)
.addClass(HEADER_CURRENT_TIME_CELL_CLASS);
});
}

_cleanCurrentTimeCells() {
(this.$element() as any)
.find(`.${HEADER_CURRENT_TIME_CELL_CLASS}`)
.removeClass(HEADER_CURRENT_TIME_CELL_CLASS);
}

_getTimePanelCells() {
return (this.$element() as any)
.find(`.${HEADER_PANEL_CELL_CLASS}:not(.${HEADER_PANEL_WEEK_CELL_CLASS})`);
Expand Down Expand Up @@ -513,6 +498,24 @@ class SchedulerTimeline extends SchedulerWorkSpace {
groupByDate,
);
}

// Old render methods.
// TODO Old render: delete these methods with the old render.

_setCurrentTimeCells(): void {
const timePanelCells = this._getTimePanelCells();
const currentTimeCellIndices = this._getCurrentTimePanelCellIndices();
currentTimeCellIndices.forEach((timePanelCellIndex) => {
timePanelCells.eq(timePanelCellIndex)
.addClass(HEADER_CURRENT_TIME_CELL_CLASS);
});
}

_cleanCurrentTimeCells(): void {
(this.$element() as any)
.find(`.${HEADER_CURRENT_TIME_CELL_CLASS}`)
.removeClass(HEADER_CURRENT_TIME_CELL_CLASS);
}
}

registerComponent('dxSchedulerTimeline', SchedulerTimeline as any);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ import HorizontalGroupedStrategy from './m_work_space_grouped_strategy_horizonta
import VerticalGroupedStrategy from './m_work_space_grouped_strategy_vertical';
import ViewDataProvider from './view_model/m_view_data_provider';

interface RenderComponentOptions {
header?: boolean;
timePanel?: boolean;
dateTable?: boolean;
allDayPanel?: boolean;
}

interface RenderRWorkspaceOptions {
renderComponents: RenderComponentOptions;
generateNewData: boolean;
}

const { tableCreator } = tableCreatorModule;

// TODO: The constant is needed so that the dragging is not sharp. To prevent small twitches
Expand Down Expand Up @@ -165,6 +177,16 @@ const CELL_SELECTOR = `.${DATE_TABLE_CELL_CLASS}, .${ALL_DAY_TABLE_CELL_CLASS}`;

const CELL_INDEX_CALCULATION_EPSILON = 0.05;

const DEFAULT_WORKSPACE_RENDER_OPTIONS: RenderRWorkspaceOptions = {
renderComponents: {
header: true,
timePanel: true,
dateTable: true,
allDayPanel: true,
},
generateNewData: true,
};

class SchedulerWorkSpace extends WidgetObserver {
_viewDataProvider: any;

Expand Down Expand Up @@ -798,6 +820,7 @@ class SchedulerWorkSpace extends WidgetObserver {
currentDate: this.option('currentDate'),
startDate: this.option('startDate'),
firstDayOfWeek: this.option('firstDayOfWeek'),
showCurrentTimeIndicator: this.option('showCurrentTimeIndicator'),

...this.virtualScrollingDispatcher.getRenderState(),
};
Expand Down Expand Up @@ -2020,16 +2043,27 @@ class SchedulerWorkSpace extends WidgetObserver {
// Methods that render renovated components. Useless in renovation
// ------------

renderRWorkSpace(componentsToRender?: any) {
const allComponents = {
header: true, timePanel: true, dateTable: true, allDayPanel: true,
};
const components = componentsToRender ?? allComponents;
renderRWorkSpace({
header,
timePanel,
dateTable,
allDayPanel,
}: RenderComponentOptions = DEFAULT_WORKSPACE_RENDER_OPTIONS.renderComponents) {
if (header) {
this.renderRHeaderPanel();
}

if (timePanel) {
this.renderRTimeTable();
}

components.header && this.renderRHeaderPanel();
components.timePanel && this.renderRTimeTable();
components.dateTable && this.renderRDateTable();
components.allDayPanel && this.renderRAllDayPanel();
if (dateTable) {
this.renderRDateTable();
}

if (allDayPanel) {
this.renderRAllDayPanel();
}
}

renderRDateTable() {
Expand Down Expand Up @@ -2725,11 +2759,13 @@ class SchedulerWorkSpace extends WidgetObserver {
});
}

_renderDateTimeIndication() { return noop(); }
protected _renderDateTimeIndication() { return noop(); }

protected renderCurrentDateTimeLineAndShader(): void { return noop(); }

_setIndicationUpdateInterval() { return noop(); }
protected renderCurrentDateTimeIndication(): void { return noop(); }

_refreshDateTimeIndication() { return noop(); }
protected _setIndicationUpdateInterval() { return noop(); }

_detachGroupCountClass() {
[
Expand Down Expand Up @@ -2775,7 +2811,7 @@ class SchedulerWorkSpace extends WidgetObserver {
this._$allDayTitle && this._$allDayTitle.remove();
}

_cleanView() {
_cleanView(): void {
this.cache.clear();
this._cleanTableWidths();
this.cellsSelectionState.clearSelectedAndFocusedCells();
Expand Down Expand Up @@ -2888,14 +2924,18 @@ class SchedulerWorkSpace extends WidgetObserver {
}
}

renderWorkSpace(isGenerateNewViewData = true) {
renderWorkSpace({
generateNewData,
renderComponents,
} = DEFAULT_WORKSPACE_RENDER_OPTIONS): void {
this.cache.clear();

this.viewDataProvider.update(this.generateRenderOptions(), isGenerateNewViewData);
this.viewDataProvider.update(this.generateRenderOptions(), generateNewData);

if (this.isRenovatedRender()) {
this.renderRWorkSpace();
this.renderRWorkSpace(renderComponents);
} else {
// TODO Old render: Delete this old render block after the SSR tests check.
this._renderDateHeader();
this._renderTimePanel();
this._renderGroupAllDayPanel();
Expand Down
Loading

0 comments on commit bdca72a

Please sign in to comment.