Commit 77cc7971 authored by Bartłomiej Żmudziński's avatar Bartłomiej Żmudziński

Merge branch 'develop' into 'staging'

Develop

See merge request geoplan/geoankieta!2171
parents 91d582a6 9e1f69d4
......@@ -122,7 +122,7 @@ export function createSheetIfNeeded(questionnaireId, language = null) {
function fetchValue(response) {
return new Promise((resolve) => {
if (typeof response.value === 'string' && response.value.startsWith('blob:http')) {
if (typeof response.value === 'string' && response.value.startsWith('blob:')) {
const reader = new FileReader()
fetch(response.value)
......@@ -131,8 +131,9 @@ function fetchValue(response) {
reader.readAsDataURL(blob)
reader.onload = () => {
response.value = reader.result
resolve(response)
const newResponse = { ...response, value: reader.result }
resolve(newResponse)
}
})
} else {
......@@ -155,8 +156,7 @@ export function saveSheet(questionnaireId, language = null, questionnaireStamp)
(response) =>
response.status === STATUS_UNSYNCHRONIZED ||
response.status === STATUS_SYNCHRONIZING ||
response.timestamp > state.sheets.lastRequestTimestamp
).map((res) => ({ ...res, value: snakeCaseConverter(res.value) }))
response.timestamp > state.sheets.lastRequestTimestamp)
if (responses.length) {
Promise.all(responses.map((response) => fetchValue(response)))
......@@ -175,7 +175,10 @@ export function saveSheet(questionnaireId, language = null, questionnaireStamp)
Authorization: `Token ${state.app.tokens[questionnaireId]}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ responses, language }),
body: JSON.stringify({
responses: responses.map((res) => ({ ...res, value: snakeCaseConverter(res.value) })),
language,
}),
}).then((response) =>
response
.json()
......@@ -287,13 +290,12 @@ export function finishSheet(questionnaireId, restarting = false) {
export function setResponse(questionnaire, input, value) {
return (dispatch) => {
const newValue = snakeCaseConverter(value)
const timestamp = Date.now()
dispatch({
type: SET_RESPONSE,
questionnaire,
payload: { input, value: newValue, timestamp },
payload: { input, value, timestamp },
})
return Promise.resolve()
......
......@@ -390,6 +390,10 @@ export default function reducer(state = initialState, action) {
if (sheetIdx > -1) {
const newSheet = Object.assign({}, state.data[sheetIdx])
if (!newSheet.responses) {
newSheet.responses = []
}
let responseIdx = -1
if (action.payload.id) {
......@@ -439,6 +443,10 @@ export default function reducer(state = initialState, action) {
if (sheetIdx > -1 && action.payload) {
const newSheet = Object.assign({}, state.data[sheetIdx])
if (!newSheet.responses) {
newSheet.responses = []
}
const responseIdx = newSheet.responses.findIndex((elem) => elem.id === action.payload)
newSheet.responses = [
......
......@@ -7,7 +7,7 @@ import { DELETE_LOCALSTAMP, DELETE_RESPONSE, SET_RESPONSE } from '../../../actio
import { Dialog, FlatButton } from 'material-ui'
import React, { Component, PropTypes } from 'react'
import { finishSheet, saveSheet, setResponse } from '../../../actionCreators/sheets'
import { getResponse, getResponses, revalidateDrawbutton, snakeCaseConverter } from '../helpers'
import { getResponse, getResponses, revalidateDrawbutton } from '../helpers'
import { isEqual, omit, some } from 'lodash'
import ErrorView from './ErrorView'
......@@ -312,15 +312,13 @@ class QuestionnairePage extends Component {
if (isValid) {
if (this.state.formFieldsData) {
Object.keys(this.state.formFieldsData).forEach((item) => {
const newValue = snakeCaseConverter(this.state.formFieldsData[item].value)
this.props.dispatch({
type: SET_RESPONSE,
questionnaire: this.props.questionnaire.id,
payload: {
input: this.state.formFieldsData[item].input,
parent: this.state.formFieldsData[item].parent.parent,
value: newValue,
value: this.state.formFieldsData[item].value,
},
})
})
......@@ -392,14 +390,13 @@ class QuestionnairePage extends Component {
}
handleFormFieldChange(id, value) {
const newValue = snakeCaseConverter(value)
const { dispatch, questionnaire, match, popup } = this.props
const timestamp = Date.now()
this.setState({
formFieldsData: {
...this.state.formFieldsData,
[id]: { input: id, parent: this.props.popup, value: newValue },
[id]: { input: id, parent: this.props.popup, value },
},
})
......@@ -409,7 +406,7 @@ class QuestionnairePage extends Component {
payload: {
input: id,
parent: popup.parent,
value: newValue,
value,
timestamp,
},
})
......
......@@ -7,7 +7,7 @@ export function getResponse(input, defaultValue = null) {
const { data, popup } = store.getState().questionnaire
const sheet = store.getState().sheets.data.find((elem) => elem.questionnaire === data.id)
if (!sheet) {
if (!sheet || !sheet.responses) {
return defaultValue
}
......@@ -21,7 +21,7 @@ export function isPending(input) {
const { data, popup } = store.getState().questionnaire
const sheet = store.getState().sheets.data.find((elem) => elem.questionnaire === data.id)
if (!sheet) {
if (!sheet || !sheet.responses) {
return false
}
......@@ -76,7 +76,7 @@ export function getResponses(input, defaultValue = null) {
const questionnaire = store.getState().questionnaire.data
const sheet = store.getState().sheets.data.find((elem) => elem.questionnaire === questionnaire.id)
if (!sheet) {
if (!sheet || !sheet.responses) {
return defaultValue
}
......
......@@ -439,6 +439,7 @@ class InputFeatureCommentViewSet(viewsets.ModelViewSet):
comment=comment,
defaults=serializer.validated_data,
)
comment.refresh_from_db()
context = {'request': request}
return Response(GetInputFeatureCommentSerializer(comment, context=context).data)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment