Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NG-ZORRO/ng-zorro-antd into wilso…
Browse files Browse the repository at this point in the history
…n_testcase
  • Loading branch information
wilsoncook committed Aug 26, 2017
2 parents 5bb3738 + 2bf24e0 commit ef3252d
Show file tree
Hide file tree
Showing 41 changed files with 609 additions and 252 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ before_script:
- npm install -g @angular/cli
- npm install -g karma
- npm install
- ng build
- ng build --prod

script:
- npm run test
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-zorro-antd",
"version": "0.5.0-rc.0",
"version": "0.5.0-rc.2",
"license": "MIT",
"description": "An enterprise-class UI components based on Ant Design and Angular",
"scripts": {
Expand Down Expand Up @@ -32,17 +32,16 @@
},
"dependencies": {
"moment": "^2.18.1",
"@angular/cdk": "^2.0.0-beta.8",
"@angular/animations": "^4.0.0"
"@angular/cdk": "^2.0.0-beta.8"
},
"devDependencies": {
"@angular/common": "^4.0.0",
"@angular/animations": "^4.0.0",
"@angular/core": "^4.0.0",
"@angular/forms": "^4.0.0",
"@angular/platform-browser": "^4.0.0",
"rxjs": "^5.0.1",
"zone.js": "^0.8.14",

"@angular/cli": "1.3.0",
"@angular/compiler": "^4.0.0",
"@angular/compiler-cli": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/checkbox/nz-checkbox.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,6 @@ export class NzCheckboxComponent implements OnInit, ControlValueAccessor {
}

ngOnInit() {
this._render.setAttribute(this._el, 'class', `${this._prefixCls}-wrapper`);
this._render.addClass(this._el, `${this._prefixCls}-wrapper`);
}
}
3 changes: 2 additions & 1 deletion src/components/dropdown/nz-dropdown-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EventEmitter,
AfterViewInit
} from '@angular/core';
import { debounceTime } from 'rxjs/operator/debounceTime';
import { DropDownAnimation } from '../core/animation/dropdown-animations';
import { NzDropDownDirective } from './nz-dropdown.directive';
import { NzDropDownComponent } from './nz-dropdown.component';
Expand Down Expand Up @@ -74,7 +75,7 @@ export class NzDropDownButtonComponent extends NzDropDownComponent implements On
@ViewChild(NzDropDownDirective) _nzOrigin;

