Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
BouzelatTarek committed Nov 28, 2024
2 parents f05befa + c0a3163 commit a62aee6
Show file tree
Hide file tree
Showing 24 changed files with 1,062 additions and 337 deletions.
2 changes: 1 addition & 1 deletion dev-page/form-configs/sapa/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"line": {
"s": "File",
"p": "http://shapes.performing-arts.ch/instantiations/File_originalName",
"o": "Z_Text_2",
"o": "OriginalName",
"sType": "http://shapes.performing-arts.ch/instantiations/File",
"oType": "http://special/Z_Text",
"values": []
Expand Down
2 changes: 1 addition & 1 deletion dev-page/form-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@
<%= js %>

<script src="sparnatural-yasgui-plugins.js"></script>
<script src="scripts/initPage.js"></script>
<script src="scripts/init-form-page.js"></script>
</body>
</html>
33 changes: 18 additions & 15 deletions dev-page/scripts/initPage.js → dev-page/scripts/init-form-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ console.log("urlParams", urlParams);
const lang = urlParams.get("lang");

sparnaturalForm.addEventListener("init", (event) => {
console.log("init sparnatural...");
sparnaturalForm.configuration = {
headers: { "User-Agent": "This is Sparnatural calling" },
autocomplete: {
maxItems: 40,
},
};
console.log("init sparnatural-form...");
console.log("Configuration ", sparnaturalForm.configuration);
// Notify all plugins of configuration updates if they support it
for (const plugin in yasr.plugins) {
Expand All @@ -23,35 +17,44 @@ sparnaturalForm.addEventListener("init", (event) => {
yasr.plugins[plugin].notifyConfiguration(
sparnaturalForm.sparnaturalForm.specProvider
);
console.log("sparnatural", sparnaturalForm.sparnaturalForm.specProvider);
}
}
});

// Listen for updates to the query and pass to YASQE
sparnaturalForm.addEventListener("queryUpdated", (event) => {
const queryStringFromJson = sparnaturalForm.expandSparql(
event.detail.queryStringFromJson
const queryString = sparnaturalForm.expandSparql(
event.detail.queryString
);
console.log("queryStringFromJson", event.detail);
console.log("queryString", event.detail);

// Update YASQE with the new SPARQL query
yasqe.setValue(queryStringFromJson);
console.log("yasr plugins", yasr.plugins);
yasqe.setValue(queryString);

for (const plugin in yasr.plugins) {
if (yasr.plugins[plugin].notifyQuery) {
yasr.plugins[plugin].notifyQuery(event.detail.queryJson);
console.log("notifying query for plugin " + plugin);
console.log(true);
}
}
});

// Listen for form submission and trigger YASQE query
sparnaturalForm.addEventListener("submit", () => {
sparnaturalForm.disablePlayBtn();
yasqe.query();
let finalResult = sparnaturalForm.executeSparql(
yasqe.getValue(),
(finalResult) => {
// send final result to YasR
yasr.setResponse(finalResult);
// re-enable submit button
sparnaturalForm.enablePlayBtn();
},
(error) => {
console.error("Got an error when executing SPARQL in Sparnatural");
console.dir(error);
}
);
});

console.log("init yasr & yasqe...");
Expand Down
Loading

0 comments on commit a62aee6

Please sign in to comment.