Commit ec101e06 authored by akucera's avatar akucera
Browse files

various bugfixes - commit before changin the edit UI structure

parent 8bfbf060
......@@ -47,7 +47,13 @@
<script src="js/scripts.js"></script>
<script>
var p = new SBMSPage(function() {
var p = new SBMSPage({
datapoints : [],
semaphore : 0,
init: function() {
$(".opDiv").hide();
// loading divs
......@@ -65,14 +71,8 @@
"data-show-div"));
});
//$("#kompasFrame").attr("src", p.mapURL);
}, {
datapoints : [],
semaphore : 0
}, {
//$("#kompasFrame").attr("src", p.mapURL);
},
delayedInit : function() {
$("#selectorTree").hide();
......@@ -87,10 +87,12 @@
$(document).ajaxStop(
function() {
$("#console").css(
if($("#c2").height() > $("#c1").height()) {
$("#console").css(
"height",
$("#c2").height() - $("#c1").height()
+ ($("#console").outerHeight()));
}
});
if (window.location.hash != null
......@@ -126,57 +128,14 @@
"#delimiter").val());
});
$("#sendRemove").click(
function() {
if($("#user").val().trim() == "" || $("#pass").val().trim() == "") {
$("#status").html($.t("Enter valid credentials."));
p.toggleButtonError("removeOverallStatus","Forbidden");
return;
}
var glyphDP = "minus";
var glyphRels = "minus";
var glyphTrends = "minus";
$("#removeStatus").html("");
var ids = $("#idsToRemove").val().split(/[\n;\s]+/);
var assertions = [];
if($("#removeDps").prop("checked")) {
assertions[assertions.length] = "datapoints";
glyphDP = "time";
}
if($("#removeRels").prop("checked")) {
assertions[assertions.length] = "relations";
glyphRels = "time";
}
if($("#removeTrends").prop("checked")) {
assertions[assertions.length] = "trends";
glyphTrends = "time";
}
for(var i = 0; i < ids.length; i++) {
var text = ids[i];
ids[i] = encodeURIComponent(ids[i]);
$("#removeStatus").append('<tr data-address-id="' + ids[i] + '">'
+ '<td>' + text + '</td>'
+ '<td data-link-type="datapoints"><span class="glyphicon glyphicon-' + glyphDP + '" aria-hidden="true"></span></td>'
+ '<td data-link-type="relations"><span class="glyphicon glyphicon-' + glyphRels + '" aria-hidden="true"></span></td>'
+ '<td data-link-type="trends"><span class="glyphicon glyphicon-' + glyphTrends+ '" aria-hidden="true"></span></td>');
};
if(assertions.length > 0 && ids.length > 0) {
p.removeAssertions(assertions, 0, ids, 0);
p.toggleButtonSending("removeOverallStatus");
}
}
);
$("#sendRemove").click(p.sendRemoveBatch());
p.loadBatchHeaders();
$("#sendBatch").click(p.sendInsertBatch);
},
loadBatchHeaders : function() {
p.loadList("field.insert", function(data, params) {
var htmlHead = "";
var columns = 0;
......@@ -190,8 +149,55 @@
"colspan", columns);
});
$("#sendBatch").click(p.sendInsertBatch);
},
sendRemoveBatch : function() {
if($("#user").val().trim() == "" || $("#pass").val().trim() == "") {
$("#status").html($.t("Enter valid credentials."));
p.toggleButtonError("removeOverallStatus","Forbidden");
return;
}
var glyphDP = "minus";
var glyphRels = "minus";
var glyphTrends = "minus";
$("#removeStatus").html("");
var ids = $("#idsToRemove").val().split(/[\n;\s]+/);
var assertions = [];
if($("#removeDps").prop("checked")) {
assertions[assertions.length] = "datapoints";
glyphDP = "time";
}
if($("#removeRels").prop("checked")) {
assertions[assertions.length] = "relations";
glyphRels = "time";
}
if($("#removeTrends").prop("checked")) {
assertions[assertions.length] = "trends";
glyphTrends = "time";
}
for(var i = 0; i < ids.length; i++) {
var text = ids[i];
ids[i] = encodeURIComponent(ids[i]);
$("#removeStatus").append('<tr data-address-id="' + ids[i] + '">'
+ '<td>' + text + '</td>'
+ '<td data-link-type="datapoints"><span class="glyphicon glyphicon-' + glyphDP + '" aria-hidden="true"></span></td>'
+ '<td data-link-type="relations"><span class="glyphicon glyphicon-' + glyphRels + '" aria-hidden="true"></span></td>'
+ '<td data-link-type="trends"><span class="glyphicon glyphicon-' + glyphTrends+ '" aria-hidden="true"></span></td>');
};
if(assertions.length > 0 && ids.length > 0) {
p.removeAssertions(assertions, 0, ids, 0);
p.toggleButtonSending("removeOverallStatus");
}
},
removeAssertions : function(assertions, iA, ids, iI) {
......
......@@ -40,7 +40,11 @@
<script>
var p = new SBMSPage(function () {
var p = new SBMSPage({
noAuth: true,
init: function () {
p.loadList("field.data", function(headers, params) {
dpId = p.getQueryVariable("bmsId");
......@@ -70,30 +74,39 @@
propVal = p.getPropertyValue(dp, f);
// when map, add button
//// when map, add button
htmlBody += p.getPropertyValueCell(dp, f);
// add map navs + actions
if(p.getFieldDisplayCategory(f)=="map" && propVal != "") {
/*
if(p.getFieldDisplayCategory(f)=="map" && propVal != "") {
$("#mapTabs").append('<li role="presentation" id="nav' + p.getId(f) + '"><a href="#" data-field="' + encodeURIComponent(f) + '" data-field-value="' + encodeURIComponent(propVal) + '">'
+ $.t(f) + '</a></li>').find("li a").click(p.switchMaps);
//$("#mapTabs li:last-child a").click(switchMaps);
}
*/
});
$("table#dpInfo thead tr:eq(0)").html(htmlHead);
$("table#dpInfo tbody tr:eq(0)").html(htmlBody);
p.enrichPropertyValueCells("table#dpInfo", function() {
//add actions to map buttons
$("table#dpInfo .mapButton").click(p.switchMaps);
$("button.mapButton").each(function() {
var f = $(this).attr("data-field");
var propVal = $(this).attr("data-field-value");
// add map navs + actions
$("#mapTabs").append('<li role="presentation" id="nav' + p.getId(f) + '"><a href="#" data-field="' + encodeURIComponent(f) + '" data-field-value="' + encodeURIComponent(propVal) + '">'
+ $.t(f) + '</a></li>').find("li a").click(p.switchMaps);
//add actions to map buttons
$("table#dpInfo .mapButton").click(p.switchMaps);
});
});
$("#map").height($(window).height() - ($("body").outerHeight() - $("#map").height()) - 10);
});
});
}, { noAuth: true }, { sendDpInfo: function(dp, fields, fillTableAction) {
},
sendDpInfo: function(dp, fields, fillTableAction) {
var data = {};
......@@ -109,8 +122,8 @@
p.setAuth(xhr);
},
success: function(result) {
if(!$.isEmptyObject(result.dataPoints) && result.groups.length != 0) {
fillTableAction(result.dataPoints[result.groups[0]][0]);
if(!$.isEmptyObject(result.results) && result.groups.length != 0) {
fillTableAction(result.results[result.groups[0]][0]);
} else {
fillTableAction(null);
}
......
......@@ -104,6 +104,11 @@ var translation = {
'Forbidden' : 'Nepovolený přístup. Vyplnili jste jméno a heslo?',
'Nothing selected' : 'Nic není vybráno',
'No results match' : 'Žádné výsledky neodpovídají',
'Air' : 'Vzduch',
'Water' : 'Voda',
'TemperatureSensor' : 'Teplotní čidlo',
'Room' : 'Místnost',
'StatelessDirectSensing' : 'Přímé měření'
}
},
......
// Create Base64 Object
Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f<e.length){n=e.charCodeAt(f++);r=e.charCodeAt(f++);i=e.charCodeAt(f++);s=n>>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9+/=]/g,"");while(f<e.length){s=this._keyStr.indexOf(e.charAt(f++));o=this._keyStr.indexOf(e.charAt(f++));u=this._keyStr.indexOf(e.charAt(f++));a=this._keyStr.indexOf(e.charAt(f++));n=s<<2|o>>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/rn/g,"n");var t="";for(var n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r)}else if(r>127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n<e.length){r=e.charCodeAt(n);if(r<128){t+=String.fromCharCode(r);n++}else if(r>191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}}
function SBMSPage(initFunc, vars, customFunc) {
function SBMSPage(custom) {
//this.vars = vars;
//this.cf = customFunc;
fk = Object.keys(customFunc);
fk = Object.keys(custom);
for(var i = 0; i < fk.length; i++) {
this[fk[i]] = customFunc[fk[i]];
this[fk[i]] = custom[fk[i]];
}
vk = Object.keys(vars);
for(var i = 0; i < vk.length; i++) {
this[vk[i]] = vars[vk[i]];
}
var initFunc = this.init;
$(document).ready([this.showLoading, function() {
if($("#menu").length) {
......@@ -23,7 +18,7 @@ function SBMSPage(initFunc, vars, customFunc) {
$("#menu").load("inclMenu.html", function() {
var page = location.pathname.substring(location.pathname.lastIndexOf("/") + 1).replace(".html","");
$('#menu li[data-page="' + page + '"]').addClass("active");
if(vars["noAuth"]) {
if(SBMSPage["noAuth"]) {
$("#login").hide();
}
SBMSPage.prototype.i18nInit();
......@@ -310,7 +305,7 @@ function SBMSPage(initFunc, vars, customFunc) {
tools = ' <button type="button" class="btn btn-default btn-xs mapButton" data-field="' + encodeURIComponent(field) + '" data-field-value="' + encodeURIComponent(propVal) + '"><span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span></button>';
}
*/
return '<td class="propCell" data-prop-val="' + propVal + '" data-prop-field="' + field + '">' + $.t(propVal) + '</td>';
return '<td class="propCell" data-field-value="' + propVal + '" data-field="' + field + '">' + $.t(propVal) + '</td>';
};
SBMSPage.prototype.enrichPropertyValueCells = function(parent, callback) {
......@@ -330,8 +325,8 @@ function SBMSPage(initFunc, vars, customFunc) {
SBMSPage.prototype.enrichPVC = function(parent, fl, callback) {
$(parent + ' td.propCell').each(function() {
var field = $(this).attr("data-prop-field");
var propVal = $(this).attr("data-prop-val");
var field = $(this).attr("data-field");
var propVal = $(this).attr("data-field-value");
if(propVal.trim() != "") {
if(fl[field] == "bim") {
$(this).append(' <button type="button" class="btn btn-default btn-xs mapButton" data-field="' + encodeURIComponent(field) + '" data-field-value="' + encodeURIComponent(propVal) + '"><span class="glyphicon glyphicon-map-marker" aria-hidden="true"></span></button>');
......
......@@ -49,7 +49,9 @@
<script>
var p = new SBMSPage (function() {
var p = new SBMSPage ({
init: function() {
$("#results").hide();
$("#resultsJSON").hide();
......@@ -101,9 +103,6 @@ var p = new SBMSPage (function() {
},
{},
{
makeTableFromJSON: function(data, fieldsSelector, target) {
var html="<table id='jsonTable' class='table table-bordered table-hover'><thead><tr><th>group</th>";
......
......@@ -4,34 +4,58 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title data-i18n="sbmsClient">Semantic BMS client</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<!-- Latest compiled and minified JavaScript -->
<link rel="stylesheet"
href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<!-- Latest compiled and minified JavaScript
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
-->
<script src="js/bootstrap.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- https://github.com/jonmiles/bootstrap-treeview -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css">
<script
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/i18next/3.1.0/i18next.min.js"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/css/bootstrap-select.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.2/js.cookie.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.10.0/js/bootstrap-select.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/i18next/3.1.0/i18next.min.js"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/2.1.2/js.cookie.min.js"></script>
<script src="js/i18n.js"></script>
<script src="js/i18n.js"></script>
<script src="js/scripts.js"></script>
<script type="text/javascript">
var p = new SBMSPage(
function() {
var p = new SBMSPage({
init: function() {
$("#send").click(p.sendSPARQL);
$("#sparql").click(function() {
$("#sparql").attr("rows", "20");
});
}, {}, {
},
sendSPARQL: function () {
var format = $('input[name=format]:checked', '#queryForm').val();
var query= p.sbmsURL + "query/?sparql="+encodeURIComponent($("#sparql").val()) + "&format="
......@@ -122,8 +146,8 @@ WHERE {
<label class="radio-inline"><input type="radio" name="format" value="json">JSON</label>
</div>
<div class="form-group form-inline">
<button type="button" id="send" class="sendButton btn btn-primary">Send query</button>
<span id="status" class="label label-success">Ready</span>
<h3><button type="button" id="send" class="sendButton btn btn-primary">Send query</button>
<span id="status" class="label label-success">Ready</span></h3>
</div>
<div class="form-group">
<div id="results" name="results"></div>
......
......@@ -34,23 +34,27 @@ public class ModelUpdater {
Resource dp = m.createResource(NS.sbmsd + d.getResourceId());
Resource obs = m.createResource(NS.sbmsd + d.getResourceId() + "Obs");
if(!TypesProvider.getDataPointTypes().getMembers().contains(d.getType())) {
//throw new IllegalArgumentException("Unknown datapoint type");
return failInsert("Unknown datapoint type");
}
// ?dataPoint rdf:type ?dataPointClass.
// ?observation rdf:type sbms:Observation.
if(!dp.hasProperty(RDF.type)) {
if(!TypesProvider.getDataPointTypes().getMembers().contains(d.getType())) {
//throw new IllegalArgumentException("Unknown datapoint type");
return failInsert("Unknown datapoint type");
}
logger.debug("Inserting dp type: " + d.getType());
dp.addProperty(RDF.type, m.createResource(NS.sbms + d.getType()));
}
if(!obs.hasProperty(RDF.type)) {
logger.debug("Inserting observation");
obs.addProperty(RDF.type, m.createResource(NS.sbms + "Observation"));
}
// ?dataPoint sbms:hasBMSId ?bmsId.
Property p = null;
p = m.createProperty(NS.sbms + "hasBMSId");
if(!dp.hasProperty(p)) {
logger.debug("Inserting bmsId: " + d.getBmsId());
dp.addLiteral(p, d.getBmsId());
}
// ?dataPoint sbms:expressesObservation ?observation.
......@@ -65,10 +69,10 @@ public class ModelUpdater {
if(!checkBIMId(d.getPublisher().getBimId())) {
return failInsert("Publisher: unknown BIM id");
}
logger.debug("Inserting publisher: " + d.getPublisher().getResourceId());
p = m.createProperty(NS.sbms + "publishedByDevice");
if(!dp.hasProperty(p)) {
dp.addProperty(p, NS.sbmsd + d.getPublisher().getResourceId());
dp.addProperty(p, m.createResource(NS.sbmsd + d.getPublisher().getResourceId()));
}
}
if(d.getProperty() != null && d.getProperty().getDomain() != null
......@@ -83,6 +87,8 @@ public class ModelUpdater {
return failInsert("Unknown property domain type");
}
logger.debug("Inserting observed property: " + d.getProperty());
// ?property rdf:type sbms:ObservedProperty.
Resource op = m.createResource(NS.sbmsd + d.getScope().getResourceId()
+ d.getProperty().getDomain()
......@@ -110,6 +116,9 @@ public class ModelUpdater {
if(!checkBIMId(d.getSource().getBimId())) {
return failInsert("Source: unknown BIM id");
}
logger.debug("Inserting source: " + d.getSource());
// ?observation sbms:observedBy ?source.
obs.addProperty(m.createProperty(NS.sbms + "observedBy"),
m.createResource(NS.sbmsd + d.getSource().getResourceId()));
......@@ -118,6 +127,8 @@ public class ModelUpdater {
if(!checkBIMId(d.getScope().getBimId())) {
return failInsert("Scope: unknown BIM id");
}
logger.debug("Inserting scope: " + d.getScope());
// ?observation sbms:featureOfInterest ?scope.
obs.addProperty(m.createProperty(NS.sbms + "featureOfInterest"),
m.createResource(NS.sbmsd + d.getScope().getResourceId()));
......@@ -127,7 +138,8 @@ public class ModelUpdater {
if(!TypesProvider.getAllSensingTypes().getMembers().contains(d.getSensing().getType())) {
//throw new IllegalArgumentException("Unknown sensing type");
return failInsert("Unknown sensing type");
}
}
logger.debug("Inserting sensing: " + d.getSensing());
Resource sensing = m.createResource(NS.sbmsd + d.getResourceId() + "Sensing");
// ?sensing rdf:type ?sensingClass.
sensing.addProperty(RDF.type, m.createResource(NS.sbms + d.getSensing().getType()));
......@@ -177,12 +189,13 @@ public class ModelUpdater {
&& inf.getProperty().getDomain() != null
&& inf.getProperty().getQuality() != null && inf.getScope() != null &&
inf.getScope().getBimId() != null) {
logger.debug("Inserting influence: " + inf);
Resource ip = m.createResource(NS.sbmsd + inf.getScope().getResourceId()
+ inf.getProperty().getDomain()
+ inf.getProperty().getQuality() + "ObsProp");
ip.addProperty(RDF.type, NS.sbms + m.createResource(NS.sbms + "ObservedProperty"));
ip.addProperty(RDF.type, m.createResource(NS.sbms + "ObservedProperty"));
// ?datapoint sbms:influences ?property.
p = m.createProperty(NS.sbms + "influences");
......@@ -455,13 +468,14 @@ public class ModelUpdater {
}
public static void cleanup() {
logger.debug("Starting cleanup - reading unused individuals...");
List<RDFNode> o = GetUnusedObservations();
List<RDFNode> p = GetUnusedProperties();
List<RDFNode> s = GetUnusedSensings();
List<RDFNode> t = GetUnusedTrends();
List<RDFNode> a = GetUnusedAlgorithms();
Model m = TdbConnector.getWritableModel();
logger.debug("Writable model opened for cleanup.");
for(RDFNode n : o) {
n.asResource().removeAll(m.createProperty(NS.sbms + "observedBy"));
n.asResource().removeAll(m.createProperty(NS.sbms + "featureOfInterest"));
......@@ -490,6 +504,7 @@ public class ModelUpdater {
}
TdbConnector.commit();
logger.debug("Cleanup complete.");
}
private static List<RDFNode> GetUnusedAlgorithms() {
......
......@@ -104,11 +104,18 @@ public class TdbConnector {
throw new IllegalStateException("Tdb not opened");
}
if(checkDirty && dirty.compareAndSet(true, false)) {
if(checkDirty && dirty.get()) {
logger.debug("cached model is dirty - reopening");
// we will open clean model
dirty.set(false);
open();
// cleanup will set it to dirty
ModelUpdater.cleanup();
// setting back to true
dirty.set(false);
// opening clean model
open();
}
return model;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment