Reference Source
public class | source

FirebaseDatabase

You can directly use an instance of this class. Database

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
public

refDB: *

public

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

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

Returns a new unique key generated by the database.

public

Returns the storage without a reference.

public

Makes the database go offline.

public

Makes the database go online.

public

handleFirebaseLogin(accessToken: *)

public

Listens for authentication changes and only calls the onSuccess function if a user is defined.

public

listenOff(child: *, event: *, listener: *)

public

listenOn(child: string, event: string, callback: Function): Object

General function for listening to the database for events.

public

merge(originalObj: Object, newObj: Object): Object

Merges the data of two objects.

public

readBikeDataOff(listener: *)

public

Read data from the bike table every time there is a change in the database.

public

Read data from the bike table only once.

public

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

async signIn(email: string, password: string, onError: Function)

Accesses Firebase data to sign in with email and password.

public

signInwithTwitter(onError: *)

public

signOut(onSuccess: Function, onError: Function)

Sign out of the database.

public

signUp(email: *, password: *, onSuccess: *, onError: *): *

public

signinwithFB(onError: *)

public

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 Members

public currentUser: * source

public refDB: * source

public refStorage: * source

Public Methods

public checkVerify(): boolean source

Return:

boolean

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.

Params:

NameTypeAttributeDescription
newBikeData Object

New data to write

onSuccess Function

A function callback to run when writing is successful

onError Function

A function callback to run when writing fails

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.

Params:

NameTypeAttributeDescription
newProfileData Object

New data to write

onSuccess Function

A function callback to run when writing is successful

onError Function

A function callback to run when writing fails

public getCurrentUser(onComplete: Function): Function source

Returns the currently logged in user's id.

Params:

NameTypeAttributeDescription
onComplete Function

A callback function when the state has changed

Return:

Function

Function to unsubscribe from the authentication listener

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.

Return:

Object

The string names of the folders, includes '/' in each name

public getNewBikeID(): string source

Returns a new unique key generated by the database.

Return:

string

A newly generated unique key

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 getStorageWithoutRef(): Object source

Returns the storage without a reference.

Return:

Object

The storage without reference

public goOffline() source

Makes the database go offline.

public goOnline() source

Makes the database go online.

public handleFirebaseLogin(accessToken: *) source

Params:

NameTypeAttributeDescription
accessToken *

public listenForAuthChange(onSuccess: Function) source

Listens for authentication changes and only calls the onSuccess function if a user is defined.

Params:

NameTypeAttributeDescription
onSuccess Function

A callback function when the state has changed and a user is defined

public listenOff(child: *, event: *, listener: *) source

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
child string

A child to listen on

event string

An event to listen for

callback Function

A function callback to trigger when data is recieved

Return:

Object

A listener from the 'on' function

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.

Params:

NameTypeAttributeDescription
originalObj Object

Original data to replace

newObj Object

New data to add

Return:

Object

Merged data

public readBikeDataOff(listener: *) source

Params:

NameTypeAttributeDescription
listener *

public readBikeDataOn(callback: Function): Object source

Read data from the bike table every time there is a change in the database.

Params:

NameTypeAttributeDescription
callback Function

A function callback that is with the value(s) read

Return:

Object

A listener from the 'on' function

public readBikeDataOnce(callback: Function) source

Read data from the bike table only once.

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
id string

The current user's id

callback Function

A function callback that is with the value(s) read

public removeBikeItem(key: string, callback: Function) source

Removes a bike id from the database.

Params:

NameTypeAttributeDescription
key string

A bike id to remove

callback Function

A function callback to trigger when the bike is removed

public removeImages(thumbnails: string, callback: Function) source

Remove a images by their url from storage.

Params:

NameTypeAttributeDescription
thumbnails string

A list of images to delete

callback Function

A function to call on completion or on failure

public removeItem(table: string, removeChild: string, callback: Function) source

Removes an item from the database given by 'removeChild' in the 'table'.

Params:

NameTypeAttributeDescription
table string

A table to remove from

removeChild string

A child id to remove

callback Function

A function callback to trigger when item is removed

public sendEmail() source

public sendresetEmail(onError: *) source

Params:

NameTypeAttributeDescription
onError *

public setAccount(user: *) source

Params:

NameTypeAttributeDescription
user *

public setupDatabaseRef() source

Set up the database reference to the PProject table

public setupStorageRef() source

Set up the storage reference

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'.

Params:

NameTypeAttributeDescription
email string

A user's email

password string

A user's password

onError Function

A function callback to execute on error

public signInwithTwitter(onError: *) source

Params:

NameTypeAttributeDescription
onError *

public signOut(onSuccess: Function, onError: Function) source

Sign out of the database.

Params:

NameTypeAttributeDescription
onSuccess Function

A callback function on a successful signout

onError Function

A callback function on a failure to signout

public signUp(email: *, password: *, onSuccess: *, onError: *): * source

Params:

NameTypeAttributeDescription
email *
password *
onSuccess *
onError *

Return:

*

public signinwithFB(onError: *) source

Params:

NameTypeAttributeDescription
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.

Params:

NameTypeAttributeDescription
data Object

The temporary object to store

onError Function

A callback function if there is an error writing

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

Params:

NameTypeAttributeDescription
bikeData Object

Bike data to add to the database

onSuccess Function

A function callback to execute on the success of writing to the database

onError Function

A function callback to execute on an error when writing to the database

public async writeImage(id: string, file: Object, filename: string, baseFolder: string, onSuccess: Function, onError: Function) source

Asynchronously write an image to firebase storage.

Params:

NameTypeAttributeDescription
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

public writeProfileData(profileData: Object, onSuccess: Function, onError: Function) source

Write to the database in the table 'Users' using the user id as the child.

Params:

NameTypeAttributeDescription
profileData Object

The data to upload

onSuccess Function

A function callback to execute on the success of writing to the database

onError Function

A function callback to execute on an error when writing to the database