diff --git a/datasources/forms.py b/datasources/forms.py index e3678de99976f8f6f5c6ad0184d4db9b95e8058d..774ae7895e679d2293205a9ba23efc2361ce8bb0 100644 --- a/datasources/forms.py +++ b/datasources/forms.py @@ -97,12 +97,6 @@ class PermissionGrantForm(forms.ModelForm): fields = ['granted', 'push_granted'] -class MetadataFieldForm(forms.ModelForm): - class Meta: - model = models.MetadataItem - fields = ['field', 'value'] - - class LicenceForm(forms.ModelForm): class Meta: model = models.Licence diff --git a/datasources/static/js/metadata.js b/datasources/static/js/metadata.js index f500c613bee18c9488aefb0556faec71413a2c42..517865ae4134c111730f863856f8c9a626dc7d28 100644 --- a/datasources/static/js/metadata.js +++ b/datasources/static/js/metadata.js @@ -21,6 +21,7 @@ function setRatingUrl(url) { function getCookie(name) { + "use strict"; const re = new RegExp("(^| )" + name + "=([^;]+)"); const match = document.cookie.match(re); if (match) { @@ -28,104 +29,6 @@ function getCookie(name) { } } - -function tableAppendRow(table, values, id=null) { - const row = table.insertRow(-1); - if (id !== null) { - row.id = id; - } - - for (const value of values) { - const cell = row.insertCell(-1); - const text = document.createTextNode(value); - cell.appendChild(text); - } - - return row; -} - - -function postMetadata() { - fetch( - metadataUrl, - { - method: "POST", - body: JSON.stringify({ - field: document.getElementById("id_field").value, - value: document.getElementById("id_value").value - }), - headers: { - "Accept": "application/json", - "Content-Type": "application/json", - "X-CSRFToken": getCookie("csrftoken") - } - } - ).then( - response => response.json() - ).then( - function (response) { - if (response.status === "success") { - const table = document.getElementById("tableMetadata"); - const field = response.data.field; - const value = response.data.value; - - const row = tableAppendRow( - table, - [field, value], - "metadata-row-" + response.data.field_short + "-" + value - ); - - const buttonCell = row.insertCell(-1); - const button = document.createElement("button"); - - button.id = "btn-" + field + "-" + value; - button.classList.add("btn", "btn-sm", "btn-danger", "float-right"); - button.addEventListener( - "click", - function () { - const f = response.data.field_short; - const v = value; - deleteMetadata(f, v); - } - ); - button.textContent = "Delete"; - buttonCell.appendChild(button); - row.appendChild(buttonCell); - } - } - ).catch( - function (e) { - console.log(e); - } - ) -} - -function deleteMetadata(field, value) { - fetch( - metadataUrl, - { - method: "DELETE", - body: JSON.stringify({ - field: field, - value: value - }), - headers: { - "Accept": "application/json", - "Content-Type": "application/json", - "X-CSRFToken": getCookie("csrftoken") - } - } - ).then( - response => response.json() - ).then(function (response) { - if (response.status === "success") { - const row = document.getElementById("metadata-row-" + field + "-" + value); - row.parentNode.removeChild(row); - } - - }) -} - function updateMetadata(metadataIdField, valueField) { "use strict"; diff --git a/datasources/templates/datasources/datasource/detail.html b/datasources/templates/datasources/datasource/detail.html index 89c965b8f7571d72730c77b4f49d1f2f926209f9..9fb47628180b2b76edf5b0277d9bab17e80b189e 100644 --- a/datasources/templates/datasources/datasource/detail.html +++ b/datasources/templates/datasources/datasource/detail.html @@ -1,18 +1,6 @@ {% extends "base.html" %} {% load bootstrap4 %} -{% block extra_head %} - {% if metadata_field_form %} - {% load static %} - - <script type="application/javascript" src="{% static 'js/metadata.js' %}"></script> - - <script type="application/javascript"> - setMetadataUrl("/datasources/{{ datasource.pk }}/metadata"); - </script> - {% endif %} -{% endblock %} - {% block content %} <nav aria-label="breadcrumb"> <ol class="breadcrumb"> @@ -144,9 +132,6 @@ <thead> <th scope="col" class="w-25 border-0"></th> <th scope="col" class="border-0"></th> - {% if metadata_field_form %} - <th scope="col" class="w-25 border-0"></th> - {% endif %} </thead> <tbody> @@ -154,36 +139,10 @@ <tr id="metadata-row-{{ metadata_item.field.short_name }}-{{ metadata_item.value }}"> <td>{{ metadata_item.field.name }}</td> <td>{{ metadata_item.value }}</td> - - {% if metadata_field_form %} - <td> - <button role="button" - onclick="deleteMetadata('{{ metadata_item.field.short_name }}','{{ metadata_item.value }}')" - class="btn btn-sm btn-danger float-right">Delete</button> - </td> - {% endif %} </tr> {% endfor %} </tbody> </table> - - {% if metadata_field_form %} - <form id="formMetadata" class="form" action="javascript:postMetadata();"> - {% csrf_token %} - - <div class="row"> - <div class="col-3"> - {% bootstrap_field metadata_field_form.field layout='inline' %} - </div> - <div class="col-6"> - {% bootstrap_field metadata_field_form.value layout='inline' %} - </div> - <div class="col-3"> - <button type="submit" class="btn btn-block btn-success">Add</button> - </div> - </div> - </form> - {% endif %} </div> </div> diff --git a/datasources/views/datasource.py b/datasources/views/datasource.py index b3d6ea15197f0c10bf22a13c9fc6956615978426..57b223034630ac8941669c476b6de3f067116373 100644 --- a/datasources/views/datasource.py +++ b/datasources/views/datasource.py @@ -37,8 +37,6 @@ class DataSourceDetailView(DetailView): context = super().get_context_data(**kwargs) context['has_edit_permission'] = self.request.user.is_superuser or self.request.user == self.object.owner - if context['has_edit_permission']: - context['metadata_field_form'] = forms.MetadataFieldForm() try: context['is_catalogue'] = self.object.is_catalogue