FirebaseDatabase
Class for the firebase database connection and operations
Constructor Summary
Public Constructor | ||
public |
Creates an instance of the FirebaseDatabase class. |
Member Summary
Public Members | ||
public |
currentUser: * |
|
public |
refDB: * |
|
public |
refStorage: * |
Method Summary
Public Methods | ||
public |
|
|
public |
editBikeData(newBikeData: Object, onSuccess: Function, onError: Function) Overwrites data in the database by reading the data, merging it with the new values and writing back to the same ID. |
|
public |
editProfileData(newProfileData: Object, onSuccess: Function, onError: Function) Overwrites data in the database by reading the data, merging it with the new values and writing back to the same ID. |
|
public |
getCurrentUser(onComplete: Function): Function Returns the currently logged in user's id. |
|
public |
Return the possible image folders in the firebase storage. |
|
public |
Returns a new unique key generated by the database. |
|
public |
getNewProfileID(): * Returns a new unique key generated by the database. |
|
public |
Returns the storage without a reference. |
|
public |
Makes the database go offline. |
|
public |
goOnline() Makes the database go online. |
|
public |
handleFirebaseLogin(accessToken: *) |
|
public |
listenForAuthChange(onSuccess: Function) Listens for authentication changes and only calls the onSuccess function if a user is defined. |
|
public |
listenOff(child: *, event: *, listener: *) |
|
public |
General function for listening to the database for events. |
|
public |
Merges the data of two objects. |
|
public |
readBikeDataOff(listener: *) |
|
public |
readBikeDataOn(callback: Function): Object Read data from the bike table every time there is a change in the database. |
|
public |
readBikeDataOnce(callback: Function) Read data from the bike table only once. |
|
public |
readProfileDataOnce(id: string, callback: Function) Read data from the user table once, only looking for a specific user id. |
|
public |
removeBikeItem(key: string, callback: Function) Removes a bike id from the database. |
|
public |
removeImages(thumbnails: string, callback: Function) Remove a images by their url from storage. |
|
public |
removeItem(table: string, removeChild: string, callback: Function) Removes an item from the database given by 'removeChild' in the 'table'. |
|
public |
|
|
public |
sendresetEmail(onError: *) |
|
public |
setAccount(user: *) |
|
public |
Set up the database reference to the PProject table |
|
public |
Set up the storage reference |
|
public |
Accesses Firebase data to sign in with email and password. |
|
public |
signInwithTwitter(onError: *) |
|
public |
Sign out of the database. |
|
public |
signUp(email: *, password: *, onSuccess: *, onError: *): * |
|
public |
signinwithFB(onError: *) |
|
public |
triggerTemporaryItem(data: Object, onError: Function) Trigger the on reads by adding and removing an item from the database in the Bike Table. |
|
public |
writeBikeData(bikeData: Object, onSuccess: Function, onError: Function) Write to the database in table 'Bike' using the id as the child. |
|
public |
async writeImage(id: string, file: Object, filename: string, baseFolder: string, onSuccess: Function, onError: Function) Asynchronously write an image to firebase storage. |
|
public |
writeProfileData(profileData: Object, onSuccess: Function, onError: Function) Write to the database in the table 'Users' using the user id as the child. |
Public Constructors
public constructor() source
Creates an instance of the FirebaseDatabase class. Initializes the app as a firebase app and sets up the storage references.
Public Methods
public editBikeData(newBikeData: Object, onSuccess: Function, onError: Function) source
Overwrites data in the database by reading the data, merging it with the new values and writing back to the same ID.
public editProfileData(newProfileData: Object, onSuccess: Function, onError: Function) source
Overwrites data in the database by reading the data, merging it with the new values and writing back to the same ID.
public getCurrentUser(onComplete: Function): Function source
Returns the currently logged in user's id.
Params:
Name | Type | Attribute | Description |
onComplete | Function | A callback function when the state has changed |
public getImageFolders(): Object source
Return the possible image folders in the firebase storage. See top definitions for names. Possible TODO : Fetch folder names from the storage so to not hardcode them in.
public getNewProfileID(): * source
Returns a new unique key generated by the database. Shouldn't need to use this because user IDs are generated on Sign-up.
Return:
* |
public handleFirebaseLogin(accessToken: *) source
Params:
Name | Type | Attribute | Description |
accessToken | * |
public listenForAuthChange(onSuccess: Function) source
Listens for authentication changes and only calls the onSuccess function if a user is defined.
Params:
Name | Type | Attribute | Description |
onSuccess | Function | A callback function when the state has changed and a user is defined |
public listenOff(child: *, event: *, listener: *) source
Params:
Name | Type | Attribute | Description |
child | * | ||
event | * | ||
listener | * |
public listenOn(child: string, event: string, callback: Function): Object source
General function for listening to the database for events. Be as specific as possible when specifying the child (don't just listen on root). See https://firebase.google.com/docs/reference/js/firebase.database.Reference#on for event names.
public merge(originalObj: Object, newObj: Object): Object source
Merges the data of two objects. Keeps everything in originalObj, adds any key in newObj and overwrites duplicates in originalObj.
public readBikeDataOff(listener: *) source
Params:
Name | Type | Attribute | Description |
listener | * |
public readBikeDataOn(callback: Function): Object source
Read data from the bike table every time there is a change in the database.
Params:
Name | Type | Attribute | Description |
callback | Function | A function callback that is with the value(s) read |
public readBikeDataOnce(callback: Function) source
Read data from the bike table only once.
Params:
Name | Type | Attribute | Description |
callback | Function | A function callback that is with the value(s) read |
public readProfileDataOnce(id: string, callback: Function) source
Read data from the user table once, only looking for a specific user id.
public removeImages(thumbnails: string, callback: Function) source
Remove a images by their url from storage.
public removeItem(table: string, removeChild: string, callback: Function) source
Removes an item from the database given by 'removeChild' in the 'table'.
public sendEmail() source
public sendresetEmail(onError: *) source
Params:
Name | Type | Attribute | Description |
onError | * |
public setAccount(user: *) source
Params:
Name | Type | Attribute | Description |
user | * |
public async signIn(email: string, password: string, onError: Function) source
Accesses Firebase data to sign in with email and password. This function is called asynchronously. Use 'async' and 'await'.
public signInwithTwitter(onError: *) source
Params:
Name | Type | Attribute | Description |
onError | * |
public signUp(email: *, password: *, onSuccess: *, onError: *): * source
Params:
Name | Type | Attribute | Description |
* | |||
password | * | ||
onSuccess | * | ||
onError | * |
Return:
* |
public signinwithFB(onError: *) source
Params:
Name | Type | Attribute | Description |
onError | * |
public triggerTemporaryItem(data: Object, onError: Function) source
Trigger the on reads by adding and removing an item from the database in the Bike Table.
public writeBikeData(bikeData: Object, onSuccess: Function, onError: Function) source
Write to the database in table 'Bike' using the id as the child. Adds a date time and owner to the data
public async writeImage(id: string, file: Object, filename: string, baseFolder: string, onSuccess: Function, onError: Function) source
Asynchronously write an image to firebase storage.
Params:
Name | Type | Attribute | Description |
id | string | The id of the bike to write to |
|
file | Object | The file object to write |
|
filename | string | The name of the file |
|
baseFolder | string | The base folder of the images. One of "BikeImages/", "ProfileImages/" etc. (Must include '/') |
|
onSuccess | Function | The callback to call on a successful upload |
|
onError | Function | The callback to call on a failed upload |