Skip to content

Commit

Permalink
#1863 very crudely implemented addAND and removeSelected filter on Fi…
Browse files Browse the repository at this point in the history
…lter TreeTable
  • Loading branch information
dk1844 committed Aug 27, 2021
1 parent d666f97 commit 4f3d2b0
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 6 deletions.
22 changes: 16 additions & 6 deletions menas/ui/components/mappingTable/addMappingTable.fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,21 @@
</VBox>
<Label text="Filter"/>
<Text text="{entity>/filterJson}"/>
<Label text="Filter Tree" />
<t:TreeTable id="filterTreeEdit"
rows="{path:'entity>/updatedFilters'}"
>
<Label text="Filter Tree"/>
<t:TreeTable id="filterTreeEdit" rows="{path:'entity>/updatedFilters'}">
<t:extension>
<OverflowToolbar style="Clear">
<Title id="title" text="Add:"/>
<Button id="addAndBtn" text="AND" icon="sap-icon://scissors" />
<Button id="addOrBtn" text="OR" icon="sap-icon://paste" />
<Button id="addNotBtn" text="NOT" icon="sap-icon://scissors" />
<Button id="addEqualsBtn" text="Equals" icon="sap-icon://scissors" />
<Button id="addDiffersBtn" text="Differs" icon="sap-icon://scissors" />
<Button id="addIsNullBtn" text="IsNull" icon="sap-icon://scissors" />
<ToolbarSpacer/>
<Button id="removeSelectedBtn" text="Remove selected" icon="sap-icon://delete" />
</OverflowToolbar>
</t:extension>
<t:columns>
<t:Column label="FilterName">
<t:template>
Expand All @@ -72,7 +83,7 @@
</t:Column>
<t:Column label="Column">
<t:template>
<Input type="Text" value="{entity>columnName}" visible="{= !!${entity>columnName}}" />
<Input type="Text" value="{entity>columnName}" visible="{= !!${entity>columnName}}"/>
</t:template>
</t:Column>
<t:Column label="Value">
Expand All @@ -88,7 +99,6 @@
</t:Column>
</t:columns>
</t:TreeTable>

</form:content>
</form:SimpleForm>
</VBox>
Expand Down
67 changes: 67 additions & 0 deletions menas/ui/service/EntityDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ class MappingTableDialog extends EntityDialog {
oController.byId("newMappingTableCancelButton").attachPress(this.cancel, this);
oController.byId("newMappingTableName").attachChange(this.onNameChange, this);

// filter toolbar:
oController.byId("addAndBtn").attachPress(this.onFilterAddAnd, this);
oController.byId("removeSelectedBtn").attachPress(this.onRemoveSelected, this);

oController.byId("toggleHdfsBrowser").attachPress(this.onHdfsBrowserToggle, this);
}

Expand Down Expand Up @@ -466,6 +470,69 @@ class MappingTableDialog extends EntityDialog {
this.oDialog.getModel("entity").setProperty("/nameUnique", true);
}
}

onFilterAddAnd() {
console.log("onAddAnd event fired");

var oTreeTable = this.oController.byId("filterTreeEdit");
var aSelectedIndices = oTreeTable.getSelectedIndices();
var oModel = oTreeTable.getBinding().getModel();

console.log(`aSelectedIndices = ${aSelectedIndices.length}`);

if (aSelectedIndices.length !== 1) {
sap.m.MessageToast.show("Select exactly one row first.");
return;
}

var oNewParentContext = oTreeTable.getContextByIndex(aSelectedIndices[0]);
var oNewParent = oNewParentContext.getProperty();

const blankAnd = {
_t : "AndJoinedFilters",
filterItems : []
};

// based on what type of filter is selected, attach the new filter to it
if (oNewParent.filterItems) { //and / or -> add
oNewParent.filterItems = oNewParent.filterItems.concat(blankAnd)
} else if (oNewParent.inputFilter) {
oNewParent.inputFilter = blankAnd // not -> replace
} else {
sap.m.MessageToast.show("Could not add filter. Leaf filter was selected"); // todo solve for empty
return;

}

oModel.refresh();
}

onRemoveSelected() {
console.log("onRemoveSelected event fired");

var oTreeTable = this.oController.byId("filterTreeEdit");
var aSelectedIndices = oTreeTable.getSelectedIndices();
var oModel = oTreeTable.getBinding().getModel();

console.log(`aSelectedIndices = ${aSelectedIndices.length}`);

if (aSelectedIndices.length === 0) {
sap.m.MessageToast.show("Select at least one row first.");
return;
}

// delete the data.
aSelectedIndices.forEach(idx => {
var oContext = oTreeTable.getContextByIndex(idx);
var oData = oContext.getProperty();

if (oData) {
// The property is simply set to undefined to preserve the tree state (expand/collapse states of nodes).
oModel.setProperty(oContext.getPath(), undefined, oContext, true);
}
}
);
}
}

class AddMappingTableDialog extends MappingTableDialog {
Expand Down

0 comments on commit 4f3d2b0

Please sign in to comment.