Skip to content

Commit

Permalink
feat: remove endpoint label in title and search with enter (#213)
Browse files Browse the repository at this point in the history
* feat: remove endpoint label in title and search with enter

* feat: better formatting

* feat: data before message

* feat: remove unnecessary comment

* feat:dont highlight status code 406 or 300
  • Loading branch information
micahwoodard authored Apr 3, 2024
1 parent 52e593c commit 36ae1ef
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
1 change: 0 additions & 1 deletion src/aind_metadata_service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
LabTracksClient,
LabTracksSettings,
)

from aind_metadata_service.response_handler import EtlResponse
from aind_metadata_service.sharepoint.client import (
SharePointClient,
Expand Down
14 changes: 9 additions & 5 deletions src/aind_metadata_service/tars/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,16 @@ def integrate_injection_materials(
or tars_response.status_code
== StatusCodes.INVALID_DATA.value
):
data = json.loads(tars_response.body)["data"]
data = json.loads(tars_response.body)[
"data"
]
new_material = ViralMaterial(**data)
new_material.titer = injection_material.titer
procedure.injection_materials[
idx
] = new_material
new_material.titer = (
injection_material.titer
)
procedure.injection_materials[idx] = (
new_material
)
elif (
tars_response.status_code
== StatusCodes.NO_DATA_FOUND.value
Expand Down
25 changes: 17 additions & 8 deletions src/aind_metadata_service/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
&.pending { color: darkorange; }
&.success { color: green; }
&.error { color: red; }
&.partialError { color: black; }
}
.path, pre {
font-family: monospace;
Expand Down Expand Up @@ -101,11 +102,10 @@ <h1>{{ service_name }}</h1>
<div>
<div class="container">
<div class="heading">{{ e.endpoint|title }}
<span class="path">{{ "/%s/{%s}"|format(e.endpoint, e.parameter) }}</span>
</div>
<p>{{ e.description }}</p>
<label for="param-id-{{ e.endpoint }}">{{ e.parameter_label or e.parameter }}:</label>
<input type="text" id="param-id-{{ e.endpoint }}" size="6" placeholder="{{ e.parameter }}" />
<input type="text" id="param-id-{{ e.endpoint }}" size="6" placeholder="{{ e.parameter }}" onkeydown="searchWithEnter('{{ e.endpoint }}')" />
</div>
<button id="search" type="button" class="primary" onclick="queryEndpoint('{{ e.endpoint }}')">Search</button>
</div>
Expand All @@ -114,17 +114,22 @@ <h1>{{ service_name }}</h1>
<div id="user-message"></div>
<div id="response" class="container" hidden>
<div class="heading">Response</div>
<div>Message:<pre id="response-message"></pre></div>
<div>Data:<pre id="response-data"></pre></div>
<div>Message:<pre id="response-message"></pre></div>
<div id="response-raw-div" hidden>Raw Response:<pre id="response-raw"></pre></div>
<button id="toggle-raw" type="button" class="secondary" onclick="toggleViewRawResponse()">View raw response</button>
</div>
</div>
</div>

<script>
searchWithEnter = function (endpoint) {
if(event.key === 'Enter') {
queryEndpoint(endpoint);
}
};
displayPendingUI = function () {
$("#user-message").removeClass("success error").addClass("pending");
$("#user-message").removeClass("success error partialError").addClass("pending");
$("#user-message").html("Searching.... Please do not refresh or re-submit.");
for (let id of ["message", "data", "raw"]) {
$(`#response-${id}`).html("");
Expand All @@ -138,7 +143,11 @@ <h1>{{ service_name }}</h1>
"response-data" : JSON.stringify(response?.data, null, 2),
"response-raw" : JSON.stringify(response, null, 2)
}
$("#user-message").removeClass("pending").addClass(isError ? "error" : "success");
if (statusCode === 406 || statusCode === 300){
$("#user-message").removeClass("pending error success").addClass("partialError")
} else{
$("#user-message").removeClass("pending").addClass(isError ? "error" : "success");
}
Object.keys(responseText).forEach((id) => {
$(`#${id}`).html(responseText[id]);
});
Expand All @@ -149,9 +158,9 @@ <h1>{{ service_name }}</h1>
const viewOrHide = $("#response-raw-div").is(":visible") ? "Hide" : "View";
$("#toggle-raw").text(`${viewOrHide} raw response`);
};
queryEndpoint = function (endpoint) {
let parameter = $(`#param-id-${endpoint}`).val();
$.ajax({
queryEndpoint = function (endpoint) {
let parameter = $(`#param-id-${endpoint}`).val();
$.ajax({
url: `/${endpoint}/${parameter}`,
type: "GET",
beforeSend: function () {
Expand Down

0 comments on commit 36ae1ef

Please sign in to comment.