Skip to content

Commit

Permalink
fixed event unsubscriptions which led to multiple agent generations
Browse files Browse the repository at this point in the history
  • Loading branch information
André Antakli committed Apr 19, 2024
1 parent 47cbe5b commit 26be8cc
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 102 deletions.
42 changes: 25 additions & 17 deletions app/components/agents/action-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,8 @@ export default Component.extend({
"http://localhost:8090/rdf4j/repositories") +
globals.agentsRepository;

this.get('dataBus').on('updatedAG', function () {
Promise.resolve(token.resolveToken(that.ajax, localStorage.currentStore))
.then((token) => {
$.ajax({
url: repo + "/statements",
type: "GET",
contentType: "application/trig; charset=utf-8",
headers: getHeaders(token)
}).then(function (data) {
that.set("fileContent", URL.createObjectURL(new Blob([data])));
});
});
});

this.get('dataBus').on('updateAgentDefs', function (defs) {
that.set("agentDefs", defs);
});
this.get('dataBus').on('updatedAG', updatedAG);
this.get('dataBus').on('updateAgentDefs', setAgentDefs);
},

actions: {
Expand All @@ -75,6 +60,11 @@ export default Component.extend({
loadFile() {
loadFile(event)
}
},

willDestroyElement() {
this.get('dataBus').off('updatedAG', updatedAG);
this.get('dataBus').off('updateAgentDefs', setAgentDefs);
}
});

Expand Down Expand Up @@ -137,3 +127,21 @@ function updateType(content, importFile) {
.then(window.location.reload());
}
}

function updatedAG() {
Promise.resolve(token.resolveToken(that.ajax, localStorage.currentStore))
.then((token) => {
$.ajax({
url: repo + "/statements",
type: "GET",
contentType: "application/trig; charset=utf-8",
headers: getHeaders(token)
}).then(function (data) {
that.set("fileContent", URL.createObjectURL(new Blob([data])));
});
});
}

