Merge branch 'master' into 82-chart-improvements

This commit is contained in:
Julia Friesel
2018-08-16 14:46:08 +02:00
16 changed files with 603 additions and 65 deletions
+31 -4
View File
@@ -98,11 +98,20 @@ export default class DayView extends Component {
<Text style={styles.symptomDayView}>Desire</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('desireEditView')}
onPress={() => this.showView('DesireEditView')}
title={getLabel('desire', cycleDay.desire)}>
</Button>
</View>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>Sex</Text>
<View style={styles.symptomEditButton}>
<Button
onPress={() => this.showView('SexEditView')}
title={getLabel('sex', cycleDay.sex)}>
</Button>
</View>
</View>
</View >
)
}
@@ -132,15 +141,22 @@ function getLabel(symptomName, symptom) {
typeof mucus.texture === 'number' &&
typeof mucus.value === 'number'
) {
let mucusLabel = `${feelingLabels[mucus.feeling]} + ${textureLabels[mucus.texture]} ( ${computeSensiplanMucusLabels[mucus.value]} )`
let mucusLabel =
`${feelingLabels[mucus.feeling]} +
${textureLabels[mucus.texture]}
( ${computeSensiplanMucusLabels[mucus.value]} )`
if (mucus.exclude) mucusLabel = "( " + mucusLabel + " )"
return mucusLabel
}
},
cervix: cervix => {
if (cervix.opening > -1 && cervix.firmness > -1) {
let cervixLabel = `${openingLabels[cervix.opening]} + ${firmnessLabels[cervix.firmness]}`
if (cervix.position > -1) cervixLabel += `+ ${positionLabels[cervix.position]}`
let cervixLabel =
`${openingLabels[cervix.opening]} +
${firmnessLabels[cervix.firmness]}`
if (cervix.position > -1) {
cervixLabel += `+ ${positionLabels[cervix.position]}`
}
if (cervix.exclude) cervixLabel = "( " + cervixLabel + " )"
return cervixLabel
}
@@ -153,6 +169,17 @@ function getLabel(symptomName, symptom) {
const desireLabel = `${intensityLabels[desire.value]}`
return desireLabel
}
},
sex: sex => {
let sexLabel = ''
if ( sex.solo || sex.partner ) {
sexLabel += 'Activity '
}
if (sex.condom || sex.pill || sex.iud ||
sex.patch || sex.ring || sex.implant || sex.other) {
sexLabel += 'Contraceptive'
}
return sexLabel ? sexLabel : 'edit'
}
}
+13
View File
@@ -6,6 +6,19 @@ export const cervixOpening = ['closed', 'medium', 'open']
export const cervixFirmness = ['hard', 'soft']
export const cervixPosition = ['low', 'medium', 'high']
export const intensity = ['low', 'medium', 'high']
export const sexActivity = {
solo: 'Solo',
partner: 'Partner'
}
export const contraceptives = {
condom: 'Condom',
pill: 'Pill',
iud: 'IUD',
patch: 'Patch',
ring: 'Ring',
implant: 'Implant',
other: 'Other'
}
export const fertilityStatus = {
fertile: 'fertile',
+4 -2
View File
@@ -4,6 +4,7 @@ import MucusEditView from './mucus'
import CervixEditView from './cervix'
import NoteEditView from './note'
import DesireEditView from './desire'
import SexEditView from './sex'
export default {
BleedingEditView,
@@ -11,5 +12,6 @@ export default {
MucusEditView,
CervixEditView,
NoteEditView,
DesireEditView
}
DesireEditView,
SexEditView
}
+156
View File
@@ -0,0 +1,156 @@
import React, { Component } from 'react'
import {
CheckBox,
Text,
TextInput,
View
} from 'react-native'
import styles from '../../../styles'
import { saveSymptom } from '../../../db'
import {
sexActivity as activityLabels,
contraceptives as contraceptiveLabels
} from '../labels/labels'
export default class Sex extends Component {
constructor(props) {
super(props)
this.cycleDay = props.cycleDay
this.state = {}
if (this.cycleDay.sex !== null ) {
Object.assign(this.state, this.cycleDay.sex)
// We make sure other is always true when there is a note,
// e.g. when import is messed up.
if (this.cycleDay.sex && this.cycleDay.sex.note) {
this.state.other = true
}
}
}
render() {
return (
<View style={styles.symptomEditView}>
<Text style={styles.symptomDayView}>SEX</Text>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>{activityLabels.solo}</Text>
<CheckBox
value={this.state.solo}
onValueChange={(val) => {
this.setState({solo: val})
}}
/>
<Text style={styles.symptomDayView}>{activityLabels.partner}</Text>
<CheckBox
value={this.state.partner}
onValueChange={(val) => {
this.setState({partner: val})
}}
/>
</View>
<Text style={styles.symptomDayView}>CONTRACEPTIVES</Text>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.condom}
</Text>
<CheckBox
value={this.state.condom}
onValueChange={(val) => {
this.setState({condom: val})
}}
/>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.pill}
</Text>
<CheckBox
value={this.state.pill}
onValueChange={(val) => {
this.setState({pill: val})
}}
/>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.iud}
</Text>
<CheckBox
value={this.state.iud}
onValueChange={(val) => {
this.setState({iud: val})
}}
/>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.patch}
</Text>
<CheckBox
value={this.state.patch}
onValueChange={(val) => {
this.setState({patch: val})
}}
/>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.ring}
</Text>
<CheckBox
value={this.state.ring}
onValueChange={(val) => {
this.setState({ring: val})
}}
/>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.implant}
</Text>
<CheckBox
value={this.state.implant}
onValueChange={(val) => {
this.setState({implant: val})
}}
/>
</View>
<View style={styles.symptomViewRowInline}>
<Text style={styles.symptomDayView}>
{contraceptiveLabels.other}
</Text>
<CheckBox
value={this.state.other}
onValueChange={(val) => {
this.setState({
other: val,
focusTextArea: true
})
}}
/>
</View>
{ this.state.other &&
<TextInput
autoFocus={this.state.focusTextArea}
multiline={true}
placeholder="Enter"
value={this.state.note}
onChangeText={(val) => {
this.setState({note: val})
}}
/>
}
<View style={styles.actionButtonRow}>
{this.props.makeActionButtons(
{
symptom: 'sex',
cycleDay: this.cycleDay,
saveAction: () => {
const copyOfState = Object.assign({}, this.state)
if (!copyOfState.other) {
copyOfState.note = null
}
saveSymptom('sex', this.cycleDay, copyOfState)
},
saveDisabled: Object.values(this.state).every(value => !value)
}
)}
</View>
</View>
)
}
}
+30 -7
View File
@@ -1,10 +1,33 @@
export const settings = {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
shared: {
cancel: 'Cancel',
errorTitle: 'Error',
successTitle: 'Success'
},
exportTitle: 'My Drip data export',
exportSubject: 'My Drip data export',
buttonLabel: 'Export data'
export: {
errors: {
noData: 'There is no data to export',
couldNotConvert: 'Could not convert data to CSV',
problemSharing: 'There was a problem sharing the data export file'
},
title: 'My Drip data export',
subject: 'My Drip data export',
button: 'Export data',
},
import: {
button: 'Import data',
title: 'Keep existing data?',
message: `There are two options for the import:
1. Keep existing cycle days and replace only the ones in the import file.
2. Delete all existing cycle days and import cycle days from file.`,
replaceOption: 'Import and replace',
deleteOption: 'Import and delete existing',
errors: {
couldNotOpenFile: 'Could not open file',
postFix: 'No data was imported or changed'
},
success: {
message: 'Data successfully imported'
}
}
}
+94 -27
View File
@@ -7,9 +7,12 @@ import {
} from 'react-native'
import Share from 'react-native-share'
import getDataAsCsvDataUri from '../lib/export-to-csv'
import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker'
import rnfs from 'react-native-fs'
import styles from '../styles/index'
import { settings as labels } from './labels'
import getDataAsCsvDataUri from '../lib/import-export/export-to-csv'
import importCsv from '../lib/import-export/import-from-csv'
export default class Settings extends Component {
render() {
@@ -18,36 +21,100 @@ export default class Settings extends Component {
<View style={styles.homeButtons}>
<View style={styles.homeButton}>
<Button
onPress={async () => {
let data
try {
data = getDataAsCsvDataUri()
if (!data) {
return Alert.alert(labels.errors.noData)
}
} catch (err) {
console.error(err)
return Alert.alert(labels.errors.couldNotConvert)
}
try {
await Share.open({
title: labels.exportTitle,
url: data,
subject: labels.exportSubject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return Alert.alert(labels.errors.problemSharing)
}
}}
title={labels.buttonLabel}>
onPress={ openShareDialogAndExport }
title={labels.export.button}>
</Button>
</View>
<View style={styles.homeButton}>
<Button
title={labels.import.button}
onPress={ openImportDialogAndImport }>
</Button>
</View>
</View>
</ScrollView>
)
}
}
async function openShareDialogAndExport() {
let data
try {
data = getDataAsCsvDataUri()
if (!data) {
return alertError(labels.errors.noData)
}
} catch (err) {
console.error(err)
return alertError(labels.errors.couldNotConvert)
}
try {
await Share.open({
title: labels.export.title,
url: data,
subject: labels.export.subject,
type: 'text/csv',
showAppsToView: true
})
} catch (err) {
console.error(err)
return alertError(labels.export.errors.problemSharing)
}
}
function openImportDialogAndImport() {
Alert.alert(
labels.import.title,
labels.import.message,
[{
text: labels.import.replaceOption,
onPress: () => getFileContentAndImport({ deleteExisting: false })
}, {
text: labels.import.deleteOption,
onPress: () => getFileContentAndImport({ deleteExisting: true })
}, {
text: labels.shared.cancel, style: 'cancel', onPress: () => { }
}]
)
}
async function getFileContentAndImport({ deleteExisting }) {
let fileInfo
try {
fileInfo = await new Promise((resolve, reject) => {
DocumentPicker.show({
filetype: [DocumentPickerUtil.allFiles()],
}, (err, res) => {
if (err) return reject(err)
resolve(res)
})
})
} catch (err) {
// because cancelling also triggers an error, we do nothing here
return
}
let fileContent
try {
fileContent = await rnfs.readFile(fileInfo.uri, 'utf8')
} catch (err) {
return importError(labels.import.errors.couldNotOpenFile)
}
try {
await importCsv(fileContent, deleteExisting)
Alert.alert(labels.import.success.title, labels.import.success.message)
} catch(err) {
importError(err.message)
}
}
function alertError(msg) {
Alert.alert(labels.shared.errorTitle, msg)
}
function importError(msg) {
const postFixed = `${msg}\n\n${labels.import.errors.postFix}`
alertError(postFixed)
}