diff --git a/app/components/behaviors/action-bar.js b/app/components/behaviors/action-bar.js index 3fb1d432..91a6f277 100644 --- a/app/components/behaviors/action-bar.js +++ b/app/components/behaviors/action-bar.js @@ -37,6 +37,7 @@ export default Component.extend({ ajax: Ember.inject.service(), repoFileName: "behaviors.ttl", availableBTs: undefined, + unsaved: false, repoContent: "", btFileName: "", btContent: "", @@ -52,6 +53,11 @@ export default Component.extend({ 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\r@prefix xsd: . " + bt.definition]))); diff --git a/app/components/behaviors/behavior-graph.js b/app/components/behaviors/behavior-graph.js index bac5a0b2..c885dbd0 100644 --- a/app/components/behaviors/behavior-graph.js +++ b/app/components/behaviors/behavior-graph.js @@ -53,6 +53,7 @@ export default Ember.Component.extend({ init() { this._super(...arguments); that = this; + this.get('dataBus').on('addBT', function (bt) { createBT(bt); }); @@ -151,13 +152,19 @@ function loadBTRdfGraphData() { } function rdfDataHasLoaded(rdfData) { - rdfGraph.set(rdfData); + console.log("has Loaded"); + rdfGraph.set(rdfData); + rdfGraph.setUnsavedMethod(unsavedChanges); setAvailableBTs(); bindEvents(); cy.resize(); that.dataBus.updatedBT(); } +function unsavedChanges() { + that.dataBus.unsavedChanges(); +} + function setAvailableBTs() { let behaviorTrees = actions.getBehaviorTrees(); that.set("availableBTs", behaviorTrees); diff --git a/app/helpers/RDFServices/RDF-graph.js b/app/helpers/RDFServices/RDF-graph.js index f30fc23e..9af974c1 100644 --- a/app/helpers/RDFServices/RDF-graph.js +++ b/app/helpers/RDFServices/RDF-graph.js @@ -23,19 +23,40 @@ import rdfFact from "ajan-editor/helpers/RDFServices/RDF-factory"; class RDFGraph { constructor() { - this.data = undefined; + this.data = undefined; + this.unsavedMethod = undefined; + this.publishedChanges = false; this.unsavedChanges = false; } // Only used for initiating reset() { this.data = undefined; - this.unsavedChanges = false; + this.unsavedChanges = false; + this.unsavedMethod = undefined; + this.publishedChanges = false; } - set(newData) { - this.data = newData; - } + set(newData) { + this.data = newData; + this.unsavedChanges = false; + this.unsavedMethod = undefined; + this.publishedChanges = false; + } + + setUnsavedMethod(unsavedMethod) { + if (!this.unsavedMethod) { + this.unsavedMethod = unsavedMethod; + } + } + + setUnsavedChanges(value) { + this.unsavedChanges = value; + if (this.unsavedMethod && this.unsavedChanges && !this.publishedChanges) { + this.publishedChanges = true; + this.unsavedMethod(); + } + } get() { return this.data; @@ -43,12 +64,12 @@ class RDFGraph { add(quad) { this.data.add(quad); - this.unsavedChanges = true; + this.setUnsavedChanges(true); } addAll(quads) { this.data.addAll(quads); - this.unsavedChanges = true; + this.setUnsavedChanges(true); } existsSome(value) { @@ -82,13 +103,13 @@ class RDFGraph { remove(quad) { this.data.remove(quad); - this.unsavedChanges = true; + this.setUnsavedChanges(true); console.warn("Delete", quad); } removeMatches(ele) { this.data.removeMatches(ele); - this.unsavedChanges = true; + this.setUnsavedChanges(true); console.warn("Delete matches", ele); } @@ -151,7 +172,7 @@ class RDFGraph { // Update quad if (o !== quad.object.value) { quad.object.value = o; - this.unsavedChanges = true; + this.setUnsavedChanges(true); } } else { // Create and add quad @@ -168,7 +189,7 @@ class RDFGraph { console.log(quad.object); if (o !== quad.object) { quad.object = o; - this.unsavedChanges = true; + this.setUnsavedChanges(true); } } else { // Create and add quad @@ -179,7 +200,7 @@ class RDFGraph { // Removes all quads which have an element related to val removeAllRelated(val, noObject) { - this.unsavedChanges = true; + this.setUnsavedChanges(true); console.warn("Delete related to", val); if (noObject) { this.data._quads = this.data._quads.filter(quad => { @@ -200,7 +221,7 @@ class RDFGraph { } removeRelatedQuads(subject, predicate) { - this.unsavedChanges = true; + this.setUnsavedChanges(true); let remove = []; console.warn("Delete related to", subject, predicate); this.data.forEach(quad => { @@ -218,7 +239,7 @@ class RDFGraph { } removeQuad(removeQuad) { - this.unsavedChanges = true; + this.setUnsavedChanges(true); console.warn("Delete", removeQuad); this.data._quads = this.data._quads.filter(quad => { return !removeQuad.equals(quad); diff --git a/app/services/data-bus.js b/app/services/data-bus.js index 9e790b8a..08ce818f 100644 --- a/app/services/data-bus.js +++ b/app/services/data-bus.js @@ -21,6 +21,10 @@ import Ember from "ember"; export default Ember.Service.extend(Ember.Evented, { + unsavedChanges() { + this.trigger('unsavedChanges'); + }, + createBT() { this.trigger('createBT'); }, diff --git a/app/styles/components/behaviors/action-bar.css b/app/styles/components/behaviors/action-bar.css index 291e5603..7b3683f6 100644 --- a/app/styles/components/behaviors/action-bar.css +++ b/app/styles/components/behaviors/action-bar.css @@ -38,6 +38,10 @@ text-align: right; } +:global(.behaviors-save-button.unsavedChanges button) { + color: #FFF !important; +} + /***********************/ /* Triplestore Display */ /***********************/ diff --git a/app/templates/components/behaviors/action-bar.hbs b/app/templates/components/behaviors/action-bar.hbs index ba377fff..7084adc6 100644 --- a/app/templates/components/behaviors/action-bar.hbs +++ b/app/templates/components/behaviors/action-bar.hbs @@ -61,10 +61,21 @@ label="Sort" onClick=(action "sort") }} - {{ui/menu-bar/button - label="Save" - onClick=(action "save") - }} + {{#if this.unsaved}} + {{ui/menu-bar/button + label="Save" + class="behaviors-save-button unsavedChanges" + icon="save icon" + onClick=(action "save") + }} + {{/if}} + {{#unless this.unsaved}} + {{ui/menu-bar/button + label="Save" + class="behaviors-save-button" + onClick=(action "save") + }} + {{/unless}} {{ui/menu-bar/button label="Delete" onClick=(action "delete") diff --git a/app/templates/components/ui/menu-bar/button.hbs b/app/templates/components/ui/menu-bar/button.hbs index e495592d..f5823c21 100644 --- a/app/templates/components/ui/menu-bar/button.hbs +++ b/app/templates/components/ui/menu-bar/button.hbs @@ -1 +1 @@ - +