Skip to content

Commit

Permalink
Merge pull request #235 from bullhorn/f/customSort
Browse files Browse the repository at this point in the history
add option to custom sort the job list in app.json
  • Loading branch information
charlesabarnes committed Oct 26, 2018
2 parents 3224714 + 84df879 commit 7d826df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/app.json.template
Expand Up @@ -28,7 +28,8 @@
"field": "[ FILTER FIELD HERE ]",
"values": [
"[ FILTER VALUE HERE ]"
]
],
"sort": "-dateLastPublished"
},
"defaultGridState": "list-view",
"eeoc": {
Expand Down
10 changes: 3 additions & 7 deletions src/app/services/search.service.js
Expand Up @@ -18,10 +18,6 @@ class SearchService {
return SearchService._.fields || (SearchService._.fields = 'id,title,publishedCategory(id,name),address(city,state),employmentType,dateLastPublished,publicDescription,isOpen,isPublic,isDeleted');
}

static get _sort() {
return SearchService._.sort || (SearchService._.sort = '-dateLastPublished');
}

get _() {
return this.__ || (this.__ = Object.create(null));
}
Expand Down Expand Up @@ -96,7 +92,7 @@ class SearchService {

get requestParams() {
return this._.requestParams || (this._.requestParams = {
sort: () => this.searchParams.sort || SearchService._sort,
sort: () => this.searchParams.sort || this.configuration.additionalJobCriteria.sort,
count: () => this.searchParams.count || SearchService._count,
start: () => this.searchParams.start || 0,
publishedCategory: (isSearch, fields) => {
Expand Down Expand Up @@ -207,10 +203,10 @@ class SearchService {
return '?start=0&query=' + where + '&fields=id&count=' + SearchService._count;
},
assembleForQueryForIDs: (start, count) => {
return '?where=' + this.requestParams.query(false) + '&fields=' + SearchService._fields + '&count=' + count + '&orderBy=' + SearchService._sort + '&start=' + start;
return '?where=' + this.requestParams.query(false) + '&fields=' + SearchService._fields + '&count=' + count + '&orderBy=' + this.configuration.additionalJobCriteria.sort + '&start=' + start;
},
assembleForSearchForJobs: (start, count) => {
return '?query=' + this.requestParams.query(true) + '&fields=' + SearchService._fields + '&count=' + count + '&sort=' + SearchService._sort + '&start=' + start;
return '?query=' + this.requestParams.query(true) + '&fields=' + SearchService._fields + '&count=' + count + '&sort=' + this.configuration.additionalJobCriteria.sort + '&start=' + start;
},
assembleForGroupByWhereIDs: (fields, orderByFields, start, count, jobs) => {
return '?where=' + this.requestParams.whereIDs(jobs, false) + '&groupBy=' + fields + '&fields=' + fields + ',count(id)&count=' + count + '&orderBy=+' + orderByFields + ',-count.id&start=' + start;
Expand Down
15 changes: 10 additions & 5 deletions test/unit/services/search.service.spec.js
Expand Up @@ -12,7 +12,8 @@ describe('Service: SearchService', () => {
field: '[ FILTER FIELD HERE ]',
values: [
'[ FILTER VALUE HERE ]'
]
],
sort: "-dateLastPublished"
}
});
//$provide.value('job', {});
Expand Down Expand Up @@ -124,7 +125,8 @@ describe('Service: SearchService', () => {
field: 'employmentType',
values: [
'blah'
]
],
sort: "-dateLastPublished"
},
};
expect(SearchService.jobCriteria(true)).toBe(' AND (employmentType:"blah")');
Expand All @@ -136,7 +138,8 @@ describe('Service: SearchService', () => {
values: [
'blah',
'blahy'
]
],
sort: "-dateLastPublished"
},
};
expect(SearchService.jobCriteria(true)).toBe(' AND (employmentType:"blah" OR employmentType:"blahy")');
Expand All @@ -147,7 +150,8 @@ describe('Service: SearchService', () => {
field: '[ FILTER FIELD HERE ]',
values: [
'[ FILTER VALUE HERE ]'
]
],
sort: "-dateLastPublished"
},
};
expect(SearchService.jobCriteria(true)).toBe('');
Expand All @@ -158,7 +162,8 @@ describe('Service: SearchService', () => {
field: 'employmentType',
values: [
'blah'
]
],
sort: "-dateLastPublished"
},
};
expect(SearchService.jobCriteria(false)).toBe(' AND (employmentType=\'blah\')');
Expand Down

0 comments on commit 7d826df

Please sign in to comment.