Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dxScheduler - fix recurrent appointment rendering with workWeek view (T853629) #11660

Merged
merged 6 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions js/ui/scheduler/workspaces/ui.scheduler.timeline_work_week.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
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 SchedulerTimelineWorkWeek = SchedulerTimelineWeek.inherit({
_getElementClass: function() {
Expand All @@ -16,9 +16,11 @@ const SchedulerTimelineWorkWeek = SchedulerTimelineWeek.inherit({
},

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

_isSkipData: workWeekUtils.isDataOnWeekend,
Krijovnick marked this conversation as resolved.
Show resolved Hide resolved

_incrementDate: function(date) {
const day = date.getDay();
if(day === 5) {
Expand All @@ -27,24 +29,15 @@ const SchedulerTimelineWorkWeek = SchedulerTimelineWeek.inherit({
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;
},

_isSkipData: noop,

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

if(this._isSkipData(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'));
},

_isSkipData: 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
21 changes: 21 additions & 0 deletions js/ui/scheduler/workspaces/utils.work_week.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const dateUtils = require('../../../core/utils/date');
const MONDAY_INDEX = 1;

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

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