Skip to content

Commit

Permalink
Refactor #10048
Browse files Browse the repository at this point in the history
  • Loading branch information
yigitfindikli committed Apr 1, 2021
1 parent 76c8a10 commit 7816092
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 22 deletions.
12 changes: 12 additions & 0 deletions src/app/components/orderlist/orderlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export class OrderList implements AfterViewChecked,AfterContentInit {
}
}

if (this.filterValue)
this.filter();

this.movedUp = true;
this.onReorder.emit(this.selection);
}
Expand All @@ -274,6 +277,9 @@ export class OrderList implements AfterViewChecked,AfterContentInit {
}
}

if (this.filterValue)
this.filter();

this.onReorder.emit(this.selection);
this.listViewChild.nativeElement.scrollTop = 0;
}
Expand All @@ -296,6 +302,9 @@ export class OrderList implements AfterViewChecked,AfterContentInit {
}
}

if (this.filterValue)
this.filter();

this.movedDown = true;
this.onReorder.emit(this.selection);
}
Expand All @@ -316,6 +325,9 @@ export class OrderList implements AfterViewChecked,AfterContentInit {
}
}

if (this.filterValue)
this.filter();

this.onReorder.emit(this.selection);
this.listViewChild.nativeElement.scrollTop = this.listViewChild.nativeElement.scrollHeight;
}
Expand Down
59 changes: 37 additions & 22 deletions src/app/components/picklist/picklist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import {ObjectUtils, UniqueComponentId} from 'primeng/utils';
template: `
<div [class]="styleClass" [ngStyle]="style" [ngClass]="'p-picklist p-component'" cdkDropListGroup>
<div class="p-picklist-buttons p-picklist-source-controls" *ngIf="showSourceControls">
<button type="button" pButton pRipple icon="pi pi-angle-up" [disabled]="disabled" (click)="moveUp(sourcelist,source,selectedItemsSource,onSourceReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-up" [disabled]="disabled" (click)="moveTop(sourcelist,source,selectedItemsSource,onSourceReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-down" [disabled]="disabled" (click)="moveDown(sourcelist,source,selectedItemsSource,onSourceReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-down" [disabled]="disabled" (click)="moveBottom(sourcelist,source,selectedItemsSource,onSourceReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-up" [disabled]="disabled" (click)="moveUp(sourcelist,source,selectedItemsSource,onSourceReorder,SOURCE_LIST)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-up" [disabled]="disabled" (click)="moveTop(sourcelist,source,selectedItemsSource,onSourceReorder,SOURCE_LIST)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-down" [disabled]="disabled" (click)="moveDown(sourcelist,source,selectedItemsSource,onSourceReorde,SOURCE_LIST)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-down" [disabled]="disabled" (click)="moveBottom(sourcelist,source,selectedItemsSource,onSourceReorder,SOURCE_LIST)"></button>
</div>
<div class="p-picklist-list-wrapper p-picklist-source-wrapper">
<div class="p-picklist-header" *ngIf="sourceHeader">
Expand Down Expand Up @@ -77,10 +77,10 @@ import {ObjectUtils, UniqueComponentId} from 'primeng/utils';
</ul>
</div>
<div class="p-picklist-buttons p-picklist-target-controls" *ngIf="showTargetControls">
<button type="button" pButton pRipple icon="pi pi-angle-up" [disabled]="disabled" (click)="moveUp(targetlist,target,selectedItemsTarget,onTargetReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-up" [disabled]="disabled" (click)="moveTop(targetlist,target,selectedItemsTarget,onTargetReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-down" [disabled]="disabled" (click)="moveDown(targetlist,target,selectedItemsTarget,onTargetReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-down" [disabled]="disabled" (click)="moveBottom(targetlist,target,selectedItemsTarget,onTargetReorder)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-up" [disabled]="disabled" (click)="moveUp(targetlist,target,selectedItemsTarget,onTargetReorder,TARGET_LIST)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-up" [disabled]="disabled" (click)="moveTop(targetlist,target,selectedItemsTarget,onTargetReorder,TARGET_LIST)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-down" [disabled]="disabled" (click)="moveDown(targetlist,target,selectedItemsTarget,onTargetReorder,TARGET_LIST)"></button>
<button type="button" pButton pRipple icon="pi pi-angle-double-down" [disabled]="disabled" (click)="moveBottom(targetlist,target,selectedItemsTarget,onTargetReorder,TARGET_LIST)"></button>
</div>
</div>
`,
Expand Down Expand Up @@ -310,19 +310,22 @@ export class PickList implements AfterViewChecked,AfterContentInit {

onFilter(event: KeyboardEvent, data: any[], listType: number) {
let query = ((<HTMLInputElement> event.target).value.trim() as any).toLocaleLowerCase(this.filterLocale);
this.filter(query, data, listType);
if (listType === this.SOURCE_LIST)
this.filterValueSource = query;
else if (listType === this.TARGET_LIST)
this.filterValueTarget = query;

this.filter(data, listType);
}

filter(query: string, data: any[], listType: number) {
filter(data: any[], listType: number) {
let searchFields = this.filterBy.split(',');

if (listType === this.SOURCE_LIST) {
this.filterValueSource = query;
this.visibleOptionsSource = this.filterService.filter(data, searchFields, this.filterValueSource, this.filterMatchMode, this.filterLocale);
this.onSourceFilter.emit({query: this.filterValueSource, value: this.visibleOptionsSource});
}
else if (listType === this.TARGET_LIST) {
this.filterValueTarget = query;
this.visibleOptionsTarget = this.filterService.filter(data, searchFields, this.filterValueTarget, this.filterMatchMode, this.filterLocale);
this.onTargetFilter.emit({query: this.filterValueTarget, value: this.visibleOptionsTarget});
}
Expand Down Expand Up @@ -361,7 +364,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
ObjectUtils.findIndexInList(item1, list) - ObjectUtils.findIndexInList(item2, list));
}

moveUp(listElement, list, selectedItems, callback) {
moveUp(listElement, list, selectedItems, callback, listType) {
if (selectedItems && selectedItems.length) {
selectedItems = this.sortByIndexInList(selectedItems, list);
for(let i = 0; i < selectedItems.length; i++) {
Expand All @@ -379,13 +382,16 @@ export class PickList implements AfterViewChecked,AfterContentInit {
}
}

if ((this.filterValueSource && listType === this.SOURCE_LIST) || (this.filterValueTarget && listType === this.TARGET_LIST))
this.filter(list, listType);

this.movedUp = true;
this.reorderedListElement = listElement;
callback.emit({items: selectedItems});
}
}

moveTop(listElement, list, selectedItems, callback) {
moveTop(listElement, list, selectedItems, callback, listType) {
if (selectedItems && selectedItems.length) {
selectedItems = this.sortByIndexInList(selectedItems, list);
for(let i = 0; i < selectedItems.length; i++) {
Expand All @@ -401,12 +407,15 @@ export class PickList implements AfterViewChecked,AfterContentInit {
}
}

if ((this.filterValueSource && listType === this.SOURCE_LIST) || (this.filterValueTarget && listType === this.TARGET_LIST))
this.filter(list, listType);

listElement.scrollTop = 0;
callback.emit({items: selectedItems});
}
}

moveDown(listElement, list, selectedItems, callback) {
moveDown(listElement, list, selectedItems, callback, listType) {
if (selectedItems && selectedItems.length) {
selectedItems = this.sortByIndexInList(selectedItems, list);
for(let i = selectedItems.length - 1; i >= 0; i--) {
Expand All @@ -424,13 +433,16 @@ export class PickList implements AfterViewChecked,AfterContentInit {
}
}

if ((this.filterValueSource && listType === this.SOURCE_LIST) || (this.filterValueTarget && listType === this.TARGET_LIST))
this.filter(list, listType);

this.movedDown = true;
this.reorderedListElement = listElement;
callback.emit({items: selectedItems});
}
}

moveBottom(listElement, list, selectedItems, callback) {
moveBottom(listElement, list, selectedItems, callback, listType) {
if (selectedItems && selectedItems.length) {
selectedItems = this.sortByIndexInList(selectedItems, list);
for(let i = selectedItems.length - 1; i >= 0; i--) {
Expand All @@ -446,6 +458,9 @@ export class PickList implements AfterViewChecked,AfterContentInit {
}
}

if ((this.filterValueSource && listType === this.SOURCE_LIST) || (this.filterValueTarget && listType === this.TARGET_LIST))
this.filter(list, listType);

listElement.scrollTop = listElement.scrollHeight;
callback.emit({items: selectedItems});
}
Expand All @@ -465,7 +480,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
this.selectedItemsSource = [];

if (this.filterValueTarget) {
this.filter(this.filterValueTarget, this.target, this.TARGET_LIST);
this.filter(this.target, this.TARGET_LIST);
}
}
}
Expand All @@ -490,7 +505,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
this.selectedItemsSource = [];

if (this.filterValueTarget) {
this.filter(this.filterValueTarget, this.target, this.TARGET_LIST);
this.filter(this.target, this.TARGET_LIST);
}
}
}
Expand All @@ -510,7 +525,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
this.selectedItemsTarget = [];

if (this.filterValueSource) {
this.filter(this.filterValueSource, this.source, this.SOURCE_LIST);
this.filter(this.source, this.SOURCE_LIST);
}
}
}
Expand All @@ -535,7 +550,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
this.selectedItemsTarget = [];

if (this.filterValueSource) {
this.filter(this.filterValueSource, this.source, this.SOURCE_LIST);
this.filter(this.source, this.SOURCE_LIST);
}
}
}
Expand Down Expand Up @@ -567,7 +582,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
}

if (this.filterValueSource) {
this.filter(this.filterValueSource, this.source, this.SOURCE_LIST);
this.filter(this.source, this.SOURCE_LIST);
}
}
else {
Expand All @@ -585,7 +600,7 @@ export class PickList implements AfterViewChecked,AfterContentInit {
}

if (this.filterValueTarget) {
this.filter(this.filterValueTarget, this.target, this.TARGET_LIST);
this.filter(this.target, this.TARGET_LIST);
}
}
}
Expand Down

0 comments on commit 7816092

Please sign in to comment.