function setAgentDefs(defs) {
that.set("agentDefs", defs);
}
63 changes: 35 additions & 28 deletions app/components/behaviors/action-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,10 @@ export default Component.extend({

readURLParameters();

this.get('dataBus').on('save', function (content) {
saveGraph(content);
});

this.get('dataBus').on('unsavedChanges', function () {
console.log("Unsaved changes!");
if (!that.get("unsaved")) that.set("unsaved", true);
});

this.get('dataBus').on('saveExportedBT', function (bt) {
that.set("btFileName", bt.label + "_bt.ttl");
that.set("btContent", URL.createObjectURL(new Blob(["# Root: <" + bt.uri + "> \r# Label: '" + bt.label + "' \r \r@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + bt.definition])));
});

this.get('dataBus').on('updatedBT', function () {
Promise.resolve(token.resolveToken(that.ajax, localStorage.currentStore))
.then((token) => {
$.ajax({
url: repo,
type: "POST",
contentType: "application/sparql-query; charset=utf-8",
headers: getHeaders(token),
data: queries.constructGraph
}).then(function (data) {
that.set("repoContent", URL.createObjectURL(new Blob([data])));
});
});
});
this.get('dataBus').on('save', saveGraph);
this.get('dataBus').on('unsavedChanges', unsavedChanges);
this.get('dataBus').on('saveExportedBT', saveExportedBT);
this.get('dataBus').on('updatedBT', updatedBT);
},

actions: {
Expand Down Expand Up @@ -133,6 +109,13 @@ export default Component.extend({
loadRepo() {
loadRepo(event);
}
},

willDestroyElement() {
this.get('dataBus').off('save', saveGraph);
this.get('dataBus').off('unsavedChanges', unsavedChanges);
this.get('dataBus').off('saveExportedBT', saveExportedBT);
this.get('dataBus').off('updatedBT', updatedBT);
}
});

Expand Down Expand Up @@ -174,6 +157,21 @@ function loadBT(event) {
reader.readAsText(file);
}

function updatedBT() {
Promise.resolve(token.resolveToken(that.ajax, localStorage.currentStore))
.then((token) => {
$.ajax({
url: repo,
type: "POST",
contentType: "application/sparql-query; charset=utf-8",
headers: getHeaders(token),
data: queries.constructGraph
}).then(function (data) {
that.set("repoContent", URL.createObjectURL(new Blob([data])));
});
});
}

function loadRepo(event) {
let file = event.target.files[0];
console.log("File: " + file.name);
Expand Down Expand Up @@ -236,3 +234,12 @@ function readURLParameters() {
that.set("agentRepo", repo);
}
}

function unsavedChanges() {
if (!that.get("unsaved")) that.set("unsaved", true);
}

function saveExportedBT(bt) {
that.set("btFileName", bt.label + "_bt.ttl");
that.set("btContent", URL.createObjectURL(new Blob(["# Root: <" + bt.uri + "> \r# Label: '" + bt.label + "' \r \r@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . " + bt.definition])));
}
47 changes: 24 additions & 23 deletions app/components/behaviors/behavior-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,17 @@ export default Ember.Component.extend({
this._super(...arguments);
that = this;

this.get('dataBus').on('addBT', function (bt) {
createBT(bt);
});
this.get('dataBus').on('generateAgent', function (bt) {
generateAgent();
});
this.get('dataBus').on('cloneBT', function () {
cloneBT();
});
this.get('dataBus').on('exportBT', function () {
that.get('dataBus').saveExportedBT(exportBT());
});
this.get('dataBus').on('importBT', function (bt) {
importBT(bt);
});
this.get('dataBus').on('deleteBT', function () {
deleteBT();
});
this.get('dataBus').on('addBT', createBT);
this.get('dataBus').on('generateAgent', generateAgent);
this.get('dataBus').on('cloneBT', cloneBT);
this.get('dataBus').on('exportBT', saveExportedBT);
this.get('dataBus').on('importBT', importBT);
this.get('dataBus').on('deleteBT', deleteBT);
},

// After the element has been inserted into the DOM
didInsertElement() {
this._super(...arguments);
didInsertElement() {
this._super(...arguments);

initializeCytoscape(this);
initializeGlobals(this);
Expand All @@ -96,8 +84,17 @@ export default Ember.Component.extend({
},

willDestroyElement() {
this._super(...arguments);
cleanDOM();
this._super(...arguments);

this.get('dataBus').off('addBT', createBT);
this.get('dataBus').off('generateAgent', generateAgent);
this.get('dataBus').off('cloneBT', cloneBT);
this.get('dataBus').off('exportBT', saveExportedBT);
this.get('dataBus').off('importBT', importBT);
this.get('dataBus').off('deleteBT', deleteBT);
console.log("adele");

cleanDOM();
}
}); // end Ember export

Expand Down Expand Up @@ -198,7 +195,6 @@ function generateAgent() {
let agentRepo = (localStorage.currentStore || "http://localhost:8090/rdf4j/repositories/") + "agents";
let selected = localStorage.getItem("bt-selected");
let selectedBt = that.get("availableBTs").filter(item => item.uri == selected);
console.log(selectedBt);
let includedEvents = { all: new Array(), handle: new Array(), produce: new Array()};
getEvents(includedEvents, selectedBt[0], that.get("availableBehaviors").filter(item => item.bt.uri != selectedBt[0].uri), true);
let includedBehaviors = getBehaviors(selectedBt[0], includedEvents);
Expand All @@ -215,6 +211,7 @@ function generateAgent() {
function saveGeneratedAgent(repo, stringRDF) {
try {
actions.saveAgentGraph(globals.ajax, repo, stringRDF);
//window.location.reload();
} catch (e) {
$("#error-message").trigger("showToast", [
"Error while saving generated Agent"
Expand Down Expand Up @@ -330,6 +327,10 @@ function exportBT() {
return bt;
}

function saveExportedBT() {
that.get('dataBus').saveExportedBT(exportBT());
}

function deleteBT() {
let selected = localStorage.getItem("bt-selected");
let bts = that.get("availableBTs").filter(item => item.uri == selected);
Expand Down
30 changes: 19 additions & 11 deletions app/components/domain/action-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,8 @@ export default Component.extend({
this._super(...arguments);
that = this;

this.get('dataBus').on('updateDomain', function (editor, repo) {
that.set("rdfContent", editor.session.getValue(), repo);
that.set("repo", repo);
that.set("update", true);
that.set("unsaved", true);
});

this.get('dataBus').on('noUpdateDomain', function () {
that.set("update", false);
that.set("unsaved", true);
});
this.get('dataBus').on('updateDomain', updateDomain);
this.get('dataBus').on('noUpdateDomain', noUpdateDomain);
},

actions: {
Expand All @@ -65,5 +56,22 @@ export default Component.extend({
noSave() {
alert("Nothing has Changed");
}
},

willDestroyElement() {
this.get('dataBus').off('updateDomain', updateDomain);
this.get('dataBus').off('noUpdateDomain', noUpdateDomain);
}
});

function updateDomain(editor, repo) {
that.set("rdfContent", editor.session.getValue(), repo);
that.set("repo", repo);
that.set("update", true);
that.set("unsaved", true);
}

function noUpdateDomain() {
that.set("update", false);
that.set("unsaved", true);
}
51 changes: 29 additions & 22 deletions app/components/services/action-bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,12 @@ export default Component.extend({
init() {
this._super(...arguments);
that = this;
repo =
(localStorage.currentStore ||
repo = (localStorage.currentStore ||
"http://localhost:8090/rdf4j/repositories") +
globals.servicesRepository;

this.get('dataBus').on('updatedSG', function () {
Promise.resolve(token.resolveToken(that.ajax, localStorage.currentStore))
.then((token) => {
$.ajax({
url: repo,
type: "POST",
contentType: "application/sparql-query; charset=utf-8",
headers: getHeaders(token),
data: queries.getAllServiceActions
}).then(function (data) {
that.set("fileContent", URL.createObjectURL(new Blob([data])));
});
});
});

this.get('dataBus').on('deletedSG', function () {
sendFile(that.ajax, repo, that.get("importContent"))
.then(window.location.reload());
});
this.get('dataBus').on('updatedSG', updatedSG);
this.get('dataBus').on('deletedSG', deletedSG);
},

actions: {
Expand All @@ -75,7 +57,12 @@ export default Component.extend({
loadFile() {
loadFile(event)
}
}
},

willDestroyElement() {
this.get('dataBus').off('updatedSG', updatedSG);
this.get('dataBus').off('deletedSG', deletedSG);
}
});

function getHeaders(token) {
Expand Down Expand Up @@ -130,3 +117,23 @@ function deleteAllServiceActions() {
});
actions.saveGraph(globals.ajax, repo, that.dataBus, "deleted");
}

function updatedSG() {
Promise.resolve(token.resolveToken(that.ajax, localStorage.currentStore))
.then((token) => {
$.ajax({
url: repo,
type: "POST",
contentType: "application/sparql-query; charset=utf-8",
headers: getHeaders(token),
data: queries.getAllServiceActions
}).then(function (data) {
that.set("fileContent", URL.createObjectURL(new Blob([data])));
});
});
}

function deletedSG() {
sendFile(that.ajax, repo, that.get("importContent"))
.then(window.location.reload());
}
1 change: 0 additions & 1 deletion app/helpers/RDFServices/node-definitions/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function generateStyle(styleURI, defaultLabel, selector, fixedLabel = false) {
if (icon) icon = iconPrefix + icon;
let node_icon = util.getObjectValue(quads, styleURI, ND.node_icon);
if (node_icon) node_icon = iconPrefix + node_icon;
console.log(node_icon);
//TODO: Check whether label will be properly overwritten for dynamic labels later on
if (defaultLabel && fixedLabel) style["label"] = defaultLabel;
let bgColor = util.getObjectValue(quads, styleURI, ND.color);
Expand Down

0 comments on commit 26be8cc

Please sign in to comment.