Created
March 31, 2017 16:10
-
-
Save javebratt/eb4d4e9269951726b73df89ecc08e9d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// FUNCTION 1 | |
createEvent(eventName: string, other_params, eventMainPicture = null): any { | |
return this.eventList.push({ | |
name: eventName, | |
... // All the other information you're adding. | |
... | |
... | |
}).then( newEvent => { | |
// When the event is created we pass in the base64 string that represents the picture to the | |
// Firebase SDK so it transforms it into a picture and uploads it to Storage: | |
firebase.storage().ref(`eventPictures/${newEvent.key}/mainPicture.png`) | |
.putString(eventMainPicture, 'base64', {contentType: 'image/png'}).then( savedPicture => { | |
// Then we add the download URL to the event's mainPicture property. | |
this.eventList.child(eventId).child('mainPicture').set(savedPicture.downloadURL); | |
}); | |
}); | |
} | |
// FUNCTION 2 | |
addPictureToEvent(eventId: string, pictureName: string, picture: string) { | |
firebase.storage().ref(`eventPictures/${eventId}/${pictureName}.png`) | |
.putString(picture, 'base64', {contentType: 'image/png'}).then( savedPicture => { | |
// Then we add the download URL to the event's mainPicture property. | |
this.eventList.child(eventId).child('pictures').push({ | |
picture: savedPicture.downloadURL, | |
pictureName: pictureName | |
}); | |
}); | |
} | |
// FUNCTION 3 | |
createEvent(eventName: string, eventBrand: string, eventColor: string, | |
eventSize: string, eventMeasurement: string, eventValue: number, eventDescription: string) { | |
this.eventData.createEvent(eventName, eventBrand, eventColor, eventSize, eventMeasurement, eventValue, | |
eventDescription, this.eventPicture).then( () => { | |
this.nav.pop(); | |
this.eventPicture = null; | |
}); | |
} | |
// FUNCTION 4 | |
addPicture(){ | |
this.camera.getPicture({ | |
quality : 95, | |
destinationType : this.camera.DestinationType.DATA_URL, | |
sourceType : this.camera.PictureSourceType.PHOTOLIBRARY, | |
allowEdit : true, | |
encodingType: this.camera.EncodingType.PNG, | |
targetWidth: 500, | |
targetHeight: 500, | |
saveToPhotoAlbum: true | |
}).then(imageData => { | |
this.eventPicture = imageData; | |
}, error => { | |
console.log("ERROR -> " + JSON.stringify(error)); | |
}); | |
} | |
// FUNCTION 5 | |
addExtraPicture(eventId: string, pictureName: string, picture: string){ | |
this.camera.getPicture({ | |
quality : 95, | |
destinationType : this.camera.DestinationType.DATA_URL, | |
sourceType : this.camera.PictureSourceType.PHOTOLIBRARY, | |
allowEdit : true, | |
encodingType: this.camera.EncodingType.PNG, | |
targetWidth: 500, | |
targetHeight: 500, | |
saveToPhotoAlbum: true | |
}).then(imageData => { | |
// Here you call the provider and pass the information: | |
this.eventData.addPictureToEvent(eventId, pictureName, picture).then( newPicture => { | |
// Here the picture was added and you could do whatever you want in the page now | |
// My suggestion is to clear the form so they can add more pictures | |
}); | |
}, error => { | |
console.log("ERROR -> " + JSON.stringify(error)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment