Skip to content

Commit

Permalink
fix(): fix cancel event
Browse files Browse the repository at this point in the history
  • Loading branch information
jkuri committed Jun 30, 2017
1 parent d47c939 commit 89a3f48
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-uploader",
"version": "3.1.3",
"version": "3.2.0",
"main": "bundles/ngx-uploader.umd.js",
"module": "index.js",
"esnext": "index.js",
Expand Down
12 changes: 9 additions & 3 deletions src/components/app-home/app-home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ <h1>Drag & Drop</h1>
</div>
<div class="column is-10 is-offset-1" *ngIf="files && files.length">
<div class="upload-file" *ngFor="let f of files; let i = index;">
<div class="progress-bar-container">
<div class="bar" [style.width]="f.progress.data.percentage + '%'" [ngClass]="{ 'green': f.progress.data.percentage === 100 }"></div>
</div>
<div class="columns">
<div class="column is-11">
<div class="progress-bar-container">
<div class="bar" [style.width]="f.progress.data.percentage + '%'" [ngClass]="{ 'green': f.progress.data.percentage === 100 }"></div>
</div>
</div>
<div class="column is-1 centered">
<button type="button" class="button" (click)="cancelUpload(f.id)">Cancel</button>
</div>
</div>
</div>
<div class="column is-10 is-offset-1" *ngIf="formData.verbose">
Expand Down
23 changes: 10 additions & 13 deletions src/ngx-uploader/classes/ngx-uploader.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { EventEmitter } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { Subscription } from 'rxjs/Subscription';
import { Subscriber } from 'rxjs/Subscriber';
import 'rxjs/add/observable/merge';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/mergeAll';
import 'rxjs/add/operator/combineLatest';
import 'rxjs/add/operator/merge';

export enum UploadStatus {
Queue,
Expand Down Expand Up @@ -125,19 +123,18 @@ export class NgUploaderService {
break;
case 'uploadAll':
const concurrency = event.concurrency > 0 ? event.concurrency : Number.POSITIVE_INFINITY;

const subscriber = Subscriber.create((data: UploadOutput) => {
this.serviceEvents.emit(data);
});

this.uploads = this.uploads.concat(this.files.map(file => {
return { file: file, sub: null };
return { file: file, sub: { instance: null } };
}));

const subscription = Observable.from(this.files.map(file => this.uploadFile(file, event)))
.mergeAll(concurrency)
.combineLatest(data => data)
.subscribe(subscriber);
Observable.from(this.files.map(file => this.uploadFile(file, event)))
.merge(concurrency)
.subscribe((uploadInstance: Observable<UploadOutput>) => {
const index = this.uploads.findIndex(u => u.sub.instance === null);
this.uploads[index].sub.instance = uploadInstance.subscribe((data: UploadOutput) => {
this.serviceEvents.emit(data);
});
});
break;
case 'cancel':
const id = event.id || null;
Expand Down
12 changes: 12 additions & 0 deletions src/styles/app.sass
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,15 @@ html, body, .hero
.centered
display: flex
align-items: center

.upload-file

.button
background: $white
border: none
color: $black
outline: none
padding: 10px 20px
border-radius: 4px
display: block
font-size: 14px

0 comments on commit 89a3f48

Please sign in to comment.