UNPKG

12.9 kBTypeScriptView Raw
1/// <reference types="angular" />
2/**
3 * ngTable: Table + Angular JS
4 *
5 * @author Vitalii Savchuk <esvit666@gmail.com>
6 * @url https://github.com/esvit/ng-table/
7 * @license New BSD License <http://creativecommons.org/licenses/BSD/>
8 */
9import * as ng1 from 'angular';
10import { IScope } from 'angular';
11import { DataResult } from './data';
12import { IPageButton } from './paging';
13import { NgTableParams } from './ngTableParams';
14/**
15 * Alias for the types that can be used to filter events
16 */
17export declare type EventSelector<T> = NgTableParams<T> | IEventSelectorFunc;
18/**
19 * Signature of the event hander that is registered to receive the *afterCreated* event
20 */
21export interface IAfterCreatedListener {
22 (publisher: NgTableParams<any>): any;
23}
24/**
25 * Signature of the event hander that is registered to receive the *afterReloadData* event
26 */
27export interface IAfterReloadDataListener<T> {
28 (publisher: NgTableParams<T>, newData: DataResult<T>[], oldData: DataResult<T>[]): any;
29}
30/**
31 * Signature of the event hander that is registered to receive the *datasetChanged* event
32 */
33export interface IDatasetChangedListener<T> {
34 (publisher: NgTableParams<T>, newDataset: T[], oldDataset: T[]): any;
35}
36/**
37 * Signature of the function used to filter the events to only specific instances of
38 * {@link NgTableParams}
39 */
40export interface IEventSelectorFunc {
41 (publisher: NgTableParams<any>): boolean;
42}
43/**
44 * Signature of the event hander that is registered to receive the *pagesChanged* event
45 */
46export interface IPagesChangedListener {
47 (publisher: NgTableParams<any>, newPages: IPageButton[], oldPages: IPageButton[]): any;
48}
49/**
50* Signature of the event hander that is registered to receive the *afterDataFiltered* event
51*/
52export interface IAfterDataFilteredListener<T> {
53 (publisher: NgTableParams<T>, newData: DataResult<T>[]): any;
54}
55/**
56* Signature of the event hander that is registered to receive the *afterDataSorted* event
57*/
58export interface IAfterDataSortedListener<T> {
59 (publisher: NgTableParams<T>, newData: DataResult<T>[]): any;
60}
61/**
62 * Signature of the function used to explicitly unregister an event handler so that it stops
63 * receiving notifications
64 */
65export interface IUnregistrationFunc {
66 (): void;
67}
68/**
69 * Strongly typed pub/sub for {@link NgTableParams}
70 *
71 * Supported events:
72 *
73 * * afterCreated - raised when a new instance of {@link NgTableParams} has finished being constructed
74 * * afterReloadData - raised when the {@link NgTableParams} `reload` method has finished loading new data
75 * * datasetChanged - raised when {@link ISettings} `dataset` receives a new data array
76 * * pagesChanged - raised when a new pages array has been generated
77 */
78export interface NgTableEventsChannel {
79 /**
80 * Subscribe to receive notification whenever a new `NgTableParams` instance has finished being constructed.
81 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called. Supply a
82 * `scope` to have angular automatically unregister the listener when the `scope` is destroyed.
83 *
84 * @param listener the function that will be called when the event fires
85 * @param scope the angular `$scope` that will limit the lifetime of the event subscription
86 * @param eventFilter a predicate function that should return true to receive the event
87 * @return a unregistration function that when called will unregister the `listener`
88 */
89 onAfterCreated(listener: IAfterCreatedListener, scope: IScope, eventFilter?: IEventSelectorFunc): IUnregistrationFunc;
90 /**
91 * Subscribe to receive notification whenever a new `NgTableParams` instance has finished being constructed.
92 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
93 *
94 * @param listener the function that will be called when the event fires
95 * @param eventFilter a predicate function that should return true to receive the event
96 * @return a unregistration function that when called will unregister the `listener`
97 */
98 onAfterCreated(listener: IAfterCreatedListener, eventFilter?: IEventSelectorFunc): IUnregistrationFunc;
99 /**
100 * Subscribe to receive notification whenever the `reload` method of an `NgTableParams` instance has successfully executed
101 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called. Supply a
102 * `scope` to have angular automatically unregister the listener when the `scope` is destroyed.
103 *
104 * @param listener the function that will be called when the event fires
105 * @param scope the angular `$scope` that will limit the lifetime of the event subscription
106 * @param eventFilter either the specific `NgTableParams` instance you want to receive events for or a predicate function that should return true to receive the event
107 * @return a unregistration function that when called will unregister the `listener`
108 */
109 onAfterReloadData<T>(listener: IAfterReloadDataListener<T>, scope: IScope, eventFilter?: EventSelector<T>): IUnregistrationFunc;
110 /**
111 * Subscribe to receive notification whenever the `reload` method of an `NgTableParams` instance has successfully executed
112 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
113 *
114 * @param listener the function that will be called when the event fires
115 * @param eventFilter a predicate function that should return true to receive the event
116 * @return a unregistration function that when called will unregister the `listener`
117 */
118 onAfterReloadData<T>(listener: IAfterReloadDataListener<T>, eventFilter?: EventSelector<T>): IUnregistrationFunc;
119 /**
120 * Subscribe to receive notification whenever a new data rows *array* is supplied as a `settings` value to a `NgTableParams` instance.
121 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called. Supply a
122 * `scope` to have angular automatically unregister the listener when the `scope` is destroyed.
123 *
124 * @param listener the function that will be called when the event fires
125 * @param scope the angular `$scope` that will limit the lifetime of the event subscription
126 * @param eventFilter either the specific `NgTableParams` instance you want to receive events for or a predicate function that should return true to receive the event
127 * @return a unregistration function that when called will unregister the `listener`
128 */
129 onDatasetChanged<T>(listener: IDatasetChangedListener<T>, scope: IScope, eventFilter?: EventSelector<T>): IUnregistrationFunc;
130 /**
131 * Subscribe to receive notification whenever a new data rows *array* is supplied as a `settings` value to a `NgTableParams` instance.
132 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
133 *
134 * @param listener the function that will be called when the event fires
135 * @param eventFilter either the specific `NgTableParams` instance you want to receive events for or a predicate function that should return true to receive the event
136 * @return a unregistration function that when called will unregister the `listener`
137 */
138 onDatasetChanged<T>(listener: IDatasetChangedListener<T>, eventFilter?: EventSelector<T>): IUnregistrationFunc;
139 /**
140 * Subscribe to receive notification whenever the paging buttons for an `NgTableParams` instance change
141 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called. Supply a
142 * `scope` to have angular automatically unregister the listener when the `scope` is destroyed.
143 *
144 * @param listener the function that will be called when the event fires
145 * @param scope the angular `$scope` that will limit the lifetime of the event subscription
146 * @param eventFilter either the specific `NgTableParams` instance you want to receive events for or a predicate function that should return true to receive the event
147 * @return a unregistration function that when called will unregister the `listener`
148 */
149 onPagesChanged<T>(listener: IPagesChangedListener, scope: IScope, eventFilter?: EventSelector<T>): IUnregistrationFunc;
150 /**
151 * Subscribe to receive notification whenever the paging buttons for an `NgTableParams` instance change
152 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
153 *
154 * @param listener the function that will be called when the event fires
155 * @param eventFilter either the specific `NgTableParams` instance you want to receive events for or a predicate function that should return true to receive the event
156 * @return a unregistration function that when called will unregister the `listener`
157 */
158 onPagesChanged<T>(listener: IPagesChangedListener, eventFilter?: EventSelector<T>): IUnregistrationFunc;
159 /**
160 * Subscribe to receive notification whenever a `ngTableDefaultGetData` instance filters data
161 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
162 *
163 * @param listener the function that will be called when the event fires
164 * @param scope the angular `$scope` that will limit the lifetime of the event subscription
165 * @param eventFilter either the specific `IDefaultGetData` instance you want to receive events for or a predicate function that should return true to receive the event
166 * @return a unregistration function that when called will unregister the `listener`
167 */
168 onAfterDataFiltered<T>(listener: IAfterDataFilteredListener<T>, scope: IScope, eventFilter?: EventSelector<T>): IUnregistrationFunc;
169 /**
170 * Subscribe to receive notification whenever a `ngTableDefaultGetData` instance filters data
171 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
172 *
173 * @param listener the function that will be called when the event fires
174 * @param eventFilter either the specific `IDefaultGetData` instance you want to receive events for or a predicate function that should return true to receive the event
175 * @return a unregistration function that when called will unregister the `listener`
176 */
177 onAfterDataFiltered<T>(listener: IAfterDataFilteredListener<T>, eventFilter?: EventSelector<T>): IUnregistrationFunc;
178 /**
179 * Subscribe to receive notification whenever a `ngTableDefaultGetData` instance orders data
180 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
181 *
182 * @param listener the function that will be called when the event fires
183 * @param scope the angular `$scope` that will limit the lifetime of the event subscription
184 * @param eventFilter either the specific `IDefaultGetData` instance you want to receive events for or a predicate function that should return true to receive the event
185 * @return a unregistration function that when called will unregister the `listener`
186 */
187 onAfterDataSorted<T>(listener: IAfterDataSortedListener<T>, scope: IScope, eventFilter?: EventSelector<T>): IUnregistrationFunc;
188 /**
189 * Subscribe to receive notification whenever a `ngTableDefaultGetData` instance orders data
190 * Optionally supply an `eventFilter` to restrict which events that should trigger the `listener` to be called.
191 *
192 * @param listener the function that will be called when the event fires
193 * @param eventFilter either the specific `IDefaultGetData` instance you want to receive events for or a predicate function that should return true to receive the event
194 * @return a unregistration function that when called will unregister the `listener`
195 */
196 onAfterDataSorted<T>(listener: IAfterDataSortedListener<T>, eventFilter?: EventSelector<T>): IUnregistrationFunc;
197 publishAfterCreated<T>(publisher: NgTableParams<T>): void;
198 publishAfterReloadData<T>(publisher: NgTableParams<T>, newData: T[], oldData: T[]): void;
199 publishDatasetChanged<T>(publisher: NgTableParams<T>, newDataset: T[], oldDataset: T[]): void;
200 publishPagesChanged<T>(publisher: NgTableParams<T>, newPages: IPageButton[], oldPages: IPageButton[]): void;
201 publishAfterDataFiltered<T>(publisher: NgTableParams<T>, newData: T[]): void;
202 publishAfterDataSorted<T>(params: NgTableParams<T>, newData: T[]): void;
203}
204export declare class NgTableEventsChannel {
205 private $rootScope;
206 static $inject: string[];
207 constructor($rootScope: ng1.IRootScopeService);
208 private addTableParamsEvent(eventName, target);
209 private createPublishEventFn(eventName);
210 private createEventSubscriptionFn(eventName);
211}