UNPKG

sparnatural

Version:

Visual client-side SPARQL query builder and knowledge graph exploration tool

144 lines 7.34 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _ActionStore_instances, _ActionStore_addCustomEventListners; import { Order } from "../SparnaturalQueryIfc"; import toggleVarNames from "./actions/ToggleVarNames"; import updateVarName from "./actions/UpdateVarName"; import redrawBackgroundAndLinks from "./actions/RedrawBackgroundAndLinks"; import deleteGrpWrapper from "./actions/DeleteGrpWrapper"; import { updateVarList } from "./actions/UpdateVarList"; import { selectViewVar } from "./actions/SelectViewVar"; import { QueryGenerator } from "./actions/GenerateQuery"; import { Model } from "rdf-shacl-commons"; export var MaxVarAction; (function (MaxVarAction) { MaxVarAction[MaxVarAction["INCREASE"] = 0] = "INCREASE"; MaxVarAction[MaxVarAction["DECREASE"] = 1] = "DECREASE"; MaxVarAction[MaxVarAction["RESET"] = 2] = "RESET"; })(MaxVarAction || (MaxVarAction = {})); /* The ActionStore is responsible of the statehandling. It is inspired by redux where Events are dispatched and then caught by the Eventlisteners. They then change the state and trigger the right actions in the UI */ class ActionStore { constructor(sparnatural, specProvider) { _ActionStore_instances.add(this); this.language = "en"; //default this.showVariableNames = true; //variable decides whether the variableNames (?Musee_1) or the label name (museum) is shown // when quiet, don't emit onQueryUpdated events // this is set when a query is loaded this.quiet = false; this.specProvider = specProvider; this.sparnatural = sparnatural; __classPrivateFieldGet(this, _ActionStore_instances, "m", _ActionStore_addCustomEventListners).call(this); } } _ActionStore_instances = new WeakSet(), _ActionStore_addCustomEventListners = function _ActionStore_addCustomEventListners() { this.sparnatural.html[0].addEventListener("generateQuery", (event) => { event.stopImmediatePropagation(); event.preventDefault(); // trigger query generation + re-enable submit button new QueryGenerator(this).generateQuery(); }); // executed by VariableSelection, Start-EndclassGroup & VariableSelector // called by click on "Eye" btn this.sparnatural.html[0].addEventListener("onSelectViewVar", (e) => { e.stopImmediatePropagation(); if (!("val" in e.detail && "selected" in e.detail)) throw Error("onSelectViewVar expects object of type {val:SelectedVal,selected:boolean}"); // add variable to selected variables selectViewVar(this, e.detail, e.target); // trigger query generation + re-enable submit button new QueryGenerator(this).generateQuery(); }); // Switch which toggles if the Start and Endvalues are shown as their Var name. e.g Country_1 this.sparnatural.html[0].addEventListener("toggleVarNames", (e) => { e.stopImmediatePropagation(); toggleVarNames(this.sparnatural, this.showVariableNames); this.showVariableNames ? (this.showVariableNames = false) : (this.showVariableNames = true); }); this.sparnatural.html[0].addEventListener("getSelectedVariables", (e) => { }); this.sparnatural.html[0].addEventListener("getMaxDepth", (e) => { e.stopImmediatePropagation(); var maxDepth = 1; this.sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePostOrder((grpWrapper) => { if (grpWrapper.depth > maxDepth) { maxDepth = grpWrapper.depth; } }); // return the index in callback e.detail(maxDepth); }); this.sparnatural.html[0].addEventListener("updateVarList", (e) => { e.stopImmediatePropagation(); updateVarList(this); }); this.sparnatural.html[0].addEventListener("getSparqlVar", (e) => { let payload = e.detail; if (!("type" in payload)) throw Error("getSparqlVar event requires an object of { type: string }"); e.stopImmediatePropagation(); let maxVariableIndexPerTypes = this.sparnatural.getMaxVariableIndexByTypes(); let currentTypeIndex = maxVariableIndexPerTypes.get(payload.type) || 0; // return the variable name in callback if (currentTypeIndex === 0) { // if first variable of this type don't add the index to have more readable variable names when there's only one of each type, // e.g ?Country instead of ?Country_1 payload.callback(`${Model.getSparqlVariableNameFromUri(payload.type)}`); } else { payload.callback(`${Model.getSparqlVariableNameFromUri(payload.type)}_${currentTypeIndex + 1}`); } }); this.sparnatural.html[0].addEventListener("getSelectedVarLength", (e) => { e.stopImmediatePropagation(); e.detail(this.sparnatural.variableSection.listVariables().length); }); this.sparnatural.html[0].addEventListener("resetVars", (e) => { e.stopImmediatePropagation(); this.sparnatural.variableSection.html.remove(); this.sparnatural.variableSection.render(); // not sure we should regenerate the query here new QueryGenerator(this).generateQuery(); }); this.sparnatural.html[0].addEventListener("changeSortOrder", (e) => { if (!Object.values(Order).includes(e.detail)) throw Error("changeSortOrder expects a payload of Order enum"); // this.order = e.detail; // trigger query generation + re-enable submit button new QueryGenerator(this).generateQuery(); }); this.sparnatural.html[0].addEventListener("updateVariablesOrder", (e) => { // update/reset variable names in the state // readVariablesFromUI(this); // trigger query generation + re-enable submit button new QueryGenerator(this).generateQuery(); }); this.sparnatural.html[0].addEventListener("updateVarName", (e) => { let payload = e.detail; if (!("state" in payload)) throw Error("updateVarName event requires an object of { state: { } }"); updateVarName(this, payload.state, payload.previousVarName); // trigger query generation + re-enable submit button new QueryGenerator(this).generateQuery(); }); this.sparnatural.html[0].addEventListener("updateAggr", (e) => { // trigger query generation + re-enable submit button new QueryGenerator(this).generateQuery(); }); this.sparnatural.html[0].addEventListener("redrawBackgroundAndLinks", (e) => { e.stopImmediatePropagation(); redrawBackgroundAndLinks(this.sparnatural); }); this.sparnatural.html[0].addEventListener("deleteGrpWrapper", (e) => { deleteGrpWrapper(this.sparnatural, e); }); }; export default ActionStore; //# sourceMappingURL=ActionStore.js.map