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

Commit

Permalink
feat: Allow unshow more items
Browse files Browse the repository at this point in the history
  • Loading branch information
Hervé TINANT committed Jul 13, 2017
1 parent 2dbf891 commit 0001181
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 39 deletions.
1 change: 0 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export { TreeSelectDefaultOptions } from './src/model/tree-select-default-options';
export { TreeSelectComponent } from './src/component/tree-select.component';
export { ItemPipe } from './src/pipe/item.pipe';
export { IsVisiblePipe } from './src/pipe/isVisible.pipe';
export { NgxTreeSelectModule } from './src/module';
53 changes: 35 additions & 18 deletions src/lib/src/component/tree-select.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,45 @@

<!-- Control display -->
<div [class.disabled]="disabled">
<span tabindex="-1" class="btn btn-default btn-secondary form-control" [class.selected-container-text]="!multiple" [class.selected-container-item]="multiple"
(click)="toggle($event)">
<span *ngIf="selection.length <= 0"
class="ui-select-placeholder text-muted">{{placeholder}}</span>
<span *ngFor="let itm of selection | IsVisiblePipe" class="pull-left" [class.selected-item-text]="!multiple" [class.selected-item-item]="multiple"
[class.btn]="multiple" [class.btn-default]="multiple" [class.btn-xs]="multiple">
{{itm.text}}
<a *ngIf="multiple && !disabled"
class="close"
(click)="removeItem($event, itm)">x</a>
</span>
<span class="pull-right more-items-icon" (click)="loadMore($event)" *ngIf="loadAllItems">(...)</span>
<i class="caret pull-right"></i>
<span tabindex="-1"
class="btn btn-default btn-secondary form-control"
[class.selected-container-text]="!multiple"
[class.selected-container-item]="multiple"
(click)="toggle($event)">
<span *ngIf="selection.length <= 0"
class="ui-select-placeholder text-muted">{{placeholder}}</span>
<span *ngFor="let itm of selection; let idx=index">
<span *ngIf="moreLoaded || maxVisibleItemCount == 0 || idx<maxVisibleItemCount"
class="pull-left"
[class.selected-item-text]="!multiple"
[class.selected-item-item]="multiple"
[class.btn]="multiple"
[class.btn-default]="multiple"
[class.btn-xs]="multiple">
{{itm.text}}
<a *ngIf="multiple && !disabled" class="close" (click)="removeItem($event, itm)">x</a>
</span>
</span>

</span>
<span class="pull-right more-items-icon" (click)="loadMore($event)" *ngIf="showMoreLink">(...)</span>
<i class="caret pull-right"></i>
</div>
<!-- options template -->
<ul *ngIf="!disabled && isOpen && internalItems && internalItems.length > 0" class="dropdown-menu" role="menu">
<input name="filterText" *ngIf="allowFilter" type="text" [(ngModel)]="filter" (click)="setInputFocus()" (blur)="setInputFocusOut()"
class="form-control" placeholder="{{filterPlaceholder}}" [ngModelOptions]="{standalone: true}" />
<ul *ngIf="!disabled && isOpen && internalItems && internalItems.length > 0"
class="dropdown-menu"
role="menu">
<input name="filterText"
*ngIf="allowFilter"
type="text"
[(ngModel)]="filter"
(click)="setInputFocus()"
(blur)="setInputFocusOut()"
class="form-control"
placeholder="{{filterPlaceholder}}"
[ngModelOptions]="{standalone: true}" />
<li *ngFor="let o of internalItems | ItemPipe: filter " role="menuitem">
<tree-select-item [item]="o" (selected)="itemSelected()" [onTouchedCallBack]="onTouchedCallback">
</tree-select-item>
<tree-select-item [item]="o" (selected)="itemSelected()" [onTouchedCallBack]="onTouchedCallback"></tree-select-item>
</li>
</ul>
</div>
5 changes: 3 additions & 2 deletions src/lib/src/component/tree-select.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ ul {
.more-items-icon {
opacity: 0.5;
height: 10px;
margin-top: -2px;
position: absolute;
right: 20px;
top: 30%;
bottom: 23px;
z-index: 100;
}

.close {
Expand All @@ -65,6 +65,7 @@ ul {
margin-left: 5px;
padding-top: 3px;
position: absolute;
z-index: 50;
}

.caret {
Expand Down
10 changes: 5 additions & 5 deletions src/lib/src/component/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export class TreeSelectComponent implements ControlValueAccessor {
private onChangeCallback: (_: any) => void = noop;
private haveFocus = false;
private inputFocus = false;
public showMoreLink = false;
public moreLoaded = false;

@Input() public disabled = false;
@Input() public filterPlaceholder = 'Type here for filtering items...';
Expand Down Expand Up @@ -86,9 +88,7 @@ export class TreeSelectComponent implements ControlValueAccessor {
}

public get selection(): SelectableItem[] {
if (this.maxVisibleItemCount && ((this.svc.getInternalSelection().length - this.maxVisibleItemCount) > 0)) {
this.svc.setConfiguration(opt => opt.loadAllItems = true, false);
}
this.showMoreLink = (this.maxVisibleItemCount > 0 && ((this.svc.getInternalSelection().length - this.maxVisibleItemCount) > 0));
return this.svc.getInternalSelection();
}

Expand Down Expand Up @@ -177,8 +177,8 @@ export class TreeSelectComponent implements ControlValueAccessor {

loadMore($event: any) {
$event.stopPropagation();
this.svc.setConfiguration(opt => opt.loadAllItems = false, false);
this.svc.setConfiguration(opt => opt.maxVisibleItemCount = 0, false);
this.moreLoaded = !this.moreLoaded;
//this.svc.setConfiguration(opt => opt.maxVisibleItemCount = 0, false);
}

ProcessMatchFilterTreeItem(tree: SelectableItem, filter: string): boolean {
Expand Down
4 changes: 1 addition & 3 deletions src/lib/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { TreeSelectComponent } from './component/tree-select.component';
import { TreeSelectItemComponent } from './component/tree-select-item.component';
import { OffClickDirective } from './directive/off-click.directive';
import { ItemPipe } from './pipe/item.pipe';
import { IsVisiblePipe } from './pipe/isVisible.pipe';

@NgModule({
imports: [
Expand All @@ -18,8 +17,7 @@ import { IsVisiblePipe } from './pipe/isVisible.pipe';
TreeSelectComponent,
TreeSelectItemComponent,
OffClickDirective,
ItemPipe,
IsVisiblePipe
ItemPipe
],
exports: [
TreeSelectComponent
Expand Down
10 changes: 0 additions & 10 deletions src/lib/src/pipe/isVisible.pipe.ts

This file was deleted.

0 comments on commit 0001181

Please sign in to comment.