tablevu 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/webapi.js CHANGED
@@ -1,31 +1,33 @@
1
- /*
2
- props: {
3
- pageSize
4
- currentPage
5
- search
6
- order
7
- }
8
-
9
- C# : methodXYZ(string search, int top, int skip, string orderBy, string orderdir)
10
- */
11
- export default function param(uri, header, props) {
12
- const url = new URL(uri);
13
- //
14
- // Paging //
15
- if (props.pageSize) {
16
- url.searchParams.append('skip', props.pageSize * (props.currentPage - 1));
17
- url.searchParams.append('top', props.pageSize);
18
- }
19
-
20
- // Filter //
21
- if (props.search)
22
- url.searchParams.append('search', props.search);
23
-
24
- // Order //
25
- if (props.order.length > 0) {
26
- url.searchParams.append('orderby', props.order.map(m => { return props.cols[m.index].name }).join(','));
27
- url.searchParams.append('orderdir', props.order.map(m => { return m.type ? m.type : 'asc' }).join(','));
28
- }
29
-
30
- return new Request(url, header);
31
- }
1
+ import get from './get.js';
2
+
3
+ export default class webapi {
4
+ constructor(req, data, events) {
5
+ this.adapter = (props) => {
6
+ const u = new URL(req.url);
7
+
8
+ // Paging //
9
+ if (props.pageSize) {
10
+ u.searchParams.append('skip', props.pageSize * (props.currPage - 1));
11
+ u.searchParams.append('top', props.pageSize);
12
+ }
13
+
14
+ // Search //
15
+ if (props.search)
16
+ u.searchParams.append('search', props.search);
17
+
18
+ // Sort //
19
+ if (props.sort && props.sort.length > 0) {
20
+ u.searchParams.append('orderby', props.sort.map(m => { let n = { index: -1, name: '' }; if (Object.prototype.hasOwnProperty.call(m, 'index')) { n.index = m.index } else { n.name = m.name }; return n; }).map(m => { return (m.index > -1 ? props.cols[m.index].name : m.name) }));
21
+ //u.searchParams.append('orderdir', );
22
+ };
23
+
24
+ let r = null;
25
+ if (events.onfetch && typeof events.onfetch == 'function')
26
+ r = events.onfetch(new Request(u, req))
27
+ else
28
+ r = new Request(u, req);
29
+
30
+ return get(r);
31
+ }
32
+ }
33
+ }