Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion public/grapheditor/js/EditorUi.js
Original file line number Diff line number Diff line change
Expand Up @@ -1161,8 +1161,10 @@ EditorUi.prototype.init = function()
this.updateActionStates();


if(window.location.pathname.split('/')[2] !== 'thesaurus-editor')
if(window.location.pathname.split('/')[2] !== 'thesaurus-editor') {
compileCells(editor.graph.getModel());
autoSave();
}

}));

Expand Down Expand Up @@ -4828,3 +4830,59 @@ EditorUi.prototype.destroy = function()
}
}
};


// Save the graph on edit the graph with autosave enabled
function autoSave() {
if ($("#switch").is(":checked")) {
let CSRF_TOKEN = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
// Fires the Ajax request when the button is clicked

document.getElementById('save-ontology').innerHTML = '<div class="overlay"><i style="color: white !important;" class="fa fa-spinner fa-spin"></i></div>';
document.getElementById('save-ontology').style.backgroundColor = "#00a65a";
document.getElementById('save-ontology').style.borderColor = "#00a65a";
$.ajax({
/* the route pointing to the post function */
url: '/' + getLanguage() + '/updateOrCreate',
type: 'POST',
/* send the csrf-token and the input to the controller */
data: {
_token: CSRF_TOKEN,
id: document.getElementById('id').value,
xml_string: new XMLSerializer().serializeToString(editor.getGraphXml()),
name: document.getElementById('name-input').value,
publication_date: document.getElementById('publication-date').value,
last_uploaded: document.getElementById('last-uploaded').value,
description: document.getElementById('description').value,
link: document.getElementById('link').value,
domain: document.getElementById('ontology-domain').value,
general_purpose: document.getElementById('general-purpose').value,
profile_users: document.getElementById('profile-users').value,
intended_use: document.getElementById('intended-use').value,
type_of_ontology: document.getElementById('type-of-ontology').value,
degree_of_formality: document.getElementById('degree-of-formality').value,
scope: document.getElementById('scope').value,
competence_questions: document.getElementById('competence-questions').value,
namespace: $("#namespace-select").val().toString(),
collaborators: $("#collaborators-select").val()
},

dataType: 'JSON',
/* remind that 'data' is the response of the OntologyController */
success: function (data) {
updateSaveButtonInFrontEnd(true);
document.getElementById('id').value = data['id'];
document.getElementById('title').textContent = document.getElementById('name-input').value + ' | Onto4ALL - Ontology Graphical Editor';
document.getElementById('last-update').innerHTML = '<span class="time"><i class="fa fa-clock-o"></i> ' + 'Last update: ' + data['updated_at'];;
},

error: function (jqXHR, textStatus, errorThrown) {
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);

updateSaveButtonErrorInFrontEnd();
}
})
}
}

50 changes: 50 additions & 0 deletions public/grapheditor/styles/grapheditor.css
Original file line number Diff line number Diff line change
Expand Up @@ -1807,3 +1807,53 @@ div.picker { z-index: 10007; }
cursor:pointer;
margin:5px;
}

/* Switch autosave */

.autosave {
display: flex;
margin-top: 16px;
}

.autosave h5 {
color: #fff;
font-size: 14px;
padding-left: 8px;
margin: 0 0 16px;
}

.autosave input[type=checkbox]{
height: 0;
width: 0;
visibility: hidden;
}

.autosave label {
cursor: pointer;
width: 30px;
height: 14px;
background: grey;
display: block;
border-radius: 100px;
position: relative;
}

.autosave label:after {
content: '';
position: absolute;
left: 2px;
width: 14px;
height: 14px;
background: #fff;
border-radius: 14px;
transition: 0.3s;
}

.autosave input:checked + label {
background: rgb(0, 166, 90);;
}

.autosave input:checked + label:after {
left: calc(100% - 2px);
transform: translateX(-100%);
}
56 changes: 56 additions & 0 deletions public/js/OntologyManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,62 @@ document.addEventListener("DOMContentLoaded", function () {

});

// Request to save automatically the current ontology
// Update form
$(".tab-content :input").bind('keydown keyup', function (e) {

if ($("#switch").is(":checked")) {
let CSRF_TOKEN = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
// Fires the Ajax request when the button is clicked

document.getElementById('save-ontology').innerHTML = '<div class="overlay"><i style="color: white !important;" class="fa fa-spinner fa-spin"></i></div>';
document.getElementById('save-ontology').style.backgroundColor = "#00a65a";
document.getElementById('save-ontology').style.borderColor = "#00a65a";
$.ajax({
/* the route pointing to the post function */
url: '/' + getLanguage() + '/updateOrCreate',
type: 'POST',
/* send the csrf-token and the input to the controller */
data: {
_token: CSRF_TOKEN,
id: document.getElementById('id').value,
xml_string: new XMLSerializer().serializeToString(editor.getGraphXml()),
name: document.getElementById('name-input').value,
publication_date: document.getElementById('publication-date').value,
last_uploaded: document.getElementById('last-uploaded').value,
description: document.getElementById('description').value,
link: document.getElementById('link').value,
domain: document.getElementById('ontology-domain').value,
general_purpose: document.getElementById('general-purpose').value,
profile_users: document.getElementById('profile-users').value,
intended_use: document.getElementById('intended-use').value,
type_of_ontology: document.getElementById('type-of-ontology').value,
degree_of_formality: document.getElementById('degree-of-formality').value,
scope: document.getElementById('scope').value,
competence_questions: document.getElementById('competence-questions').value,
namespace: $("#namespace-select").val().toString(),
collaborators: $("#collaborators-select").val()
},

dataType: 'JSON',
/* remind that 'data' is the response of the OntologyController */
success: function (data) {
updateSaveButtonInFrontEnd(true);
document.getElementById('id').value = data['id'];
document.getElementById('title').textContent = document.getElementById('name-input').value + ' | Onto4ALL - Ontology Graphical Editor';
document.getElementById('last-update').innerHTML = '<span class="time"><i class="fa fa-clock-o"></i> ' + 'Last update: ' + data['updated_at'];;
},

error: function (jqXHR, textStatus, errorThrown) {
console.log(JSON.stringify(jqXHR));
console.log("AJAX error: " + textStatus + ' : ' + errorThrown);

updateSaveButtonErrorInFrontEnd();
}
})
}
});

// Reads the current ontology XML and then writes the report on a string for download
document.addEventListener("DOMContentLoaded", function () {
document.getElementById('download-ontology-report').addEventListener('click', function () {
Expand Down
5 changes: 5 additions & 0 deletions resources/views/vendor/adminlte/page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
<li class="favorite-ontology">
<a onclick="favoriteOntology()" value="0" title="Favorite ontology" href="#" id="favorite-ontology" class="geItem"></a>
</li>
<li>
<div class="autosave">
<input type="checkbox" id="switch" /><label for="switch"></label> <h5> {{__('Autosave')}} </h5>
</div>
</li>
<li>
<a id="save-ontology" class=" btn btn-default unsaved">
<i class="fa fa-fw fa-cloud-upload"></i> {{__('Unsaved changes. Click here to save')}}
Expand Down