11import { Component , OnInit } from '@angular/core' ;
22import { Profile } from 'api/models' ;
3- import { AlertController , NavController } from 'ionic-angular' ;
3+ import { AlertController , NavController , Platform } from 'ionic-angular' ;
44import { MeteorObservable } from 'meteor-rxjs' ;
55import { ChatsPage } from '../chats/chats' ;
6+ import { PictureService } from '../../services/picture' ;
7+ import { Pictures } from 'api/collections' ;
68
79@Component ( {
810 selector : 'profile' ,
@@ -14,13 +16,42 @@ export class ProfilePage implements OnInit {
1416
1517 constructor (
1618 private alertCtrl : AlertController ,
17- private navCtrl : NavController
19+ private navCtrl : NavController ,
20+ private pictureService : PictureService ,
21+ private platform : Platform
1822 ) { }
1923
2024 ngOnInit ( ) : void {
2125 this . profile = Meteor . user ( ) . profile || {
2226 name : ''
2327 } ;
28+
29+ MeteorObservable . subscribe ( 'user' ) . subscribe ( ( ) => {
30+ let platform = this . platform . is ( 'android' ) ? "android" :
31+ this . platform . is ( 'ios' ) ? "ios" : "" ;
32+ platform = this . platform . is ( 'cordova' ) ? platform : "" ;
33+
34+ this . picture = Pictures . getPictureUrl ( this . profile . pictureId , platform ) ;
35+ } ) ;
36+ }
37+
38+ selectProfilePicture ( ) : void {
39+ this . pictureService . select ( ) . then ( ( blob ) => {
40+ this . uploadProfilePicture ( blob ) ;
41+ } )
42+ . catch ( ( e ) => {
43+ this . handleError ( e ) ;
44+ } ) ;
45+ }
46+
47+ uploadProfilePicture ( blob : File ) : void {
48+ this . pictureService . upload ( blob ) . then ( ( picture ) => {
49+ this . profile . pictureId = picture . _id ;
50+ this . picture = picture . url ;
51+ } )
52+ . catch ( ( e ) => {
53+ this . handleError ( e ) ;
54+ } ) ;
2455 }
2556
2657 updateProfile ( ) : void {
0 commit comments