-
Notifications
You must be signed in to change notification settings - Fork 321
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f45282b
commit d94b31b
Showing
3 changed files
with
136 additions
and
95 deletions.
There are no files selected for viewing
113 changes: 31 additions & 82 deletions
113
hasher-matcher-actioner/src/OpenMediaMatch/templates/components/add_to_bank_form.html.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,38 @@ | ||
{# Copyright (c) Meta Platforms, Inc. and affiliates. #} | ||
<h3> Add Content to Bank</h3> | ||
<form id="add_content_to_bank"> | ||
<div class="row"> | ||
<div class="col"> | ||
<input class="form-control" type="file" name="file" required> | ||
</div> | ||
<div class="col"> | ||
<select class="form-select" name="bank_name" required> | ||
<option selected disabled value="">Select bank</option> | ||
{% for b in bankList %} | ||
<option value="{{b['name']}}">{{b['name']}}</option> | ||
{% endfor %} | ||
</select> | ||
</div> | ||
<div class="col"> | ||
<select class="form-select" name="content_type" required> | ||
<option selected disabled value="">Select content type</option> | ||
{% for c in content %} | ||
{% if c['enabled'] %} | ||
<option value="{{c['name']}}">{{c['name'].capitalize()}}</option> | ||
{% endif %} | ||
{% endfor %} | ||
</select> | ||
</div> | ||
<div class="col"> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
<button type="button" class="btn btn-light" data-bs-toggle="modal" data-bs-target="#{{bank_title}}">Add content</button> | ||
<!-- Modal --> | ||
<div class="modal fade" id="{{bank_title}}" tabindex="-1"> | ||
<div class="modal-dialog modal-dialog-centered modal-xl" style="width: 60%; max-width: none;"> | ||
<div class="modal-content modal-xl" style="padding: 10px"> | ||
<form id="add_content_to_bank_{{ bank_title }}"> | ||
<div class="modal-header"> | ||
<h1 class="modal-title fs-5">Add Content: {{ bank_title }}</h1> | ||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> | ||
|
||
</div> | ||
<div class="modal-body"> | ||
<div class="row" style="width: 80%"> | ||
<input class="form-control" type="file" name="file" required style="margin-bottom: 20px"> | ||
<select class="form-select" name="content_type" required> | ||
<option selected disabled value="">Select content type</option> | ||
{% for c in content %} | ||
{% if c['enabled'] %} | ||
<option value="{{c['name']}}">{{c['name'].capitalize()}}</option> | ||
{% endif %} | ||
{% endfor %} | ||
</select> | ||
</div> | ||
</div> | ||
<div class="modal-footer"> | ||
<button type="submit" class="btn btn-primary">Submit</button> | ||
</div> | ||
</form> | ||
<div id="hash_result_{{ bank_title }}"> | ||
<!-- Added to by javascript --> | ||
</div> | ||
</div> | ||
</div> | ||
</form> | ||
<div id="content_result"> | ||
<!-- Added to by javascript --> | ||
</div> | ||
<script> | ||
const add_content_to_bank_form = document.getElementById("add_content_to_bank"); | ||
const content_result = document.getElementById("content_result"); | ||
add_content_to_bank_form.addEventListener("submit", (event) => { | ||
event.preventDefault(); | ||
const formData = new FormData(event.target); | ||
formData.append(event.target.content_type.value, event.target.file.files[0]); | ||
formData.delete("file"); | ||
fetch(`/c/bank/${event.target.bank_name.value}/content`, { | ||
method: 'POST', | ||
body: formData | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
// Handle the response from the server here | ||
renderAddBankResult(data); | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
}) | ||
const renderAddBankResult = (result) => { | ||
const hashHeader = ` | ||
<h4>Added Hashes:</h4> | ||
<p>Content ID: ${result.id}</p> | ||
`; | ||
// Render hashes table | ||
const hashesTableHTML = renderHashTable(result.signals); | ||
// render on HTML | ||
content_result.innerHTML = hashHeader + hashesTableHTML; | ||
} | ||
const renderHashTable = (hashes) => { | ||
return ` | ||
<h3>Hash Values:</h3> | ||
<table> | ||
<tr> | ||
<th>Key</th> | ||
<th>Value</th> | ||
</tr> | ||
${Object.entries(hashes).map(([key, value]) => ` | ||
<tr> | ||
<td>${key}</td> | ||
<td>${value}</td> | ||
</tr> | ||
`).join('')} | ||
</table> | ||
`; | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters