-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add orderBy support to filter queries (HELM-174)
- Loading branch information
Benjamin Reed
committed
Aug 29, 2019
1 parent
138f524
commit 6e7edfa
Showing
6 changed files
with
130 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// tslint:disable:max-classes-per-file | ||
|
||
import {forLabel, OnmsEnum} from '../internal/OnmsEnum'; | ||
|
||
/** | ||
* Represents a sort order. | ||
* @category Filtering API | ||
*/ | ||
export class Order extends OnmsEnum<string> { | ||
/** Given a label ('ASC', 'DESC'), return the corresponding order. */ | ||
public static forLabel(label: string) { | ||
return forLabel(Orders, label); | ||
} | ||
|
||
/** Whether this order matches the given order string. */ | ||
public matches(label: string) { | ||
return (label.toLowerCase() === this.label.toLowerCase()); | ||
} | ||
} | ||
|
||
const Orders = { | ||
ASC: new Order('ASC', 'ASC'), | ||
DESC: new Order('DESC', 'DESC'), | ||
}; | ||
const frozen = Object.freeze(Orders); | ||
export {frozen as Orders}; | ||
|
||
/** | ||
* Column ordering. | ||
* @category Filtering API | ||
*/ | ||
export class OrderBy { | ||
/** given an OrderBy JSON structure, return an OrderBy object */ | ||
public static fromJson(orderBy: any): OrderBy|undefined { | ||
if (orderBy && orderBy.attribute) { | ||
return new OrderBy(orderBy.attribute, Order.forLabel(orderBy.order.label)); | ||
} | ||
return undefined; | ||
} | ||
|
||
/** the attribute to order by */ | ||
public readonly attribute: string; | ||
|
||
/** the order to sort */ | ||
public readonly order: Order; | ||
|
||
public constructor(attribute: string, order?: Order) { | ||
this.attribute = attribute; | ||
this.order = order || Orders.ASC; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters