Skip to content

Commit

Permalink
use ajax to run jobs for sparql
Browse files Browse the repository at this point in the history
  • Loading branch information
Pooya-Oladazimi committed Nov 2, 2023
1 parent 6a53866 commit 79abe49
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
7 changes: 3 additions & 4 deletions ckanext/crc1153/controllers/crcDcatProfileController.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from flask import render_template
import ckan.plugins.toolkit as toolkit
import ckan.model as model
import ckan.logic as logic
from ckan.model import Package
from ckanext.dcat.processors import RDFSerializer
from xml.etree import ElementTree
Expand All @@ -12,6 +10,7 @@
from ckanext.crc1153.libs.crc_profile.helpers import Crc1153DcatProfileHelper as Helper
from ckanext.crc1153.libs.auth_helpers import AuthHelpers
from ckan.model import Package
import json



Expand Down Expand Up @@ -39,7 +38,7 @@ def push_to_sparql():

toolkit.enqueue_job(push_catalog_to_sparql, kwargs={'catalog_graphs': all_graphs})

return '0'
return json.dumps({"_result": True})



Expand All @@ -57,7 +56,7 @@ def delete_from_sparql():

toolkit.enqueue_job(delete_catalog_from_sparql, kwargs={'catalog_graphs': all_graphs})

return '0'
return json.dumps({"_result": True})



Expand Down
71 changes: 71 additions & 0 deletions ckanext/crc1153/public/crc_profile/profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
$(document).ready(function(){

$('#push-to-sparql-btn').click(function(){
let endPoint = $('#push-to-sparql-url').val();
$.ajax({
url: endPoint,
method: "GET",
dataType: "json",
success: function(responseData) {
if (responseData["_result"]){
createSuccessAlert();

}
},
error: function(jqXHR, textStatus, errorThrown) {
createFailAlert();
}
});
});


$('#delete-sparql-btn').click(function(){
let endPoint = $('#delete-sparql-url').val();
$.ajax({
url: endPoint,
method: "GET",
dataType: "json",
success: function(responseData) {
console.info(responseData)
if (responseData["_result"]){
createSuccessAlert();

}
},
error: function(jqXHR, textStatus, errorThrown) {
createFailAlert();
}
});
});



});



function createSuccessAlert(){
let alertDiv = document.createElement("div");
alertDiv.classList.add("alert", "alert-success");
let strongElement = document.createElement("strong");
strongElement.textContent = "Job is in queue!";
let textNode = document.createTextNode(" It may take some time to finish. You can check the result in the CKAN log.");
alertDiv.appendChild(strongElement);
alertDiv.appendChild(textNode);
let container = document.getElementById("alert_container");
container.appendChild(alertDiv);
}



function createFailAlert(){
let alertDiv = document.createElement("div");
alertDiv.classList.add("alert", "alert-danger");
let strongElement = document.createElement("strong");
strongElement.textContent = "Something wen wrong!";
let textNode = document.createTextNode("Please try later or check CKAN for possible bugs/issues!");
alertDiv.appendChild(strongElement);
alertDiv.appendChild(textNode);
let container = document.getElementById("alert_container");
container.appendChild(alertDiv);
}
8 changes: 6 additions & 2 deletions ckanext/crc1153/templates/crc_profile/admin_panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
{% set export_action = h.url_for('crc1153_dcat_profile.export_catalog', _external=True) %}
{% set push_sparql_action = h.url_for('crc1153_dcat_profile.push_to_sparql', _external=True) %}
{% set delete_sparql_action = h.url_for('crc1153_dcat_profile.delete_from_sparql', _external=True) %}
<input type="hidden" value="{{push_sparql_action}}" id="push-to-sparql-url" />
<input type="hidden" value="{{delete_sparql_action}}" id="delete-sparql-url" />
<div class="row" id="alert_container"></div>

<div class="row">
<div class="col-sm-12">
<a class="btn btn-primary" href="{{export_action}}" id="export-catalog-btn" target="_blank">Export Catalog</a>
Expand All @@ -15,13 +19,13 @@
<br/>
<div class="row">
<div class="col-sm-12">
<a class="btn btn-primary" href="{{push_sparql_action}}" id="push-to-sparql-btn">Push CKAN Datasets Metadata To SPARQL</a>
<a class="btn btn-primary" href="#" id="push-to-sparql-btn" >Push CKAN Datasets Metadata To SPARQL</a>
</div>
</div>
<br/>
<div class="row">
<div class="col-sm-12">
<a class="btn btn-danger" href="{{delete_sparql_action}}" id="delete-sparql-btn">Delete CKAN Datasets Metadata From SPARQL</a>
<a class="btn btn-danger" href="#" id="delete-sparql-btn">Delete CKAN Datasets Metadata From SPARQL</a>
</div>
</div>
{% endif %}
Expand Down

0 comments on commit 79abe49

Please sign in to comment.