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

Pr2058 #2074

Closed
wants to merge 2 commits into from
Closed

Pr2058 #2074

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { FormsModule} from '@angular/forms';
import { RouterModule } from '@angular/router';
import { Ng2PageScrollModule } from 'ng2-page-scroll/ng2-page-scroll';
import { AppComponent } from './app.component';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { TimepickerModule } from 'ngx-bootstrap/timepicker';

Expand All @@ -17,6 +17,7 @@ import { routes } from './demo-timepicker.routes';
imports: [
CommonModule,
FormsModule,
ReactiveFormsModule,
SharedModule,
TimepickerModule.forRoot(),
RouterModule.forChild(routes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<p>Illustrates custom validation, you have to select time between 11:00 and 12:59</p>

<div class="form-group" [class.has-success]="ctrl.valid" [class.has-danger]="!ctrl.valid">
<timepicker [(ngModel)]="myTime" [formControl]="ctrl" required></timepicker>
</div>

<pre class="alert alert-info">Time is: {{myTime}}</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';

@Component({
selector: 'demo-timepicker-custom-validation',
templateUrl: './custom-validation.html'
})
export class DemoTimepickerCustomValidationComponent {
public myTime: Date;

public ctrl = new FormControl('', (control: FormControl) => {
const value = control.value;
console.log('control', control);
}
24 changes: 23 additions & 1 deletion demo/src/app/components/+timepicker/demos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ import { DemoTimepickerMeridianComponent } from './meridian/meridian';
import { DemoTimepickerDisabledComponent } from './disabled/disabled';
import { DemoTimepickerCustomComponent } from './custom/custom';
import { DemoTimepickerDynamicComponent } from './dynamic/dynamic';
import { DemoTimepickerMinMaxComponent } from './min-max/min-max';
import { DemoTimepickerSecondsComponent } from './seconds/seconds';
import { DemoTimepickerMousewheelArrowkeysComponent } from './mousewheel-arrowkeys/mousewheel-arrowkeys';
import { DemoTimepickerCustomValidationComponent } from './custom-validation/custom-validation';

export const DEMO_COMPONENTS = [
DemoTimepickerBasicComponent, DemoTimepickerConfigComponent, DemoTimepickerMeridianComponent,
DemoTimepickerDisabledComponent, DemoTimepickerCustomComponent, DemoTimepickerDynamicComponent
DemoTimepickerMinMaxComponent, DemoTimepickerDisabledComponent, DemoTimepickerCustomComponent,
DemoTimepickerDynamicComponent, DemoTimepickerSecondsComponent, DemoTimepickerMousewheelArrowkeysComponent,
DemoTimepickerCustomValidationComponent
];

export const DEMOS = {
Expand All @@ -19,6 +25,10 @@ export const DEMOS = {
component: require('!!raw-loader?lang=typescript!./meridian/meridian'),
html: require('!!raw-loader?lang=markup!./meridian/meridian.html')
},
minmax: {
component: require('!!raw-loader?lang=typescript!./min-max/min-max'),
html: require('!!raw-loader?lang=markup!./min-max/min-max.html')
},
disabled: {
component: require('!!raw-loader?lang=typescript!./disabled/disabled'),
html: require('!!raw-loader?lang=markup!./disabled/disabled.html')
Expand All @@ -34,5 +44,17 @@ export const DEMOS = {
config: {
component: require('!!raw-loader?lang=typescript!./config/config'),
html: require('!!raw-loader?lang=markup!./config/config.html')
},
seconds: {
component: require('!!raw-loader?lang=typescript!./seconds/seconds'),
html: require('!!raw-loader?lang=markup!./seconds/seconds.html')
},
mousewheel: {
component: require('!!raw-loader?lang=typescript!./mousewheel-arrowkeys/mousewheel-arrowkeys'),
html: require('!!raw-loader?lang=markup!./mousewheel-arrowkeys/mousewheel-arrowkeys.html')
},
customvalidation: {
component: require('!!raw-loader?lang=typescript!./custom-validation/custom-validation'),
html: require('!!raw-loader?lang=markup!./custom-validation/custom-validation.html')
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

<pre class="alert alert-info">Time is: {{mytime}}</pre>

<hr>
<br>

<button type="button" class="btn btn-info" (click)="toggleMode()">12H / 24H</button>

<hr>

<timepicker [(ngModel)]="mytime2" [meridians]="meridianText"></timepicker>

<pre class="alert alert-info">Time is: {{mytime2}}</pre>
11 changes: 7 additions & 4 deletions demo/src/app/components/+timepicker/demos/meridian/meridian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { Component } from '@angular/core';
templateUrl: './meridian.html'
})
export class DemoTimepickerMeridianComponent {
public ismeridian:boolean = true;
public ismeridian: boolean = true;

public mytime:Date = new Date();
public mytime: Date = new Date();

public toggleMode():void {
public mytime2: Date = new Date();

public meridianText = ['12h', '24h'];

public toggleMode(): void {
this.ismeridian = !this.ismeridian;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<timepicker [(ngModel)]="myTime" [min]="minTime" [max]="maxTime"></timepicker>

<pre class="alert alert-info">Time is: {{myTime}}</pre>
18 changes: 18 additions & 0 deletions demo/src/app/components/+timepicker/demos/min-max/min-max.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-timepicker-min-max',
templateUrl: './min-max.html'
})
export class DemoTimepickerMinMaxComponent {
public myTime: Date = new Date();
public minTime: Date = new Date();
public maxTime: Date = new Date();

constructor() {
this.minTime.setHours(8);
this.minTime.setMinutes(0);
this.maxTime.setHours(17);
this.maxTime.setMinutes(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<p>Without mousewheel</p>

<timepicker [(ngModel)]="myTime1" [mousewheel]="false"></timepicker>

<pre class="alert alert-info">Time is: {{myTime1}}</pre>

<p>Without arrowkeys</p>

<timepicker [(ngModel)]="myTime2" [arrowkeys]="false" (change)="changed()"></timepicker>

<pre class="alert alert-info">Time is: {{myTime2}}</pre>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-timepicker-mousewheel-arrowkeys',
templateUrl: './mousewheel-arrowkeys.html'
})
export class DemoTimepickerMousewheelArrowkeysComponent {
public myTime1: Date = new Date();
public myTime2: Date = new Date();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<timepicker [(ngModel)]="myTime" [showSeconds]="showSec"></timepicker>

<pre class="alert alert-info">Time is: {{myTime}}</pre>
10 changes: 10 additions & 0 deletions demo/src/app/components/+timepicker/demos/seconds/seconds.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from '@angular/core';

@Component({
selector: 'demo-timepicker-seconds',
templateUrl: './seconds.html'
})
export class DemoTimepickerSecondsComponent {
public myTime: Date = new Date();
public showSec: boolean = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,14 @@ let titleDoc = require('html-loader!markdown-loader!./docs/title.md');
<ul>
<li><a routerLink="." fragment="basic">Timepicker</a></li>
<li><a routerLink="." fragment="meridian">Meridian</a></li>
<li><a routerLink="." fragment="min-max">Min - Max</a></li>
<li><a routerLink="." fragment="seconds">Show seconds</a></li>
<li><a routerLink="." fragment="disabled">Disabled</a></li>
<li><a routerLink="." fragment="custom">Custom steps</a></li>
<li><a routerLink="." fragment="custom-validation">Custom validation</a></li>
<li><a routerLink="." fragment="dynamic">Dynamic</a></li>
<li><a routerLink="." fragment="config">Configuring defaults</a></li>
<li><a routerLink="." fragment="mouse-wheel">Mouse wheel and Arrow keys</a></li>
</ul>
</li>
<li><a routerLink="." fragment="api-reference">API Reference</a>
Expand All @@ -45,6 +49,16 @@ let titleDoc = require('html-loader!markdown-loader!./docs/title.md');
<ng-sample-box [ts]="demos.meridian.component" [html]="demos.meridian.html">
<demo-timepicker-meridian></demo-timepicker-meridian>
</ng-sample-box>

<h2 routerLink="." fragment="min-max" id="min-max">Min - Max</h2>
<ng-sample-box [ts]="demos.minmax.component" [html]="demos.minmax.html">
<demo-timepicker-min-max></demo-timepicker-min-max>
</ng-sample-box>

<h2 routerLink="." fragment="seconds" id="seconds">Show seconds</h2>
<ng-sample-box [ts]="demos.seconds.component" [html]="demos.seconds.html">
<demo-timepicker-seconds></demo-timepicker-seconds>
</ng-sample-box>

<h2 routerLink="." fragment="disabled" id="disabled">Disabled</h2>
<ng-sample-box [ts]="demos.disabled.component" [html]="demos.disabled.html">
Expand All @@ -54,6 +68,11 @@ let titleDoc = require('html-loader!markdown-loader!./docs/title.md');
<h2 routerLink="." fragment="custom" id="custom">Custom steps</h2>
<ng-sample-box [ts]="demos.custom.component" [html]="demos.custom.html">
<demo-timepicker-custom></demo-timepicker-custom>
</ng-sample-box>

<h2 routerLink="." fragment="custom-validation" id="custom-validation">Custom validation</h2>
<ng-sample-box [ts]="demos.customvalidation.component" [html]="demos.customvalidation.html">
<demo-timepicker-custom-validation></demo-timepicker-custom-validation>
</ng-sample-box>

<h2 routerLink="." fragment="dynamic" id="dynamic">Dynamic</h2>
Expand All @@ -65,6 +84,11 @@ let titleDoc = require('html-loader!markdown-loader!./docs/title.md');
<ng-sample-box [ts]="demos.config.component" [html]="demos.config.html">
<demo-timepicker-config></demo-timepicker-config>
</ng-sample-box>

<h2 routerLink="." fragment="mouse-wheel" id="mouse-wheel">Mouse wheel and Arrow keys</h2>
<ng-sample-box [ts]="demos.mousewheel.component" [html]="demos.mousewheel.html">
<demo-timepicker-mousewheel-arrowkeys></demo-timepicker-mousewheel-arrowkeys>
</ng-sample-box>

<h2 routerLink="." fragment="api-reference" id="api-reference">API Reference</h2>

Expand Down
16 changes: 16 additions & 0 deletions src/mini-ngrx/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export interface Action {
type: string;
payload?: any;
}

export type ActionReducer<T> = (state: T, action: Action) => T;

export { MiniState } from './state.class';
export { MiniStore } from './store.class';

/**
* sample usage class
*
*
*
*/
23 changes: 23 additions & 0 deletions src/mini-ngrx/state.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';
import { Action, ActionReducer } from './index';
import { observeOn } from 'rxjs/operator/observeOn';
import { queue } from 'rxjs/scheduler/queue';
import { scan } from 'rxjs/operator/scan';

export class MiniState<T> extends BehaviorSubject<T> {
constructor(_initialState: T, actionsDispatcher$: Observable<Action>, reducer: ActionReducer<T>) {
super(_initialState);

const actionInQueue$ = observeOn.call(actionsDispatcher$, queue);
const state$ = scan.call(actionInQueue$, (state: T, action: Action) => {
if (!action) {
return state;
}

return reducer(state, action);
}, _initialState);

state$.subscribe((value: T) => this.next(value));
}
}
39 changes: 39 additions & 0 deletions src/mini-ngrx/store.class.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Observable } from 'rxjs/Observable';
import { Observer } from 'rxjs/Observer';
import { Operator } from 'rxjs/Operator';
import { distinctUntilChanged } from 'rxjs/operator/distinctUntilChanged';

import { map } from 'rxjs/operator/map';
import { Action, ActionReducer } from './index';

export class MiniStore<T> extends Observable<T> implements Observer<Action> {

constructor(private _dispatcher: Observer<Action>,
private _reducer: ActionReducer<any>,
state$: Observable<any>) {
super();

this.source = state$;
}

select<R>(pathOrMapFn: (state: T) => R): Observable<R> {
const mapped$: Observable<R> = map.call(this, pathOrMapFn);

return distinctUntilChanged.call(mapped$);
}

lift<R>(operator: Operator<T, R>): MiniStore<R> {
const store = new MiniStore<R>(this._dispatcher, this._reducer, this);
store.operator = operator;

return store;
}

dispatch(action: Action) { this._dispatcher.next(action); }

next(action: Action) { this._dispatcher.next(action); }

error(err: any) { this._dispatcher.error(err); }

complete() {/*noop*/}
}
3 changes: 3 additions & 0 deletions src/old-timepicker/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { TimepickerConfig } from './timepicker.config';
export { TimepickerComponent } from './timepicker.component';
export { TimepickerModule } from './timepicker.module';