Reference Source
public class | source

AddBikePresenter

Extends:

* → AddBikePresenter

Class for the AddBike presenter and view

Constructor Summary

Public Constructor
public

Creates an instance of AddBikePresenter

Member Summary

Public Members
public

changeText(colours: List, renderer: Function): *

Converts a list of colour objects to a list of objects with a component using the renderer function.

public

checkEditingState(editingState: Boolean, success: Function, failure: Function): *

Checks the editing state of the view and calls one of its passed in functions.

public

checkInputs(inputData: List, inputRequirementFailure: Function): Boolean: *

Checks the input data for required inputs and calls an alert function if inputs are missing.

public

Resets the current photos to the default photos.

public
public

deleteBike(id: string, callback: Function): *

Delete a bike from the database

public

getCurrentPhotos: List: *

Returns a deep copy of the current photos.

public

Gets the data from the model and returns it to the caller.

public

getTextInputData(data: Object, isEditPage: Boolean): List: *

Return the data for the text inputs.

public

If the view or presenter is destroyed, unsubscribe the presenter from the model.

public

onUpdated(newData: Object): *

Called when the model is updated with new data.

public

toggleColours(sectionedMultiSelect: Object, data: Object, onColoursFound: Function, UNIQUE_KEY: string): *

Toggles the colours from the data if the data is present.

public

update(newData: Object, callback: Function): *

Updates the bike model with new data.

public

view: *

Private Members
private

Build the data obtained from the view and insert it into a new data object.

private

_deepCopy: List: *

Returns a deep copy of the array by reassigning the values.

private

_getRequiredInputs(inputs: List): List: *

Returns the required inputs based on the required property

private

_getString(val: Number/string): string: *

Checks if the value is valid and if so, convert it to a string.

private

_translateDataToInput(data: Object): List: *

Translates data input (Bike data) to the text inputs.

private

check: *

private
private

getProp: *

Method Summary

Public Methods
public

selectPhotoTapped(imagePicker: Object, setEditing: Function, id: Number, photos: List)

Open the image picker.

Public Constructors

public constructor(view: Object) source

Creates an instance of AddBikePresenter

Params:

NameTypeAttributeDescription
view Object

An instance of a view class

Public Members

public changeText(colours: List, renderer: Function): * source

Converts a list of colour objects to a list of objects with a component using the renderer function.

public checkEditingState(editingState: Boolean, success: Function, failure: Function): * source

Checks the editing state of the view and calls one of its passed in functions.

public checkInputs(inputData: List, inputRequirementFailure: Function): Boolean: * source

Checks the input data for required inputs and calls an alert function if inputs are missing.

Return:

Boolean

true: some required inputs are blank; false: required inputs are not blank

public clearPhotos: * source

Resets the current photos to the default photos.

public currentPhotos: * source

public deleteBike(id: string, callback: Function): * source

Delete a bike from the database

public getCurrentPhotos: List: * source

Returns a deep copy of the current photos.

Return:

List

A list of the current photos

public getData: Object: * source

Gets the data from the model and returns it to the caller.

Return:

Object

Data from the model.

public getTextInputData(data: Object, isEditPage: Boolean): List: * source

Return the data for the text inputs. Object: name: the name/label of the text input disabled: true: if the field is disabled; false: otherwise multiline: true: if the input is allowed to span multiple lines; false: otherwise text: initial text of the input

Return:

List

A list of data objects (name, multiline, text)

public onDestroy: * source

If the view or presenter is destroyed, unsubscribe the presenter from the model.

public onUpdated(newData: Object): * source

Called when the model is updated with new data. Refreshes the state of the view. Method is supplied with the data to add. Better way to refresh the state?

public toggleColours(sectionedMultiSelect: Object, data: Object, onColoursFound: Function, UNIQUE_KEY: string): * source

Toggles the colours from the data if the data is present.

public update(newData: Object, callback: Function): * source

Updates the bike model with new data.

public view: * source

Private Members

private _buildDataFromView(newData: Object): Object: * source

Build the data obtained from the view and insert it into a new data object. Current attributes of newData object: {Object} inputTextData: [{name, multiline, disabled, text}] {List} selectedColours {Object} picture: uri

Return:

Object

The built data of the object. Attributes: data

private _deepCopy: List: * source

Returns a deep copy of the array by reassigning the values. This is to make sure we can clear the data.

Return:

List

A list to copy

private _getRequiredInputs(inputs: List): List: * source

Returns the required inputs based on the required property

Return:

List

A list of required text inputs

private _getString(val: Number/string): string: * source

Checks if the value is valid and if so, convert it to a string.

Return:

string

Value converted to a string

private _translateDataToInput(data: Object): List: * source

Translates data input (Bike data) to the text inputs. Could be refactored to be made easier for adaptations.

Return:

List

A copy of the data that is now in the form of the text input

private check: * source

private filterItems: * source

private getProp: * source

Public Methods

public selectPhotoTapped(imagePicker: Object, setEditing: Function, id: Number, photos: List) source

Open the image picker. Set the editing option to true.

Params:

NameTypeAttributeDescription
imagePicker Object

The ImagePicker class from react-native-image-picker

setEditing Function

A function so the presenter can set the editing value

id Number

The index of the photo to change

photos List

A list of photos as strings