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
54442260
Commit
54442260
authored
Sep 28, 2020
by
Markus Scheidgen
Browse files
Added repo url to API helper dialog.
parent
f4b586b3
Pipeline
#83172
failed with stages
in 28 minutes and 40 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
gui/src/components/ApiDialogButton.js
View file @
54442260
...
...
@@ -58,6 +58,8 @@ export function ApiDialog({title, data, onClose, ...dialogProps}) {
<
DialogTitle
>
{
title
||
'
API Code
'
}
<
/DialogTitle
>
<
DialogContent
classes
=
{{
root
:
classes
.
content
}}
>
{
data
.
code
&&
data
.
code
.
repo_url
&&
renderCode
(
<
span
>
URL
to
this
query
on
the
repository
API
:
<
/span>, data.code.repo_url
)
}
{
data
.
code
&&
data
.
code
.
curl
&&
renderCode
(
<
span
>
Access
the
archive
as
JSON
via
<
i
>
curl
<
/i>:</
span
>
,
data
.
code
.
curl
)}
{
data
.
code
&&
data
.
code
.
python
&&
...
...
nomad/app/api/common.py
View file @
54442260
...
...
@@ -121,6 +121,8 @@ search_model_fields = {
'A list of search results. Each result is a dict with quantitie names as key and '
'values as values'
),
allow_null
=
True
,
skip_none
=
True
),
'code'
:
fields
.
Nested
(
api
.
model
(
'Code'
,
{
'repo_url'
:
fields
.
String
(
description
=
(
'An encoded URL for the search query on the repo api.'
)),
'python'
:
fields
.
String
(
description
=
(
'A piece of python code snippet which can be executed to reproduce the api result.'
)),
'curl'
:
fields
.
String
(
description
=
(
...
...
@@ -350,7 +352,7 @@ def _query_api_url(*args, query: Dict[str, Any] = None):
query_string: A dict with query string parameters
'''
url
=
os
.
path
.
join
(
config
.
api_url
(
False
),
*
args
)
if
query
is
not
None
:
if
query
is
not
None
and
len
(
query
)
>
0
:
url
=
'%s?%s'
%
(
url
,
urlencode
(
query
,
doseq
=
True
))
return
url
...
...
@@ -399,6 +401,20 @@ def _filter_api_query(query):
return
result
def
query_api_repo_url
(
query
):
'''
Creates an encoded URL string access a search query on the repo api.
'''
query
=
dict
(
query
)
for
to_delete
in
[
'per_page'
,
'page'
,
'exclude'
]:
if
to_delete
in
query
:
del
(
query
[
to_delete
])
for
key
,
value
in
dict
(
order_by
=
[
'upload_time'
],
order
=
[
'-1'
],
domain
=
[
'dft'
],
owner
=
[
'public'
]).
items
():
if
key
in
query
and
query
[
key
]
==
value
or
query
[
key
]
==
value
:
del
(
query
[
key
])
return
_query_api_url
(
'repo'
,
query
=
query
)
def
query_api_clientlib
(
**
kwargs
):
'''
Creates a string of python code to execute a search query on the archive using
...
...
nomad/app/api/repo.py
View file @
54442260
...
...
@@ -35,7 +35,8 @@ from .api import api
from
.auth
import
authenticate
from
.common
import
search_model
,
calc_route
,
add_pagination_parameters
,
\
add_scroll_parameters
,
add_search_parameters
,
apply_search_parameters
,
\
query_api_python
,
query_api_curl
,
query_api_clientlib
,
_search_quantities
query_api_python
,
query_api_curl
,
query_api_clientlib
,
query_api_repo_url
,
\
_search_quantities
ns
=
api
.
namespace
(
'repo'
,
description
=
'Access repository metadata.'
)
...
...
@@ -260,6 +261,7 @@ class RepoCalcsResource(Resource):
if
'statistics'
in
code_args
:
del
(
code_args
[
'statistics'
])
results
[
'code'
]
=
{
'repo_url'
:
query_api_repo_url
(
code_args
),
'curl'
:
query_api_curl
(
code_args
),
'python'
:
query_api_python
(
code_args
),
'clientlib'
:
query_api_clientlib
(
**
code_args
)
...
...
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