add progress bar for file uploads resolves #53

This commit is contained in:
Morgan McMillian 2018-02-24 07:22:13 -08:00
parent 305b570cfa
commit e5cdc80b64

View file

@ -361,6 +361,7 @@ export class StreamPage {
</button> </button>
</ion-col> </ion-col>
</ion-row> </ion-row>
<progress id='p' *ngIf="showProgress"></progress>
<ion-list> <ion-list>
<ion-item *ngFor="let f of files"> <ion-item *ngFor="let f of files">
<ion-thumbnail item-start> <ion-thumbnail item-start>
@ -380,6 +381,7 @@ export class NewPostModal {
title: string; title: string;
replyid: string; replyid: string;
ptext: string = ""; ptext: string = "";
showProgress: boolean = false;
files: Array<Object> = []; files: Array<Object> = [];
fname: string = ""; fname: string = "";
fpath: string = ""; fpath: string = "";
@ -491,7 +493,7 @@ export class NewPostModal {
} }
attachImage() { attachImage() {
console.log('file chooser'); // console.log('file chooser');
const fileTransfer: FileTransferObject = this.transfer.create(); const fileTransfer: FileTransferObject = this.transfer.create();
this.fileChooser.open().then(uri => { this.fileChooser.open().then(uri => {
@ -499,9 +501,6 @@ export class NewPostModal {
this.filePath.resolveNativePath(uri).then(filePath => { this.filePath.resolveNativePath(uri).then(filePath => {
this.fpath = filePath; this.fpath = filePath;
this.fname = filePath.split('/').pop(); this.fname = filePath.split('/').pop();
console.log('-filepath-');
console.log(this.fpath);
console.log(this.fname);
let options: FileUploadOptions = { let options: FileUploadOptions = {
fileKey: 'content', fileKey: 'content',
@ -514,10 +513,9 @@ export class NewPostModal {
headers: {'Authorization': 'Bearer ' + this.authToken} headers: {'Authorization': 'Bearer ' + this.authToken}
} }
this.showProgress = true;
fileTransfer.upload(this.fpath, 'https://api.pnut.io/v0/files', options).then((response) => { fileTransfer.upload(this.fpath, 'https://api.pnut.io/v0/files', options).then((response) => {
console.log('-file created-');
console.log(response.response);
console.log('-file created-');
let rdata = JSON.parse(response.response); let rdata = JSON.parse(response.response);
let oembed = { let oembed = {
'+io.pnut.core.file': { '+io.pnut.core.file': {
@ -526,7 +524,7 @@ export class NewPostModal {
format: 'oembed' format: 'oembed'
} }
} }
console.log(JSON.stringify(oembed)); // console.log(JSON.stringify(oembed));
this.raw.push({ this.raw.push({
type: "io.pnut.core.oembed", type: "io.pnut.core.oembed",
value: oembed value: oembed
@ -536,10 +534,10 @@ export class NewPostModal {
link: rdata.data.link, link: rdata.data.link,
id: this.raw.length - 1 id: this.raw.length - 1
}); });
this.showProgress = false;
}).catch((err) => { }).catch((err) => {
console.log('-create file error-');
console.log(JSON.stringify(err)); this.showProgress = false;
console.log('-create file error-');
let edata = JSON.parse(err.body); let edata = JSON.parse(err.body);
this.presentToast(edata.meta.error_message); this.presentToast(edata.meta.error_message);
}); });