Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Catalog
catalog.genesys-pgr.org
Commits
e4e1adc3
Commit
e4e1adc3
authored
Feb 06, 2018
by
Matija Obreza
Browse files
Load Genesys descriptors and display decoded MCPD
parent
203216c8
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/actions/descriptorList.ts
View file @
e4e1adc3
...
...
@@ -27,7 +27,7 @@ const loadingDescriptorLists = (page, results, sortBy, filter, order) => ({
});
// Just load a descriptor list
export
const
loadDescriptorList
=
(
uuid
:
string
)
=>
(
dispatch
,
getState
)
=>
{
export
const
loadDescriptorList
=
(
uuid
:
string
,
success
?:
(
d
)
=>
any
,
fail
?:
(
error
)
=>
any
)
=>
(
dispatch
,
getState
)
=>
{
log
(
'
Loading descriptor list
'
,
uuid
);
const
token
=
getState
().
login
.
access_token
;
...
...
@@ -39,9 +39,15 @@ export const loadDescriptorList = (uuid: string) => (dispatch, getState) => {
// .then((descriptorList) => {
// await setTimeout(() => dispatch(receiveDescriptorList(descriptorList)), 10000);
.
then
((
descriptorList
)
=>
{
if
(
success
)
{
return
success
(
descriptorList
);
}
dispatch
(
receiveDescriptorList
(
descriptorList
));
}).
catch
((
error
)
=>
{
log
(
`No descriptor list with uuid
${
uuid
}
`
,
error
);
if
(
fail
)
{
return
fail
(
error
);
}
});
};
...
...
src/actions/descriptors.ts
View file @
e4e1adc3
...
...
@@ -36,7 +36,7 @@ export function showDescriptorsDashboard() {
};
}
export
function
loadDescriptor
(
uuid
:
string
)
{
export
function
loadDescriptor
(
uuid
:
string
,
success
?:
(
d
)
=>
any
,
fail
?:
(
error
)
=>
any
)
{
log
(
'
Loading descriptor
'
,
uuid
);
return
(
dispatch
,
getState
)
=>
{
const
token
=
getState
().
login
.
access_token
;
...
...
@@ -45,9 +45,15 @@ export function loadDescriptor(uuid: string) {
return
DescriptorService
.
loadDescriptor
(
token
,
uuid
)
.
then
((
loaded
)
=>
{
if
(
success
)
{
return
success
(
loaded
);
}
dispatch
(
receiveDescriptor
(
loaded
));
}).
catch
((
error
)
=>
{
log
(
`No descriptor with uuid
${
uuid
}
`
,
error
);
if
(
fail
)
{
return
fail
(
error
);
}
throw
new
SubmissionError
({
title
:
'
Title already used
'
,
_error
:
error
.
error
});
});
};
...
...
src/actions/genesys.ts
View file @
e4e1adc3
// import {push} from 'react-router-redux';
import
{
GenesysService
}
from
'
service/GenesysService
'
;
// import {CREATE_CROP, GET_CROP, RECEIVE_CROP, RECEIVE_CROPS} from 'constants/crop';
// import {IReducerAction} from 'model/common.model';
import
{
Descriptor
,
DataType
,
DescriptorList
,
DescriptorListExtra
}
from
'
model/descriptor.model
'
;
import
{
loadDescriptorList
}
from
'
actions/descriptorList
'
;
import
{
loadDescriptor
}
from
'
actions/descriptors
'
;
import
{
log
}
from
'
utilities/debug
'
;
export
const
listAccessions
=
(
filters
:
object
,
page
:
number
=
0
,
results
:
number
=
50
)
=>
(
dispatch
,
getState
)
=>
{
...
...
@@ -13,3 +15,26 @@ export const listAccessions = (filters: object, page: number = 0, results: numbe
log
(
`Genesys error`
,
error
);
});
};
export
const
loadGenesysDescriptors
=
()
=>
(
dispatch
,
getState
)
=>
{
log
(
'
Loading Genesys descriptor list
'
,
'
dc1d4e81-a6dd-4f03-b682-53a3a1383988
'
);
return
dispatch
(
loadDescriptorList
(
'
dc1d4e81-a6dd-4f03-b682-53a3a1383988
'
,
// TODO this can go to a state reducer
async
(
descriptorList
:
DescriptorList
)
=>
{
if
(
descriptorList
.
extras
[
DescriptorListExtra
.
JSON_MAPPING
])
{
descriptorList
.
extras
[
DescriptorListExtra
.
JSON_MAPPING
]
=
JSON
.
parse
(
descriptorList
.
extras
[
DescriptorListExtra
.
JSON_MAPPING
]);
for
(
const
descriptor
of
descriptorList
.
descriptors
.
filter
((
d
)
=>
d
.
dataType
===
DataType
.
SCALE
||
d
.
dataType
===
DataType
.
CODED
))
{
await
dispatch
(
loadDescriptor
(
descriptor
.
uuid
,
(
d
:
Descriptor
)
=>
{
console
.
log
(
`Loaded details for
${
d
.
uuid
}
`
,
d
);
descriptor
.
terms
=
d
.
terms
;
}));
}
}
return
descriptorList
;
},
(
error
)
=>
{
log
(
`No Genesys PGR descriptor list`
,
error
);
return
error
;
}));
};
src/service/GenesysService.ts
View file @
e4e1adc3
...
...
@@ -44,6 +44,7 @@ export class GenesysService {
});
})
.
then
(({
data
})
=>
new
Page
<
object
>
(
data
));
// TODO catch 403 -- reauth
}
}
...
...
src/ui/pages/genesys/BrowsePage.tsx
View file @
e4e1adc3
import
*
as
React
from
'
react
'
;
import
{
connect
}
from
'
react-redux
'
;
import
{
bindActionCreators
}
from
'
redux
'
;
import
{
withStyles
}
from
'
material-ui/styles
'
;
import
{
log
}
from
'
utilities/debug
'
;
import
{
listCrops
}
from
'
actions/crop
'
;
import
{
listAccessions
}
from
'
actions/genesys
'
;
import
{
listAccessions
,
loadGenesysDescriptors
}
from
'
actions/genesys
'
;
import
{
Descriptor
,
DescriptorList
,
DescriptorListExtra
}
from
'
model/descriptor.model
'
;
import
{
VocabularyTerm
}
from
'
model/vocabulary.model
'
;
import
{
Page
,
Pagination
}
from
'
model/common.model
'
;
import
{
withStyles
}
from
'
material-ui/styles
'
;
import
Grid
from
'
material-ui/Grid
'
;
import
Loading
from
'
ui/common/Loading
'
;
import
PaginationComponent
from
'
ui/common/pagination
'
;
import
GenesysBrowseFilters
from
'
./c/Filters
'
;
import
PrettyFilters
from
'
ui/common/filter/PrettyFilters
'
;
import
DOI
from
'
ui/common/DOI
'
;
import
Grid
from
'
material-ui/Grid
'
;
const
styles
=
(
theme
)
=>
({
filterSection
:
theme
.
leftPanel
.
root
,
});
...
...
@@ -29,6 +31,7 @@ interface IBrowsePageProps extends React.ClassAttributes<any> {
pagination
?:
Pagination
<
object
>
;
listCrops
:
any
;
listAccessions
:
any
;
loadGenesysDescriptors
:
any
;
}
...
...
@@ -39,6 +42,7 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
protected
static
needs
=
[
listCrops
,
loadGenesysDescriptors
,
];
...
...
@@ -49,10 +53,32 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
public
componentWillMount
()
{
const
{
pagination
,
listCrops
}
=
this
.
props
;
const
{
pagination
,
listCrops
,
loadGenesysDescriptors
}
=
this
.
props
;
log
(
`BrowsePage.componentWillMount...`
,
this
.
props
);
listCrops
();
// Descriptors
loadGenesysDescriptors
()
.
then
((
genesysMcpd
:
DescriptorList
)
=>
{
// console.log('Genesys descriptors', g);
const
mapping
:
Map
<
string
,
Descriptor
>
=
new
Map
<
string
,
Descriptor
>
();
const
decoder
:
Map
<
string
,
Map
<
string
,
VocabularyTerm
>>
=
new
Map
<
string
,
Map
<
string
,
VocabularyTerm
>>
();
if
(
genesysMcpd
&&
genesysMcpd
.
extras
)
{
console
.
log
(
'
Genesys PGR mapping
'
,
genesysMcpd
.
extras
[
DescriptorListExtra
.
JSON_MAPPING
]);
for
(
const
m
of
genesysMcpd
.
extras
[
DescriptorListExtra
.
JSON_MAPPING
])
{
const
d
=
genesysMcpd
.
descriptors
.
find
((
d
)
=>
d
.
uuid
===
m
.
uuid
);
mapping
.
set
(
m
.
jsonPath
,
d
);
if
(
d
&&
d
.
terms
)
{
decoder
.
set
(
m
.
jsonPath
,
d
.
terms
.
reduce
((
codes
,
term
)
=>
codes
.
set
(
term
.
code
,
term
),
new
Map
<
string
,
VocabularyTerm
>
()));
}
}
}
console
.
log
(
mapping
,
decoder
);
this
.
setState
({
...
this
.
state
,
mapping
,
decoder
});
return
genesysMcpd
;
});
// if (! paged) {
log
(
'
Loading genesys accessions
'
);
this
.
fetchAccessions
(
this
.
state
.
filter
,
pagination
.
page
,
pagination
.
size
);
...
...
@@ -103,6 +129,28 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
return
{
__html
:
taxonomyHtml
};
}
private
decode
(
obj
,
path
):
string
{
if
(
!
obj
)
{
return
null
;
}
const
val
=
obj
[
path
];
// FIXME use proper JSONpath
// console.log(obj, path, obj[path]);
const
{
decoder
}
=
this
.
state
;
if
(
!
decoder
)
{
return
val
;
}
const
terms
=
decoder
.
get
(
path
);
// console.log(path, terms);
if
(
terms
)
{
const
term
=
terms
.
get
(
`
${
val
}
`
);
// console.log(val, term);
return
term
?
term
.
title
:
val
;
}
return
val
;
}
public
render
()
{
const
{
classes
}
=
this
.
props
;
const
{
paged
,
filter
}
=
this
.
state
;
...
...
@@ -133,13 +181,13 @@ class BrowsePage extends React.Component<IBrowsePageProps, any> {
{
paged
.
content
.
map
((
acce
,
index
)
=>
(
<
Grid
item
xs
=
{
12
}
key
=
{
`
${
index
}
`
}
className
=
"stripy-item"
style
=
{
{
margin
:
'
.3rem 0
'
,
padding
:
'
.3rem 1rem
'
}
}
>
<
Grid
container
spacing
=
{
0
}
>
<
Grid
item
xs
=
{
4
}
md
=
{
2
}
>
{
acce
.
acceNumb
}
</
Grid
>
<
Grid
item
xs
=
{
4
}
md
=
{
2
}
>
{
acce
.
acceNumb
}
<
b
>
{
acce
.
acceName
}
</
b
>
</
Grid
>
<
Grid
item
xs
=
{
4
}
md
=
{
2
}
><
DOI
value
=
{
acce
.
doi
}
noPrefix
/></
Grid
>
<
Grid
item
xs
=
{
4
}
md
=
{
2
}
>
{
acce
.
institute
.
code
}
</
Grid
>
<
Grid
item
xs
=
{
12
}
md
=
{
6
}
>
{
acce
.
orgCty
?
acce
.
orgCty
.
name
:
''
}
</
Grid
>
<
Grid
item
xs
=
{
4
}
md
=
{
2
}
>
{
acce
.
sampStat
}
</
Grid
>
<
Grid
item
xs
=
{
8
}
md
=
{
2
}
>
{
acce
.
orgCty
?
acce
.
orgCty
.
name
:
''
}
</
Grid
>
<
Grid
item
xs
=
{
12
}
md
=
{
12
}
dangerouslySetInnerHTML
=
{
this
.
htmlTaxa
(
acce
.
taxonomy
.
sciNameHtml
)
}
/>
<
Grid
item
xs
=
{
12
}
md
=
{
6
}
dangerouslySetInnerHTML
=
{
this
.
htmlTaxa
(
acce
.
taxonomy
.
sciNameHtml
)
}
/>
<
Grid
item
xs
=
{
12
}
md
=
{
6
}
>
{
this
.
decode
(
acce
,
'
sampStat
'
)
}
</
Grid
>
</
Grid
>
</
Grid
>
))
}
...
...
@@ -171,6 +219,7 @@ const mapStateToProps = (state, ownProps) => ({
const
mapDispatchToProps
=
(
dispatch
)
=>
bindActionCreators
({
listCrops
,
listAccessions
,
loadGenesysDescriptors
,
},
dispatch
);
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
withStyles
(
styles
)(
BrowsePage
));
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment