Browse Source

Add button to delete documents on dataset page

pull/193/head
Clemens Wolff 5 years ago
parent
commit
3759edb544
4 changed files with 23 additions and 0 deletions
  1. 8
      app/server/static/js/dataset.js
  2. 11
      app/server/templates/dataset.html
  3. 3
      app/server/views.py
  4. 1
      app/server/webpack.config.js

8
app/server/static/js/dataset.js

@ -0,0 +1,8 @@
import HTTP from './http';
document.querySelectorAll('.delete-document-button').forEach((deleteButton) => {
deleteButton.addEventListener('click', () => {
const documentId = deleteButton.getAttribute('data-delete-document-id');
HTTP.delete(`docs/${documentId}`).then(() => window.location.reload());
});
});

11
app/server/templates/dataset.html

@ -17,6 +17,7 @@
<tr>
<th>#</th>
<th>Text</th>
<th></th>
</tr>
</thead>
<tbody>
@ -24,6 +25,16 @@
<tr>
<td>{{ forloop.counter0|add:page_obj.start_index }}</td>
<td>{{ doc.text|truncatechars:200 }}</td>
<td>
<p class="control">
<button class="button is-text delete-document-button" data-delete-document-id="{{ doc.id }}">
<span class="icon is-small">
<i class="fas fa-trash"></i>
</span>
<span>Delete</span>
</button>
</p>
</td>
</tr>
{% endfor %}
</tbody>

3
app/server/views.py

@ -34,6 +34,9 @@ class ProjectsView(LoginRequiredMixin, TemplateView):
class DatasetView(SuperUserMixin, LoginRequiredMixin, ListView):
template_name = 'dataset.html'
paginate_by = 5
extra_context = {
'bundle_name': 'dataset'
}
def get_queryset(self):
project = get_object_or_404(Project, pk=self.kwargs['project_id'])

1
app/server/webpack.config.js

@ -16,6 +16,7 @@ module.exports = {
'stats': './static/js/stats.js',
'label': './static/js/label.js',
'guideline': './static/js/guideline.js',
'dataset': './static/js/dataset.js',
'demo_text_classification': './static/js/demo/demo_text_classification.js',
'demo_named_entity': './static/js/demo/demo_named_entity.js',
'demo_translation': './static/js/demo/demo_translation.js',

Loading…
Cancel
Save