Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
310939b6
Commit
310939b6
authored
Aug 24, 2018
by
Markus Scheidgen
Browse files
Added stub for repo calc view. Added repo API endpoint.
parent
c0304278
Changes
6
Hide whitespace changes
Inline
Side-by-side
gui/src/api.js
View file @
310939b6
...
...
@@ -61,10 +61,16 @@ function archive(uploadHash, calcHash) {
.
then
(
response
=>
response
.
json
())
}
function
repo
(
uploadHash
,
calcHash
)
{
return
fetch
(
`
${
apiBase
}
/repo/
${
uploadHash
}
/
${
calcHash
}
`
)
.
then
(
response
=>
response
.
json
())
}
const
api
=
{
createUpload
:
createUpload
,
getUploads
:
getUploads
,
archive
:
archive
archive
:
archive
,
repo
:
repo
};
export
default
api
;
\ No newline at end of file
gui/src/components/App.js
View file @
310939b6
...
...
@@ -5,6 +5,7 @@ import Navigation from './Navigation';
import
{
BrowserRouter
,
Switch
,
Route
}
from
'
react-router-dom
'
;
import
Uploads
from
'
./Uploads
'
import
ArchiveCalc
from
'
./ArchiveCalc
'
;
import
RepoCalc
from
'
./RepoCalc
'
;
function
App
()
{
return
(
...
...
@@ -13,7 +14,8 @@ function App() {
<
Navigation
>
<
Switch
>
<
Route
exact
path
=
"
/
"
render
=
{()
=>
<
div
>
Home
<
/div>} /
>
<
Route
path
=
"
/repo
"
render
=
{()
=>
<
div
>
Browse
<
/div>} /
>
<
Route
exact
path
=
"
/repo
"
render
=
{()
=>
<
div
>
Browse
<
/div>} /
>
<
Route
path
=
"
/repo/:uploadHash/:calcHash
"
component
=
{
RepoCalc
}
/
>
<
Route
path
=
"
/upload
"
component
=
{
Uploads
}
/
>
<
Route
exact
path
=
"
/archive
"
render
=
{()
=>
<
div
>
Archive
<
/div>} /
>
<
Route
path
=
"
/archive/:uploadHash/:calcHash
"
component
=
{
ArchiveCalc
}
/
>
...
...
gui/src/components/RepoCalc.js
0 → 100644
View file @
310939b6
import
React
from
'
react
'
;
import
PropTypes
from
'
prop-types
'
;
import
{
withStyles
,
Paper
,
LinearProgress
}
from
'
@material-ui/core
'
;
import
ReactJson
from
'
react-json-view
'
import
api
from
'
../api
'
;
import
Markdown
from
'
./Markdown
'
;
class
RepoCalc
extends
React
.
Component
{
static
propTypes
=
{
classes
:
PropTypes
.
object
.
isRequired
}
static
styles
=
theme
=>
({
root
:
{},
calcData
:
{
padding
:
theme
.
spacing
.
unit
}
});
constructor
(
props
)
{
super
(
props
)
this
.
state
=
{
data
:
null
}
}
componentDidMount
()
{
const
{
uploadHash
,
calcHash
}
=
this
.
props
.
match
.
params
api
.
repo
(
uploadHash
,
calcHash
).
then
(
data
=>
{
this
.
setState
({
data
:
data
})
})
}
render
()
{
const
{
classes
}
=
this
.
props
const
{
data
}
=
this
.
state
return
(
<
div
className
=
{
classes
.
root
}
>
<
Markdown
>
{
`
## The Repository – Raw Code Data
`
}
<
/Markdown
>
<
Paper
className
=
{
classes
.
calcData
}
>
{
data
?
<
ReactJson
src
=
{
this
.
state
.
data
}
enableClipboard
=
{
false
}
collapsed
=
{
4
}
/>
:
<
LinearProgress
variant
=
"
query
"
/>
}
<
/Paper
>
<
/div
>
)
}
}
export
default
withStyles
(
RepoCalc
.
styles
)(
RepoCalc
);
\ No newline at end of file
nomad/api.py
View file @
310939b6
...
...
@@ -4,6 +4,7 @@ from datetime import datetime
import
mongoengine.errors
from
flask_cors
import
CORS
import
logging
from
elasticsearch.exceptions
import
NotFoundError
from
nomad
import
users
,
files
,
search
from
nomad.processing
import
UploadProc
...
...
@@ -76,14 +77,22 @@ class Upload(Resource):
class
Repo
(
Resource
):
@
staticmethod
def
_render
(
data
:
dict
):
if
'upload_time'
in
data
:
data
[
'upload_time'
]
=
data
[
'upload_time'
].
isoformat
()
return
{
key
:
value
for
key
,
value
in
data
.
items
()
if
value
is
not
None
}
def
get
(
self
,
upload_hash
,
calc_hash
):
try
:
data
=
search
.
Calc
.
get
(
id
=
'%s/%s'
%
(
upload_hash
,
calc_hash
))
except
NotFoundError
:
abort
(
404
,
message
=
'There is no calculation for %s/%s'
%
(
upload_hash
,
calc_hash
))
except
Exception
as
e
:
# TODO
abort
(
404
,
message
=
str
(
e
))
abort
(
500
,
message
=
str
(
e
))
return
data
,
200
return
Repo
.
_render
(
data
.
to_dict
())
,
200
@
app
.
route
(
'/archive/<string:upload_hash>/<string:calc_hash>'
,
methods
=
[
'GET'
])
...
...
tests/test_api.py
View file @
310939b6
...
...
@@ -13,6 +13,9 @@ from tests.test_processing import example_files
from
tests.test_files
import
assert_exists
# import fixtures
from
tests.test_files
import
clear_files
,
archive_id
# pylint: disable=unused-import
from
tests.test_normalizing
import
normalized_vasp_example
# pylint: disable=unused-import
from
tests.test_parsing
import
parsed_vasp_example
# pylint: disable=unused-import
from
tests.test_search
import
example_entry
# pylint: disable=unused-import
from
tests.test_processing
import
celery_config
,
celery_includes
# pylint: disable=unused-import
...
...
@@ -150,6 +153,16 @@ def test_processing(client, file, celery_session_worker):
assert_exists
(
config
.
files
.
uploads_bucket
,
upload
[
'upload_id'
])
def
test_get_repo
(
client
,
example_entry
):
rv
=
client
.
get
(
'/repo/%s/%s'
%
(
example_entry
.
upload_hash
,
example_entry
.
calc_hash
))
assert
rv
.
status_code
==
200
def
test_non_existing_repo
(
client
):
rv
=
client
.
get
(
'/repo/doesnt/exist'
)
assert
rv
.
status_code
==
404
def
test_get_archive
(
client
,
archive_id
):
rv
=
client
.
get
(
'/archive/%s'
%
archive_id
)
assert
rv
.
status_code
==
302
...
...
tests/test_processing.py
View file @
310939b6
...
...
@@ -28,7 +28,6 @@ from nomad.processing import start_processing
from
tests.test_files
import
example_file
,
empty_file
# import fixtures
from
tests.test_search
import
index
# pylint: disable=unused-import
from
tests.test_files
import
clear_files
# pylint: disable=unused-import
example_files
=
[
empty_file
,
example_file
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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