sparnatural
Version:
Visual client-side SPARQL query builder and knowledge graph exploration tool
132 lines • 6.36 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 _WidgetWrapper_instances, _WidgetWrapper_addSelectAllListener, _WidgetWrapper_initWidgetComponent, _WidgetWrapper_addWidgetHTML, _WidgetWrapper_getEndLabel, _WidgetWrapper_createWidgetComponent;
import { Config } from "../../../../../ontologies/SparnaturalConfig";
import { getSettings } from "../../../../../settings/defaultSettings";
import { I18n } from "../../../../../settings/I18n";
import { HTMLComponent } from "../../../../HtmlComponent";
import { WidgetFactory } from "./WidgetFactory";
/**
* creates the corresponding widget
**/
class WidgetWrapper extends HTMLComponent {
constructor(parentComponent, specProvider, startClassVal, objectPropVal, endClassVal) {
super("WidgetWrapper", parentComponent, null);
_WidgetWrapper_instances.add(this);
this.settings = getSettings();
this.add_or = true;
this.specProvider = specProvider;
this.startClassVal = startClassVal;
this.objectPropVal = objectPropVal;
this.endClassVal = endClassVal;
this.widgetType = this.specProvider.getProperty(this.objectPropVal.type).getPropertyType(this.endClassVal.type);
}
render() {
super.render();
if (!this.widgetComponent) {
__classPrivateFieldGet(this, _WidgetWrapper_instances, "m", _WidgetWrapper_initWidgetComponent).call(this);
}
// always re-render the few labels before widget that can change depending if a value has already been selected or not
$(this.html).find("#selectAllWrapper").remove();
__classPrivateFieldGet(this, _WidgetWrapper_instances, "m", _WidgetWrapper_addWidgetHTML).call(this, this.widgetType);
// if there is already a widget component rendered, then only render it since we would like to keep the state
if (this.widgetComponent) {
// could still be null in case of non selectable property
this.widgetComponent.render();
}
__classPrivateFieldGet(this, _WidgetWrapper_instances, "m", _WidgetWrapper_addSelectAllListener).call(this);
return this;
}
getWidgetType() {
return this.widgetType;
}
}
_WidgetWrapper_instances = new WeakSet(), _WidgetWrapper_addSelectAllListener = function _WidgetWrapper_addSelectAllListener() {
$(this.html)
.find(".selectAll")
.first()
.on("click", () => {
this.html[0].dispatchEvent(new CustomEvent("selectAll", { bubbles: true }));
});
}, _WidgetWrapper_initWidgetComponent = function _WidgetWrapper_initWidgetComponent() {
// if non selectable, simply exit
if (this.widgetType == Config.NON_SELECTABLE_PROPERTY) {
this.html[0].dispatchEvent(new CustomEvent("redrawBackgroundAndLinks", { bubbles: true }));
return this;
}
this.widgetComponent = __classPrivateFieldGet(this, _WidgetWrapper_instances, "m", _WidgetWrapper_createWidgetComponent).call(this, this.widgetType);
}, _WidgetWrapper_addWidgetHTML = function _WidgetWrapper_addWidgetHTML(widgetType) {
var parenthesisLabel = " (" + this.specProvider.getEntity(this.endClassVal.type).getLabel() + ") ";
if (this.widgetType == Config.BOOLEAN_PROPERTY) {
parenthesisLabel = " ";
}
let lineSpan = `<span class="edit-trait first">
<span class="edit-trait-top"></span>
<span class="edit-num">
1
</span>
</span>`;
let selectAnySpan = `<span class="selectAll" id="selectAll">
<span class="underline">
${I18n.labels.SelectAllValues}
</span>
${parenthesisLabel}
</span>`;
let orSpan = `<span class="or">
${I18n.labels.Or}
</span> `;
let endLabel = __classPrivateFieldGet(this, _WidgetWrapper_instances, "m", _WidgetWrapper_getEndLabel).call(this, this.widgetType);
let endLabelSpan = `<span>
${endLabel}
</span>
`;
let htmlString = '';
widgetType == Config.NON_SELECTABLE_PROPERTY
? (htmlString = lineSpan + selectAnySpan)
// if there is a value, do not propose the "Any" selection option
// : (this.widgetComponent.getWidgetValues().length > 0)
: (this.parentComponent.parentComponent.parentComponent.endClassWidgetGroup.getWidgetValues().length > 0)
? (htmlString = lineSpan + endLabelSpan)
: (htmlString = lineSpan + selectAnySpan + orSpan + endLabelSpan);
this.widgetHtml = $(`<span id="selectAllWrapper">${htmlString}</span>`);
this.html.append(this.widgetHtml);
}, _WidgetWrapper_getEndLabel = function _WidgetWrapper_getEndLabel(widgetType) {
if (widgetType == Config.SEARCH_PROPERTY ||
widgetType == Config.STRING_EQUALS_PROPERTY ||
widgetType == Config.GRAPHDB_SEARCH_PROPERTY ||
widgetType == Config.VIRTUOSO_SEARCH_PROPERTY ||
widgetType == Config.TREE_PROPERTY) {
// label of the "Search" pseudo-class is inserted alone in this case
return this.specProvider.getEntity(this.endClassVal.type).getLabel();
}
else if (widgetType == Config.LIST_PROPERTY ||
widgetType == Config.TIME_PROPERTY_DATE ||
widgetType == Config.TIME_PROPERTY_YEAR) {
return I18n.labels.Select + " :";
}
else if (widgetType == Config.BOOLEAN_PROPERTY) {
return "";
}
else if (widgetType == Config.NUMBER_PROPERTY) {
return I18n.labels.Range + " :";
}
else {
return I18n.labels.Find + " :";
}
}, _WidgetWrapper_createWidgetComponent = function _WidgetWrapper_createWidgetComponent(widgetType) {
let factory = new WidgetFactory(
// parent component
this,
// spec provider
this.specProvider,
// factory settings
this.settings,
// catalog
this.getRootComponent().catalog);
return factory.buildWidget(this.startClassVal, this.objectPropVal, this.endClassVal);
};
export default WidgetWrapper;
//# sourceMappingURL=WidgetWrapper.js.map