From 7d3c7ff386d8029700cb12962e93da6f881778ea Mon Sep 17 00:00:00 2001 From: Thomas Francart Date: Sun, 1 Dec 2024 12:29:18 +0100 Subject: [PATCH] Fix #687 --- .../components/FormFieldGenerator.ts | 8 ---- src/sparnatural/components/HtmlComponent.ts | 10 ++--- .../builder-section/ComponentsList.ts | 2 +- .../groupwrapper/GroupWrapper.ts | 4 +- .../criteriagroup/CriteriaGroup.ts | 11 ++--- .../edit-components/EditComponents.ts | 1 + .../edit-components/WidgetWrapper.ts | 9 +++-- .../ObjectPropertyTypeId.ts | 4 +- .../startendclassgroup/ClassTypeId.ts | 20 +++++----- .../startendclassgroup/EndClassGroup.ts | 2 +- .../startendclassgroup/EndClassWidgetGroup.ts | 11 ++++- .../HierarchicalClassSelectBuilder.ts | 8 ++-- .../startendclassgroup/StartClassGroup.ts | 2 +- .../events/AddAndComponent.ts | 2 +- .../buttons/VariableOptionsSelectBtn.ts | 2 +- .../variableorder/DraggableComponent.ts | 10 ++--- .../variableorder/VariableOrderMenu.ts | 2 +- .../variablesort/VariableSortOptions.ts | 2 +- .../components/widgets/AbstractWidget.ts | 40 ++----------------- .../components/widgets/AutoCompleteWidget.ts | 3 +- .../components/widgets/BooleanWidget.ts | 6 +-- .../components/widgets/DatesWidget.ts | 2 +- .../components/widgets/ListWidget.ts | 3 +- .../components/widgets/MapWidget.ts | 11 ++--- .../components/widgets/NumberWidget.ts | 4 +- .../components/widgets/SearchRegexWidget.ts | 3 +- .../TimeDatePickerWidget.ts | 4 +- .../widgets/treewidget/TreeWidget.ts | 1 - src/sparnatural/generators/json/ISparJson.ts | 1 + .../json/SparnaturalJsonGenerator.ts | 6 ++- .../generators/sparql/WhereBuilder.ts | 24 ++++++----- .../sparql/fromjson/JsonSparqlTranslator.ts | 3 +- .../querypreloading/QueryLoader.ts | 2 +- .../shacl/SHACLSpecificationEntity.ts | 3 +- .../statehandling/actions/DeleteGrpWrapper.ts | 2 +- .../statehandling/actions/GenerateQuery.ts | 3 +- 36 files changed, 98 insertions(+), 133 deletions(-) diff --git a/src/sparnatural-form/components/FormFieldGenerator.ts b/src/sparnatural-form/components/FormFieldGenerator.ts index 89af3b5e..14b6083a 100644 --- a/src/sparnatural-form/components/FormFieldGenerator.ts +++ b/src/sparnatural-form/components/FormFieldGenerator.ts @@ -141,14 +141,6 @@ class FormField { const removeBtn = new UnselectBtn(widget, () => { selectedValues.delete(val); - widget.onRemoveValue( - widget - .getWidgetValues() - .find( - (w: { value: { label: string } }) => w.value.label === val.label - ) - ); - console.log("widget.getWidgetValues()", widget.getWidgetValues()); console.log(selectedValues); updateValueDisplay(); queryLine.values = Array.from(selectedValues); diff --git a/src/sparnatural/components/HtmlComponent.ts b/src/sparnatural/components/HtmlComponent.ts index 156d671f..aec9f3f4 100644 --- a/src/sparnatural/components/HtmlComponent.ts +++ b/src/sparnatural/components/HtmlComponent.ts @@ -7,7 +7,7 @@ class HTMLComponent implements IRenderable { baseCssClass: string; static BaseClassFactory = new BaseClassFactory(); - ParentComponent: HTMLComponent; + parentComponent: HTMLComponent; widgetHtml: JQuery; html: JQuery; // TODO this is only temporarly. Some components (ActionWhere) don't need to be attached on there parentcomponent but somewhere else @@ -19,7 +19,7 @@ class HTMLComponent implements IRenderable { widgetHtml: JQuery ) { this.baseCssClass = baseCssClass; - this.ParentComponent = ParentComponent; + this.parentComponent = ParentComponent; // create the HTML element this.html = HTMLComponent.BaseClassFactory.getBaseClass(this.baseCssClass); @@ -32,7 +32,7 @@ class HTMLComponent implements IRenderable { if (this.htmlParent) { this.htmlParent.append(this.html); } else { - $(this.html).appendTo(this.ParentComponent.html); + $(this.html).appendTo(this.parentComponent.html); } } @@ -65,10 +65,10 @@ class HTMLComponent implements IRenderable { * @returns moves up the component hierarchy and returns the one that does not have a parent component */ getRootComponent():HTMLComponent { - if(this.ParentComponent == null) { + if(this.parentComponent == null) { return this; } else { - return this.ParentComponent.getRootComponent(); + return this.parentComponent.getRootComponent(); } } diff --git a/src/sparnatural/components/builder-section/ComponentsList.ts b/src/sparnatural/components/builder-section/ComponentsList.ts index 42f9200e..33abe008 100644 --- a/src/sparnatural/components/builder-section/ComponentsList.ts +++ b/src/sparnatural/components/builder-section/ComponentsList.ts @@ -42,7 +42,7 @@ class ComponentsList extends HTMLComponent { attachNewRoot(grpWrapper: GroupWrapper) { this.rootGroupWrapper = grpWrapper; // this should already be the case, but we are just making sure it is - this.rootGroupWrapper.ParentComponent = this; + this.rootGroupWrapper.parentComponent = this; // display its eye and selects it // TODO : this should be done only if previous StartClassGroup was itself selected diff --git a/src/sparnatural/components/builder-section/groupwrapper/GroupWrapper.ts b/src/sparnatural/components/builder-section/groupwrapper/GroupWrapper.ts index df95569a..8453c9e3 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/GroupWrapper.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/GroupWrapper.ts @@ -50,9 +50,9 @@ class GroupWrapper extends HTMLComponent { isRootGrpWrapper(): boolean{ return ( - (this.ParentComponent instanceof ComponentsList) + (this.parentComponent instanceof ComponentsList) && - ((this.ParentComponent as ComponentsList).rootGroupWrapper == this) + ((this.parentComponent as ComponentsList).rootGroupWrapper == this) ); } diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/CriteriaGroup.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/CriteriaGroup.ts index aca10ff6..09bad285 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/CriteriaGroup.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/CriteriaGroup.ts @@ -30,14 +30,14 @@ class CriteriaGroup extends HTMLComponent { unselectBtn: UnselectBtn; constructor( - ParentComponent: GroupWrapper, + parentComponent: GroupWrapper, specProvider: any, startClassVal?: SelectedVal, startClassEyeBtn?: boolean ) { - super("CriteriaGroup", ParentComponent, null); + super("CriteriaGroup", parentComponent, null); this.specProvider = specProvider; - this.ParentGroupWrapper = ParentComponent; + this.ParentGroupWrapper = parentComponent; this.StartClassGroup = new StartClassGroup( this, this.specProvider, @@ -168,10 +168,7 @@ class CriteriaGroup extends HTMLComponent { "updateWidgetList expects an object of type EndClassWidgetValue" ); e.stopImmediatePropagation(); - let removed = e.detail.unselectedVal as EndClassWidgetValue; - this.EndClassGroup.editComponents.widgetWrapper.widgetComponent?.onRemoveValue( - removed.widgetVal - ); + this.html[0].dispatchEvent( new CustomEvent("generateQuery", { bubbles: true }) ); diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/EditComponents.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/EditComponents.ts index 1d173ff0..1f796b55 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/EditComponents.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/EditComponents.ts @@ -42,6 +42,7 @@ class EditComponents extends HTMLComponent { widgetWrapper: WidgetWrapper; specProvider: ISparnaturalSpecification; RENDER_WHERE = RENDER_WHERE_ENUM; + constructor( parentComponent: EndClassGroup, startCassVal: SelectedVal, diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/WidgetWrapper.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/WidgetWrapper.ts index 1c750aed..973e299b 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/WidgetWrapper.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/edit-components/WidgetWrapper.ts @@ -7,6 +7,7 @@ import HTMLComponent from "../../../../HtmlComponent"; import { SelectedVal } from "../../../../SelectedVal"; import SparnaturalComponent from "../../../../SparnaturalComponent"; import { AbstractWidget } from "../../../../widgets/AbstractWidget"; +import CriteriaGroup from "../CriteriaGroup"; import EditComponents from "./EditComponents"; import { WidgetFactory } from "./WidgetFactory"; @@ -25,13 +26,13 @@ class WidgetWrapper extends HTMLComponent { add_or: boolean = true; constructor( - ParentComponent: HTMLComponent, + parentComponent: HTMLComponent, specProvider: ISparnaturalSpecification, startClassVal: SelectedVal, objectPropVal: SelectedVal, endClassVal: SelectedVal ) { - super("WidgetWrapper", ParentComponent, null); + super("WidgetWrapper", parentComponent, null); this.specProvider = specProvider; this.startClassVal = startClassVal; this.objectPropVal = objectPropVal; @@ -121,8 +122,10 @@ class WidgetWrapper extends HTMLComponent { 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.widgetComponent.getWidgetValues().length > 0) + : ((this.parentComponent.parentComponent.parentComponent as CriteriaGroup).endClassWidgetGroup.getWidgetValues().length > 0) ?(htmlString = lineSpan + endLabelSpan) :(htmlString = lineSpan + selectAnySpan + orSpan + endLabelSpan); diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/objectpropertygroup/ObjectPropertyTypeId.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/objectpropertygroup/ObjectPropertyTypeId.ts index 5193b1ca..b2f5f6de 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/objectpropertygroup/ObjectPropertyTypeId.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/objectpropertygroup/ObjectPropertyTypeId.ts @@ -33,7 +33,7 @@ class ObjectPropertyTypeId extends HTMLComponent { ) { super("ObjectPropertyTypeId", ParentComponent, null); this.temporaryLabel = temporaryLabel; - this.GrandParent = ParentComponent.ParentComponent as CriteriaGroup; + this.GrandParent = ParentComponent.parentComponent as CriteriaGroup; this.specProvider = specProvider; this.startClassVal = startClassVal; } @@ -232,7 +232,7 @@ class PropertySelectBuilder extends HTMLComponent { initDagWidget(items:DagIfc, default_value: DagWidgetDefaultValue) { let jsonDag = this.convertToJsonDag(items.roots) ; - this.selectWidget = new HierarchicalClassSelectBuilder(this.ParentComponent, this.specProvider, jsonDag, default_value ); + this.selectWidget = new HierarchicalClassSelectBuilder(this.parentComponent, this.specProvider, jsonDag, default_value ); return this.selectWidget.buildClassSelectFromJson() ; ; } diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/ClassTypeId.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/ClassTypeId.ts index 86a777f3..8272ccc2 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/ClassTypeId.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/ClassTypeId.ts @@ -16,7 +16,7 @@ import ISpecificationEntry from "../../../../../spec-providers/ISpecificationEnt * The DOMAIN selection happens only for the very first line/criteria. **/ class ClassTypeId extends HTMLComponent { - ParentComponent: EndClassGroup | StartClassGroup; + parentComponent: EndClassGroup | StartClassGroup; id: string; frontArrow: ArrowComponent = new ArrowComponent( this, @@ -65,7 +65,7 @@ class ClassTypeId extends HTMLComponent { // no back arrow on start class - if (!isStartClassGroup(this.ParentComponent)) { + if (!isStartClassGroup(this.parentComponent)) { this.backArrow.render(); } @@ -74,7 +74,7 @@ class ClassTypeId extends HTMLComponent { currentWrapper.append(this.htmlCurentValue) ; this.html.append(currentWrapper); - if (isStartClassGroup(this.ParentComponent)) { + if (isStartClassGroup(this.parentComponent)) { if(!this.startClassVal?.type) { // If this Component is a child of the StartClassGroup component in the first row with no value selected this.widgetHtml = this.selectBuilder.buildSelect_FirstStartClassGroup(); @@ -171,12 +171,12 @@ class ClassTypeId extends HTMLComponent { ? this.html.addClass("VariableSelected") : this.html.removeClass("VariableSelected"); - if (isEndClassGroup(this.ParentComponent)) - this.#onSelectViewVar(this.ParentComponent.endClassVal,selected) + if (isEndClassGroup(this.parentComponent)) + this.#onSelectViewVar(this.parentComponent.endClassVal,selected) // The first StartClass gets an eye Btn to de/select - if(isStartClassGroup(this.ParentComponent) && this.ParentComponent.renderEyeBtn) - this.#onSelectViewVar(this.ParentComponent.startClassVal,selected) + if(isStartClassGroup(this.parentComponent) && this.parentComponent.renderEyeBtn) + this.#onSelectViewVar(this.parentComponent.startClassVal,selected) }; @@ -202,14 +202,14 @@ class ClassTypeId extends HTMLComponent { showTypeName(){ const currentSpan = this.htmlCurentValue.first()[0].getElementsByClassName('label').item(0) //display label - currentSpan.textContent = this.specProvider.getEntity(this.ParentComponent.getTypeSelected()).getLabel(); + currentSpan.textContent = this.specProvider.getEntity(this.parentComponent.getTypeSelected()).getLabel(); } // renders the variable name showVarName(){ const currentSpan = this.htmlCurentValue.first()[0].getElementsByClassName('label').item(0) // display variable - currentSpan.textContent = this.ParentComponent.getVarName(); + currentSpan.textContent = this.parentComponent.getVarName(); } } @@ -332,7 +332,7 @@ class ClassSelectBuilder extends HTMLComponent { initDagWidget(items:DagIfc, default_value: DagWidgetDefaultValue) { let jsonDag = this.convertToJsonDag(items.roots) ; - this.selectWidget = new HierarchicalClassSelectBuilder(this.ParentComponent, this.specProvider, jsonDag, default_value ); + this.selectWidget = new HierarchicalClassSelectBuilder(this.parentComponent, this.specProvider, jsonDag, default_value ); return this.selectWidget.buildClassSelectFromJson() ; ; } diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassGroup.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassGroup.ts index 8141d6e7..ec391df1 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassGroup.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassGroup.ts @@ -33,7 +33,7 @@ class EndClassGroup extends HTMLComponent { constructor(ParentCriteriaGroup: CriteriaGroup, specProvider: ISparnaturalSpecification) { super("EndClassGroup", ParentCriteriaGroup, null); this.specProvider = specProvider; - this.ParentCriteriaGroup = this.ParentComponent as CriteriaGroup; + this.ParentCriteriaGroup = this.parentComponent as CriteriaGroup; // this.endClassWidgetGroup = new EndClassWidgetGroup(this, this.specProvider); } diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassWidgetGroup.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassWidgetGroup.ts index 33d15366..3292ac07 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassWidgetGroup.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/EndClassWidgetGroup.ts @@ -137,7 +137,7 @@ export class EndClassWidgetGroup extends HTMLComponent { ) return; - // if not, then create the EndclassWidgetValue and add it to the list + // if not, then create the EndclassWidgetValue and add it to the list this.#renderEndClassWidgetVal(selectedVal); } @@ -149,7 +149,7 @@ export class EndClassWidgetGroup extends HTMLComponent { // if the widget allows multiple values to be selected then AddWidgetValueBtn // undefined for NON_SELECTABLE_PROPERTY - const widgetComp:AbstractWidget | undefined = (this.ParentComponent as CriteriaGroup).EndClassGroup.getWidgetComponent() + const widgetComp:AbstractWidget | undefined = (this.parentComponent as CriteriaGroup).EndClassGroup.getWidgetComponent() if(widgetComp && widgetComp.valueRepetition == ValueRepetition.MULTIPLE && !(widgetVal instanceof SelectAllValue) ) { // now (re)render the addMoreValuesButton this.addWidgetValueBtn?.html @@ -203,6 +203,13 @@ export class EndClassWidgetGroup extends HTMLComponent { }); return vals; } + + /** + * @returns true if the widget value is the "Any" value + */ + hasAnyValue():boolean { + return this.getWidgetValues().some((v) => (v instanceof SelectAllValue)) + } } export class EndClassWidgetValue extends HTMLComponent { diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/HierarchicalClassSelectBuilder.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/HierarchicalClassSelectBuilder.ts index b1287ef4..f8a93058 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/HierarchicalClassSelectBuilder.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/HierarchicalClassSelectBuilder.ts @@ -469,10 +469,10 @@ export class HierarchicalClassSelectBuilder extends HTMLComponent { displayClassSelector() { this.htmlSelectUiUx.addClass('open') ; - this.ParentComponent.html[0].classList.add('focus') ; + this.parentComponent.html[0].classList.add('focus') ; } hideClassSelector() { - this.ParentComponent.html[0].classList.remove('focus') ; + this.parentComponent.html[0].classList.remove('focus') ; this.htmlSelectUiUx.removeClass('open') ; } setValue(selectedValue:string) { @@ -537,11 +537,11 @@ export class HierarchicalClassSelectBuilder extends HTMLComponent { if (this.isFlatHierarchy()) { this.htmlSelectUiUx[0].classList.add('isFlat') ; - this.ParentComponent.html[0].classList.add('selectorIsFlat') ; + this.parentComponent.html[0].classList.add('selectorIsFlat') ; } if (this.hasIcon) { this.htmlSelectUiUx[0].classList.add('hasIcon') ; - this.ParentComponent.html[0].classList.add('selectorHasIcon') ; + this.parentComponent.html[0].classList.add('selectorHasIcon') ; } diff --git a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/StartClassGroup.ts b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/StartClassGroup.ts index 6f4e9a48..36f41b40 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/StartClassGroup.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/criteriagroup/startendclassgroup/StartClassGroup.ts @@ -34,7 +34,7 @@ class StartClassGroup extends HTMLComponent { this.temporaryLabel = temporaryLabel; this.inputSelector = new ClassTypeId(this, this.specProvider, this.temporaryLabel, startClassVal); - this.ParentCriteriaGroup = this.ParentComponent as CriteriaGroup; + this.ParentCriteriaGroup = this.parentComponent as CriteriaGroup; this.startClassVal = startClassVal ? startClassVal : { diff --git a/src/sparnatural/components/builder-section/groupwrapper/groupwrapperevents/events/AddAndComponent.ts b/src/sparnatural/components/builder-section/groupwrapper/groupwrapperevents/events/AddAndComponent.ts index 92b57259..65a97bad 100644 --- a/src/sparnatural/components/builder-section/groupwrapper/groupwrapperevents/events/AddAndComponent.ts +++ b/src/sparnatural/components/builder-section/groupwrapper/groupwrapperevents/events/AddAndComponent.ts @@ -8,7 +8,7 @@ export function addAndComponent( startClassVal: SelectedVal ) { grpWrapper.andSibling = new GroupWrapper( - grpWrapper.ParentComponent, + grpWrapper.parentComponent, grpWrapper.specProvider, // same depth grpWrapper.depth, diff --git a/src/sparnatural/components/buttons/VariableOptionsSelectBtn.ts b/src/sparnatural/components/buttons/VariableOptionsSelectBtn.ts index 56e84eae..9b9628ff 100644 --- a/src/sparnatural/components/buttons/VariableOptionsSelectBtn.ts +++ b/src/sparnatural/components/buttons/VariableOptionsSelectBtn.ts @@ -38,7 +38,7 @@ class VariableOptionsSelectBtn extends HTMLComponent { } render(): this { - this.htmlParent = this.ParentComponent.htmlParent; + this.htmlParent = this.parentComponent.htmlParent; super.render(); return this; } diff --git a/src/sparnatural/components/variables-section/variableorder/DraggableComponent.ts b/src/sparnatural/components/variables-section/variableorder/DraggableComponent.ts index f59dc8da..05210440 100644 --- a/src/sparnatural/components/variables-section/variableorder/DraggableComponent.ts +++ b/src/sparnatural/components/variables-section/variableorder/DraggableComponent.ts @@ -17,7 +17,7 @@ export class DraggableComponent extends HTMLComponent { aggrComponentInput: JQuery; aggrComponentBadgeValue: JQuery; aggrComponentOptionsExtend: JQuery; - ParentComponent: VariableOrderMenu; + parentComponent: VariableOrderMenu; state: DraggableComponentState; @@ -146,7 +146,7 @@ export class DraggableComponent extends HTMLComponent { } render(): this { - this.htmlParent = $(this.ParentComponent.html).find( + this.htmlParent = $(this.parentComponent.html).find( ".variablesOtherSelect" ); super.render(); @@ -240,7 +240,7 @@ export class DraggableComponent extends HTMLComponent { if(this.aggrComponentOptions[0].style.display == 'block') { return this.closeAggrOptions() ; } - if(this.ParentComponent.aggrOptionsExtend) { + if(this.parentComponent.aggrOptionsExtend) { this.aggrComponentOptions[0].classList.remove('reducted'); this.aggrComponentOptions[0].classList.add('extended'); } else { @@ -253,11 +253,11 @@ export class DraggableComponent extends HTMLComponent { if(this.aggrComponentOptions[0].classList.contains('reducted')) { this.aggrComponentOptions[0].classList.remove('reducted'); this.aggrComponentOptions[0].classList.add('extended'); - this.ParentComponent.aggrOptionsExtend = true; + this.parentComponent.aggrOptionsExtend = true; } else { this.aggrComponentOptions[0].classList.add('reducted'); this.aggrComponentOptions[0].classList.remove('extended'); - this.ParentComponent.aggrOptionsExtend = false; + this.parentComponent.aggrOptionsExtend = false; } } onpenAggrOptions() { diff --git a/src/sparnatural/components/variables-section/variableorder/VariableOrderMenu.ts b/src/sparnatural/components/variables-section/variableorder/VariableOrderMenu.ts index 2f46b177..54df64e2 100644 --- a/src/sparnatural/components/variables-section/variableorder/VariableOrderMenu.ts +++ b/src/sparnatural/components/variables-section/variableorder/VariableOrderMenu.ts @@ -16,7 +16,7 @@ class VariableOrderMenu extends HTMLComponent { } render(): this { - this.htmlParent = $(this.ParentComponent.html).find(".line2"); + this.htmlParent = $(this.parentComponent.html).find(".line2"); super.render(); let otherSelectHtml = $('
'); this.html.append(otherSelectHtml); diff --git a/src/sparnatural/components/variables-section/variablesort/VariableSortOptions.ts b/src/sparnatural/components/variables-section/variablesort/VariableSortOptions.ts index bc1d1db5..93c885b9 100644 --- a/src/sparnatural/components/variables-section/variablesort/VariableSortOptions.ts +++ b/src/sparnatural/components/variables-section/variablesort/VariableSortOptions.ts @@ -21,7 +21,7 @@ class VariableSortOption extends HTMLComponent { } render(): this { - this.htmlParent = $(this.ParentComponent.html).find(".line1"); + this.htmlParent = $(this.parentComponent.html).find(".line1"); super.render(); this.ascendBtn = new AscendBtn(this, this.changeSortOrderCallBack).render(); this.descendBtn = new DescendBtn(this, this.changeSortOrderCallBack).render(); diff --git a/src/sparnatural/components/widgets/AbstractWidget.ts b/src/sparnatural/components/widgets/AbstractWidget.ts index 28936211..2597260f 100644 --- a/src/sparnatural/components/widgets/AbstractWidget.ts +++ b/src/sparnatural/components/widgets/AbstractWidget.ts @@ -70,7 +70,6 @@ export class RdfTermValue implements WidgetValue { export abstract class AbstractWidget extends HTMLComponent { public valueRepetition: ValueRepetition; - protected widgetValues: Array = []; startClassVal: SelectedVal; objectPropVal: SelectedVal; endClassVal: SelectedVal; @@ -104,48 +103,16 @@ export abstract class AbstractWidget extends HTMLComponent { // Is used to parse the inputs from the ISparnaturalJson e.g "preloaded" queries abstract parseInput(value: WidgetValue["value"]): WidgetValue; - addWidgetValue(widgetValue: WidgetValue) { - this.widgetValues.push(widgetValue); - } - - // returns null if valueObject has not been set before - getWidgetValues(): WidgetValue[] { - return this.widgetValues; - } - - // This method gets called when an selected value gets deleted again. - // For example: Germany and France are chosen from the list widget and now get deleted - onRemoveValue(val: WidgetValue) { - this.widgetValues = this.widgetValues.filter((v) => { - if (v === val) return false; - return true; - }); - } // fires the event to render the label of the WidgetValue on the UI - renderWidgetVal(widgetValue: WidgetValue) { - if (!this.widgetValues.find((v) => v.key() == widgetValue.key())) { - // don't add double values - // store value - this.widgetValues.push(widgetValue); - this.html[0].dispatchEvent( - new CustomEvent("renderWidgetVal", { - bubbles: true, - detail: widgetValue, - }) - ); - } - } - - renderWidgetValues(widgetValues: WidgetValue[]) { - widgetValues.forEach((v) => this.widgetValues.push(v)); + // can take either a single value or an array of values + triggerRenderWidgetVal(widgetValue: WidgetValue | WidgetValue[]) { this.html[0].dispatchEvent( new CustomEvent("renderWidgetVal", { bubbles: true, - detail: widgetValues, + detail: widgetValue, }) ); - console.log("problem here !"); } // Method to disable the widget @@ -175,6 +142,7 @@ export abstract class AbstractWidget extends HTMLComponent { element.removeAttribute("disabled"); }); } + // toggle spinner component when loading a datasource toggleSpinner(message?: string) { const elements = this.spinner.html[0].getElementsByClassName("load"); diff --git a/src/sparnatural/components/widgets/AutoCompleteWidget.ts b/src/sparnatural/components/widgets/AutoCompleteWidget.ts index e53639fd..605d384c 100644 --- a/src/sparnatural/components/widgets/AutoCompleteWidget.ts +++ b/src/sparnatural/components/widgets/AutoCompleteWidget.ts @@ -25,7 +25,6 @@ export class AutoCompleteWidget extends AbstractWidget { maxItems:15 } - protected widgetValues: RdfTermValue[]; protected configuration: AutocompleteConfiguration; constructor( @@ -131,7 +130,7 @@ export class AutoCompleteWidget extends AbstractWidget { // set the value on the criteria inputHtml.val(autocompleteValue.value.label); - this.renderWidgetVal(autocompleteValue); + this.triggerRenderWidgetVal(autocompleteValue); }); // add the behavior on the input HTML element to fetch the autocompletion value diff --git a/src/sparnatural/components/widgets/BooleanWidget.ts b/src/sparnatural/components/widgets/BooleanWidget.ts index c92cfe73..af3e7107 100644 --- a/src/sparnatural/components/widgets/BooleanWidget.ts +++ b/src/sparnatural/components/widgets/BooleanWidget.ts @@ -25,7 +25,7 @@ export class BooleanWidgetValue implements WidgetValue { } export class BooleanWidget extends AbstractWidget { - protected widgetValues: BooleanWidgetValue[]; + constructor( parentComponent: HTMLComponent, startClassVal: SelectedVal, @@ -60,7 +60,7 @@ export class BooleanWidget extends AbstractWidget { boolean: true, }); - this.renderWidgetVal(widgetValue); + this.triggerRenderWidgetVal(widgetValue); }); falseSpan[0].addEventListener("click", (e) => { @@ -69,7 +69,7 @@ export class BooleanWidget extends AbstractWidget { boolean: false, }); - this.renderWidgetVal(widgetValue); + this.triggerRenderWidgetVal(widgetValue); }); return this; } diff --git a/src/sparnatural/components/widgets/DatesWidget.ts b/src/sparnatural/components/widgets/DatesWidget.ts index 9f2ef538..673235cb 100644 --- a/src/sparnatural/components/widgets/DatesWidget.ts +++ b/src/sparnatural/components/widgets/DatesWidget.ts @@ -153,7 +153,7 @@ export class DatesWidget extends AbstractWidget { stop: this.inputEnd.val().toString(), label: "", }; - this.renderWidgetVal(this.parseInput(val)); + this.triggerRenderWidgetVal(this.parseInput(val)); }; parseInput(dateValue:DateValue["value"]): DateValue { diff --git a/src/sparnatural/components/widgets/ListWidget.ts b/src/sparnatural/components/widgets/ListWidget.ts index effaa67a..446dda34 100644 --- a/src/sparnatural/components/widgets/ListWidget.ts +++ b/src/sparnatural/components/widgets/ListWidget.ts @@ -28,7 +28,6 @@ export class ListWidget extends AbstractWidget { configuration: ListConfiguration; - protected widgetValues: WidgetValue[]; selectHtml: JQuery; constructor( @@ -130,7 +129,7 @@ export class ListWidget extends AbstractWidget { let itemLabel = option[0].getAttribute("data-itemLabel"); let listWidgetValue: WidgetValue = this.buildValue(option[0].value, itemLabel); - this.renderWidgetVal(listWidgetValue); + this.triggerRenderWidgetVal(listWidgetValue); }); } else { diff --git a/src/sparnatural/components/widgets/MapWidget.ts b/src/sparnatural/components/widgets/MapWidget.ts index adb0a4b0..4b0d5612 100644 --- a/src/sparnatural/components/widgets/MapWidget.ts +++ b/src/sparnatural/components/widgets/MapWidget.ts @@ -16,6 +16,7 @@ import { SelectedVal } from "../SelectedVal"; import { NamedNode } from '@rdfjs/types/data-model'; import { I18n } from '../../settings/I18n'; import HTMLComponent from '../HtmlComponent'; +import CriteriaGroup from '../builder-section/groupwrapper/criteriagroup/CriteriaGroup'; const factory = new DataFactory(); @@ -93,7 +94,6 @@ export default class MapWidget extends AbstractWidget { } protected configuration: MapConfiguration; - protected parentComponent: any; protected endClassWidgetGroup: any; protected widgetValues: MapValue[]; //protected widgetValue: MapWidgetValue[]; @@ -120,7 +120,7 @@ export default class MapWidget extends AbstractWidget { this.configuration = configuration; this.parentComponent = parentComponent; - this.endClassWidgetGroup = this.parentComponent.ParentComponent.ParentComponent.ParentComponent.endClassWidgetGroup ; + this.endClassWidgetGroup = (this.parentComponent.parentComponent.parentComponent.parentComponent as CriteriaGroup).endClassWidgetGroup ; } render(): this { @@ -247,7 +247,7 @@ export default class MapWidget extends AbstractWidget { onClick: () => { //this.widgetValue = [this.widgetValue] this.#setWidgetValue(this.drawingLayer) ; - this.renderWidgetValues(this.widgetValues); + this.triggerRenderWidgetVal(this.widgetValues); $(this.parentComponent).trigger("change"); console.log(this) ; console.log(this.endClassWidgetGroup) ; @@ -337,9 +337,6 @@ export default class MapWidget extends AbstractWidget { } #setWidgetValue = (layer:any) => { - if(this.widgetValues?.length > 0) { - this.onRemoveValue(this.widgetValues[0]) ; - } this.widgetValues = [] ; switch ((layer as any).pm._shape) { @@ -364,7 +361,7 @@ export default class MapWidget extends AbstractWidget { #closeMap = () => { if(this.widgetValues?.length > 0 ) { - this.renderWidgetValues(this.widgetValues); + this.triggerRenderWidgetVal(this.widgetValues); $(this.parentComponent).trigger("change"); } }; diff --git a/src/sparnatural/components/widgets/NumberWidget.ts b/src/sparnatural/components/widgets/NumberWidget.ts index 2f0f4ad8..e8bed456 100644 --- a/src/sparnatural/components/widgets/NumberWidget.ts +++ b/src/sparnatural/components/widgets/NumberWidget.ts @@ -40,8 +40,6 @@ export class NumberWidget extends AbstractWidget { static defaultConfiguration: NumberConfiguration = { } - - protected widgetValues: NumberWidgetValue[]; configuration: NumberConfiguration; form: JQuery; @@ -125,7 +123,7 @@ export class NumberWidget extends AbstractWidget { }; numberWidgetValue = this.#checkInput(numberWidgetValue); - this.renderWidgetVal(this.parseInput(numberWidgetValue)); + this.triggerRenderWidgetVal(this.parseInput(numberWidgetValue)); // prevent actual form submission event.preventDefault(); diff --git a/src/sparnatural/components/widgets/SearchRegexWidget.ts b/src/sparnatural/components/widgets/SearchRegexWidget.ts index 540c3558..4250c110 100644 --- a/src/sparnatural/components/widgets/SearchRegexWidget.ts +++ b/src/sparnatural/components/widgets/SearchRegexWidget.ts @@ -32,7 +32,6 @@ export interface SearchConfiguration { } export class SearchRegexWidget extends AbstractWidget { - protected widgetValues: SearchRegexWidgetValue[]; configuration: SearchConfiguration; addValueBtn: AddUserInputBtn; @@ -87,7 +86,7 @@ export class SearchRegexWidget extends AbstractWidget { label: this.searchInput.val().toString(), regex: this.searchInput.val().toString(), }; - this.renderWidgetVal(this.parseInput(searchWidgetValue)); + this.triggerRenderWidgetVal(this.parseInput(searchWidgetValue)); }; parseInput(input: SearchRegexWidgetValue["value"]): SearchRegexWidgetValue { diff --git a/src/sparnatural/components/widgets/timedatepickerwidget/TimeDatePickerWidget.ts b/src/sparnatural/components/widgets/timedatepickerwidget/TimeDatePickerWidget.ts index 49dd3411..25a73655 100644 --- a/src/sparnatural/components/widgets/timedatepickerwidget/TimeDatePickerWidget.ts +++ b/src/sparnatural/components/widgets/timedatepickerwidget/TimeDatePickerWidget.ts @@ -46,7 +46,7 @@ export class TimeDatePickerWidget extends AbstractWidget { protected widgetValues: DateTimePickerValue[]; datesHandler: any; - ParentComponent: any; + parentComponent: any; dateFormat: any; inputStart: JQuery; inputEnd: JQuery; @@ -176,7 +176,7 @@ export class TimeDatePickerWidget extends AbstractWidget { stringDateTimeVal ); if (!widgetVal) return; - this.renderWidgetVal(widgetVal); + this.triggerRenderWidgetVal(widgetVal); }; parseInput(input: StringDateTimeValue["value"]): DateTimePickerValue { diff --git a/src/sparnatural/components/widgets/treewidget/TreeWidget.ts b/src/sparnatural/components/widgets/treewidget/TreeWidget.ts index 4101bd72..df883b2f 100644 --- a/src/sparnatural/components/widgets/treewidget/TreeWidget.ts +++ b/src/sparnatural/components/widgets/treewidget/TreeWidget.ts @@ -30,7 +30,6 @@ export class TreeWidget extends AbstractWidget { maxSelectedItems: 3 } - protected widgetValues: RdfTermValue[]; configuration:TreeConfiguration; IdCriteriaGroupe: any; jsTree: any; diff --git a/src/sparnatural/generators/json/ISparJson.ts b/src/sparnatural/generators/json/ISparJson.ts index eb3b190f..f72b1464 100644 --- a/src/sparnatural/generators/json/ISparJson.ts +++ b/src/sparnatural/generators/json/ISparJson.ts @@ -5,6 +5,7 @@ export interface ISparJson { variables: Array; order?: Order; branches: Array; + limit?: number; } export interface Branch { diff --git a/src/sparnatural/generators/json/SparnaturalJsonGenerator.ts b/src/sparnatural/generators/json/SparnaturalJsonGenerator.ts index f869c6a0..5b9008a2 100644 --- a/src/sparnatural/generators/json/SparnaturalJsonGenerator.ts +++ b/src/sparnatural/generators/json/SparnaturalJsonGenerator.ts @@ -35,7 +35,8 @@ class SparnaturalJsonGenerator { generateQuery( variables: Array | string[], order: Order, - distinct: boolean + distinct: boolean, + limit:number ) { this.json.distinct = distinct; this.json.variables = this.#toVariables( @@ -52,6 +53,9 @@ class SparnaturalJsonGenerator { this.sparnatural.BgWrapper.componentsList.rootGroupWrapper, false ); + + this.json.limit = limit; + return this.json; } diff --git a/src/sparnatural/generators/sparql/WhereBuilder.ts b/src/sparnatural/generators/sparql/WhereBuilder.ts index 32a6a6c2..b57f36b1 100644 --- a/src/sparnatural/generators/sparql/WhereBuilder.ts +++ b/src/sparnatural/generators/sparql/WhereBuilder.ts @@ -8,6 +8,7 @@ import ClassBuilder from "./ClassBuilder"; import IntersectionBuilder from "./IntersectionBuilder"; import SparqlFactory from "./SparqlFactory"; import ValueBuilderIfc, { ValueBuilderFactory } from "./ValueBuilder"; +import { SelectAllValue } from "../../components/builder-section/groupwrapper/criteriagroup/edit-components/EditComponents"; const factory = new DataFactory(); @@ -49,7 +50,6 @@ export default class WhereBuilder { this.#isChild = isChild; this.#isInOption = isInOption; this.settings = settings; - // this.#widgetComponent = this.#grpWrapper.CriteriaGroup.EndClassGroup?.editComponents?.widgetWrapper?.widgetComponent // create the object to convert widget values to SPARQL let endClassValue = @@ -70,9 +70,12 @@ export default class WhereBuilder { this.#grpWrapper.CriteriaGroup.ObjectPropertyGroup.objectPropVal, this.#grpWrapper.CriteriaGroup.EndClassGroup.endClassVal, this.#grpWrapper.CriteriaGroup.EndClassGroup.isVarSelected(), - this.#grpWrapper.CriteriaGroup.EndClassGroup?.editComponents?.widgetWrapper?.widgetComponent - ?.getWidgetValues() - .map((v) => v.value) + this.#grpWrapper.CriteriaGroup.endClassWidgetGroup + .getWidgetValues() + .filter((v) => !(v instanceof SelectAllValue)) + .map((v) => { + return v.value; + }) ); } } @@ -126,15 +129,14 @@ export default class WhereBuilder { } #buildRdfPtrn() { - let widgetComponent = - this.#grpWrapper.CriteriaGroup.EndClassGroup?.editComponents - ?.widgetWrapper?.widgetComponent; - if (widgetComponent?.getWidgetValues()?.length > 0) { + // exclude the "Any" value + if ( + (this.#grpWrapper.CriteriaGroup.endClassWidgetGroup?.getWidgetValues()?.length > 0) + && + !(this.#grpWrapper.CriteriaGroup.endClassWidgetGroup?.hasAnyValue()) + ) { this.#rdfPtrns = this.#valueBuilder.build(); } - - //get the information from the widget if there are widgetvalues selected - // if (this.#widgetComponent?.getwidgetValues()?.length > 0 ) this.#rdfPtrns = this.#widgetComponent.getRdfJsPattern(); } #buildEndClassPtrn() { diff --git a/src/sparnatural/generators/sparql/fromjson/JsonSparqlTranslator.ts b/src/sparnatural/generators/sparql/fromjson/JsonSparqlTranslator.ts index c1e041f9..d6ad772b 100644 --- a/src/sparnatural/generators/sparql/fromjson/JsonSparqlTranslator.ts +++ b/src/sparnatural/generators/sparql/fromjson/JsonSparqlTranslator.ts @@ -25,7 +25,6 @@ export default class JsonSparqlTranslator { prefixes: { [key: string]: string } = {}; jsonQuery: ISparJson; settings: any; - limit: number; defaultLabelVars: Variable[] = []; @@ -55,7 +54,7 @@ export default class JsonSparqlTranslator { prefixes: this.prefixes, order: this.#orderToRDFJS(this.jsonQuery.order, jsonQuery.variables[0]), // sets a limit if provided, otherwise leave to undefined - limit: this.limit && this.limit > 0 ? this.limit : undefined, + limit: jsonQuery.limit && jsonQuery.limit > 0 ? jsonQuery.limit : undefined, }; // if the RdfJsQuery contains empty 'where' array, then the generator crashes. diff --git a/src/sparnatural/querypreloading/QueryLoader.ts b/src/sparnatural/querypreloading/QueryLoader.ts index c114bff7..309a93ba 100644 --- a/src/sparnatural/querypreloading/QueryLoader.ts +++ b/src/sparnatural/querypreloading/QueryLoader.ts @@ -105,7 +105,7 @@ export default class QueryLoader{ const parsedVal: WidgetValue = grpWarpper.CriteriaGroup.EndClassGroup.editComponents.widgetWrapper.widgetComponent.parseInput(v) // if there are multiple values rendered, click first the 'plus' btn, to add more values if(grpWarpper.CriteriaGroup.endClassWidgetGroup.widgetValues.length > 0) this.#clickOn(grpWarpper.CriteriaGroup.endClassWidgetGroup.addWidgetValueBtn.html) - grpWarpper.CriteriaGroup.EndClassGroup.editComponents.widgetWrapper.widgetComponent.renderWidgetVal(parsedVal) + grpWarpper.CriteriaGroup.EndClassGroup.editComponents.widgetWrapper.widgetComponent.triggerRenderWidgetVal(parsedVal) }); // if there is no value, and no children, set an "Any" value diff --git a/src/sparnatural/spec-providers/shacl/SHACLSpecificationEntity.ts b/src/sparnatural/spec-providers/shacl/SHACLSpecificationEntity.ts index b5eb0b20..6b617e55 100644 --- a/src/sparnatural/spec-providers/shacl/SHACLSpecificationEntity.ts +++ b/src/sparnatural/spec-providers/shacl/SHACLSpecificationEntity.ts @@ -85,8 +85,7 @@ export class SHACLSpecificationEntity extends SHACLSpecificationEntry implements // read all sh:property and find the ones that can target the selected class var items: string[] = []; let propShapes = this.getProperties(); - propShapes - .forEach(ps => { + propShapes.forEach(ps => { let prop = new SHACLSpecificationProperty(ps, this.provider, this.store, this.lang); let pRange = prop.getRange(); if(pRange.indexOf(range) > -1) { diff --git a/src/sparnatural/statehandling/actions/DeleteGrpWrapper.ts b/src/sparnatural/statehandling/actions/DeleteGrpWrapper.ts index 4fce5cfe..262261fa 100644 --- a/src/sparnatural/statehandling/actions/DeleteGrpWrapper.ts +++ b/src/sparnatural/statehandling/actions/DeleteGrpWrapper.ts @@ -35,7 +35,7 @@ export default function deleteGrpWrapper( if(elToDel.whereChild) deleteWhereChilds(elToDel) if(elToDel.andSibling) { // We are making the andSibling the root grpWrapper - (grpWrapper.ParentComponent as ComponentsList).attachNewRoot(elToDel.andSibling); + (grpWrapper.parentComponent as ComponentsList).attachNewRoot(elToDel.andSibling); deleteIt(elToDel) } else { sparnatural.BgWrapper.resetCallback(); diff --git a/src/sparnatural/statehandling/actions/GenerateQuery.ts b/src/sparnatural/statehandling/actions/GenerateQuery.ts index a40135a9..95c1366c 100644 --- a/src/sparnatural/statehandling/actions/GenerateQuery.ts +++ b/src/sparnatural/statehandling/actions/GenerateQuery.ts @@ -33,7 +33,8 @@ export class QueryGenerator { var jsonQuery = qryGen.generateQuery( this.actionStore.sparnatural.variableSection.listVariables(), this.actionStore.sparnatural.variableSection.getOrder(), - settings.addDistinct + settings.addDistinct, + settings.limit ); if (jsonQuery != null) {