sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
107 lines • 5.78 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 _OptionsGroup_instances, _OptionsGroup_checkIfoptionalArrowisRenderable, _OptionsGroup_renderOptionalComponents, _OptionsGroup_addOptionsPossible, _OptionsGroup_checkIfOptionsPossible, _OptionsGroup_removeOptionalComponents, _OptionsGroup_renderOptionsGroupoptionalArrow;
import { OptionalArrow } from "../../../../buttons/OptionalArrow";
import { HTMLComponent } from "../../../../HtmlComponent";
import NotExistsComponent from "./optioncomponents/NotExistsComponent";
import OptionalComponent from "./optioncomponents/OptionalComponent";
/**
* Name corresponds to the CSS class set on the CriteriaGroup and the linkWhereBottom
* See TriggerOption.switchState()
*/
export var OptionTypes;
(function (OptionTypes) {
OptionTypes["OPTIONAL"] = "optionalEnabled";
OptionTypes["NOTEXISTS"] = "notExistsEnabled";
OptionTypes["SERVICE"] = "serviceEnabled";
OptionTypes["NONE"] = "noOption";
})(OptionTypes || (OptionTypes = {}));
/**
* Contains the components for Optional and not exists arrow.
* Components can be triggered when:
* 1. None of the parents rows (list elements) has it already chosen
**/
export class OptionsGroup extends HTMLComponent {
constructor(ParentCriteriaGroup, specProvider) {
super("OptionsGroup", ParentCriteriaGroup, null);
_OptionsGroup_instances.add(this);
this.specProvider = specProvider;
this.ParentCriteriaGroup = ParentCriteriaGroup;
this.OptionalComponent = new OptionalComponent(this);
this.NotExistsComponent = new NotExistsComponent(this);
}
render() {
super.render();
return this;
}
// called by ParentCriteriaGroup
onObjectPropertyGroupSelected(optionState) {
__classPrivateFieldGet(this, _OptionsGroup_instances, "m", _OptionsGroup_checkIfoptionalArrowisRenderable).call(this, optionState);
}
// the selected arrow needs to have css class .Enabled (green dark)
setNewState(newState) {
if (newState == OptionTypes.NONE) {
this.NotExistsComponent.unselect();
this.OptionalComponent.unselect();
}
if (newState == OptionTypes.NOTEXISTS) {
this.NotExistsComponent.select();
this.OptionalComponent.unselect();
}
if (newState == OptionTypes.OPTIONAL) {
this.NotExistsComponent.unselect();
this.OptionalComponent.select();
}
}
enable() {
if (this.optionalArrow?.html) {
this.optionalArrow.render();
}
}
disable() {
if (this.optionalArrow?.html) {
this.optionalArrow.html[0].classList.add('disabledbutton');
this.OptionalComponent.html.remove();
this.NotExistsComponent.html.remove();
}
}
}
_OptionsGroup_instances = new WeakSet(), _OptionsGroup_checkIfoptionalArrowisRenderable = function _OptionsGroup_checkIfoptionalArrowisRenderable(optionState) {
if (__classPrivateFieldGet(this, _OptionsGroup_instances, "m", _OptionsGroup_checkIfOptionsPossible).call(this)
&&
!this.optionalArrow
&&
optionState == OptionTypes.NONE) {
//Options like NOTEXISTS are possible and none of the parent has it already activated
__classPrivateFieldGet(this, _OptionsGroup_instances, "m", _OptionsGroup_addOptionsPossible).call(this);
}
}, _OptionsGroup_renderOptionalComponents = function _OptionsGroup_renderOptionalComponents() {
// MUST BE WRAPPED INTO LIST DIV
if (this.specProvider.getProperty(this.ParentCriteriaGroup.objectPropertyGroup.objectPropVal.type).isEnablingOptional()) {
this.OptionalComponent.render();
}
if (this.specProvider.getProperty(this.ParentCriteriaGroup.objectPropertyGroup.objectPropVal.type).isEnablingNegation()) {
this.NotExistsComponent.render();
}
this.html[0].dispatchEvent(new CustomEvent("redrawBackgroundAndLinks", { bubbles: true }));
}, _OptionsGroup_addOptionsPossible = function _OptionsGroup_addOptionsPossible() {
__classPrivateFieldGet(this, _OptionsGroup_instances, "m", _OptionsGroup_renderOptionsGroupoptionalArrow).call(this);
}, _OptionsGroup_checkIfOptionsPossible = function _OptionsGroup_checkIfOptionsPossible() {
return (this.specProvider.getProperty(this.ParentCriteriaGroup.objectPropertyGroup.objectPropVal.type).isEnablingOptional()
||
this.specProvider.getProperty(this.ParentCriteriaGroup.objectPropertyGroup.objectPropVal.type).isEnablingNegation());
}, _OptionsGroup_removeOptionalComponents = function _OptionsGroup_removeOptionalComponents() {
this.OptionalComponent.html.remove();
this.NotExistsComponent.html.remove();
this.html[0].dispatchEvent(new CustomEvent("redrawBackgroundAndLinks", { bubbles: true }));
}, _OptionsGroup_renderOptionsGroupoptionalArrow = function _OptionsGroup_renderOptionsGroupoptionalArrow() {
this.optionalArrow = new OptionalArrow(this, (selected) => {
selected
? __classPrivateFieldGet(this, _OptionsGroup_instances, "m", _OptionsGroup_renderOptionalComponents).call(this)
: __classPrivateFieldGet(this, _OptionsGroup_instances, "m", _OptionsGroup_removeOptionalComponents).call(this);
}).render();
};
//# sourceMappingURL=OptionsGroup.js.map