@olenbetong/appframe-core 1.1.1 → 1.2.2
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/dist/esm/af.common.js +153 -1
- package/dist/esm/af.common.min.js +6 -6
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +150 -1
- package/dist/iife/af.common.min.js +6 -6
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/downloadBlob.d.ts +1 -0
- package/es/downloadBlob.js +21 -0
- package/es/downloadRequest.d.ts +11 -0
- package/es/downloadRequest.js +59 -0
- package/es/exportDataObject.d.ts +89 -0
- package/es/exportDataObject.js +61 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +4 -1
- package/package.json +2 -2
- package/src/downloadBlob.ts +21 -0
- package/src/downloadRequest.ts +82 -0
- package/src/exportDataObject.ts +110 -0
- package/src/index.ts +3 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { DataObject, DataObjectOptions } from "@olenbetong/appframe-data";
|
|
2
|
+
import { RetrieveParameters } from "@olenbetong/appframe-data";
|
|
3
|
+
export declare type DataExportColumn = {
|
|
4
|
+
name: string;
|
|
5
|
+
caption?: string;
|
|
6
|
+
cellFormat?: string;
|
|
7
|
+
format?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare type DataExportOptions = RetrieveParameters<any> & {
|
|
10
|
+
columns: DataExportColumn[];
|
|
11
|
+
};
|
|
12
|
+
export declare type DataObjectReportParams = {
|
|
13
|
+
articleId: string;
|
|
14
|
+
controller?: AbortController;
|
|
15
|
+
dataObject: string;
|
|
16
|
+
format: "pdf" | "xlsx" | "csv" | "xls";
|
|
17
|
+
fileName?: string;
|
|
18
|
+
options: DataExportOptions;
|
|
19
|
+
id?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
subTitle?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Whether the title should be shown in the exported file (default true)
|
|
24
|
+
*/
|
|
25
|
+
includeTitle?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the filter should be shown in the exported file (default true)
|
|
28
|
+
*/
|
|
29
|
+
includefilter?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Whether we should try to convert from camelCase to human readable names (default true)
|
|
32
|
+
*/
|
|
33
|
+
formatHeaders?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Whether the header should be frozen on top of the excel file.
|
|
36
|
+
*/
|
|
37
|
+
freezeHeader?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get columns and retrieve parameters from a data object to be used to create a report.
|
|
41
|
+
* @param dataObject Data object to get parameters and columns from
|
|
42
|
+
* @param specifiedOptions Options to override the data object options
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export declare function exportOptionsFromDataObject(dataObject: DataObject<any>, specifiedOptions: Partial<DataObjectOptions<any>>): {
|
|
46
|
+
allowDelete?: boolean | undefined;
|
|
47
|
+
allowInsert?: boolean | undefined;
|
|
48
|
+
allowUpdate?: boolean | undefined;
|
|
49
|
+
articleId?: string | undefined;
|
|
50
|
+
dataHandler?: import("@olenbetong/appframe-data").DataHandlerDescriptor | import("@olenbetong/appframe-data").DataHandler<any> | undefined;
|
|
51
|
+
dataSourceId?: string | undefined;
|
|
52
|
+
disableAutoload?: boolean | undefined;
|
|
53
|
+
dynamicLoading?: boolean | undefined;
|
|
54
|
+
errorHandler?: ((error: string, callback?: Function | undefined) => void) | undefined;
|
|
55
|
+
fields?: import("@olenbetong/appframe-data").FieldDefinition[] | undefined;
|
|
56
|
+
groupBy?: string | number | symbol | string[] | null | undefined;
|
|
57
|
+
hasIDTrig?: boolean | undefined;
|
|
58
|
+
hasIITrig?: boolean | undefined;
|
|
59
|
+
hasIUTrig?: boolean | undefined;
|
|
60
|
+
linkFields?: (string | number | symbol)[] | Record<string | number | symbol, string> | null | undefined;
|
|
61
|
+
masterDataObject?: import("@olenbetong/appframe-data").AfDataObject<any> | null | undefined;
|
|
62
|
+
optimisticLocking?: boolean | undefined;
|
|
63
|
+
parameters?: RetrieveParameters<any> | undefined;
|
|
64
|
+
selectFirstRow?: boolean | undefined;
|
|
65
|
+
systemFieldNames?: Record<string, string | number | symbol> | undefined;
|
|
66
|
+
strict?: boolean | undefined;
|
|
67
|
+
timeout?: number | undefined;
|
|
68
|
+
uniqueIdField?: string | number | symbol | undefined;
|
|
69
|
+
columns: {
|
|
70
|
+
name: string;
|
|
71
|
+
}[];
|
|
72
|
+
distinctRows: boolean | undefined;
|
|
73
|
+
filterObject: import("@olenbetong/appframe-data").Filter | undefined;
|
|
74
|
+
filterString: string | undefined;
|
|
75
|
+
maxRecords: number | undefined;
|
|
76
|
+
sortOrder: Record<string | number | symbol, import("@olenbetong/appframe-data").SortOrder>[] | undefined;
|
|
77
|
+
whereClause: string | undefined;
|
|
78
|
+
whereObject: import("@olenbetong/appframe-data").Filter | undefined;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Get a request object to download a report from a data object.
|
|
82
|
+
* @param params Parameters to use to create a report
|
|
83
|
+
* @returns Request object for the report
|
|
84
|
+
*/
|
|
85
|
+
export declare function getDataObjectReportRequest(params: DataObjectReportParams): {
|
|
86
|
+
controller: AbortController;
|
|
87
|
+
request: Request;
|
|
88
|
+
};
|
|
89
|
+
export declare function openDataObjectReport(params: DataObjectReportParams): Promise<void>;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { downloadRequest } from "./downloadRequest.js";
|
|
2
|
+
/**
|
|
3
|
+
* Get columns and retrieve parameters from a data object to be used to create a report.
|
|
4
|
+
* @param dataObject Data object to get parameters and columns from
|
|
5
|
+
* @param specifiedOptions Options to override the data object options
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function exportOptionsFromDataObject(dataObject, specifiedOptions) {
|
|
9
|
+
return {
|
|
10
|
+
columns: dataObject.getFields().map((field) => ({ name: field.name })),
|
|
11
|
+
distinctRows: dataObject.getParameter("distinctRows"),
|
|
12
|
+
filterObject: dataObject.getParameter("filterObject"),
|
|
13
|
+
filterString: dataObject.getParameter("filterString"),
|
|
14
|
+
maxRecords: dataObject.getParameter("maxRecords"),
|
|
15
|
+
sortOrder: dataObject.getParameter("sortOrder"),
|
|
16
|
+
whereClause: dataObject.getParameter("whereClause"),
|
|
17
|
+
whereObject: dataObject.getParameter("whereObject"),
|
|
18
|
+
...specifiedOptions,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const defaultOptions = {
|
|
22
|
+
columns: [],
|
|
23
|
+
distinctRows: false,
|
|
24
|
+
filterObject: null,
|
|
25
|
+
filterString: "",
|
|
26
|
+
maxRecords: -1,
|
|
27
|
+
sortOrder: [],
|
|
28
|
+
whereClause: "",
|
|
29
|
+
whereObject: null,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Get a request object to download a report from a data object.
|
|
33
|
+
* @param params Parameters to use to create a report
|
|
34
|
+
* @returns Request object for the report
|
|
35
|
+
*/
|
|
36
|
+
export function getDataObjectReportRequest(params) {
|
|
37
|
+
const { articleId, dataObject, format, options } = params;
|
|
38
|
+
const reportOptions = options ? Object.assign({}, defaultOptions, options) : defaultOptions;
|
|
39
|
+
const body = "data=" + encodeURIComponent(JSON.stringify(reportOptions));
|
|
40
|
+
const requestUrl = `/api/data-object/export/${articleId}/${dataObject}/${format}`;
|
|
41
|
+
const controller = params.controller ?? new AbortController();
|
|
42
|
+
return {
|
|
43
|
+
controller,
|
|
44
|
+
request: new Request(requestUrl, {
|
|
45
|
+
body,
|
|
46
|
+
credentials: "same-origin",
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
49
|
+
},
|
|
50
|
+
method: "POST",
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
}),
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export function openDataObjectReport(params) {
|
|
56
|
+
const { dataObject, fileName, format } = params;
|
|
57
|
+
const { request } = getDataObjectReportRequest(params);
|
|
58
|
+
return downloadRequest(request, {
|
|
59
|
+
fileName: `${fileName || dataObject}.${format}`,
|
|
60
|
+
});
|
|
61
|
+
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { default as mitt } from "mitt";
|
|
2
|
+
export { downloadBlob } from "./downloadBlob.js";
|
|
3
|
+
export * from "./downloadRequest.js";
|
|
4
|
+
export * from "./exportDataObject.js";
|
|
2
5
|
export { default as expose } from "./expose.js";
|
|
3
6
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
4
7
|
export { default as localStorage } from "./localStorage.js";
|
package/es/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { default as mitt } from "mitt";
|
|
2
|
+
export { downloadBlob } from "./downloadBlob.js";
|
|
3
|
+
export * from "./downloadRequest.js";
|
|
4
|
+
export * from "./exportDataObject.js";
|
|
2
5
|
export { default as expose } from "./expose.js";
|
|
3
6
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
4
7
|
export { default as localStorage } from "./localStorage.js";
|
|
@@ -6,4 +9,4 @@ export { default as SessionHandler } from "./SessionHandler.js";
|
|
|
6
9
|
export { default as UserSession } from "./UserSession.js";
|
|
7
10
|
export { formDataToDataObjectRecord, formDataToObject, formDataToProcedureParameters } from "./formDataToObject.js";
|
|
8
11
|
export * from "./settings.js";
|
|
9
|
-
export const version = "1.
|
|
12
|
+
export const version = "1.2.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.2",
|
|
4
4
|
"description": "Javascript libraries to utilize the Appframe framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./es/index.js",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"chalk": "^5.0.1"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "110516c6cd639ad0a5d593be42bddcfba5a60cc6"
|
|
39
39
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function downloadBlob(blob: Blob | MediaSource, fileName: string) {
|
|
2
|
+
return new Promise<void>(function (resolve, reject) {
|
|
3
|
+
try {
|
|
4
|
+
const url = URL.createObjectURL(blob);
|
|
5
|
+
const parent = document.body;
|
|
6
|
+
const anchor = document.createElement("a");
|
|
7
|
+
anchor.setAttribute("download", fileName);
|
|
8
|
+
anchor.href = url;
|
|
9
|
+
parent.append(anchor);
|
|
10
|
+
anchor.click();
|
|
11
|
+
parent.removeChild(anchor);
|
|
12
|
+
|
|
13
|
+
setTimeout(function () {
|
|
14
|
+
URL.revokeObjectURL(url);
|
|
15
|
+
resolve();
|
|
16
|
+
}, 250);
|
|
17
|
+
} catch (ex) {
|
|
18
|
+
reject(ex);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { downloadBlob } from "./downloadBlob.js";
|
|
2
|
+
|
|
3
|
+
export type DownloadItem = {
|
|
4
|
+
status: "cancelled" | "error" | "requested" | "downloading" | "downloaded" | "completed";
|
|
5
|
+
bytesReceived?: number;
|
|
6
|
+
error?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type DownloadParameters = {
|
|
10
|
+
controller?: AbortController;
|
|
11
|
+
fileName: string;
|
|
12
|
+
onProgress?: (progress: DownloadItem) => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export async function downloadRequest(request: Request, { fileName, controller, onProgress }: DownloadParameters) {
|
|
16
|
+
function reportProgress(progress: DownloadItem) {
|
|
17
|
+
if (typeof onProgress === "function") {
|
|
18
|
+
onProgress({ ...progress });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let bytesReceived = 0;
|
|
23
|
+
|
|
24
|
+
reportProgress({ status: "requested" });
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
let response = await fetch(request);
|
|
28
|
+
|
|
29
|
+
if (!response.ok || !response.body) {
|
|
30
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
31
|
+
let data = await response.json();
|
|
32
|
+
if (data.error) {
|
|
33
|
+
throw new Error(data.error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw new Error(response.status + " " + response.statusText);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const reader = response.body.getReader();
|
|
41
|
+
const stream = new ReadableStream({
|
|
42
|
+
start: function (controller) {
|
|
43
|
+
function pump(): Promise<void> {
|
|
44
|
+
return reader.read().then(function (read) {
|
|
45
|
+
if (read.done) {
|
|
46
|
+
controller.close();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
bytesReceived += read.value.length;
|
|
51
|
+
reportProgress({ bytesReceived, status: "downloading" });
|
|
52
|
+
controller.enqueue(read.value);
|
|
53
|
+
|
|
54
|
+
return pump();
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return pump();
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
response = new Response(stream);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
65
|
+
console.warn("Failed to replace response stream to log download progress.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const blob = await response.blob();
|
|
69
|
+
|
|
70
|
+
reportProgress({ bytesReceived, status: "downloaded" });
|
|
71
|
+
|
|
72
|
+
await downloadBlob(blob, fileName);
|
|
73
|
+
|
|
74
|
+
reportProgress({ bytesReceived, status: "completed" });
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (controller?.signal?.aborted) {
|
|
77
|
+
reportProgress({ status: "cancelled" });
|
|
78
|
+
} else {
|
|
79
|
+
reportProgress({ error: (err as Error).message, status: "error" });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { DataObject, DataObjectOptions } from "@olenbetong/appframe-data";
|
|
2
|
+
import { RetrieveParameters } from "@olenbetong/appframe-data";
|
|
3
|
+
|
|
4
|
+
import { downloadRequest } from "./downloadRequest.js";
|
|
5
|
+
|
|
6
|
+
export type DataExportColumn = {
|
|
7
|
+
name: string;
|
|
8
|
+
caption?: string;
|
|
9
|
+
cellFormat?: string;
|
|
10
|
+
format?: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type DataExportOptions = RetrieveParameters<any> & { columns: DataExportColumn[] };
|
|
14
|
+
export type DataObjectReportParams = {
|
|
15
|
+
articleId: string;
|
|
16
|
+
controller?: AbortController;
|
|
17
|
+
dataObject: string;
|
|
18
|
+
format: "pdf" | "xlsx" | "csv" | "xls";
|
|
19
|
+
fileName?: string;
|
|
20
|
+
options: DataExportOptions;
|
|
21
|
+
id?: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
subTitle?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Whether the title should be shown in the exported file (default true)
|
|
26
|
+
*/
|
|
27
|
+
includeTitle?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether the filter should be shown in the exported file (default true)
|
|
30
|
+
*/
|
|
31
|
+
includefilter?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether we should try to convert from camelCase to human readable names (default true)
|
|
34
|
+
*/
|
|
35
|
+
formatHeaders?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether the header should be frozen on top of the excel file.
|
|
38
|
+
*/
|
|
39
|
+
freezeHeader?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Get columns and retrieve parameters from a data object to be used to create a report.
|
|
44
|
+
* @param dataObject Data object to get parameters and columns from
|
|
45
|
+
* @param specifiedOptions Options to override the data object options
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export function exportOptionsFromDataObject(
|
|
49
|
+
dataObject: DataObject<any>,
|
|
50
|
+
specifiedOptions: Partial<DataObjectOptions<any>>
|
|
51
|
+
) {
|
|
52
|
+
return {
|
|
53
|
+
columns: dataObject.getFields().map((field) => ({ name: field.name })),
|
|
54
|
+
distinctRows: dataObject.getParameter("distinctRows"),
|
|
55
|
+
filterObject: dataObject.getParameter("filterObject"),
|
|
56
|
+
filterString: dataObject.getParameter("filterString"),
|
|
57
|
+
maxRecords: dataObject.getParameter("maxRecords"),
|
|
58
|
+
sortOrder: dataObject.getParameter("sortOrder"),
|
|
59
|
+
whereClause: dataObject.getParameter("whereClause"),
|
|
60
|
+
whereObject: dataObject.getParameter("whereObject"),
|
|
61
|
+
...specifiedOptions,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const defaultOptions: DataExportOptions = {
|
|
66
|
+
columns: [],
|
|
67
|
+
distinctRows: false,
|
|
68
|
+
filterObject: null,
|
|
69
|
+
filterString: "",
|
|
70
|
+
maxRecords: -1,
|
|
71
|
+
sortOrder: [],
|
|
72
|
+
whereClause: "",
|
|
73
|
+
whereObject: null,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get a request object to download a report from a data object.
|
|
78
|
+
* @param params Parameters to use to create a report
|
|
79
|
+
* @returns Request object for the report
|
|
80
|
+
*/
|
|
81
|
+
export function getDataObjectReportRequest(params: DataObjectReportParams) {
|
|
82
|
+
const { articleId, dataObject, format, options } = params;
|
|
83
|
+
const reportOptions = options ? Object.assign({}, defaultOptions, options) : defaultOptions;
|
|
84
|
+
const body = "data=" + encodeURIComponent(JSON.stringify(reportOptions));
|
|
85
|
+
const requestUrl = `/api/data-object/export/${articleId}/${dataObject}/${format}`;
|
|
86
|
+
|
|
87
|
+
const controller = params.controller ?? new AbortController();
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
controller,
|
|
91
|
+
request: new Request(requestUrl, {
|
|
92
|
+
body,
|
|
93
|
+
credentials: "same-origin",
|
|
94
|
+
headers: {
|
|
95
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
96
|
+
},
|
|
97
|
+
method: "POST",
|
|
98
|
+
signal: controller.signal,
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function openDataObjectReport(params: DataObjectReportParams) {
|
|
104
|
+
const { dataObject, fileName, format } = params;
|
|
105
|
+
const { request } = getDataObjectReportRequest(params);
|
|
106
|
+
|
|
107
|
+
return downloadRequest(request, {
|
|
108
|
+
fileName: `${fileName || dataObject}.${format}`,
|
|
109
|
+
});
|
|
110
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export { default as mitt } from "mitt";
|
|
2
|
+
export { downloadBlob } from "./downloadBlob.js";
|
|
3
|
+
export * from "./downloadRequest.js";
|
|
4
|
+
export * from "./exportDataObject.js";
|
|
2
5
|
export { default as expose } from "./expose.js";
|
|
3
6
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
4
7
|
export { default as localStorage } from "./localStorage.js";
|