Skip to content

Commit

Permalink
dxScheduler - fix recurrent appointment rendering with workWeek view …
Browse files Browse the repository at this point in the history
…(T853629) (#11660)
  • Loading branch information
Krijovnick authored Jan 27, 2020
1 parent 099f3ed commit 24b129f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 25 deletions.
26 changes: 10 additions & 16 deletions js/ui/scheduler/workspaces/ui.scheduler.timeline_work_week.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
const registerComponent = require('../../../core/component_registrator');
const SchedulerTimelineWeek = require('./ui.scheduler.timeline_week');
const dateUtils = require('../../../core/utils/date');
const workWeekUtils = require('./utils.work_week');
const toMs = dateUtils.dateToMilliseconds;

const TIMELINE_CLASS = 'dx-scheduler-timeline-work-week';
const MONDAY_INDEX = 1;
const LAST_DAY_WEEK_INDEX = 5;

const SchedulerTimelineWorkWeek = SchedulerTimelineWeek.inherit({
_getElementClass: function() {
Expand All @@ -16,35 +17,28 @@ const SchedulerTimelineWorkWeek = SchedulerTimelineWeek.inherit({
},

_firstDayOfWeek: function() {
return this.option('firstDayOfWeek') || MONDAY_INDEX;
return workWeekUtils.getFirstDayOfWeek(this.option('firstDayOfWeek'));
},

_isSkippedData: workWeekUtils.isDataOnWeekend,

_incrementDate: function(date) {
const day = date.getDay();
if(day === 5) {
if(day === LAST_DAY_WEEK_INDEX) {
date.setDate(date.getDate() + 2);
}
this.callBase(date);
},

_getOffsetByCount: function(cellIndex, rowIndex) {
_getOffsetByCount: function(cellIndex) {
const weekendCount = Math.floor(cellIndex / (5 * this._getCellCountInDay()));
if(weekendCount > 0) {
return toMs('day') * weekendCount * 2;
} else {
return 0;
}
return toMs('day') * weekendCount * 2;
},

_getWeekendsCount: function(days) {
return 2 * Math.floor(days / 7);
},
_getWeekendsCount: workWeekUtils.getWeekendsCount,

_setFirstViewDate: function() {
this._firstViewDate = dateUtils.getFirstWeekDate(this.option('currentDate'), this._firstDayOfWeek());

this._firstViewDate = dateUtils.normalizeDateByWeek(this._firstViewDate, this.option('currentDate'));

this._firstViewDate = workWeekUtils.getFirstViewDate(this.option('currentDate'), this._firstDayOfWeek());
this._setStartDayHour(this._firstViewDate);
}
});
Expand Down
6 changes: 6 additions & 0 deletions js/ui/scheduler/workspaces/ui.scheduler.work_space.js
Original file line number Diff line number Diff line change
Expand Up @@ -2166,10 +2166,16 @@ const SchedulerWorkSpace = Widget.inherit({
: 0;
},

_isSkippedData: function() { return false; },

getCoordinatesByDateInGroup: function(date, appointmentResources, inAllDayRow) {
const indexes = this._getGroupIndexes(appointmentResources);
const result = [];

if(this._isSkippedData(date)) {
return result;
}

if(indexes.length) {
for(let i = 0; i < indexes.length; i++) {
result.push(this.getCoordinatesByDate(date, indexes[i], inAllDayRow));
Expand Down
15 changes: 6 additions & 9 deletions js/ui/scheduler/workspaces/ui.scheduler.work_space_work_week.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const registerComponent = require('../../../core/component_registrator');
const dateUtils = require('../../../core/utils/date');
const workWeekUtils = require('./utils.work_week');
const toMs = dateUtils.dateToMilliseconds;
const SchedulerWorkSpaceWeek = require('./ui.scheduler.work_space_week');
const dateLocalization = require('../../../localization/date');

const WORK_WEEK_CLASS = 'dx-scheduler-work-space-work-week';

Expand All @@ -21,9 +21,11 @@ const SchedulerWorkSpaceWorkWeek = SchedulerWorkSpaceWeek.inherit({
},

_firstDayOfWeek: function() {
return this.option('firstDayOfWeek') || 1;
return workWeekUtils.getFirstDayOfWeek(this.option('firstDayOfWeek'));
},

_isSkippedData: workWeekUtils.isDataOnWeekend,

_getDateByIndex: function(headerIndex) {
const resultDate = new Date(this._firstViewDate);

Expand All @@ -48,15 +50,10 @@ const SchedulerWorkSpaceWorkWeek = SchedulerWorkSpaceWeek.inherit({
this.callBase();
},

_getWeekendsCount: function(days) {
return 2 * Math.floor(days / 7);
},
_getWeekendsCount: workWeekUtils.getWeekendsCount,

_setFirstViewDate: function() {
this._firstViewDate = dateUtils.getFirstWeekDate(this._getViewStartByOptions(), this._firstDayOfWeek() || dateLocalization.firstDayOfWeekIndex());

this._firstViewDate = dateUtils.normalizeDateByWeek(this._firstViewDate, this._getViewStartByOptions());

this._firstViewDate = workWeekUtils.getFirstViewDate(this._getViewStartByOptions(), this._firstDayOfWeek());
this._setStartDayHour(this._firstViewDate);
},

Expand Down
23 changes: 23 additions & 0 deletions js/ui/scheduler/workspaces/utils.work_week.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const dateUtils = require('../../../core/utils/date');
const MONDAY_INDEX = 1;
const SATURDAY_INDEX = 6;
const SUNDAY_INDEX = 0;

export const isDataOnWeekend = (date) => {
const day = date.getDay();
return day === SATURDAY_INDEX || day === SUNDAY_INDEX;
};

export const getFirstDayOfWeek = (firstDayOfWeekOption) => {
return firstDayOfWeekOption || MONDAY_INDEX;
};

export const getWeekendsCount = (days) => {
return 2 * Math.floor(days / 7);
};

export const getFirstViewDate = (viewStart, firstDayOfWeek) => {
const firstViewDate = dateUtils.getFirstWeekDate(viewStart, firstDayOfWeek);
return dateUtils.normalizeDateByWeek(firstViewDate, viewStart);
};

12 changes: 12 additions & 0 deletions testing/tests/DevExpress.ui.widgets.scheduler/timeline.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,18 @@ QUnit.test('\'getCoordinatesByDate\' should return right coordinates with view o
assert.equal(coords.left, targetCellPosition.left, 'Cell coordinates are right');
});

QUnit.test('\'getCoordinatesByDateInGroup\' method should return only work week days (t853629)', function(assert) {
this.instance.option({
intervalCount: 2,
currentDate: new Date(2018, 4, 21),
});

assert.ok(!this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 26))[0]);
assert.ok(!this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 27))[0]);
assert.ok(this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 23))[0]);
assert.ok(this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 28))[0]);
});

QUnit.module('TimelineWeek with grouping by date', {
beforeEach: function() {
this.instance = $('#scheduler-timeline').dxSchedulerTimelineWeek({
Expand Down
11 changes: 11 additions & 0 deletions testing/tests/DevExpress.ui.widgets.scheduler/workSpace.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3180,6 +3180,17 @@ QUnit.testStart(function() {
assert.deepEqual(lastCellData.endDate, new Date(2017, 6, 10, 1), 'cell has right endtDate');
});

QUnit.test('\'getCoordinatesByDateInGroup\' method should return only work week days (t853629)', function(assert) {
this.createInstance({
intervalCount: 2,
currentDate: new Date(2018, 4, 21),
});

assert.ok(!this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 26))[0]);
assert.ok(!this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 27))[0]);
assert.ok(this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 23))[0]);
assert.ok(this.instance.getCoordinatesByDateInGroup(new Date(2018, 4, 28))[0]);
});
})('Work Space Work Week with intervalCount');

(function() {
Expand Down

0 comments on commit 24b129f

Please sign in to comment.