Skip to content

Commit 00c5636

Browse files
authored
Merge pull request DSpace#2007 from arvoConsultores/DS-8408
In Advanced Search, list collections alphabetically
2 parents 8264872 + 938bf33 commit 00c5636

23 files changed

Lines changed: 128 additions & 11 deletions

config/config.example.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,3 +369,8 @@ vocabularies:
369369
- filter: 'subject'
370370
vocabulary: 'srsc'
371371
enabled: true
372+
373+
# Default collection/community sorting order at Advanced search, Create/update community and collection when there are not a query.
374+
comcolSelectionSort:
375+
sortField: 'dc.title'
376+
sortDirection: 'ASC'

src/app/shared/dso-selector/dso-selector/dso-selector.component.spec.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { PaginatedSearchOptions } from '../../search/models/paginated-search-opt
1111
import { hasValue } from '../../empty.util';
1212
import { createPaginatedList } from '../../testing/utils.test';
1313
import { NotificationsService } from '../../notifications/notifications.service';
14+
import { SortDirection, SortOptions } from '../../../core/cache/models/sort-options.model';
1415

1516
describe('DSOSelectorComponent', () => {
1617
let component: DSOSelectorComponent;
@@ -34,7 +35,7 @@ describe('DSOSelectorComponent', () => {
3435
];
3536

3637
const searchService = {
37-
search: (options: PaginatedSearchOptions) => {
38+
search: (options: PaginatedSearchOptions, responseMsToLive?: number, useCachedVersionIfAvailable = true) => {
3839
if (hasValue(options.query) && options.query.startsWith('search.resourceid')) {
3940
return createSuccessfulRemoteDataObject$(createPaginatedList([searchResult]));
4041
} else if (options.pagination.currentPage === 1) {
@@ -120,6 +121,43 @@ describe('DSOSelectorComponent', () => {
120121
});
121122
});
122123

124+
describe('search', () => {
125+
beforeEach(() => {
126+
spyOn(searchService, 'search').and.callThrough();
127+
});
128+
129+
it('should specify how to sort if no query is given', () => {
130+
component.sort = new SortOptions('dc.title', SortDirection.ASC);
131+
component.search(undefined, 0);
132+
133+
expect(searchService.search).toHaveBeenCalledWith(
134+
jasmine.objectContaining({
135+
query: undefined,
136+
sort: jasmine.objectContaining({
137+
field: 'dc.title',
138+
direction: SortDirection.ASC,
139+
}),
140+
}),
141+
null,
142+
true
143+
);
144+
});
145+
146+
it('should not specify how to sort if a query is given', () => {
147+
component.sort = new SortOptions('dc.title', SortDirection.ASC);
148+
component.search('testQuery', 0);
149+
150+
expect(searchService.search).toHaveBeenCalledWith(
151+
jasmine.objectContaining({
152+
query: 'testQuery',
153+
sort: null,
154+
}),
155+
null,
156+
true
157+
);
158+
});
159+
});
160+
123161
describe('when search returns an error', () => {
124162
beforeEach(() => {
125163
spyOn(searchService, 'search').and.returnValue(createFailedRemoteDataObject$());

src/app/shared/dso-selector/dso-selector/dso-selector.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { getFirstCompletedRemoteData, getFirstSucceededRemoteDataPayload } from
3131
import { hasNoValue, hasValue, isEmpty, isNotEmpty } from '../../empty.util';
3232
import { buildPaginatedList, PaginatedList } from '../../../core/data/paginated-list.model';
3333
import { SearchResult } from '../../search/models/search-result.model';
34+
import { SortOptions } from '../../../core/cache/models/sort-options.model';
3435
import { RemoteData } from '../../../core/data/remote-data';
3536
import { NotificationsService } from '../../notifications/notifications.service';
3637
import { TranslateService } from '@ngx-translate/core';
@@ -69,6 +70,11 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
6970
*/
7071
@Input() types: DSpaceObjectType[];
7172

73+
/**
74+
* The sorting options
75+
*/
76+
@Input() sort: SortOptions;
77+
7278
// list of allowed selectable dsoTypes
7379
typesString: string;
7480

@@ -221,13 +227,16 @@ export class DSOSelectorComponent implements OnInit, OnDestroy {
221227
* @param useCache Whether or not to use the cache
222228
*/
223229
search(query: string, page: number, useCache: boolean = true): Observable<RemoteData<PaginatedList<SearchResult<DSpaceObject>>>> {
230+
// default sort is only used when there is not query
231+
let efectiveSort = query ? null : this.sort;
224232
return this.searchService.search(
225233
new PaginatedSearchOptions({
226234
query: query,
227235
dsoTypes: this.types,
228236
pagination: Object.assign({}, this.defaultPagination, {
229237
currentPage: page
230-
})
238+
}),
239+
sort: efectiveSort
231240
}),
232241
null,
233242
useCache,

src/app/shared/dso-selector/modal-wrappers/create-collection-parent-selector/create-collection-parent-selector.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import {
88
getCollectionCreateRoute,
99
COLLECTION_PARENT_PARAMETER
1010
} from '../../../../collection-page/collection-page-routing-paths';
11-
11+
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
12+
import { environment } from '../../../../../environments/environment';
1213
/**
1314
* Component to wrap a list of existing communities inside a modal
1415
* Used to choose a community from to create a new collection in
@@ -23,6 +24,7 @@ export class CreateCollectionParentSelectorComponent extends DSOSelectorModalWra
2324
selectorTypes = [DSpaceObjectType.COMMUNITY];
2425
action = SelectorActionType.CREATE;
2526
header = 'dso-selector.create.collection.sub-level';
27+
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
2628

2729
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
2830
super(activeModal, route);

src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ <h3 class="position-relative py-1 my-3 font-weight-normal">
1414
</h3>
1515

1616
<h5 class="px-2">{{'dso-selector.create.community.sub-level' | translate}}</h5>
17-
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" (onSelect)="selectObject($event)"></ds-dso-selector>
17+
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" [sort]="defaultSort" (onSelect)="selectObject($event)"></ds-dso-selector>
1818
</div>
1919
</div>

src/app/shared/dso-selector/modal-wrappers/create-community-parent-selector/create-community-parent-selector.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
getCommunityCreateRoute,
1313
COMMUNITY_PARENT_PARAMETER
1414
} from '../../../../community-page/community-page-routing-paths';
15+
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
16+
import { environment } from '../../../../../environments/environment';
1517

1618
/**
1719
* Component to wrap a button - for top communities -
@@ -29,6 +31,7 @@ export class CreateCommunityParentSelectorComponent extends DSOSelectorModalWrap
2931
objectType = DSpaceObjectType.COMMUNITY;
3032
selectorTypes = [DSpaceObjectType.COMMUNITY];
3133
action = SelectorActionType.CREATE;
34+
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
3235

3336
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
3437
super(activeModal, route);

src/app/shared/dso-selector/modal-wrappers/create-item-parent-selector/create-item-parent-selector.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { DSpaceObjectType } from '../../../../core/shared/dspace-object-type.mod
44
import { DSpaceObject } from '../../../../core/shared/dspace-object.model';
55
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
66
import { DSOSelectorModalWrapperComponent, SelectorActionType } from '../dso-selector-modal-wrapper.component';
7+
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
8+
import { environment } from '../../../../../environments/environment';
79

810
/**
911
* Component to wrap a list of existing collections inside a modal
@@ -21,6 +23,7 @@ export class CreateItemParentSelectorComponent extends DSOSelectorModalWrapperCo
2123
selectorTypes = [DSpaceObjectType.COLLECTION];
2224
action = SelectorActionType.CREATE;
2325
header = 'dso-selector.create.item.sub-level';
26+
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
2427

2528
/**
2629
* If present this value is used to filter collection list by entity type

src/app/shared/dso-selector/modal-wrappers/dso-selector-modal-wrapper.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
</div>
77
<div class="modal-body">
88
<h5 *ngIf="header" class="px-2">{{header | translate}}</h5>
9-
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" (onSelect)="selectObject($event)"></ds-dso-selector>
9+
<ds-dso-selector [currentDSOId]="dsoRD?.payload.uuid" [types]="selectorTypes" [sort]="defaultSort" (onSelect)="selectObject($event)"></ds-dso-selector>
1010
</div>
1111
</div>

src/app/shared/dso-selector/modal-wrappers/dso-selector-modal-wrapper.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { RemoteData } from '../../../core/data/remote-data';
55
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
66
import { DSpaceObjectType } from '../../../core/shared/dspace-object-type.model';
77
import { hasValue, isNotEmpty } from '../../empty.util';
8+
import { SortOptions } from '../../../core/cache/models/sort-options.model';
89

910
export enum SelectorActionType {
1011
CREATE = 'create',
@@ -49,6 +50,11 @@ export abstract class DSOSelectorModalWrapperComponent implements OnInit {
4950
*/
5051
action: SelectorActionType;
5152

53+
/**
54+
* Default DSO ordering
55+
*/
56+
defaultSort: SortOptions;
57+
5258
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute) {
5359
}
5460

src/app/shared/dso-selector/modal-wrappers/edit-collection-selector/edit-collection-selector.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
SelectorActionType
99
} from '../dso-selector-modal-wrapper.component';
1010
import { getCollectionEditRoute } from '../../../../collection-page/collection-page-routing-paths';
11+
import { SortDirection, SortOptions } from '../../../../core/cache/models/sort-options.model';
12+
import { environment } from '../../../../../environments/environment';
1113

1214
/**
1315
* Component to wrap a list of existing collections inside a modal
@@ -22,6 +24,7 @@ export class EditCollectionSelectorComponent extends DSOSelectorModalWrapperComp
2224
objectType = DSpaceObjectType.COLLECTION;
2325
selectorTypes = [DSpaceObjectType.COLLECTION];
2426
action = SelectorActionType.EDIT;
27+
defaultSort = new SortOptions(environment.comcolSelectionSort.sortField, environment.comcolSelectionSort.sortDirection as SortDirection);
2528

2629
constructor(protected activeModal: NgbActiveModal, protected route: ActivatedRoute, private router: Router) {
2730
super(activeModal, route);

0 commit comments

Comments
 (0)