Skip to content

Commit

Permalink
fix tslint
Browse files Browse the repository at this point in the history
add modal in demo
  • Loading branch information
cipchk committed Mar 3, 2018
1 parent 47027b0 commit ac243ce
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 6 deletions.
6 changes: 5 additions & 1 deletion components/upload/demo/picture-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ import { NzMessageService, UploadFile } from 'ng-zorro-antd';
<i class="anticon anticon-plus"></i>
<div class="ant-upload-text">Upload</div>
</nz-upload>
modal待实现:{{ previewVisible | json }}
<nz-modal [nzVisible]="previewVisible" [nzContent]="modalContent" [nzFooter]="null" (nzOnCancel)="previewVisible=false">
<ng-template #modalContent>
<img [src]="previewImage" [ngStyle]="{ 'width': '100%' }" />
</ng-template>
</nz-modal>
</div>
`,
styles: [
Expand Down
3 changes: 1 addition & 2 deletions components/upload/interface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// tslint:disable:prefer-method-signature
// tslint:disable:no-any prefer-method-signature
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

// tslint:disable:no-any
/** 状态 */
export type UploadFileStatus = 'error' | 'success' | 'done' | 'uploading' | 'removed';

Expand Down
2 changes: 2 additions & 0 deletions components/upload/nz-upload-btn.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { HttpClient, HttpEventType, HttpHeaders, HttpRequest, HttpResponse } fro
import { ChangeDetectorRef, Component, ElementRef, HostListener, Input, OnChanges, OnDestroy, OnInit, Optional, SimpleChange, SimpleChanges, ViewChild } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';

import { NzUpdateHostClassService } from '../core/services/update-host-class.service';

import { UploadFile, UploadXHRArgs, ZipButtonOptions } from './interface';

@Component({
Expand Down
4 changes: 3 additions & 1 deletion components/upload/nz-upload-list.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// tslint:disable: no-any
import { animate, state, style, transition, trigger } from '@angular/animations';
import { Component, ElementRef, Input, OnChanges, OnInit, SimpleChange, SimpleChanges } from '@angular/core';

import { NzUpdateHostClassService } from '../core/services/update-host-class.service';
import { NzI18nService } from '../i18n/nz-i18n.service';

import { ShowUploadListInterface, UploadFile, UploadListType } from './interface';

@Component({
Expand Down Expand Up @@ -64,7 +66,7 @@ import { ShowUploadListInterface, UploadFile, UploadListType } from './interface
<i *ngIf="icons.showRemoveIcon" (click)="handleRemove(file, $event)" class="anticon anticon-cross" title="{{ locale.removeFile }}"></i>
</ng-template>
<div *ngIf="file.status === 'uploading'" class="ant-upload-list-item-progress">
<nz-progress [ngModel]="file.percent" [nzShowInfo]="false" [nzStrokeWidth]="2"></nz-progress>
<nz-progress [ngModel]="file.percent" [nzShowInfo]="false" [nzStrokeWidth]="2" ngDefaultControl></nz-progress>
</div>
</div>
`,
Expand Down
6 changes: 4 additions & 2 deletions components/upload/nz-upload.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { of } from 'rxjs/observable/of';
import { filter } from 'rxjs/operators';

import { toBoolean, toNumber } from '../core/util/convert';
import { NzI18nService } from '../i18n/nz-i18n.service';

import { ShowUploadListInterface, UploadChangeParam, UploadFile, UploadFileStatus, UploadFilter, UploadListType, UploadType, ZipButtonOptions } from './interface';
import { NzUploadBtnComponent } from './nz-upload-btn.component';

Expand Down Expand Up @@ -67,15 +69,15 @@ export class NzUploadComponent implements OnInit, OnChanges, OnDestroy {
private _limit: number = 0;
@Input()
set nzLimit(value: number) {
this._limit = toNumber(value);
this._limit = toNumber(value, null);
}
get nzLimit(): number {
return this._limit;
}
private _size: number = 0;
@Input()
set nzSize(value: number) {
this._size = toNumber(value);
this._size = toNumber(value, null);
}
get nzSize(): number {
return this._size;
Expand Down
2 changes: 2 additions & 0 deletions components/upload/nz-upload.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CommonModule } from '@angular/common';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';

import { NzI18nModule } from '../i18n';
import { NzToolTipModule } from '../tooltip/nz-tooltip.module';

import { NzProgressModule } from './../progress/nz-progress.module';
import { NzUploadBtnComponent } from './nz-upload-btn.component';
import { NzUploadListComponent } from './nz-upload-list.component';
Expand Down
49 changes: 49 additions & 0 deletions components/upload/upload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';

import { NzI18nModule, NzI18nService } from '../i18n';
import { NzProgressModule } from '../progress/nz-progress.module';
import { NzToolTipModule } from '../tooltip/nz-tooltip.module';

import { ShowUploadListInterface, UploadChangeParam, UploadFile, UploadFilter, UploadListType, UploadType, ZipButtonOptions } from './interface';
import { NzUploadBtnComponent } from './nz-upload-btn.component';
import { NzUploadListComponent } from './nz-upload-list.component';
Expand Down Expand Up @@ -310,6 +312,53 @@ describe('upload', () => {
});
});
});

describe('[nzFilter]', () => {
it('shoule be custom limit', () => {
instance.nzMultiple = true;
instance.nzLimit = 1;
instance.nzFilter = [
{
name: 'limit',
fn: (fileList: UploadFile[]) => fileList.slice(-instance.nzLimit)
}
];
fixture.detectChanges();
expect(instance._beforeUploadList.length).toBe(0);
pageObject.postFile([
...PNGSMALL.target.files,
...PNGSMALL.target.files,
...PNGSMALL.target.files
]);
expect(instance._beforeUploadList.length).toBe(instance.nzLimit);
});
it('shoule be custom size', () => {
instance.nzSize = 1;
instance.nzFilter = [
{
name: 'size',
fn: (fileList: UploadFile[]) => fileList.filter(w => (w.size / 1024) <= instance.nzSize)
}
];
fixture.detectChanges();
expect(instance._beforeUploadList.length).toBe(0);
pageObject.postLarge();
expect(instance._beforeUploadList.length).toBe(0);
});
it('shoule be custom type', () => {
instance.nzFileType = 'image/png';
instance.nzFilter = [
{
name: 'type',
fn: (fileList: UploadFile[]) => fileList.filter(w => ~[ instance.nzFileType ].indexOf(w.type))
}
];
fixture.detectChanges();
expect(instance._beforeUploadList.length).toBe(0);
pageObject.postFile(JPGSMALL.target.files);
expect(instance._beforeUploadList.length).toBe(0);
});
});
});

describe('CORS', () => {
Expand Down

0 comments on commit ac243ce

Please sign in to comment.