Skip to content

Commit

Permalink
changing the language now updates the headers
Browse files Browse the repository at this point in the history
  • Loading branch information
wacki committed Feb 19, 2016
1 parent f7b8685 commit 67768d8
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 59 deletions.
11 changes: 10 additions & 1 deletion app/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,22 @@ a.header-icon {
height: 100%;
display: block;
/* vertical-align: middle; */
line-height: 25px;
margin-right: 1px;
float: right;
padding: 0;

.fa {
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
line-height: 24px;
}
}




div.loading-indicator {
display: block;
margin: 0 3.5%;
Expand Down
2 changes: 1 addition & 1 deletion app/elements/datacube-table-element.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h3>Generated Query (Read Only)</h3>

</form>
<div>
<h1>Raum, Umwelt</h1><i class="fa fa-filter"></i>
<h1>Raum, Umwelt</h1>
<h2 class="datasetname">Title</h2>
<p class="datasetcomment">Description</p>
<p>1.1.1984 - 31.12.2014</p>
Expand Down
166 changes: 112 additions & 54 deletions app/js/data-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
var datastructuredefinition = "";
var datasetname = "";
var datasetcomment = "";
var fallbackLanguage = "de";

// bundle individual sparql query parts in an object for now
var sparqlQuery = {
Expand Down Expand Up @@ -110,6 +111,54 @@
queryDataStructureDefinition();
}


function loadColumnInfo() {
var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"PREFIX u28: <http://environment.data.admin.ch/ubd/28/>" +
"PREFIX qb: <http://purl.org/linked-data/cube#>" +
"SELECT ?datasetname ?datasetcomment WHERE { " +
"<" + datastructuredefinition + "> a qb:DataStructureDefinition ." +
"?dataset a qb:DataSet." +
"?dataset rdfs:label ?datasetname." +
"?dataset rdfs:comment ?datasetcomment." +
"?dataset qb:structure <" + datastructuredefinition + ">" +
"}";


var req = $.ajax({
dataType: "json",
type: "POST",
data: { query: query },
url: endPoint,
callbackParameter: "callback",
Accept: "application/sparql-results+json",
cache: true,
success: function (resp, textStatus, jqXHR) {

datasetname = resp.results.bindings[0].datasetname.value;
datasetcomment = resp.results.bindings[0].datasetcomment.value;
onDatasetMetadataRetrieved.notify({name: datasetname, comment: datasetcomment });

},
error: function () {
console.log("couldn't dataset name and comment");
}
});

/*
// set the columns if not already set.
if (columns.length === 0) {
var vars = responseData.head.vars;
$.each(vars, function (i, col) {
columns.push({ id: col, name: col, field: col, sortable: true });
});
onColumnsChanged.notify(columns);
}
*/
}
function queryDataStructureMetadata() {

var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
Expand Down Expand Up @@ -160,20 +209,39 @@
"?y rdfs:label ?l" +
"}";/**/

var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n" +
"PREFIX u28: <http://environment.data.admin.ch/ubd/28/>\n" +
"PREFIX qb: <http://purl.org/linked-data/cube#>\n" +
"SELECT ?column ?columnLabel ?columnComment ?componentType WHERE {\n" +
"<" + datastructuredefinition + "> a qb:DataStructureDefinition .\n" +
"<" + datastructuredefinition + "> ?p ?component .\n" +
"?component ?componentType ?column.\n" +
"?column rdfs:label ?columnLabel .\n" +


"OPTIONAL { \n" +
" ?column <http://www.w3.org/2000/01/rdf-schema#comment> ?columnLabelUserLang .\n" +
" FILTER(LANGMATCHES(lang(?columnLabelUserLang), '" + selectedLang + "'))\n" +
"}\n" +
"OPTIONAL { \n" +
" ?column <http://www.w3.org/2000/01/rdf-schema#comment> ?columnLabelDefaultLang .\n" +
" FILTER(LANGMATCHES(lang(?columnLabelDefaultLang), '" + fallbackLanguage + "'))\n" +
"}\n" +
"BIND(COALESCE(?columnLabelUserLang, ?columnLabelDefaultLang) AS ?columnLabel)\n" +


"OPTIONAL { \n" +
" ?column <http://www.w3.org/2000/01/rdf-schema#comment> ?columnCommentUserLang .\n" +
" FILTER(LANGMATCHES(lang(?columnCommentUserLang), '" + selectedLang + "'))\n" +
"}\n" +
"OPTIONAL { \n" +
" ?column <http://www.w3.org/2000/01/rdf-schema#comment> ?columnCommentDefaultLang .\n" +
" FILTER(LANGMATCHES(lang(?columnCommentDefaultLang), '" + fallbackLanguage + "'))\n" +
"}\n" +
"BIND(COALESCE(?columnCommentUserLang, ?columnCommentDefaultLang) AS ?columnComment)\n" +
"}\n";

var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>" +
"PREFIX u28: <http://environment.data.admin.ch/ubd/28/>" +
"PREFIX qb: <http://purl.org/linked-data/cube#>" +
"SELECT * WHERE {" +
"<" + datastructuredefinition + "> a qb:DataStructureDefinition ." +
"<" + datastructuredefinition + "> ?p ?o ." +
"?o ?x ?y." +
"?y rdfs:label ?l" +
"}";

// get labels out of ?l
// find a way to get the exact types out of

// load dsd and build our query
var req = $.ajax({
Expand All @@ -196,30 +264,50 @@

// add column selectors
newQuery += "SELECT ";
for(var i in resp.results.bindings)
newQuery += "?" + resp.results.bindings[i].l.value + " "; // todo: careful, if more than one language this part will fail!
for(var i in resp.results.bindings) {
var col = /[^/]*$/.exec(resp.results.bindings[i].column.value)[0];
newQuery += "?" + col + "Value "; // todo: careful, if more than one language this part will fail!
}
newQuery += " WHERE {\n";

for(i in resp.results.bindings) {
var binding = resp.results.bindings[i];
var col = /[^/]*$/.exec(binding.column.value)[0];
var colValueUserLang = col + "UserLang";
var colValueDefaultLang = col + "DefaultLang";
var colValue = col + "Value";
var columnComment = (binding.columnComment != undefined) ? binding.columnComment.value : "";
columns.push({ id: colValue, name: binding.columnLabel.value, field: colValue, sortable: true, comment: columnComment, componentType: binding.componentType.value });

// if dimension then look for label and filter language
// if attribute
if(binding.x.value != "http://purl.org/linked-data/cube#measure") {
newQuery += "?m <" + binding.y.value + "> ?" + binding.l.value + "Temp.\n" +
if(binding.componentType.value != "http://purl.org/linked-data/cube#measure") {
newQuery += "?m <" + binding.column.value + "> ?" + col + ".\n" +
"OPTIONAL { \n" +
" ?" + col + " rdfs:label ?" + colValueUserLang + ".\n" +
" FILTER(LANGMATCHES(lang(?" + colValueUserLang + "), '" + selectedLang + "') || lang(?" + colValueUserLang + ") = '')\n" +
"}\n" +
// go and get the fallback language value as well
"OPTIONAL { \n" +
" ?" + binding.l.value + "Temp rdfs:label ?" + binding.l.value + ".\n" +
" FILTER(lang(?" + binding.l.value + ") = '' || LANGMATCHES(lang(?" + binding.l.value + "), '" + selectedLang + "'))\n" +
"}\n\n";
" ?" + col + " rdfs:label ?" + colValueDefaultLang + ".\n" +
" FILTER(LANGMATCHES(lang(?" + colValueDefaultLang + "), '" + fallbackLanguage + "') || lang(?" + colValueDefaultLang + ") = '')\n" +
"}\n" +
// finally choose assign the correct language to ?col
"BIND(COALESCE(?" + colValueUserLang + ", ?" + colValueDefaultLang + ") AS ?" + colValue + ")\n\n";
}
// else just get the raw value of a measurement type
else {
newQuery += "?m <" + binding.y.value + "> ?" + binding.l.value + ".\n\n";
newQuery += "?m <" + binding.column.value + "> ?" + colValue + ".\n\n";
}

}
newQuery += "}";

//console.log("\nGENERATED QUERY: \n\n" + newQuery);

onColumnsChanged.notify(columns);
/**/


console.log("\nGENERATED QUERY: \n\n" + newQuery);
setQuery(newQuery);
if(complete)
complete();
Expand All @@ -231,36 +319,6 @@
}
});

/* goal query
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX u28: <http://environment.data.admin.ch/ubd/28/>
SELECT ?station ?pollutant ?aggregation ?year ?measurement ?unit WHERE {
?m a <http://example.org/Measurement> .
?m <http://example.org/measurement> ?measurement.
?m <http://example.org/aggregation> ?a.
?a rdfs:label ?aggregation.
FILTER (lang(?aggregation) = 'de')
?m <http://example.org/station> ?s.
?s rdfs:label ?station.
?m <http://example.org/unit> ?u.
?u rdfs:label ?unit.
FILTER (lang(?unit) = 'de')
?m <http://example.org/pollutant> ?p.
?p rdfs:label ?pollutant.
FILTER (lang(?pollutant) = 'de')
?m <http://example.org/year> ?y
BIND(SUBSTR(xsd:string(?y),46) AS ?year)
}
*/

}

// from and to are 0-based row indices.
Expand Down Expand Up @@ -538,7 +596,7 @@
var result = endPoint + "?query=" + encodeURIComponent(compileSparqlQuery(options, queryObject));
return result;
}

function loaderFunction(page) {

//console.log("Sending new data request.");
Expand Down
4 changes: 1 addition & 3 deletions app/lib/SlickGrid/slick.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,7 @@ if (typeof Slick === "undefined") {
// custom modification for filter dropdown links
if ($(e.target).hasClass("slick-sort-ignore"))
return;

console.log(e.target);


var $col = $(e.target).closest(".slick-header-column");
if (!$col.length) {
return;
Expand Down

0 comments on commit 67768d8

Please sign in to comment.