Skip to content

Commit

Permalink
Merge pull request #160 from khanlab/show-logs-no-react
Browse files Browse the repository at this point in the history
Show logs in task tables
  • Loading branch information
tkkuehn authored Sep 8, 2022
2 parents 4ac3d43 + 18f3461 commit 6f023b2
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 88 deletions.
4 changes: 2 additions & 2 deletions autobidsportal/static/lib/autobids-react/dist/index.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions autobidsportal/static/lib/autobids-react/src/TaskList/TaskList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from "react";
import PropTypes from "prop-types";

import TaskListItem from "./TaskListItem";

function TaskList(props) {
const { children } = props;

return (
<div className="table-responsive" style={{ maxHeight: "400px" }}>
<table className="table table-light overflow-auto">
<thead>
<tr>
<th scope="col">Start Date and Time</th>
<th scope="col">End Date and Time</th>
<th scope="col">Completion Status</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>{children}</tbody>
</table>
</div>
);
}

TaskList.propTypes = {
children: PropTypes.arrayOf(PropTypes.instanceOf(TaskListItem)),
};

export default TaskList;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useState } from "react";
import PropTypes from "prop-types";

import TaskLogModal from "./TaskLogModal";

function TaskListItem(props) {
const { start, end, complete, log } = props;

const [modalOpen, setModalOpen] = useState(false);

const modalElement = document.getElementById("autobidsModal");
const openModal = () => setModalOpen(true);
modalElement.addEventListener("hidden.bs.modal", (event) =>
setModalOpen(false)
);

return (
<>
<tr>
<td>{start}</td>
<td>{end}</td>
<td>{complete}</td>
<td>
<button
className="btn btn-primary btn-sm"
type="button"
onClick={openModal}
data-bs-toggle="modal"
data-bs-target="#autobidsModal"
disabled={!log}
>
View log
</button>
</td>
</tr>
{modalOpen ? <TaskLogModal log={log} /> : null}
</>
);
}

TaskListItem.propTypes = {
start: PropTypes.string.isRequired,
end: PropTypes.string.isRequired,
complete: PropTypes.string.isRequired,
log: PropTypes.string,
};

export default TaskListItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
import * as ReactDOM from "react-dom";
import PropTypes from "prop-types";

function TaskLogModal(props) {
const { log } = props;

return ReactDOM.createPortal(
<>
<div className="modal-header">
<h5 className="modal-title">Task log</h5>
<button
type="button"
className="btn-close"
data-bs-dismiss="modal"
aria-label="close"
></button>
</div>
<div className="modal-body">
<pre>{log}</pre>
</div>
</>,
document.querySelector("#autobidsModalContent")
);
}

TaskLogModal.propTypes = {
log: PropTypes.string.isRequired,
};

export default TaskLogModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as TaskList } from "./TaskList";
export { default as TaskListItem } from "./TaskListItem";
export { default as TaskLogModal } from "./TaskLogModal";
7 changes: 7 additions & 0 deletions autobidsportal/static/lib/autobids-react/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Accordion, TextItem, DirItem, genAccordion } from "./Accordion";
import { TableLauncher, TableLauncherRow } from "./TableLauncher";
import { TaskList, TaskListItem } from "./TaskList";
import ReactDOM from "react-dom";
import React from "react";

Expand All @@ -9,6 +10,8 @@ globalThis.DirItem = DirItem;
globalThis.genAccordion = genAccordion;
globalThis.TableLauncher = TableLauncher;
globalThis.TableLauncherRow = TableLauncherRow;
globalThis.TaskList = TaskList;
globalThis.TaskListItem = TaskListItem;
globalThis.ReactDOM = ReactDOM;
globalThis.React = React;