ngOnInit() {
this._$mouseSubject.debounceTime(300).subscribe((data: boolean) => {
debounceTime.call(this._$mouseSubject, 300).subscribe((data: boolean) => {
if (this.nzDisable) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions src/components/dropdown/nz-dropdown.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
Output,
EventEmitter, AfterViewInit
} from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';
import { debounceTime } from 'rxjs/operator/debounceTime';
import { NzMenuComponent } from '../menu/nz-menu.component';
import { DropDownAnimation } from '../core/animation/dropdown-animations';
import { NzDropDownDirective } from './nz-dropdown.directive';
Expand Down Expand Up @@ -120,7 +121,7 @@ export class NzDropDownComponent implements OnInit, OnDestroy, AfterViewInit {
}

ngOnInit() {
this._$mouseSubject.debounceTime(300).subscribe((data: boolean) => {
debounceTime.call(this._$mouseSubject, 300).subscribe((data: boolean) => {
this.nzVisible = data;
if (this.nzVisible) {
if (!this._triggerWidth) {
Expand Down
8 changes: 8 additions & 0 deletions src/components/input/nz-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
<ng-template [ngIf]="nzType!='textarea'">
<input
(blur)="_emitBlur($event)"
(focus)="_emitFocus($event)"
[attr.id]="nzId"
[disabled]="nzDisabled"
[attr.type]="nzType"
Expand All @@ -40,6 +41,7 @@ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
<ng-template [ngIf]="nzType=='textarea'">
<textarea
(blur)="_emitBlur($event)"
(focus)="_emitFocus($event)"
[attr.id]="nzId"
#inputTextarea
[disabled]="nzDisabled"
Expand Down Expand Up @@ -100,6 +102,7 @@ export class NzInputComponent implements AfterContentInit, ControlValueAccessor
}

@Output() nzBlur: EventEmitter<MouseEvent> = new EventEmitter();
@Output() nzFocus: EventEmitter<MouseEvent> = new EventEmitter();
@ContentChild('addOnBefore') _addOnContentBefore: TemplateRef<any>;
@ContentChild('addOnAfter') _addOnContentAfter: TemplateRef<any>;

Expand Down Expand Up @@ -134,6 +137,11 @@ export class NzInputComponent implements AfterContentInit, ControlValueAccessor

_emitBlur($event) {
this.nzBlur.emit($event);
this.onTouched();
}

_emitFocus($event) {
this.nzFocus.emit($event);
}

constructor(private _elementRef: ElementRef, private _renderer: Renderer2) {
Expand Down
28 changes: 19 additions & 9 deletions src/components/menu/nz-menu-item.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
AfterViewInit,
HostListener,
ChangeDetectorRef,
Renderer2,
Optional,
ElementRef
} from '@angular/core';
Expand All @@ -14,17 +15,31 @@ import { NzSubMenuComponent } from './nz-submenu.component';
export const PADDING_BASE = 24;

@Component({
selector : '[nz-menu-item]',
template : `
selector: '[nz-menu-item]',
template: `
<ng-content></ng-content>`,
})

export class NzMenuItemComponent implements AfterViewInit {
level = 0;
padding = null;
isInDropDown = false;
selected = false;
@Input() nzDisable = false;
@Input() nzSelected = false;

@Input()
set nzSelected(value: boolean) {
this.selected = value;
if (value) {
this._renderer.addClass(this.hostElement.nativeElement, 'ant-menu-item-selected')
} else {
this._renderer.removeClass(this.hostElement.nativeElement, 'ant-menu-item-selected')
}
}

get nzSelected() {
return this.selected;
}

/** clear all item selected status except this */
@HostListener('click', [ '$event' ])
Expand All @@ -51,11 +66,6 @@ export class NzMenuItemComponent implements AfterViewInit {
return this.isInDropDown && this.nzDisable;
}

@HostBinding('class.ant-menu-item-selected')
get setMenuSelectedClass() {
return this.nzSelected;
}

@HostBinding('class.ant-menu-item-disabled')
get setMenuDisableClass() {
return (!this.isInDropDown) && this.nzDisable;
Expand All @@ -80,7 +90,7 @@ export class NzMenuItemComponent implements AfterViewInit {
}
}

constructor(public cd: ChangeDetectorRef, private nzMenuComponent: NzMenuComponent, @Optional() public nzSubMenuComponent: NzSubMenuComponent, private hostElement: ElementRef) {
constructor(private _renderer: Renderer2, public cd: ChangeDetectorRef, private nzMenuComponent: NzMenuComponent, @Optional() public nzSubMenuComponent: NzSubMenuComponent, private hostElement: ElementRef) {
this.nzMenuComponent.menuItems.push(this);
/** store origin padding in padding */
if (this.hostElement.nativeElement.style[ 'padding-left' ]) {
Expand Down
9 changes: 5 additions & 4 deletions src/components/menu/nz-submenu.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
} from '@angular/core';
import { style, animate, state, transition, trigger } from '@angular/animations';
import { NzMenuComponent } from './nz-menu.component';
import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';
import { debounceTime } from 'rxjs/operator/debounceTime';

@Component({
selector : '[nz-submenu]',
Expand Down Expand Up @@ -50,7 +51,7 @@ import { Subject } from 'rxjs/Rx';

export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
isInDropDown = false;
level = 0;
level = 1;
_$mouseSubject = new Subject();
@ContentChildren(NzSubMenuComponent) subMenus;
@Input() nzOpen = false;
Expand Down Expand Up @@ -135,7 +136,7 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
ngAfterViewInit() {
this.isInDropDown = this.nzMenuComponent.isInDropDown;
if (this.subMenus.length && (this.nzMenuComponent.nzMode === 'inline')) {
this.subMenus.forEach(menu => {
this.subMenus.filter(x => x !== this).forEach(menu => {
setTimeout(_ => {
menu.level = this.level + 1;
});
Expand All @@ -144,7 +145,7 @@ export class NzSubMenuComponent implements OnInit, OnDestroy, AfterViewInit {
}

ngOnInit() {
this._$mouseSubject.debounceTime(300).subscribe((data: boolean) => {
debounceTime.call(this._$mouseSubject, 300).subscribe((data: boolean) => {
this.nzOpen = data;
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/modal/nz-modal-subject.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Rx';
import { Subject } from 'rxjs/Subject';

/* modal的事件枚举 */
const enum modalEvent {
Expand Down
26 changes: 26 additions & 0 deletions src/components/ng-zorro-antd.module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { async, TestBed } from '@angular/core/testing';
import { NgZorroAntdModule, NZ_ROOT_CONFIG, NzRootConfig } from './ng-zorro-antd.module';

describe('NgZorroAntdModule with Angular integration', () => {
it('should not provide root config with empty forRoot', async(() => {
TestBed.configureTestingModule({
imports: [
NgZorroAntdModule.forRoot(),
],
}).compileComponents();

expect(TestBed.get(NZ_ROOT_CONFIG)).not.toBeDefined();
}));

it('should provide root config with params in forRoot', async(() => {
const options: NzRootConfig = { extraFontName: '', extraFontUrl: '' };

TestBed.configureTestingModule({
imports: [
NgZorroAntdModule.forRoot(options),
],
}).compileComponents();

expect(TestBed.get(NZ_ROOT_CONFIG)).toBeDefined();
}));
});
9 changes: 7 additions & 2 deletions src/components/ng-zorro-antd.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ import { NzMessageService } from './message/nz-message.service';
import { NzModalService } from './modal/nz-modal.service';
import { NzModalSubject } from './modal/nz-modal-subject.service';

// Tokens (eg. global services' config)
import { NZ_ROOT_CONFIG, NzRootConfig } from './root/nz-root-config'

// ---------------------------------------------------------
// | Exports
// ---------------------------------------------------------
Expand Down Expand Up @@ -116,6 +119,7 @@ export { NzModalSubject } from './modal/nz-modal-subject.service';
// Tokens (eg. global services' config)
export { NZ_MESSAGE_CONFIG } from './message/nz-message-config';
export { NZ_NOTIFICATION_CONFIG } from './notification/nz-notification-config';
export { NZ_ROOT_CONFIG, NzRootConfig } from './root/nz-root-config';

// ---------------------------------------------------------
// | Root module
Expand Down Expand Up @@ -171,13 +175,14 @@ export { NZ_NOTIFICATION_CONFIG } from './notification/nz-notification-config';
})
export class NgZorroAntdModule {

static forRoot(): ModuleWithProviders {
static forRoot(options?: NzRootConfig): ModuleWithProviders {
return {
ngModule: NgZorroAntdModule,
providers: [
// Services
NzNotificationService,
NzMessageService
NzMessageService,
{ provide: NZ_ROOT_CONFIG, useValue: options },
]
};
}
Expand Down
Loading

0 comments on commit ef3252d

Please sign in to comment.