Skip to content

Commit

Permalink
Work on ActionStore
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Apr 5, 2024
1 parent 1a0c3fc commit 9b4ceda
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
9 changes: 4 additions & 5 deletions src/sparnatural/statehandling/ActionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ import SparnaturalComponent from "../components/SparnaturalComponent";
import { Order } from "../generators/ISparJson";
import toggleVarNames from "./actions/ToggleVarNames";
import updateVarName from "./actions/UpdateVarName";
import redrawBackgroundAndLinks from "./actions/InitGeneralEvent";
import redrawBackgroundAndLinks from "./actions/RedrawBackgroundAndLinks";
import deleteGrpWrapper from "./actions/DeleteGrpWrapper";
import { updateVarList } from "./actions/UpdateVarList";
import { selectViewVar } from "./actions/SelectViewVar";
import { readVariablesFromUI } from "./actions/SelectViewVar";
import { SelectQuery } from "sparqljs";
import GroupWrapper from "../components/builder-section/groupwrapper/GroupWrapper";
import { QueryGenerator } from "./actions/GenerateQuery";

Expand Down Expand Up @@ -73,7 +72,7 @@ class ActionStore {
// 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,this.showVariableNames);
toggleVarNames(this.sparnatural,this.showVariableNames);
this.showVariableNames? this.showVariableNames = false : this.showVariableNames = true
});

Expand Down Expand Up @@ -168,13 +167,13 @@ class ActionStore {

this.sparnatural.html[0].addEventListener("redrawBackgroundAndLinks", (e) => {
e.stopImmediatePropagation();
redrawBackgroundAndLinks(this);
redrawBackgroundAndLinks(this.sparnatural);
});

this.sparnatural.html[0].addEventListener(
"deleteGrpWrapper",
(e: CustomEvent) => {
deleteGrpWrapper(this, e);
deleteGrpWrapper(this.sparnatural, e);
}
);

Expand Down
15 changes: 8 additions & 7 deletions src/sparnatural/statehandling/actions/DeleteGrpWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import SparnaturalComponent from "../../components/SparnaturalComponent";
import ComponentsList from "../../components/builder-section/ComponentsList";
import GroupWrapper from "../../components/builder-section/groupwrapper/GroupWrapper";
import ActionStore, { MaxVarAction } from "../ActionStore";

/*
This method traverses first preorder through the tree and looks for the child component to delete.
It then traverses postorder through the descendants of the element to delete and deletes them all
*/
export default function deleteGrpWrapper(
actionStore: ActionStore,
sparnatural: SparnaturalComponent,
e: CustomEvent
) {
// element to delete
Expand All @@ -28,7 +29,7 @@ export default function deleteGrpWrapper(
}

// traversePreOrder through components and calculate background / linkAndBottoms / for them
actionStore.sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
(grpWrapper: GroupWrapper) => {
if(grpWrapper === elToDel && grpWrapper.isRootGrpWrapper()) {
if(elToDel.whereChild) deleteWhereChilds(elToDel)
Expand All @@ -37,7 +38,7 @@ export default function deleteGrpWrapper(
(grpWrapper.ParentComponent as ComponentsList).attachNewRoot(elToDel.andSibling);
deleteIt(elToDel)
} else {
actionStore.sparnatural.BgWrapper.resetCallback();
sparnatural.BgWrapper.resetCallback();
}
return // we are done here
}
Expand All @@ -64,15 +65,15 @@ export default function deleteGrpWrapper(
}
);

actionStore.sparnatural.html[0].dispatchEvent(
sparnatural.html[0].dispatchEvent(
new CustomEvent("redrawBackgroundAndLinks")
);
// there might have been variables in the variable section which now got deleted
actionStore.sparnatural.html[0].dispatchEvent(
sparnatural.html[0].dispatchEvent(
new CustomEvent("updateVarList")
);
// update the query
actionStore.sparnatural.html[0].dispatchEvent(
sparnatural.html[0].dispatchEvent(
new CustomEvent("generateQuery", { bubbles: true })
);
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { getSettings } from "../../../sparnatural/settings/defaultSettings";
import { getSettings } from "../../settings/defaultSettings";
import { OptionTypes } from "../../components/builder-section/groupwrapper/criteriagroup/optionsgroup/OptionsGroup";
import GroupWrapper from "../../components/builder-section/groupwrapper/GroupWrapper";
import ActionStore from "../ActionStore";
import SparnaturalComponent from "../../components/SparnaturalComponent";
/*
Triggered either on an addSiblingComponen/addWhereChild OR a onRemoveGrpWrapper
*/
export default function redrawBackgroundAndLinks(actionStore: ActionStore) {
export default function redrawBackgroundAndLinks(sparnatural: SparnaturalComponent) {
let cssdef = ``;
//index used in callback
let index = 0;
let currentHeight = 0;
let previousHeight = 0;
// traversePreOrder through components and calculate background / linkAndBottoms / for them
actionStore.sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
(grpWrapper: GroupWrapper) => {
renderLinks(grpWrapper);
rerenderOptionState(grpWrapper);
Expand Down Expand Up @@ -48,7 +48,7 @@ export default function redrawBackgroundAndLinks(actionStore: ActionStore) {
}
);
let linGradCss = `linear-gradient(${cssdef})`;
actionStore.sparnatural.BgWrapper.html.css({ background: linGradCss });
sparnatural.BgWrapper.html.css({ background: linGradCss });
}

// if the grpWrapper doesn't have prop .html, then it got deleted and the links don't need to be rerendered
Expand Down
9 changes: 5 additions & 4 deletions src/sparnatural/statehandling/actions/ToggleVarNames.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SparnaturalComponent from "../../components/SparnaturalComponent";
import GroupWrapper from "../../components/builder-section/groupwrapper/GroupWrapper";
import ActionStore from "../ActionStore";

export default function toggleVarNames(actionsStore: ActionStore,showVarNames:boolean) {
actionsStore.sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
export default function toggleVarNames(sparnatural:SparnaturalComponent,showVarNames:boolean) {
sparnatural.BgWrapper.componentsList.rootGroupWrapper.traversePreOrder(
(grpWrapper: GroupWrapper) => {
let startGrp = grpWrapper.CriteriaGroup.StartClassGroup;
let endGrp = grpWrapper.CriteriaGroup.EndClassGroup;
Expand All @@ -15,7 +15,8 @@ export default function toggleVarNames(actionsStore: ActionStore,showVarNames:bo
}
}
);
actionsStore.sparnatural.html[0].dispatchEvent(

sparnatural.html[0].dispatchEvent(
new CustomEvent("redrawBackgroundAndLinks")
);
}

0 comments on commit 9b4ceda

Please sign in to comment.