@itrocks/list 0.1.2 → 0.1.3
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/cjs/feed.d.ts +13 -0
- package/cjs/feed.js +27 -0
- package/cjs/list.d.ts +2 -1
- package/cjs/list.js +7 -11
- package/package.json +1 -1
package/cjs/feed.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Option } from '@itrocks/storage';
|
|
2
|
+
import { Request } from '@itrocks/request-response';
|
|
3
|
+
export declare class Feed {
|
|
4
|
+
static DEFAULT_LIMIT: number;
|
|
5
|
+
static DEFAULT_LINE_HEIGHT: number;
|
|
6
|
+
static DEFAULT_OFFSET: number;
|
|
7
|
+
limit: number;
|
|
8
|
+
lineHeight: number;
|
|
9
|
+
offset: number;
|
|
10
|
+
template: string;
|
|
11
|
+
getParams(request: Request): void;
|
|
12
|
+
readOptions(options: Array<Option>): Option[];
|
|
13
|
+
}
|
package/cjs/feed.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Feed = void 0;
|
|
4
|
+
const storage_1 = require("@itrocks/storage");
|
|
5
|
+
class Feed {
|
|
6
|
+
static DEFAULT_LIMIT = 50;
|
|
7
|
+
static DEFAULT_LINE_HEIGHT = 30;
|
|
8
|
+
static DEFAULT_OFFSET = 0;
|
|
9
|
+
limit = Feed.DEFAULT_LIMIT;
|
|
10
|
+
lineHeight = Feed.DEFAULT_LINE_HEIGHT;
|
|
11
|
+
offset = Feed.DEFAULT_OFFSET;
|
|
12
|
+
template = __dirname + '/feed.html';
|
|
13
|
+
getParams(request) {
|
|
14
|
+
const header = request.headers['xhr-info'];
|
|
15
|
+
const xhrInfo = header ? JSON.parse(header) : {};
|
|
16
|
+
this.limit = xhrInfo.targetHeight
|
|
17
|
+
? Math.ceil(xhrInfo.targetHeight / this.lineHeight)
|
|
18
|
+
: (xhrInfo.visibleRows ?? Feed.DEFAULT_LIMIT);
|
|
19
|
+
this.offset = +request.data.offset;
|
|
20
|
+
}
|
|
21
|
+
readOptions(options) {
|
|
22
|
+
options.push(new storage_1.Limit(this.limit, this.offset));
|
|
23
|
+
return options;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Feed = Feed;
|
|
27
|
+
//# sourceMappingURL=feed.js.map
|
package/cjs/list.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Action } from '@itrocks/action';
|
|
2
2
|
import { Request } from '@itrocks/action-request';
|
|
3
|
+
import { Feed } from './feed';
|
|
3
4
|
export declare class List<T extends object = object> extends Action<T> {
|
|
4
|
-
|
|
5
|
+
feed: Feed;
|
|
5
6
|
html(request: Request<T>): Promise<import("@itrocks/core-responses").HtmlResponse>;
|
|
6
7
|
json(request: Request<T>): Promise<import("@itrocks/core-responses").JsonResponse>;
|
|
7
8
|
}
|
package/cjs/list.js
CHANGED
|
@@ -42,7 +42,7 @@ const route_1 = require("@itrocks/route");
|
|
|
42
42
|
const route_2 = require("@itrocks/route");
|
|
43
43
|
const storage_1 = require("@itrocks/storage");
|
|
44
44
|
const storage_2 = require("@itrocks/storage");
|
|
45
|
-
const
|
|
45
|
+
const feed_1 = require("./feed");
|
|
46
46
|
let List = (() => {
|
|
47
47
|
let _classDecorators = [(0, action_3.Need)('Store', 'new'), (0, route_1.Route)('/list')];
|
|
48
48
|
let _classDescriptor;
|
|
@@ -58,18 +58,14 @@ let List = (() => {
|
|
|
58
58
|
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
59
59
|
__runInitializers(_classThis, _classExtraInitializers);
|
|
60
60
|
}
|
|
61
|
-
|
|
61
|
+
feed = new feed_1.Feed;
|
|
62
62
|
async html(request) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const limit = xhrInfo.targetHeight
|
|
66
|
-
? Math.ceil(xhrInfo.targetHeight / this.lineHeight)
|
|
67
|
-
: (xhrInfo.visibleRows ?? 50);
|
|
68
|
-
const offset = request.request.data.offset;
|
|
63
|
+
const feed = this.feed;
|
|
64
|
+
feed.getParams(request.request);
|
|
69
65
|
const type = request.type;
|
|
70
|
-
const objects = await (0, storage_1.dataSource)().readAll(type, [
|
|
71
|
-
if (offset
|
|
72
|
-
return this.htmlTemplateResponse({ objects, type }, request,
|
|
66
|
+
const objects = await (0, storage_1.dataSource)().readAll(type, feed.readOptions([storage_2.Sort]));
|
|
67
|
+
if (feed.offset) {
|
|
68
|
+
return this.htmlTemplateResponse({ objects, type }, request, feed.template);
|
|
73
69
|
}
|
|
74
70
|
const count = await (0, storage_1.dataSource)().count(type);
|
|
75
71
|
const route = (0, route_2.routeOf)(this);
|
package/package.json
CHANGED