Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Step 14.15: Use the getPicture method into messages-attachment.ts
  • Loading branch information
darkbasic committed Oct 16, 2017
1 parent 12fb8b7 commit ea9cd55
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/pages/messages/messages-attachments.ts
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { ModalController, ViewController } from 'ionic-angular';
import { AlertController, ModalController, Platform, ViewController } from 'ionic-angular';
import { NewLocationMessageComponent } from './location-message';
import { MessageType } from 'api/models';
import { PictureService } from '../../services/picture';
Expand All @@ -12,16 +12,26 @@ export class MessagesAttachmentsComponent {
constructor(
private viewCtrl: ViewController,
private modelCtrl: ModalController,
private pictureService: PictureService
private pictureService: PictureService,
private platform: Platform,
private alertCtrl: AlertController
) {}

sendPicture(): void {
this.pictureService.select().then((file: File) => {
this.viewCtrl.dismiss({
messageType: MessageType.PICTURE,
selectedPicture: file
sendPicture(camera: boolean): void {
if (camera && !this.platform.is('cordova')) {
return console.warn('Device must run cordova in order to take pictures');
}

this.pictureService.getPicture(camera, false)
.then((blob: File) => {
this.viewCtrl.dismiss({
messageType: MessageType.PICTURE,
selectedPicture: blob
});
})
.catch((e) => {
this.handleError(e);
});
});
}

sendLocation(): void {
Expand All @@ -41,4 +51,16 @@ export class MessagesAttachmentsComponent {

locationModal.present();
}

handleError(e: Error): void {
console.error(e);

const alert = this.alertCtrl.create({
title: 'Oops!',
message: e.message,
buttons: ['OK']
});

alert.present();
}
}

0 comments on commit ea9cd55

Please sign in to comment.