Skip to content

Commit

Permalink
Polish up notebook delete button
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Cassidy <[email protected]>
  • Loading branch information
stevecassidy committed Oct 17, 2023
1 parent 7b7e4bf commit 823dedd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ app.get('/notebooks/', requireAuthentication, async (req, res) => {
res.render('notebooks', {
user: user,
notebooks: notebooks,
cluster_admin: userIsClusterAdmin(user),
developer: DEVELOPER_MODE,
});
} else {
Expand Down
59 changes: 52 additions & 7 deletions views/notebooks.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,47 @@
<td>
<a href="/notebooks/{{this.non_unique_project_id}}">{{this.name}}</a>
</td>
{{#if ../developer}}
{{#if ../cluster_admin}}
<td>
<button class="btn btn-danger btn-sm" onclick="deleteNotebook('{{this.non_unique_project_id}}')">Delete</button>
<button type="button" class="btn btn-danger"
data-bs-toggle="modal" data-bs-target="#deleteNotebookModal{{this.non_unique_project_id}}">
Delete Notebook
</button>

<div class="modal fade" id="deleteNotebookModal{{this.non_unique_project_id}}" tabindex="-1" aria-labelledby="deleteNotebookModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteNotebookModalLabel{{this.non_unique_project_id}}">Delete Notebook "{{this.name}}"?</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="mb-3">
<p>Deleting this notebook will remove all records from
the database and cannot be recovered.
</p>
<label for="confirmationText{{this.non_unique_project_id}}" class="form-label">
Type <span class="text-danger">delete {{this.name}} and all records</span> to confirm deletion
</label>
<input class="form-control"
onkeyup="updateDeleteButton('{{this.non_unique_project_id}}', '{{this.name}}')"
id="confirmationText{{this.non_unique_project_id}}">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button"
id="deleteButton{{this.non_unique_project_id}}"
disabled
class="btn btn-danger"
onclick="deleteNotebook('{{this.non_unique_project_id}}', '{{this.name}}')">
Confirm Delete
</button>
</div>
</div>
</div>
</div>

</td>
{{/if}}
</tr>
Expand Down Expand Up @@ -58,7 +96,17 @@


<script>
const deleteNotebook = (project_id) => {
const updateDeleteButton = (project_id, name) => {
const confirmationText = document.getElementById(`confirmationText${project_id}`).value;
if (confirmationText === `delete ${name} and all records`) {
document.getElementById(`deleteButton${project_id}`).disabled = false;
} else {
document.getElementById(`deleteButton${project_id}`).disabled = true;
}
}
const deleteNotebook = (project_id, name) => {
fetch(`/api/notebooks/${project_id}/delete`, {
method: 'POST',
})
Expand All @@ -67,8 +115,7 @@
});
}
function uploadNotebookHandler(event) {
const uploadNotebookHandler = (event) => {
event.preventDefault();
const url = '/api/notebooks/';
const form = event.target;
Expand Down Expand Up @@ -116,8 +163,6 @@
return;
}
}
}
}
Expand Down

0 comments on commit 823dedd

Please sign in to comment.