Skip to content

Commit

Permalink
Fixed date-picker update issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleeckx committed Jul 22, 2016
1 parent 09e1813 commit b38b248
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/WebComponents/DatePicker/date-picker.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
<button is="vi-button" n="1" on-tap="_fast"><vi-icon source="FastForward"></vi-icon></button>
</header>
<main class="layout horizontal wrap" zoom$="[[zoom]]">
<template is="dom-repeat" items="[[_computeCells(cells, deferredCellsUpdate)]]" as="cell">
<div class="cell layout horizontal center-center" type$="[[cell.type]]" is-selected$="[[_isSelected(zoom, cell.date, selectedDateMoment)]]" is-today$="[[_isToday(zoom, cell.date, today)]]" is-other$="[[_isOther(cell.monthOffset)]]" break$="[[cell.break]]" on-tap="_select">[[cell.content]]</div>
<template is="dom-if" if="[[!deferredCellsUpdate]]">
<template is="dom-repeat" items="[[cells]]" as="cell">
<div class="cell layout horizontal center-center" type$="[[cell.type]]" is-selected$="[[_isSelected(zoom, cell.date, selectedDateMoment)]]" is-today$="[[_isToday(zoom, cell.date, today)]]" is-other$="[[_isOther(cell.monthOffset)]]" break$="[[cell.break]]" on-tap="_select">[[cell.content]]</div>
</template>
</template>
</main>
</div>
Expand Down
22 changes: 9 additions & 13 deletions src/WebComponents/DatePicker/date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,20 @@
}
}

private _computeCells(cells: IDatePickerCell[], deferred: boolean): IDatePickerCell[] {
return !deferred ? cells : null;
}

private _render(cells: IDatePickerCell[], currentDate: Date) {
const currentDateMoment = moment(currentDate);
private _render(cells: IDatePickerCell[], currentDate: moment.Moment) {
const currentDateMoment = currentDate.clone();

if (this.zoom === "days") {
if (cells.length !== 42 + 7)
return;

const loop = currentDateMoment.clone().startOf("month").startOf(Vidyano.CultureInfo.currentCulture.dateFormat.firstDayOfWeek > 0 ? "isoWeek" : "week");
const loop = currentDateMoment.startOf("month").startOf(Vidyano.CultureInfo.currentCulture.dateFormat.firstDayOfWeek > 0 ? "isoWeek" : "week");
const end = loop.clone().add(6, "weeks");

let index = 7; // Skip weekday cells
do {
this.set(`cells.${index}.date`, loop.clone());
this.set(`cells.${index}.content`, loop.format("D"));
this.set(`cells.${index}.monthOffset`, loop.isSame(currentDateMoment, "month") ? 0 : (loop.isBefore(currentDateMoment) ? -1 : 1));
this.set(`cells.${index}.monthOffset`, loop.isSame(currentDate, "month") ? 0 : (loop.isBefore(currentDate) ? -1 : 1));

index++;
loop.add(1, "days");
Expand All @@ -138,9 +133,9 @@
this._setHeader(`${CultureInfo.currentCulture.dateFormat.monthNames[currentDateMoment.month()]} ${currentDateMoment.year()}`);
}
else if (this.zoom === "months") {
const loop = currentDateMoment.clone().startOf("year");
const loop = currentDateMoment.startOf("year");
const end = loop.clone().add(12, "months");

let index = 0;
do {
this.set(`cells.${index}.date`, loop.clone());
Expand All @@ -154,7 +149,7 @@
this._setHeader(`${currentDateMoment.year()}`);
}
else if (this.zoom === "years") {
const loop = currentDateMoment.clone().startOf("year").subtract(6, "years");
const loop = currentDateMoment.startOf("year").subtract(6, "years");
const end = loop.clone().add(12, "years");

let index = 0;
Expand Down Expand Up @@ -206,14 +201,15 @@
this.currentDate.add(amount, "years");
else
this.currentDate.add(amount * 12, "years");

this._setCurrentDate(this.currentDate.clone());

e.stopPropagation();
}

private _fast(e: Event) {
const amount = parseInt((<Vidyano.WebComponents.Button>e.currentTarget).getAttribute("n"));

this._setCurrentDate(this.currentDate.add(amount, "years").clone());

e.stopPropagation();
Expand Down

0 comments on commit b38b248

Please sign in to comment.