From d1a7d092b74ef583fcf48fc31d232e98654b0e27 Mon Sep 17 00:00:00 2001 From: Dmitriy Shekhovtsov Date: Mon, 12 Sep 2016 14:18:36 +0300 Subject: [PATCH] fix(datepicker): removed popup stub --- components/datepicker.ts | 1 - .../datepicker/datepicker-popup.component.ts | 188 ------------------ components/datepicker/datepicker.module.ts | 6 +- 3 files changed, 2 insertions(+), 193 deletions(-) delete mode 100644 components/datepicker/datepicker-popup.component.ts diff --git a/components/datepicker.ts b/components/datepicker.ts index 699ba2475c..e23cd2f6b6 100644 --- a/components/datepicker.ts +++ b/components/datepicker.ts @@ -6,6 +6,5 @@ 4. date-disabled attribute support 5. template-url attribute support */ -export { DatePickerPopupDirective } from './datepicker/datepicker-popup.component'; export { DatePickerComponent } from './datepicker/datepicker.component'; export { DatepickerModule } from './datepicker/datepicker.module'; diff --git a/components/datepicker/datepicker-popup.component.ts b/components/datepicker/datepicker-popup.component.ts deleted file mode 100644 index 9371a48dd5..0000000000 --- a/components/datepicker/datepicker-popup.component.ts +++ /dev/null @@ -1,188 +0,0 @@ -import { - Component, ComponentRef, Directive, ElementRef, EventEmitter, Input, Output, - ReflectiveInjector, Renderer, Self, ViewContainerRef, ViewEncapsulation -} from '@angular/core'; -import { NgModel } from '@angular/forms'; - -import { KeyAttribute } from '../common'; -import { positionService } from '../position'; -import { ComponentsHelper } from '../utils/components-helper.service'; - -class PopupOptions { - public placement:string; - public animation:boolean; - public isOpen:boolean; - - public constructor(options:Object) { - Object.assign(this, options); - } -} - -const datePickerPopupConfig:KeyAttribute = { - datepickerPopup: 'YYYY-MM-dd', - currentText: 'Today', - clearText: 'Clear', - closeText: 'Done', - closeOnDateSelection: true, - showButtonBar: true, - onOpenFocus: true -}; - -@Component({ - selector: 'popup-container', - template: ` - `, - encapsulation: ViewEncapsulation.None -}) -class PopupContainerComponent { - public popupComp:DatePickerPopupDirective; - - private classMap:any; - private top:string; - private left:string; - private display:string; - private placement:string; - - // false positive - /* tslint:disable:no-unused-variable */ - private showButtonBar:boolean = true; - - @Output() - private update1:EventEmitter = new EventEmitter(false); - /* tslint:enable:no-unused-variable */ - - private element:ElementRef; - - public constructor(element:ElementRef, options:PopupOptions) { - this.element = element; - Object.assign(this, options); - this.classMap = {'in': false}; - this.classMap[options.placement] = true; - } - - public onUpdate($event:any):void { - console.log('update', $event); - if ($event) { - if ($event.toString() !== '[object Date]') { - $event = new Date($event); - } - - this.popupComp.activeDate = $event; - // this.popupComp.cd.viewToModelUpdate($event); - } - } - - public position(hostEl:ElementRef):void { - this.display = 'block'; - this.top = '0px'; - this.left = '0px'; - let p = positionService - .positionElements(hostEl.nativeElement, - this.element.nativeElement.children[0], - this.placement, false); - this.top = p.top + 'px'; - } - - public getText(key:string):string { - return (this as KeyAttribute)[key + 'Text'] || datePickerPopupConfig[key + 'Text']; - } - - public isDisabled(/*date:Date*/):boolean { - return false; - } -} - -@Directive({ - selector: '[datepickerPopup][ngModel]'/*, - // prop -> datepickerPopup - format - host: {'(cupdate)': 'onUpdate1($event)'}*/ -}) -export class DatePickerPopupDirective { - public cd:NgModel; - public viewContainerRef:ViewContainerRef; - public renderer:Renderer; - public componentsHelper:ComponentsHelper; - - private _activeDate:Date; - private _isOpen:boolean = false; - private placement:string = 'bottom'; - private popup:ComponentRef; - - public constructor(@Self() cd:NgModel, viewContainerRef:ViewContainerRef, - renderer:Renderer, componentsHelper:ComponentsHelper) { - this.cd = cd; - this.viewContainerRef = viewContainerRef; - this.renderer = renderer; - this.componentsHelper = componentsHelper; - this.activeDate = cd.model; - } - - public get activeDate():Date { - return this._activeDate; - } - - public set activeDate(value:Date) { - this._activeDate = value; - } - - private get isOpen():boolean { - return this._isOpen; - } - - @Input() - private set isOpen(value:boolean) { - let fn = () => { - this._isOpen = value; - }; - - if (value === true) { - this.show(fn); - } - - if (value === false) { - this.hide(fn); - } - } - - public hide(cb:Function):void { - if (this.popup) { - this.popup.destroy(); - } - cb(); - } - - private show(cb:Function):void { - let options = new PopupOptions({ - placement: this.placement - }); - - let binding = ReflectiveInjector.resolve([ - {provide: PopupOptions, useValue: options} - ]); - - this.popup = this.componentsHelper.appendNextToLocation(PopupContainerComponent, this.viewContainerRef, binding); - this.popup.instance.position(this.viewContainerRef.element); - this.popup.instance.popupComp = this; - /*componentRef.instance.update1.observer({ - next: (newVal) => { - setProperty(this.renderer, this.elementRef, 'value', newVal); - } - });*/ - - cb(); - } -} diff --git a/components/datepicker/datepicker.module.ts b/components/datepicker/datepicker.module.ts index b035c583ce..01b1247d13 100644 --- a/components/datepicker/datepicker.module.ts +++ b/components/datepicker/datepicker.module.ts @@ -3,8 +3,6 @@ import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { DatePickerInnerComponent } from './datepicker-inner.component'; -// import {DatePickerPopup} from './datepicker-popup'; -import { DatePickerPopupDirective } from './datepicker-popup.component'; import { DatePickerComponent } from './datepicker.component'; import { DayPickerComponent } from './daypicker.component'; import { MonthPickerComponent } from './monthpicker.component'; @@ -13,9 +11,9 @@ import { ComponentsHelper } from '../utils/components-helper.service'; @NgModule({ imports: [CommonModule, FormsModule], - declarations: [DatePickerComponent, DatePickerInnerComponent, DatePickerPopupDirective, DayPickerComponent, + declarations: [DatePickerComponent, DatePickerInnerComponent, DayPickerComponent, MonthPickerComponent, YearPickerComponent], - exports: [DatePickerComponent, DatePickerInnerComponent, DatePickerPopupDirective, DayPickerComponent, FormsModule, + exports: [DatePickerComponent, DatePickerInnerComponent, DayPickerComponent, FormsModule, MonthPickerComponent, YearPickerComponent], providers: [ComponentsHelper] })