Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
f8007fac
Commit
f8007fac
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Use db schema to make column names
parent
831e9935
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
components/settings.js
+10
-29
10 additions, 29 deletions
components/settings.js
db/index.js
+21
-3
21 additions, 3 deletions
db/index.js
with
31 additions
and
32 deletions
components/settings.js
+
10
−
29
View file @
f8007fac
...
...
@@ -7,8 +7,9 @@ import {
}
from
'
react-native
'
import
Share
from
'
react-native-share
'
import
{
Base64
}
from
'
js-base64
'
import
styles
from
'
../styles/index
'
import
objectPath
from
'
object-path
'
import
{
getColumnNamesForCsv
,
cycleDaysSortedByDate
}
from
'
../db
'
import
styles
from
'
../styles/index
'
export
default
class
Settings
extends
Component
{
constructor
(
props
)
{
...
...
@@ -27,8 +28,9 @@ export default class Settings extends Component {
<
View
style
=
{
styles
.
homeButton
}
>
<
Button
onPress
=
{
async
()
=>
{
const
data
=
makeDataURI
()
console
.
log
(
data
)
// TODO show warning that there is nothing to export
if
(
!
cycleDaysSortedByDate
.
length
)
return
const
data
=
makeDataURI
(
cycleDaysSortedByDate
)
try
{
await
Share
.
open
({
title
:
'
My Drip data export
'
,
...
...
@@ -51,24 +53,15 @@ export default class Settings extends Component {
}
}
function
makeDataURI
()
{
//TODO handle empty DB
const
data
=
[{
date
:
'
2018-06-23
'
,
temperature
:
{
value
:
36.8
,
exclude
:
false
}
}]
const
csv
=
transformToCsv
(
data
)
function
makeDataURI
(
cycleDays
)
{
const
csv
=
transformToCsv
(
cycleDays
)
const
encoded
=
Base64
.
encodeURI
(
csv
)
return
`data:text/csv;base64,
${
encoded
}
`
}
function
transformToCsv
(
json
)
{
const
day
=
json
[
0
]
const
columnNames
=
getPrefixedKeys
(
day
)
const
rows
=
json
function
transformToCsv
(
cycleDays
)
{
const
columnNames
=
getColumnNamesForCsv
()
const
rows
=
cycleDays
.
map
(
day
=>
{
return
columnNames
.
map
(
column
=>
{
return
objectPath
.
get
(
day
,
column
,
''
)
...
...
@@ -79,15 +72,3 @@ function transformToCsv(json) {
rows
.
unshift
(
columnNames
.
join
(
'
,
'
))
return
rows
.
join
(
'
\n
'
)
}
function
getPrefixedKeys
(
obj
,
prefix
)
{
return
Object
.
keys
(
obj
).
reduce
((
acc
,
key
)
=>
{
const
prefixedKey
=
prefix
?
[
prefix
,
key
].
join
(
'
.
'
)
:
key
if
(
typeof
obj
[
key
]
!=
'
object
'
)
{
acc
.
push
(
prefixedKey
)
return
acc
}
acc
.
push
(...
getPrefixedKeys
(
obj
[
key
],
prefixedKey
))
return
acc
},
[])
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
db/index.js
+
21
−
3
View file @
f8007fac
...
...
@@ -98,6 +98,7 @@ const db = new Realm(realmConfig)
const
bleedingDaysSortedByDate
=
db
.
objects
(
'
CycleDay
'
).
filtered
(
'
bleeding != null
'
).
sorted
(
'
date
'
,
true
)
const
temperatureDaysSortedByDate
=
db
.
objects
(
'
CycleDay
'
).
filtered
(
'
temperature != null
'
).
sorted
(
'
date
'
,
true
)
const
cycleDaysSortedByDate
=
db
.
objects
(
'
CycleDay
'
).
sorted
(
'
date
'
,
true
)
function
saveSymptom
(
symptom
,
cycleDay
,
val
)
{
db
.
write
(()
=>
{
...
...
@@ -105,8 +106,6 @@ function saveSymptom(symptom, cycleDay, val) {
})
}
const
cycleDaysSortedByDate
=
db
.
objects
(
'
CycleDay
'
).
sorted
(
'
date
'
,
true
)
function
getOrCreateCycleDay
(
localDate
)
{
let
result
=
db
.
objectForPrimaryKey
(
'
CycleDay
'
,
localDate
)
if
(
!
result
)
{
...
...
@@ -164,6 +163,24 @@ function getPreviousTemperature(cycleDay) {
return
winner
.
temperature
.
value
}
function
getColumnNamesForCsv
()
{
return
getPrefixedKeys
(
'
CycleDay
'
)
function
getPrefixedKeys
(
schemaName
,
prefix
)
{
const
schema
=
db
.
schema
.
find
(
x
=>
x
.
name
===
schemaName
).
properties
return
Object
.
keys
(
schema
).
reduce
((
acc
,
key
)
=>
{
const
prefixedKey
=
prefix
?
[
prefix
,
key
].
join
(
'
.
'
)
:
key
const
childSchemaName
=
schema
[
key
].
objectType
if
(
!
childSchemaName
)
{
acc
.
push
(
prefixedKey
)
return
acc
}
acc
.
push
(...
getPrefixedKeys
(
childSchemaName
,
prefixedKey
))
return
acc
},
[])
}
}
export
{
saveSymptom
,
getOrCreateCycleDay
,
...
...
@@ -173,5 +190,6 @@ export {
fillWithDummyData
,
deleteAll
,
getPreviousTemperature
,
getCycleDay
getCycleDay
,
getColumnNamesForCsv
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment