Skip to content

Commit

Permalink
feat(timepicker): merge
Browse files Browse the repository at this point in the history
  • Loading branch information
artem committed Jun 19, 2017
2 parents e283735 + acc4b2b commit c521e29
Showing 1 changed file with 138 additions and 0 deletions.
138 changes: 138 additions & 0 deletions src/timepicker/timepicker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export class TimepickerComponent implements ControlValueAccessor, TimepickerCont
invalidHours = false;
invalidMinutes = false;
invalidSeconds = false;
<<<<<<< HEAD

// time picker controls state
canIncrementHours: boolean;
Expand All @@ -197,6 +198,22 @@ export class TimepickerComponent implements ControlValueAccessor, TimepickerCont
onChange: any = Function.prototype;
onTouched: any = Function.prototype;

=======

// time picker controls state
canIncrementHours: boolean;
canIncrementMinutes: boolean;
canIncrementSeconds: boolean;

canDecrementHours: boolean;
canDecrementMinutes: boolean;
canDecrementSeconds: boolean;

// control value accessor methods
onChange: any = Function.prototype;
onTouched: any = Function.prototype;

>>>>>>> acc4b2b3055a69d11a0c90d067d1097f428c1899
constructor(_config: TimepickerConfig,
_cd: ChangeDetectorRef,
private _store: TimepickerStore,
Expand Down Expand Up @@ -239,6 +256,7 @@ export class TimepickerComponent implements ControlValueAccessor, TimepickerCont

changeHours(step: number, source?: 'wheel' | 'key'): void {
if (!this.canBeChanged(source)) {
<<<<<<< HEAD
return;
}

Expand Down Expand Up @@ -339,8 +357,111 @@ export class TimepickerComponent implements ControlValueAccessor, TimepickerCont
toggleMeridian(): void {
if (!this.showMeridian) {
return;
=======
return;
}

if (step > 0 && !this.canIncrementHours) { return; }
if (step < 0 && !this.canDecrementHours) { return; }

this._store.dispatch(this._timepickerActions.changeHours(step));
}

changeMinutes(step: number, source?: 'wheel' | 'key'): void {
if (!this.canBeChanged(source)) {
return;
}

if (step > 0 && !this.canIncrementMinutes) { return; }
if (step < 0 && !this.canDecrementMinutes) { return; }

this._store.dispatch(this._timepickerActions.changeMinutes(step));
}

changeSeconds(step: number, source?: 'wheel' | 'key'): void {
if (!this.canBeChanged(source)) {
return;
}

if (step > 0 && !this.canIncrementSeconds) { return; }
if (step < 0 && !this.canDecrementSeconds) { return; }

this._store.dispatch(this._timepickerActions.changeSeconds(step));
}

updateHours(hour: string): void {
if (!this.canBeChanged()) {
return;
}

const dex = 10;
const _hoursPerDay = 24;
const _newHour = parseInt(hour, dex);

if (isNaN(_newHour) || _newHour < 0 || _newHour > _hoursPerDay) {
this.hours = '';
this.invalidHours = true;

return;
}
this.invalidHours = false;
this._store.dispatch(this._timepickerActions
.setTimeUnit({hour: _newHour % _hoursPerDay}));
}

updateMinutes(minute: string) {
const dex = 10;
const _minutesPerHour = 60;
const _newMinute = parseInt(minute, dex);

if (isNaN(_newMinute) || _newMinute < 0 || _newMinute > _minutesPerHour) {
this.minutes = '';
this.invalidMinutes = true;

return;
}

this.invalidMinutes = false;
this._store.dispatch(this._timepickerActions
.setTimeUnit({minute: _newMinute % _minutesPerHour}));
}

updateSeconds(seconds: string) {
const dex = 10;
const _secondsPerMinute = 60;
const _newSeconds = parseInt(seconds, dex);

if (isNaN(_newSeconds) || _newSeconds < 0 || _newSeconds > _secondsPerMinute) {
this.minutes = '';
this.invalidMinutes = true;

return;
}

this.invalidMinutes = false;
this._store.dispatch(this._timepickerActions
.setTimeUnit({minute: _newSeconds % _secondsPerMinute}));
}

toggleMeridian(): void {
if (!this.showMeridian) {
return;
}

const _hoursPerDayHalf = 12;
this._store.dispatch(this._timepickerActions.changeHours(_hoursPerDayHalf));
}

/**
* Write a new value to the element.
*/
writeValue(obj: any): void {
if (isValidDate(obj)) {
this._store.dispatch(this._timepickerActions.writeValue(parseTime(obj)));
>>>>>>> acc4b2b3055a69d11a0c90d067d1097f428c1899
}

<<<<<<< HEAD
const _hoursPerDayHalf = 12;
this._store.dispatch(this._timepickerActions.changeHours(_hoursPerDayHalf));
}
Expand Down Expand Up @@ -369,6 +490,23 @@ export class TimepickerComponent implements ControlValueAccessor, TimepickerCont
}

/**
=======
/**
* Set the function to be called when the control receives a change event.
*/
registerOnChange(fn: (_: any) => {}): void {
this.onChange = fn;
}

/**
* Set the function to be called when the control receives a touch event.
*/
registerOnTouched(fn: () => {}): void {
this.onTouched = fn;
}

/**
>>>>>>> acc4b2b3055a69d11a0c90d067d1097f428c1899
* This function is called when the control status changes to or from "DISABLED".
* Depending on the value, it will enable or disable the appropriate DOM element.
*
Expand Down

0 comments on commit c521e29

Please sign in to comment.