-
Notifications
You must be signed in to change notification settings - Fork 0
/
orderby.component.ts
65 lines (64 loc) · 1.42 KB
/
orderby.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import {Component, Input, Output, EventEmitter, OnInit} from '@angular/core';
/**
* Create a sort control
*
* TODO REWVIEW this may be simplified like SelectableRow
*
* #### Example
*
* ```html
* <vs-order-by
* (onChange)="list.setOrder('id')"
* property="id"
* [order]="list.order"
* ></vs-order-by>
* ```
*/
@Component({
selector: 'vs-order-by',
template: `
<a
(click)="updateOrder()"
>
<i
class="fa pull-right"
[class.fa-sort]="order.by != property"
[class.fa-sort-desc]="order.by == property && order.mod == 'DESC'"
[class.fa-sort-asc]="order.by == property && order.mod == 'ASC'"
aria-hidden="true"
></i>
</a>
`,
})
export class OrderBy extends OnInit {
/**
* Target property
*/
@Input() property: string = null;
/**
* Table.order
*/
@Input() order: string = null;
/**
* Notify changes (when clicked)
*/
@Output() onChange: EventEmitter<any> = new EventEmitter<any>();
/**
* Assert if property or order are null
*/
ngOnInit(): void {
if (null == this.property) {
throw new Error('Attribute "property" is required');
}
if (null == this.order) {
throw new Error('Attribute "order" is required');
}
//?? if(this.onChange. == 0) throw new Error('Attribute "onChange" is required');
}
/**
* Notify it's updated
*/
updateOrder(): void {
this.onChange.emit(this.property);
}
}