1
1
import { Component } from '@angular/core' ;
2
- import { ModalController , ViewController } from 'ionic-angular' ;
2
+ import { AlertController , ModalController , Platform , ViewController } from 'ionic-angular' ;
3
3
import { NewLocationMessageComponent } from './location-message' ;
4
4
import { MessageType } from 'api/models' ;
5
5
import { PictureService } from '../../services/picture' ;
@@ -12,16 +12,26 @@ export class MessagesAttachmentsComponent {
12
12
constructor (
13
13
private viewCtrl : ViewController ,
14
14
private modelCtrl : ModalController ,
15
- private pictureService : PictureService
15
+ private pictureService : PictureService ,
16
+ private platform : Platform ,
17
+ private alertCtrl : AlertController
16
18
) { }
17
19
18
- sendPicture ( ) : void {
19
- this . pictureService . select ( ) . then ( ( file : File ) => {
20
- this . viewCtrl . dismiss ( {
21
- messageType : MessageType . PICTURE ,
22
- selectedPicture : file
20
+ sendPicture ( camera : boolean ) : void {
21
+ if ( camera && ! this . platform . is ( 'cordova' ) ) {
22
+ return console . warn ( 'Device must run cordova in order to take pictures' ) ;
23
+ }
24
+
25
+ this . pictureService . getPicture ( camera , false )
26
+ . then ( ( blob : File ) => {
27
+ this . viewCtrl . dismiss ( {
28
+ messageType : MessageType . PICTURE ,
29
+ selectedPicture : blob
30
+ } ) ;
31
+ } )
32
+ . catch ( ( e ) => {
33
+ this . handleError ( e ) ;
23
34
} ) ;
24
- } ) ;
25
35
}
26
36
27
37
sendLocation ( ) : void {
@@ -41,4 +51,16 @@ export class MessagesAttachmentsComponent {
41
51
42
52
locationModal . present ( ) ;
43
53
}
54
+
55
+ handleError ( e : Error ) : void {
56
+ console . error ( e ) ;
57
+
58
+ const alert = this . alertCtrl . create ( {
59
+ title : 'Oops!' ,
60
+ message : e . message ,
61
+ buttons : [ 'OK' ]
62
+ } ) ;
63
+
64
+ alert . present ( ) ;
65
+ }
44
66
}
0 commit comments