app.question.component.js
Functions
renderQuestion(_id)
If the modal template is already instatiated, the function open it else it creates the modal. It takes the configuration of the question to choose which elements need to be added to the modal (select, input, chips, …)
Summary: Display a modal template and fill it from config question
Param | Type | Description |
---|---|---|
_id | _id | question UUID |
getAnswersValues(id, indexQuestion) ⇒ answer
Get answer value by id recommendation and index question from local storage
Returns: answer - answer - if exists or null
Param | Type | Description |
---|---|---|
id | string | id of recommendation |
indexQuestion | number | index of the question |
initializeMaterializeComponent()
Initialize Material components. This function need to be called after adding components to the DOM. This method is useful because in our case, our components are returned by our functions before adding them to the DOM. Some errors appears with Select component with this workflow. It’s base on global scope variable ‘MATERIALIZE_FIFO’
Summary: Initialize Material components wich need to be added to the DOM before
init
renderQuestionBtn()
Create validation button and bind it with the click event.
renderQuestionField(_id, index, one_field, answerStored) ⇒ HTMLElement
Render question from ‘render_field_str’ method in case of ‘str’ : input Render question from ‘render_field_list_str’ method in case of ’list’ : chips Render question from ‘render_field_choice_str’ method in case of ‘choice’ : select
Summary: Render question depending on the answer type
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
renderFieldStr(_id, index, one_field, answerStored) ⇒ HTMLElement
Render question method in case of ‘str’ : it creates an input
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
renderFieldListStr(_id, index, one_field, answerStored) ⇒ HTMLElement
Render question method in case of ’list’ : it creates a chips element
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
renderFieldChoiceStr(_id, index, one_field, answerStored) ⇒ HTMLElement
Render question method in case of ‘choice’ : it creates a select element The Select element is an
Returns: HTMLElement - HTMLElement - Brief description of the returning value here.
Param | Type | Description |
---|---|---|
_id | _id | UUID of the recommendation |
index | index | Index of question |
one_field | one_field | configuration of the answer |
answerStored | answerStored | answer if exists or null |
retrieveListStrData(inputComponent, configType)
Get data from chips in case of ’list’, it takes values from a chips elements and add it to the local storage
Param | Type | Description |
---|---|---|
inputComponent | input_component | Chips element |
configType | configType | Configuration of the field |
retrieveStr(inputComponent, configType)
Get data from input in case of ‘str’, it takes valueand add it to the local storage
Param | Type | Description |
---|---|---|
inputComponent | input_component | Chips element |
configType | configType | Configuration of the field |
storeAnswerInLocalStorage(inputComponent, dataToSave, configType)
Update local storage with a new value. If the answer value is empty, it’s remove from local storage. If there’s already a value present, we update this value.
Summary: Update local storage with a new value.
Param | Type | Description |
---|---|---|
inputComponent | inputComponent | inputComponent is a DOM Element, it has an id : UUIDRecommendation-index |
dataToSave | dataToSave | Data already process for the back, this value will be sent |
configType | configType | config type of the question |
storeSelectedIds(id)
Manage selected IDS. Based on verification about storage item with UUID of the recommendation. If an item with the same id does not exists, we remove the id from the data We also check the local storage to create it if it’s not exists.
Summary: Manage selected IDS stored in store
Param | Type | Description |
---|---|---|
id | ParamDataTypeHere | ID of recommendation |
storeAnswerData(id, valueFormat, dataToSave)
Store answer data to localStorage
Param | Type | Description |
---|---|---|
id | inputComponent | Id of recommendation |
valueFormat | inputComponent | Data formated by our function to be store |
dataToSave | inputComponent | data to check if it’s not empty in order to remove local storage |
formatValueToStore(inputComponent, dataToSave, configType) ⇒ string
Format a value in order to be store in local storage. It’s a JSON format with three keys : value, formatType, index
Returns: string - Object - id, valueFormat
Param | Type | Description |
---|---|---|
inputComponent | inputComponent | Input component is needed to retrieve the index of answer and id recommendation |
dataToSave | inputComponent | Data in value |
configType | inputComponent | Configuration of this answer to send type answer to the back |