-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #479 from elixir-luxembourg/438-dish-import-button
Import datasets, projects and partners using the ui
- Loading branch information
Showing
14 changed files
with
500 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django import forms | ||
|
||
|
||
class ImportForm(forms.Form): | ||
file = forms.FileField(required=True, label="Choose File") |
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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"$id": "https://raw.githubusercontent.com/elixir-luxembourg/json-schemas/v0.0.5/schemas/elu-core.json", | ||
"title": "ELIXIR Luxembourg Core json schema", | ||
"description": "Schema containing core attributes for any json serialisable ELIXIR Luxembourg record.", | ||
"$schema": "http://json-schema.org/draft-04/schema#", | ||
"type": "object", | ||
"required": [ | ||
"source", | ||
"name" | ||
], | ||
"properties": { | ||
"source": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"acronym": { | ||
"type": ["string", "null"] | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": ["string", "null"] | ||
}, | ||
"external_id": { | ||
"type": ["string", "null"] | ||
}, | ||
"elu_uuid": { | ||
"type": ["string", "null"] | ||
}, | ||
"other_external_id": { | ||
"type": ["string", "null"] | ||
}, | ||
"url": { | ||
"type": ["string", "null"] | ||
}, | ||
"contacts": { | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"first_name": { | ||
"type": "string" | ||
}, | ||
"last_name": { | ||
"type": "string" | ||
}, | ||
"role": { | ||
"type": "string", | ||
"enum": [ | ||
"Principal_Investigator", | ||
"Researcher", | ||
"Data_Manager", | ||
"Data_Protection_Officer", | ||
"Legal_Representative", | ||
"Other" | ||
] | ||
}, | ||
"email": { | ||
"type": "string", | ||
"format": "email" | ||
}, | ||
"affiliations": { | ||
"description": "Names of the affiliated institutions.", | ||
"type": "array", | ||
"minItems": 1, | ||
"uniqueItems": true, | ||
"items": { | ||
"type": ["string", "null"] | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"first_name", | ||
"last_name", | ||
"role", | ||
"email", | ||
"affiliations" | ||
] | ||
} | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"items": [ | ||
{ | ||
"name": "Centre Hospitalier de Togo", | ||
"external_id": "ELU_I_19309", | ||
"acronym": "CHT", | ||
"is_clinical": true, | ||
"geo_category": "National", | ||
"sector_category": "PUBLIC", | ||
"address": "Ave De La 6, Espoir Vie Togo, Lome", | ||
"country_code": "TO", | ||
"source": "example.com" | ||
}, | ||
{ | ||
"name": "Hospitalier de Madagascar", | ||
"external_id": "ELU_I_1939", | ||
"acronym": "HMDGSK", | ||
"is_clinical": true, | ||
"geo_category": "National", | ||
"sector_category": "PUBLIC", | ||
"address": "Ave De La 6, Espoir Vie Togo, Antananarivo", | ||
"country_code": "MG", | ||
"source": "example.com" | ||
} | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
$(document).ready(function () { | ||
// Show the modal when the button is clicked | ||
$('#importModalButton').click(function () { | ||
$('#importModal').modal('show'); | ||
fetchForm(); | ||
}); | ||
|
||
// Fetch the form via AJAX | ||
function fetchForm() { | ||
$.get(importDataUrl, function (data) { | ||
$("#importForm").html(data.form_html); | ||
// Initially disable the submit button | ||
$("#ajaxSubmitButton").prop("disabled", true); | ||
// Monitor changes on the file input | ||
$("#id_file").on("change", function () { | ||
// If file input has a file, enable the submit button | ||
if ($(this).val()) { | ||
$("#ajaxSubmitButton").prop("disabled", false); | ||
} else { | ||
$("#ajaxSubmitButton").prop("disabled", true); | ||
} | ||
}); | ||
$('#ajaxSubmitButton').on('click', function () { | ||
submitForm(); | ||
}); | ||
}); | ||
} | ||
}); | ||
|
||
function submitForm() { | ||
const formData = new FormData($('#importForm form')[0]); | ||
$.ajax({ | ||
url: importDataUrl, | ||
type: 'POST', | ||
data: formData, | ||
cache: false, | ||
contentType: false, | ||
processData: false, | ||
success: function (data) { | ||
$("#importForm form").html(data.form_html); | ||
}, | ||
error: function (data) { | ||
$("#importForm form").html(data.form_html); | ||
} | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<div id="importForm"> | ||
{% if form %} | ||
<!-- Display the form --> | ||
<form class="form col-md-12 nice-selects" method="post" enctype="multipart/form-data" novalidate | ||
action="{% url 'import_data' model_type=model_type %}"> | ||
{% csrf_token %} | ||
<!-- File Upload Field --> | ||
<div class="form-group required"> | ||
<strong>{{ form.file.label_tag }}</strong> | ||
<input type="file" name="{{ form.file.name }}" class="form-control" required | ||
id="{{ form.file.id_for_label }}" accept=".json"> | ||
{% if form.file.errors %} | ||
<div class="text-danger"> | ||
{{ form.file.errors|striptags }} | ||
</div> | ||
{% endif %} | ||
</div> | ||
<button id="ajaxSubmitButton" type="button" class="btn btn-primary btn-raised btn-block">Submit</button> | ||
</form> | ||
{% else %} | ||
<div class="p-0"> | ||
<!-- Display output message --> | ||
{% if output.message %} | ||
<div class="alert alert-{% if not output.error %}success{% else %}info{% endif %} rounded" role="alert"> | ||
<strong>Output:</strong> | ||
<p>{{ output.message|linebreaksbr }}</p> | ||
</div> | ||
{% endif %} | ||
<!-- Display error --> | ||
{% if output.error %} | ||
<div class="alert alert-danger rounded" role="alert"> | ||
<strong>Error:</strong> | ||
<p>{{ output.error|linebreaksbr }}</p> | ||
</div> | ||
{% endif %} | ||
<!-- Display logs --> | ||
{% if output.logs %} | ||
<div class="alert alert-secondary rounded" role="alert"> | ||
<strong> Logs:</strong> | ||
<div class="log-container"> | ||
<p>{{ output.logs|linebreaksbr }}</p> | ||
</div> | ||
</div> | ||
{% endif %} | ||
|
||
|
||
</div> | ||
{% endif %} | ||
</div> |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="modal fade" id="importModal" tabindex="-1" aria-labelledby="modalLabel" aria-hidden="true"> | ||
<div class="modal-dialog modal-lg"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h5 class="modal-title" id="modalLabel">Import {{ search_url }}</h5> | ||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div class="modal-body px-2"> | ||
<div id="importForm"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> |
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
Oops, something went wrong.