Expand All @@ -19,6 +22,8 @@ export {
genAccordion,
TableLauncher,
TableLauncherRow,
TaskList,
TaskListItem,
ReactDOM,
React,
};
Expand All @@ -29,6 +34,8 @@ export default {
genAccordion,
TableLauncher,
TableLauncherRow,
TaskList,
TaskListItem,
ReactDOM,
React,
};
127 changes: 42 additions & 85 deletions autobidsportal/templates/answer_info.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,49 +176,7 @@ <h4 class="card-title">Accessing this study data</h4>
<h2 class="sub-header">
Cfmm2tar Runs
</h2>
<div class="table-responsive" style="max-height: 400px;">
<table class="table table-light overflow-auto">
<tr>
<th scope="col">
Start Date and Time
</th>
<th scope="col">
End Date and Time
</th>
<th scope="col">
Completion Status
</th>
</tr>
{% for t in cfmm2tar_tasks %}
<tr>
<td>
{% if t.start_time != None %}
{{ t.start_time.strftime("%Y-%m-%d %H:%M") }}
{% else %}
{{ t.start_time }}
{% endif %}
</td>
<td>
{% if t.end_time != None %}
{{ t.end_time.strftime("%Y-%m-%d %H:%M") }}
{% else %}
{{ t.end_time }}
{% endif %}
</td>
<td>
{% if t.complete == True %}
{% if t.success == True %}
Completed Successfully
{% else %}
Failed
{% endif %}
{% else %}
In Progress
{% endif %}
</td>
</tr>
{% endfor %}
</table>
<div id="cfmm2tar-table-mount">
</div>
</div>
<div class="col-6">
Expand All @@ -234,48 +192,8 @@ <h2 class="sub-header">
<h2 class="sub-header">
Tar2bids Runs
</h2>
<table class="table table-light">
<tr>
<th scope="col">
Start Date and Time
</th>
<th scope="col">
End Date and Time
</th>
<th scope="col">
Completion Status
</th>
</tr>
{% for t in tar2bids_tasks %}
<tr>
<td>
{% if t.start_time != None %}
{{ t.start_time.strftime("%Y-%m-%d %H:%M") }}
{% else %}
{{ t.start_time }}
{% endif %}
</td>
<td>
{% if t.end_time != None %}
{{ t.end_time.strftime("%Y-%m-%d %H:%M") }}
{% else %}
{{ t.end_time }}
{% endif %}
</td>
<td>
{% if t.complete == True %}
{% if t.success == True %}
Completed Successfully
{% else %}
Failed
{% endif %}
{% else %}
In Progress
{% endif %}
</td>
</tr>
{% endfor %}
</table>
<div id="tar2bids-table-mount">
</div>
</div>
<div class="col-6">
<h2 class="sub-header">
Expand Down Expand Up @@ -318,5 +236,44 @@ <h2 class="sub-header">
}
)
ReactDOM.render(tarTable, document.querySelector("#tar-table-mount"))
const e = React.createElement;
const cfmm2tarTable = e(
TaskList,
null,
[
{% for task in cfmm2tar_tasks %}
e(
TaskListItem,
{
start: "{{ task.start_time.strftime("%Y-%m-%d %H:%M") if task.start_time != None else task.start_time }}",
end: "{{ task.end_time.strftime("%Y-%m-%d %H:%M") if task.end_time != None else task.end_time }}",
complete: "{% if task.complete == True %}{% if task.success == True %}Completed Successfully{% else %}Failed{% endif %}{% else %}In Progress{% endif %}",
log: `{{ task.log|safe if task.log != None else "" }}`
},
null
),
{% endfor %}
]
)
ReactDOM.render(cfmm2tarTable, document.querySelector("#cfmm2tar-table-mount"))
const tar2bidsTable = e(
TaskList,
null,
[
{% for task in tar2bids_tasks %}
e(
TaskListItem,
{
start: "{{ task.start_time.strftime("%Y-%m-%d %H:%M") if task.start_time != None else task.start_time }}",
end: "{{ task.end_time.strftime("%Y-%m-%d %H:%M") if task.end_time != None else task.end_time }}",
complete: "{% if task.complete == True %}{% if task.success == True %}Completed Successfully{% else %}Failed{% endif %}{% else %}In Progress{% endif %}",
log: `{{ task.log|safe if task.log != None else "" }}`
},
null
),
{% endfor %}
]
)
ReactDOM.render(tar2bidsTable, document.querySelector("#tar2bids-table-mount"))
</script>
{% endblock scripts %}
2 changes: 1 addition & 1 deletion autobidsportal/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
{% block app_content %}
{% endblock app_content %}
<div class="modal fade" id="autobidsModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-dialog modal-dialog-scrollable modal-xl">
<div class="modal-content" id="autobidsModalContent"></div>
</div>
</div>
Expand Down

0 comments on commit 6f023b2

Please sign in to comment.