[ADF-3802] Default ascending order fix (#4070)

This commit is contained in:
davidcanonieto
2018-12-12 10:58:30 +00:00
committed by Eugenio Romano
parent b113ad83f1
commit 95260a7ca7
6 changed files with 48 additions and 28 deletions

View File

@@ -2,5 +2,6 @@
[options]="options"
[selected]="value"
[ascending]="ascending"
(change)="onChanged($event)">
(valueChange)="onValueChanged($event)"
(sortingChange)="onSortingChanged($event)">
</adf-sorting-picker>

View File

@@ -71,11 +71,23 @@ describe('SearchSortingPickerComponent', () => {
spyOn(queryBuilder, 'update').and.stub();
component.ngOnInit();
component.onChanged({ key: 'description', ascending: false });
component.onValueChanged('description');
expect(queryBuilder.update).toHaveBeenCalled();
expect(queryBuilder.sorting.length).toBe(1);
expect(queryBuilder.sorting[0].key).toEqual('description');
expect(queryBuilder.sorting[0].ascending).toBeTruthy();
});
it('should update query builder each time sorting is changed', () => {
spyOn(queryBuilder, 'update').and.stub();
component.ngOnInit();
component.onSortingChanged(false);
expect(queryBuilder.update).toHaveBeenCalled();
expect(queryBuilder.sorting.length).toBe(1);
expect(queryBuilder.sorting[0].key).toEqual('name');
expect(queryBuilder.sorting[0].ascending).toBeFalsy();
});
});

View File

@@ -39,13 +39,18 @@ export class SearchSortingPickerComponent implements OnInit {
const primary = this.queryBuilder.getPrimarySorting();
if (primary) {
this.value = primary.key;
this.ascending = primary.ascending;
this.ascending = this.getSortingOrder();
}
}
onChanged(sorting: { key: string, ascending: boolean }) {
this.value = sorting.key;
this.ascending = sorting.ascending;
onValueChanged(key: string) {
this.value = key;
this.ascending = this.getSortingOrder();
this.applySorting();
}
onSortingChanged(ascending: boolean) {
this.ascending = ascending;
this.applySorting();
}
@@ -67,4 +72,13 @@ export class SearchSortingPickerComponent implements OnInit {
}
}
private getSortingOrder(): boolean {
const option = this.findOptionByKey(this.value);
if (option) {
return option.ascending;
}
return this.queryBuilder.getPrimarySorting().ascending;
}
}