Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
feat: restructure hierarchy when item and child have same name
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaume committed Nov 22, 2018
1 parent 14e46c0 commit 29ac95f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/demo/app/hierarchical/hierarchical.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1>Exemple ngx-tree-select with flat datas</h1>
<form novalidate>
<tree-select name="simpleSelect" [items]="items" idField="id" textField="name" childrenField="children" [(ngModel)]="simpleSelected"
required=true #simpleSelect="ngModel" [filterPlaceholder]="FilterPlaceholder" [allowFilter]="ShowFilter" [disabled]="Disabled"
[allowParentSelection]="AllowParentSelection"></tree-select>
[allowParentSelection]="AllowParentSelection" [restructureWhenChildSameName]="RestructureWhenChildSameName"></tree-select>
<div *ngIf="simpleSelect.errors && (simpleSelect.dirty || simpleSelect.touched)" class="alert alert-danger">
<div [hidden]="!simpleSelect.errors.required">Simple select is required</div>
</div>
Expand All @@ -25,7 +25,7 @@ <h1>Exemple ngx-tree-select with flat datas</h1>
<tree-select name="multipleSelect" [items]="items" idField="id" textField="name" childrenField="children" [multiple]="true"
[(ngModel)]="multipleSelected" filterPlaceholder="Type item filter..." required=true minlength="2" maxlength="4"
[allowParentSelection]="AllowParentSelection" #multipleSelect="ngModel" [filterPlaceholder]="FilterPlaceholder" [maxVisibleItemCount]="MaxDisplayed"
[allowFilter]="ShowFilter" [disabled]="Disabled" expandMode="All">
[allowFilter]="ShowFilter" [disabled]="Disabled" expandMode="All" [restructureWhenChildSameName]="RestructureWhenChildSameName">
</tree-select>
<div *ngIf="multipleSelect.errors && (multipleSelect.dirty || multipleSelect.touched)" class="alert alert-danger">
<div [hidden]="!multipleSelect.errors.required">Multiple select is required</div>
Expand Down
1 change: 1 addition & 0 deletions src/demo/app/hierarchical/hierarchical.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class HierarchicalComponent {
public items = HierarchicalCountries;

public AllowParentSelection = true;
public RestructureWhenChildSameName = false;
public ShowFilter = true;
public Disabled = false;
public FilterPlaceholder = 'Type here to filter elements...';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ export class TreeSelectItemComponent {
return this.svc.Configuration.allowParentSelection;
}

get restructureWhenChildSameName(): boolean {
return this.svc.Configuration.restructureWhenChildSameName;
}

get needCheckBox(): boolean {
return this.svc.Configuration.isHierarchy() && this.svc.Configuration.allowMultiple;
}

public get haveChildren(): boolean {
if(this.restructureWhenChildSameName && this.item && this.item.children && this.item.children.length == 1 && this.item.text == this.item.children[0].text)
{
this.item = this.item.children[0];
}
return this.item && this.item.children && this.item.children.length > 0;
}

Expand Down
11 changes: 11 additions & 0 deletions src/ngx-tree-select/src/components/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,21 @@ export class TreeSelectComponent implements ControlValueAccessor {
public set allowParentSelection(value: boolean) {
this.svc.setConfiguration((opt) => opt.allowParentSelection = value, true);
}

public get allowParentSelection(): boolean {
return this.svc.Configuration.allowParentSelection;
}


@Input()
public set restructureWhenChildSameName(value: boolean){
this.svc.setConfiguration((opt) => opt.restructureWhenChildSameName = value, true);
}

public get restructureWhenChildSameName(): boolean {
return this.svc.Configuration.restructureWhenChildSameName;
}

@Input()
public set childrenField(value: string) {
this.svc.setConfiguration((opt) => opt.childProperty = value, true);
Expand Down
1 change: 1 addition & 0 deletions src/ngx-tree-select/src/models/select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class SelectOption {
public filter = '';
public filterCaseSensitive = false;
public allowParentSelection = false;
public restructureWhenChildSameName = false;
public maxVisibleItemCount: number;
public expandMode = ExpandMode.None;

Expand Down

0 comments on commit 29ac95f

Please sign in to comment.