-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from maikofelix47/add-time-control
Added time control
- Loading branch information
Showing
12 changed files
with
183 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
6 changes: 6 additions & 0 deletions
6
projects/ngx-formentry/src/components/ngx-time-picker/ngx-time-picker.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<input | ||
type="time" | ||
class="form-control" | ||
[ngModel]="value" | ||
(ngModelChange)="onTimeSelect($event)" | ||
/> |
73 changes: 73 additions & 0 deletions
73
projects/ngx-formentry/src/components/ngx-time-picker/ngx-time-picker.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { | ||
ControlValueAccessor, | ||
NG_VALUE_ACCESSOR | ||
} from "@angular/forms"; | ||
import { Component, OnInit, forwardRef } from "@angular/core"; | ||
import * as moment_ from "moment"; | ||
const moment = moment_; | ||
|
||
@Component({ | ||
selector: "ngx-time-picker", | ||
templateUrl: "./ngx-time-picker.component.html", | ||
styleUrls: ["./ngx-time-picker.component.css"], | ||
providers: [ | ||
{ | ||
provide: NG_VALUE_ACCESSOR, | ||
multi: true, | ||
useExisting: forwardRef(() => NgxTimePickerComponent), | ||
}, | ||
], | ||
}) | ||
export class NgxTimePickerComponent implements OnInit, ControlValueAccessor { | ||
public value: string = moment().format("HH:mm:ss"); | ||
public onChange: any = () => {}; | ||
public onTouched: any = () => {}; | ||
|
||
public ngOnInit() { | ||
} | ||
|
||
public writeValue(value: any): void { | ||
this.value = this.formatTimeValue(value); | ||
} | ||
|
||
public registerOnChange(fn: any): void { | ||
this.onChange = fn; | ||
} | ||
|
||
public registerOnTouched(fn: any): void {} | ||
|
||
public onTimeSelect($event: string): void { | ||
const timeValue = this.formatTimeValue($event); | ||
this.value = timeValue; | ||
this.onChange(timeValue); | ||
} | ||
|
||
public formatTimeValue(timeInputString: string): string { | ||
/* | ||
Allows processing of data that comes in as date-time | ||
or just time i.e '1970-03-01 12:32:21' or '12:32:21' | ||
or '12:32' or '1970-01-01T13:03:00.000+0300' | ||
*/ | ||
let timeArray = []; | ||
let dateArray = []; | ||
let timeValue = ""; | ||
|
||
if (typeof timeInputString === "undefined" || timeInputString === null) { | ||
} else { | ||
timeArray = timeInputString.split(":"); | ||
dateArray = timeInputString.split("-"); | ||
} | ||
if (timeArray.length === 1 && moment(timeInputString).isValid()) { | ||
timeValue = moment(timeInputString).format("HH:mm:ss"); | ||
} else if (timeArray.length > 1 && timeArray.length < 2) { | ||
timeValue = moment(timeInputString,moment.defaultFormat).format('HH:mm:ss'); | ||
} else if(timeArray.length >= 2 && dateArray.length > 1){ | ||
timeValue = moment(timeInputString,moment.defaultFormat).format('HH:mm:ss');; | ||
}else if(timeArray.length >= 2 && dateArray.length <= 1) { | ||
timeValue = moment(timeInputString,'HH:mm:ss').format('HH:mm:ss'); | ||
}else { | ||
timeValue = moment().format("HH:mm:ss"); | ||
} | ||
return timeValue; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
projects/ngx-formentry/src/components/ngx-time-picker/ngx-time-picker.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { FormsModule , ReactiveFormsModule } from '@angular/forms'; | ||
import { NgxTimePickerComponent } from './ngx-time-picker.component'; | ||
|
||
|
||
|
||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
FormsModule, | ||
ReactiveFormsModule | ||
], | ||
declarations: [ | ||
NgxTimePickerComponent | ||
], | ||
exports: [ | ||
NgxTimePickerComponent | ||
], | ||
providers: [ | ||
] | ||
}) | ||
export class NgxTimePickerModule { | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
projects/ngx-formentry/src/form-entry/question-models/interfaces/time-question-options.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { BaseOptions } from '../interfaces/base-options'; | ||
|
||
// tslint:disable-next-line:no-empty-interface | ||
export interface TimeQuestionOptions extends BaseOptions { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
projects/ngx-formentry/src/form-entry/question-models/time-question.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { QuestionBase } from './question-base'; | ||
import { TimeQuestionOptions } from './interfaces/time-question-options'; | ||
import { AfeControlType } from '../../abstract-controls-extension/afe-control-type'; | ||
|
||
export class TimeQuestion extends QuestionBase { | ||
constructor(options: TimeQuestionOptions) { | ||
super(options); | ||
this.renderingType = 'time'; | ||
this.controlType = AfeControlType.AfeFormControl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters