sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
141 lines • 9.04 kB
JavaScript
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 _CriteriaGroup_instances, _CriteriaGroup_renderChildComponents, _CriteriaGroup_assembleComponents, _CriteriaGroup_isSelectedVal;
import { UnselectBtn } from "../../../buttons/UnselectBtn";
import ObjectPropertyGroup from "./objectpropertygroup/ObjectPropertyGroup";
import EndClassGroup from "./startendclassgroup/EndClassGroup";
import StartClassGroup from "./startendclassgroup/StartClassGroup";
import { OptionsGroup, OptionTypes } from "./optionsgroup/OptionsGroup";
import { HTMLComponent } from "../../../HtmlComponent";
import { EndClassWidgetGroup } from "./startendclassgroup/EndClassWidgetGroup";
import ActionsGroup from "../../../buttons/actions/ActionsGroup";
import { I18n } from "../../../../settings/I18n";
class CriteriaGroup extends HTMLComponent {
constructor(parentComponent, specProvider, startClassVal, startClassEyeBtn) {
super("CriteriaGroup", parentComponent, null);
_CriteriaGroup_instances.add(this);
_CriteriaGroup_assembleComponents.set(this, () => {
// 1. User selects StartClassVal
this.html[0].addEventListener("StartClassGroupSelected", (e) => {
e.stopImmediatePropagation();
if (!__classPrivateFieldGet(this, _CriteriaGroup_instances, "m", _CriteriaGroup_isSelectedVal).call(this, e.detail))
throw Error("StartClassGroupSelected expects object of type SelectedVal");
this.objectPropertyGroup.onStartClassGroupSelected(e.detail);
this.endClassGroup.onStartClassGroupSelected(e.detail);
});
// 2. User Selects EndClassVal
this.html[0].addEventListener("EndClassGroupSelected", (e) => {
e.stopImmediatePropagation();
if (!__classPrivateFieldGet(this, _CriteriaGroup_instances, "m", _CriteriaGroup_isSelectedVal).call(this, e.detail))
throw Error("EndClassGroupSelected expects object of type SelectedVal");
this.objectPropertyGroup.onEndClassGroupSelected(e.detail);
});
// 3. Automatically selected or User selects ObjectPropertyGrpVal
this.html[0].addEventListener("onObjectPropertyGroupSelected", (e) => {
e.stopImmediatePropagation();
if (!__classPrivateFieldGet(this, _CriteriaGroup_instances, "m", _CriteriaGroup_isSelectedVal).call(this, e.detail))
throw Error("onObjectPropertyGroupSelected expects object of type SelectedVal");
// if there is already a where connection or widget values selected, don't change anything
if (!this.parentGroupWrapper.whereChild &&
this.endClassWidgetGroup?.widgetValues?.length === 0) {
this.endClassGroup.onObjectPropertyGroupSelected(e.detail);
this.endClassWidgetGroup.render();
}
this.optionsGroup.onObjectPropertyGroupSelected(this.parentGroupWrapper.currentOptionState);
// if there is no AND sibling, enable the AND action again
if (!this.parentGroupWrapper.andSibling) {
this.parentGroupWrapper.enableActionAnd();
}
// if property has a sparqlService, switch the state
if (this.specProvider.getProperty(e.detail.type).getServiceEndpoint()) {
this.parentGroupWrapper.triggerOption(OptionTypes.SERVICE);
}
else {
this.parentGroupWrapper.triggerOption(this.parentGroupWrapper.currentOptionState);
}
});
// gets called by the widget.
this.html[0].addEventListener("renderWidgetVal", (e) => {
e.stopImmediatePropagation();
if (e.detail == "" || !e.detail)
throw Error('No widgetValue received. Widget Value needs to be provided for "renderWidgetVal"');
if (Array.isArray(e.detail)) {
// if there is an array with values provided, render all of them
e.detail.forEach((v) => this.endClassWidgetGroup.renderWidgetVal(v));
}
else {
this.endClassWidgetGroup.renderWidgetVal(e.detail);
}
});
// gets called by the widget.
this.html[0].addEventListener("selectAll", (e) => {
e.stopImmediatePropagation();
this.endClassWidgetGroup.setSelectAll();
});
// when inputgot selected then we remove the where btn and EditComponents
this.html[0].addEventListener("removeEditComponents", (e) => {
e.stopImmediatePropagation();
this.endClassGroup.editComponents?.html?.empty()?.remove();
});
// gets called when a user removes a previously selected widgetValue
this.html[0].addEventListener("updateWidgetList", (e) => {
if (!("unselectedVal" in e.detail))
throw Error("updateWidgetList expects an object of type EndClassWidgetValue");
e.stopImmediatePropagation();
this.html[0].dispatchEvent(new CustomEvent("generateQuery", { bubbles: true }));
});
// gets called when the user adds widgetvalues or removes widgetvalues
this.html[0].addEventListener("renderWidgetWrapper", (e) => {
if (!("selectedValues" in e.detail) && e.detail.selectedValues.isArray)
throw Error("renderWidgetWrapper expects list of selected values.");
e.stopImmediatePropagation();
// removeEditComponents: if add btn got clicked mutiple times or the old widgetwrapper is still rendered while the last selectedvalue got deleted
this.html[0].dispatchEvent(new CustomEvent("removeEditComponents"));
if (e.detail.selectedValues.length === 0 &&
// if we are not in the case that we edit the last value in the list
// note : editedValue contains the value being edited - it could be passed again to the widget, maybe, instead
// of keeping the state in the widget
!e.detail.editedValue) {
// Render WidgetsWrapper and ActionWhere
this.endClassGroup.editComponents.render();
this.html[0].dispatchEvent(new CustomEvent("onGrpInputNotCompleted", { bubbles: true }));
}
else {
//we only need widgetswrapper
this.endClassGroup.editComponents.renderWidgetsWrapper();
}
});
});
this.specProvider = specProvider;
this.parentGroupWrapper = parentComponent;
this.startClassGroup = new StartClassGroup(this, this.specProvider, I18n.labels.StartClassTemporaryLabel, startClassVal,
// Decides if the selectviewvarBtn is rendered on the startClass. That is the case only for the first one
startClassEyeBtn);
}
render() {
super.render();
__classPrivateFieldGet(this, _CriteriaGroup_instances, "m", _CriteriaGroup_renderChildComponents).call(this);
this.unselectBtn = new UnselectBtn(this, () => {
// caught in Parentcomponent
this.html[0].dispatchEvent(new CustomEvent("onRemoveGrp", { bubbles: true }));
}).render();
return this;
}
}
_CriteriaGroup_assembleComponents = new WeakMap(), _CriteriaGroup_instances = new WeakSet(), _CriteriaGroup_renderChildComponents = function _CriteriaGroup_renderChildComponents() {
// create all the elements of the criteria
this.startClassGroup.render();
this.optionsGroup = new OptionsGroup(this, this.specProvider).render();
this.objectPropertyGroup = new ObjectPropertyGroup(this, this.specProvider, I18n.labels.ObjectPropertyTemporaryLabel).render();
this.endClassGroup = new EndClassGroup(this, this.specProvider).render();
this.endClassWidgetGroup = new EndClassWidgetGroup(this, this.specProvider);
this.actionsGroup = new ActionsGroup(this, this.specProvider).render();
__classPrivateFieldGet(this, _CriteriaGroup_assembleComponents, "f").call(this);
}, _CriteriaGroup_isSelectedVal = function _CriteriaGroup_isSelectedVal(payload) {
return "type" in payload && "variable" in payload;
};
export default CriteriaGroup;
//# sourceMappingURL=CriteriaGroup.js.map