Skip to content

Commit 7612948

Browse files
committed
feat(h-grid): add fields for child entities and not show select entity if nested
1 parent 1266803 commit 7612948

File tree

6 files changed

+66
-11
lines changed

6 files changed

+66
-11
lines changed

projects/igniteui-angular/src/lib/data-operations/filtering-condition.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export class IgxFilteringOperand {
5050
public conditionList(): string[] {
5151
return this.operations.filter(f => !f.hidden && !f.isNestedQuery).map((element) => element.name);
5252
}
53+
54+
/**
55+
* Returns "In" and "Not In" conditions
56+
*/
57+
public nestedConditionList(): string[] {
58+
return this.operations.filter(f => !f.hidden && f.isNestedQuery).map((element) => element.name);
59+
}
5360

5461
/**
5562
* Returns an array of names of the conditions which are visible in the UI, including "In" and "Not In", allowing the creation of sub-queries.

projects/igniteui-angular/src/lib/query-builder/query-builder-tree.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</ng-template>
88

99
<ng-template #selectFromTemplate>
10-
<div class="igx-filter-tree__inputs" [style.display]="(isInEditMode() && (!this.isAdvancedFiltering() || this.isHierarchicalGridNestedQuery())) ? 'flex' : 'none'">
10+
<div class="igx-filter-tree__inputs" [style.display]="(isInEditMode() && (!this.isAdvancedFiltering() && !this.isHierarchicalGridNestedQuery())) ? 'flex' : 'none'">
1111
<div class="igx-filter-tree__inputs-field">
1212
<span class="igx-query-builder__label">From</span>
1313
<igx-select #entitySelect
@@ -69,7 +69,7 @@
6969
</ng-template>
7070
</igx-combo>
7171
}
72-
@else if (!this.isAdvancedFiltering() && !this.isHierarchicalGridNestedQuery()) {
72+
@else {
7373
<igx-select #returnFieldSelect
7474
type="box"
7575
(selectionChanging)="onReturnFieldSelectChanging($event)"
@@ -466,7 +466,7 @@
466466
<ng-container>
467467
<igx-query-builder-tree
468468
[style.display]="expressionItem.inEditMode || expressionItem.expanded ? 'block' : 'none'"
469-
[entities]="(this.selectedEntity ? this.selectedEntity.childEntities : entities[0].childEntities) ?? entities"
469+
[entities]="determineEntities()"
470470
[queryBuilder]="this.queryBuilder"
471471
[parentExpression]="expressionItem"
472472
[expressionTree]="expressionItem.inEditMode ? (innerQueryNewExpressionTree ?? getExpressionTreeCopy(expressionItem.expression.searchTree, true)) : expressionItem.expression.searchTree"

projects/igniteui-angular/src/lib/query-builder/query-builder-tree.component.ts

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
517517
/** @hidden */
518518
protected isAdvancedFiltering(): boolean {
519519
return (this.entities?.length === 1 && !this.entities[0]?.name) ||
520-
this.entities.find(e => e.childEntities?.length > 0) !== undefined;
520+
this.entities.find(e => e.childEntities?.length > 0) !== undefined ||
521+
this.entities !== this.queryBuilder.entities;
521522
}
522523

523524
/** @hidden */
@@ -555,6 +556,7 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
555556
this.addExpressionDropDownOverlaySettings.outlet = this.overlayOutlet;
556557
this.groupContextMenuDropDownOverlaySettings.outlet = this.overlayOutlet;
557558

559+
console.log('ngAfterViewInit', this._expressionTree);
558560
if (this.isAdvancedFiltering() && this.entities?.length === 1) {
559561
this._selectedEntity = this.entities[0];
560562
}
@@ -575,6 +577,7 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
575577
* @hidden @internal
576578
*/
577579
public set selectedEntity(value: string) {
580+
console.log('selectedEntity', value);
578581
this._selectedEntity = this.entities?.find(el => el.name === value);
579582
}
580583

@@ -691,6 +694,10 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
691694

692695
if (this._selectedField !== value) {
693696
this._selectedField = value;
697+
if (this._selectedField && !this._selectedField.dataType) {
698+
this._selectedField.filters = this.getFilters(this._selectedField);
699+
}
700+
694701
this.selectDefaultCondition();
695702
if (oldValue && this._selectedField && this._selectedField.dataType !== oldValue.dataType) {
696703
this.searchValue.value = null;
@@ -1368,9 +1375,16 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
13681375
public getConditionList(): string[] {
13691376
if (!this.selectedField) return [];
13701377

1371-
if ((this.isAdvancedFiltering() && !this.entities[0].childEntities) ||
1372-
(this.isHierarchicalGridNestedQuery() && this.selectedEntity.name && !this.selectedEntity.childEntities)) {
1373-
return this.selectedField.filters.conditionList();
1378+
if (!this.selectedField.filters) {
1379+
this.selectedField.filters = this.getFilters(this.selectedField);
1380+
}
1381+
1382+
if (this.isAdvancedFiltering()) {
1383+
if (!this.selectedField.dataType) { // field was generated for child entity
1384+
return this.selectedField.filters.nestedConditionList();
1385+
} else {
1386+
return this.selectedField.filters.conditionList();
1387+
}
13741388
}
13751389

13761390
return this.selectedField.filters.extendedConditionList();
@@ -1436,6 +1450,16 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
14361450
}
14371451
}
14381452

1453+
public determineEntities(): EntityType[] {
1454+
// TODO: FIX, not working correctly for every scenario
1455+
1456+
if (this.entities.length === 1 && this.entities[0].childEntities && this.selectedField) {
1457+
return this.entities[0].childEntities.filter(e => e.name === this.selectedField.field);
1458+
}
1459+
1460+
return (this.selectedEntity ? this.selectedEntity.childEntities : this.entities[0].childEntities) ?? this.entities;
1461+
}
1462+
14391463
public getExpressionTreeCopy(expressionTree: IExpressionTree, shouldAssignInnerQueryExprTree?: boolean): IExpressionTree {
14401464
if (!expressionTree) {
14411465
return null;
@@ -1512,8 +1536,12 @@ export class IgxQueryBuilderTreeComponent implements AfterViewInit, OnDestroy {
15121536
}
15131537

15141538
private selectDefaultCondition() {
1515-
if (this.selectedField && this.selectedField.filters) {
1516-
this.selectedCondition = this.selectedField.filters.conditionList().indexOf('equals') >= 0 ? 'equals' : this.selectedField.filters.conditionList()[0];
1539+
if (this.selectedField) {
1540+
if (!this.selectedField.dataType) {
1541+
this.selectedCondition = 'inQuery';
1542+
} else {
1543+
this.selectedCondition = this.selectedField.filters.conditionList().indexOf('equals') >= 0 ? 'equals' : this.selectedField.filters.conditionList()[0];
1544+
}
15171545
}
15181546
}
15191547

projects/igniteui-angular/src/lib/query-builder/query-builder.component.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ export class IgxQueryBuilderComponent implements OnDestroy {
6464
*/
6565
@Input()
6666
public set entities(entities: EntityType[]) {
67+
if (entities) {
68+
this.updateEntities(entities) // add field for every child entity recursively
69+
}
70+
6771
if (entities !== this._entities) {
6872
if (entities && this.expressionTree) {
6973
this._expressionTree = recreateTree(this._expressionTree, entities);
@@ -270,6 +274,20 @@ export class IgxQueryBuilderComponent implements OnDestroy {
270274
}
271275
}
272276

277+
private updateEntities(entities: EntityType[]) {
278+
entities.forEach((entity) => {
279+
if (entity.childEntities) {
280+
entity.childEntities.forEach((childEntity) => {
281+
if (entity.fields.find((f) => f.field === childEntity.name)) {
282+
return;
283+
}
284+
entity.fields.push({ field: childEntity.name, dataType: null });
285+
});
286+
this.updateEntities(entity.childEntities);
287+
}
288+
});
289+
}
290+
273291
private registerSVGIcons(): void {
274292
const editorIcons = editor as any[];
275293

src/app/hierarchical-grid-advanced-filtering/hierarchical-grid-advanced-filtering.sample.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ export class HierarchicalGridAdvancedFilteringSampleComponent implements AfterVi
3030
const innerTree = new FilteringExpressionsTree(FilteringLogic.And, undefined, 'Albums', ['Artist']);
3131
innerTree.filteringOperands.push({
3232
fieldName: 'USBillboard200',
33+
condition: IgxNumberFilteringOperand.instance().condition('lessThanOrEqualTo'),
3334
conditionName: IgxNumberFilteringOperand.instance().condition('lessThanOrEqualTo').name,
3435
searchVal: 5
3536
});
3637
const tree = new FilteringExpressionsTree(FilteringLogic.And, undefined, 'Artists', ['*']);
3738
tree.filteringOperands.push({
38-
fieldName: 'Artist',
39+
fieldName: 'Albums',
40+
condition: IgxStringFilteringOperand.instance().condition('inQuery'),
3941
conditionName: IgxStringFilteringOperand.instance().condition('inQuery').name,
4042
searchTree: innerTree
4143
});

src/app/hierarchical-grid-remote/hierarchical-grid-remote.sample.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class HierarchicalGridRemoteSampleComponent implements OnInit {
7878

7979
const customersTree = new FilteringExpressionsTree(0, undefined, 'Customers', ['customerId', 'companyName', 'contactName', 'contactTitle']);
8080
customersTree.filteringOperands.push({
81-
fieldName: 'customerId',
81+
fieldName: 'Orders',
8282
condition: IgxStringFilteringOperand.instance().condition('notInQuery'),
8383
conditionName: IgxStringFilteringOperand.instance().condition('notInQuery').name,
8484
ignoreCase: false,

0 commit comments

Comments
 (0)