Skip to content

Commit

Permalink
Enhancements:
Browse files Browse the repository at this point in the history
1) feat(camera plugin): enabled camera functionality saving pic into firebase storage
2) Bug fixes, minor enhancements and clean up
  • Loading branch information
gigocabrera committed Sep 7, 2016
1 parent d8720f8 commit d21a9f5
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 67 deletions.
10 changes: 4 additions & 6 deletions app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,27 @@ import {Component, ViewChild, NgZone} from '@angular/core';
import {ionicBootstrap, Events, Platform, Nav, MenuController, Alert} from 'ionic-angular';
import {StatusBar, Splashscreen, TouchID} from 'ionic-native';

// Data
import {UserData} from './providers/user-data';

// Intro and Login pages
import {TutorialPage} from './pages/tutorial/tutorial';
import {LoginPage} from './pages/login/login';
import {LoginAutoPage} from './pages/loginauto/loginauto';
import {SignupPage} from './pages/signup/signup';
import {LogoutPage} from './pages/logout/logout';

// myMoney pages
// App pages
import {AccountListPage} from './pages/mymoney/account-list/account-list';
import {CategoryListPage} from './pages/mymoney/category-list/category-list';
import {BudgetListPage} from './pages/mymoney/budget-list/budget-list';
import {RecurringListPage} from './pages/mymoney/recurring-list/recurring-list';
import {PayeeListPage} from './pages/mymoney/payee-list/payee-list';
import {ReportListPage} from './pages/mymoney/report-list/report-list';

// mySettings pages
// Settings pages
import {SettingsPage} from './pages/mysettings/settings/settings';

// Firebase
// Services
import {FIREBASE_PROVIDERS, defaultFirebase,AngularFire, firebaseAuthConfig, FirebaseAuth, AuthProviders, AuthMethods} from 'angularfire2';
import {UserData} from './providers/user-data';

declare var touchid: any;

Expand Down
2 changes: 1 addition & 1 deletion app/pages/loginauto/loginauto.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ion-title>Login</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<ion-content>
<ion-list>
</ion-list>
</ion-content>
2 changes: 0 additions & 2 deletions app/pages/loginauto/loginauto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export class LoginAutoPage {
});
loading.present();

this.userData.autoLoginLocalStorage();

// Login user with Firebase
this.auth.login({email: this.userData.username, password: this.userData.userpwd}).then((authData) => {
//this.db.getMyPreferences();
Expand Down
2 changes: 1 addition & 1 deletion app/pages/myinfo/changeemail/changeemail.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content class="outer-content">
<ion-content>
<ion-item-divider>
Enter your new email
</ion-item-divider>
Expand Down
2 changes: 1 addition & 1 deletion app/pages/myinfo/changename/changename.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content class="outer-content">
<ion-content>
<ion-item-divider>
Enter your name
</ion-item-divider>
Expand Down
2 changes: 1 addition & 1 deletion app/pages/myinfo/changepassword/changepassword.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content class="outer-content">
<ion-content>
<ion-item-divider>
Enter you New password
</ion-item-divider>
Expand Down
4 changes: 2 additions & 2 deletions app/pages/myinfo/personalprofile/personalprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ <h2>{{ userSettings?.fullname }}</h2>
<h3>{{ userSettings?.email }}</h3>
</ion-card-content>
<ion-list>
<button ion-item (click)="updateName()">Update Name</button>
<button ion-item (click)="takePicture()">Update Picture</button>
<button ion-item (click)="updateName()">Change Name</button>
<button ion-item (click)="takePicture()">Change Picture</button>
<button ion-item (click)="changeEmail()">Change Email</button>
<button ion-item (click)="changePassword()">Change Password</button>
<button ion-item (click)="deleteAccount()">Delete Account</button>
Expand Down
53 changes: 10 additions & 43 deletions app/pages/myinfo/personalprofile/personalprofile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ChangeNamePage} from '../../myinfo/changename/changename';
import {ChangeEmailPage} from '../../myinfo/changeemail/changeemail';
import {ChangePasswordPage} from '../../myinfo/changepassword/changepassword';
import {TutorialPage} from '../../tutorial/tutorial';
import {PersonalProfilePhotoPage} from '../../myinfo/personalprofilephoto/personalprofilephoto';

// Services
import {PersonalProfileData} from '../../../providers/personalprofile-data';
Expand All @@ -24,16 +25,17 @@ export class PersonalProfilePage {
public userPicture: any;

constructor(
private nav: NavController,
private modalController: ModalController,
private alertController: AlertController,
private loadingController: LoadingController,
public nav: NavController,
public modalController: ModalController,
public alertController: AlertController,
public loadingController: LoadingController,
public navParams: NavParams,
public profileData: PersonalProfileData,
public userData: UserData,
public auth: FirebaseAuth) {
public auth: FirebaseAuth) {}

this.userSettings = this.navParams.data.paramSettings;
ngOnInit() {
this.userSettings = this.navParams.data.paramSettings;
}

updateName() {
Expand All @@ -46,43 +48,8 @@ export class PersonalProfilePage {
});
}

takePicture(){
Camera.getPicture({
quality : 95,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.PNG,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: true
}).then(imageData => {
const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];

for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);

const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}

const byteArray = new Uint8Array(byteNumbers);

byteArrays.push(byteArray);
}

const blob = new Blob(byteArrays, {type: contentType});
return blob;
}

this.userPicture = b64toBlob(imageData, 'image/png');

}, error => {
console.log("ERROR -> " + JSON.stringify(error));
});
takePicture() {
this.nav.push(PersonalProfilePhotoPage);
}

changeEmail() {
Expand Down
14 changes: 14 additions & 0 deletions app/pages/myinfo/personalprofilephoto/personalprofilephoto.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ion-header>
<ion-navbar mlnavbar>
<button menuToggle>
<ion-icon name="menu" mllightblue></ion-icon>
</button>
<ion-title>Profile Photo</ion-title>
<ion-buttons end>
<button (click)="savePicture()" mllightblue>Save</button>
</ion-buttons>
</ion-navbar>
</ion-header>
<ion-content class='picturebg'>
<img src="{{userPicture}}" width="100%" />
</ion-content>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.picturebg {
background-color: #000;
}
72 changes: 72 additions & 0 deletions app/pages/myinfo/personalprofilephoto/personalprofilephoto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import {Component} from '@angular/core';
import {NavController, Alert, AlertController, ActionSheet, Modal, ModalController, Loading, LoadingController, NavParams} from 'ionic-angular';
import {Camera} from 'ionic-native';

// Services
import {PersonalProfilePhotoData} from '../../../providers/personalprofilephoto-data';

@Component({
templateUrl: 'build/pages/myinfo/personalprofilephoto/personalprofilephoto.html',
providers: [PersonalProfilePhotoData]
})

export class PersonalProfilePhotoPage {

public userSettings: any;
public userPicture: any;
public userPictureblob: any;

constructor(
public nav: NavController,
public modalController: ModalController,
public alertController: AlertController,
public loadingController: LoadingController,
public personalprofilephotoData: PersonalProfilePhotoData) {

// Initialize camera on load
this.takePicture();
}

dismiss() {
this.nav.pop();
}

savePicture() {
this.personalprofilephotoData.savePicture(this.userPictureblob);
this.dismiss();
}

takePicture(){
Camera.getPicture({
quality : 95,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.PNG,
targetWidth: 800,
targetHeight: 800,
saveToPhotoAlbum: false
}).then(imageData => {
const b64toBlob = (b64Data, contentType='', sliceSize=512) => {
const byteCharacters = atob(b64Data);
const byteArrays = [];
for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
const slice = byteCharacters.slice(offset, offset + sliceSize);
const byteNumbers = new Array(slice.length);
for (let i = 0; i < slice.length; i++) {
byteNumbers[i] = slice.charCodeAt(i);
}
const byteArray = new Uint8Array(byteNumbers);
byteArrays.push(byteArray);
}
const blob = new Blob(byteArrays, {type: contentType});
return blob;
}
this.userPictureblob = b64toBlob(imageData, 'image/png');
this.userPicture = "data:image/jpeg;base64," + imageData;
}, error => {
console.log("ERROR -> " + JSON.stringify(error));
});
}

}
5 changes: 4 additions & 1 deletion app/pages/mysettings/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {PickDefaultDatePage} from '../../mypicklists/pickdefaultdate/pickdefault

// Services
import {SettingsData} from '../../../providers/settings-data';
import {UserData} from '../../../providers/user-data';

@Component({
templateUrl: 'build/pages/mysettings/settings/settings.html',
Expand All @@ -27,7 +28,8 @@ export class SettingsPage {
public nav: NavController,
public modalController: ModalController,
public platform: Platform,
public settingsData: SettingsData) {
public settingsData: SettingsData,
public userData: UserData) {

platform.ready().then(() => {
AppVersion.getVersionNumber().then(ver => {
Expand Down Expand Up @@ -57,6 +59,7 @@ export class SettingsPage {

toggleTouchID(e) {
this.settingsData.updateTouchID(e.checked);
this.userData.setEnableTouchID(e.checked);
}

changeDefaltBalance() {
Expand Down
24 changes: 24 additions & 0 deletions app/providers/personalprofilephoto-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {Injectable} from '@angular/core';

@Injectable()
export class PersonalProfilePhotoData {

public user: any;
public userdata: any;
public profilepicdata: any;

constructor() {
this.user = firebase.auth().currentUser;
this.userdata = firebase.database().ref('/users/');
this.profilepicdata = firebase.storage().ref('/profilepics/');
}

savePicture(pic): any {
this.profilepicdata.child(this.user.uid).child('profilepicture.png')
.put(pic).then((savedpicture) => {
this.userdata.child(this.user.uid).update({'profilepic' : savedpicture.downloadURL});
});
}

}

5 changes: 0 additions & 5 deletions app/providers/user-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ export class UserData {
});
}

autoLoginLocalStorage() {
this.events.publish('user:login');
}

saveLocalStorage(credentials) {
this.setUsername(credentials.email);
this.setUserPwd(credentials.password);
this.events.publish('user:login');
}

setUsername(username) {
Expand Down
1 change: 1 addition & 0 deletions app/theme/app.core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
@import "../pages/forgot-password/forgot-password";
@import "../pages/mysettings/settings/settings";
@import "../pages/myinfo/personalprofile/personalprofile";
@import "../pages/myinfo/personalprofilephoto/personalprofilephoto";
@import "../pages/about/about";
7 changes: 3 additions & 4 deletions app/theme/ml.custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ ion-item-divider[mlitemdivider] {

/* Styles for help text */
#mlhelptext {
padding: 0 10px 0 10px;
font-size: 13px;
color: #8e8e93;
padding: 0 15px 0 15px;
font-size: 14px;
color: #909095;
}

/* Custom styles for ion-list showing help text */
Expand All @@ -53,7 +53,6 @@ ion-item-divider[mlitemdivider] {

/* Styles for MoneyLeash MyInput fields */
/* ------------------------------------ */

.ml-icon-left:before {
display: block;
text-align: center;
Expand Down

0 comments on commit d21a9f5

Please sign in to comment.