@olenbetong/appframe-core 1.3.6 → 2.0.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/dist/esm/af.common.js +204 -304
- package/dist/esm/af.common.legacy.js +206 -307
- package/dist/esm/af.common.legacy.min.js +3 -3
- package/dist/esm/af.common.legacy.min.js.map +4 -4
- package/dist/esm/af.common.min.js +5 -5
- package/dist/esm/af.common.min.js.map +4 -4
- package/dist/iife/af.common.js +204 -304
- package/dist/iife/af.common.legacy.js +206 -307
- package/dist/iife/af.common.legacy.min.js +3 -3
- package/dist/iife/af.common.legacy.min.js.map +4 -4
- package/dist/iife/af.common.min.js +5 -5
- package/dist/iife/af.common.min.js.map +4 -4
- package/es/UserSession.d.ts +5 -1
- package/es/UserSession.js +5 -1
- package/es/index.d.ts +31 -3
- package/es/index.js +3 -4
- package/package.json +2 -2
- package/src/UserSession.ts +5 -1
- package/src/index.ts +36 -3
- package/es/exportDataObject.d.ts +0 -73
- package/es/exportDataObject.js +0 -61
- package/es/formDataToObject.d.ts +0 -26
- package/es/formDataToObject.js +0 -73
- package/src/exportDataObject.ts +0 -110
- package/src/formDataToObject.ts +0 -80
- package/src/global.d.ts +0 -56
package/es/UserSession.js
CHANGED
|
@@ -3,10 +3,14 @@ export default class UserSession extends SessionHandler {
|
|
|
3
3
|
constructor(userData) {
|
|
4
4
|
super();
|
|
5
5
|
this.decimalSeparator = ".";
|
|
6
|
+
this.domain = "OB";
|
|
6
7
|
this.groupSeparator = null;
|
|
7
8
|
this.shortDateFormat = "dd.MM.yyyy";
|
|
8
|
-
this.login =
|
|
9
|
+
this.login = "";
|
|
9
10
|
this.isDeveloper = false;
|
|
11
|
+
this.culture = "en-GB";
|
|
12
|
+
this.uiculture = "en-GB";
|
|
13
|
+
this.expired = () => null;
|
|
10
14
|
this.formats = {};
|
|
11
15
|
Object.assign(this, userData);
|
|
12
16
|
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,14 +1,42 @@
|
|
|
1
1
|
import "./errorHandler.js";
|
|
2
|
+
import UserSession from "./UserSession.js";
|
|
2
3
|
export { default as mitt } from "mitt";
|
|
3
4
|
export { downloadBlob } from "./downloadBlob.js";
|
|
4
5
|
export * from "./downloadRequest.js";
|
|
5
|
-
export * from "./exportDataObject.js";
|
|
6
6
|
export { default as expose } from "./expose.js";
|
|
7
7
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
8
8
|
export * from "./has.js";
|
|
9
9
|
export { default as localStorage } from "./localStorage.js";
|
|
10
10
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
11
|
-
export {
|
|
12
|
-
export { formDataToDataObjectRecord, formDataToObject, formDataToProcedureParameters } from "./formDataToObject.js";
|
|
11
|
+
export { UserSession };
|
|
13
12
|
export * from "./settings.js";
|
|
14
13
|
export declare const version: string;
|
|
14
|
+
declare global {
|
|
15
|
+
var __VERSION__: string;
|
|
16
|
+
var __DEV__: number;
|
|
17
|
+
var af: AfCore;
|
|
18
|
+
interface Window {
|
|
19
|
+
af: AfCore;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export interface AfArticle {
|
|
23
|
+
hostName: string;
|
|
24
|
+
i18n: Record<string, string>;
|
|
25
|
+
id: string;
|
|
26
|
+
}
|
|
27
|
+
export interface AfCore {
|
|
28
|
+
article: AfArticle;
|
|
29
|
+
common?: {
|
|
30
|
+
getLocalizedString?: (string: string) => string;
|
|
31
|
+
};
|
|
32
|
+
controls?: {
|
|
33
|
+
alert?: (message: string, callback?: () => void) => void;
|
|
34
|
+
confirm?: (options: {
|
|
35
|
+
title: string;
|
|
36
|
+
message: string;
|
|
37
|
+
buttons: string[];
|
|
38
|
+
callback: (button: number) => void;
|
|
39
|
+
}) => void;
|
|
40
|
+
};
|
|
41
|
+
userSession: UserSession;
|
|
42
|
+
}
|
package/es/index.js
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import "./errorHandler.js";
|
|
2
|
+
import UserSession from "./UserSession.js";
|
|
2
3
|
export { default as mitt } from "mitt";
|
|
3
4
|
export { downloadBlob } from "./downloadBlob.js";
|
|
4
5
|
export * from "./downloadRequest.js";
|
|
5
|
-
export * from "./exportDataObject.js";
|
|
6
6
|
export { default as expose } from "./expose.js";
|
|
7
7
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
8
8
|
export * from "./has.js";
|
|
9
9
|
export { default as localStorage } from "./localStorage.js";
|
|
10
10
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
11
|
-
export {
|
|
12
|
-
export { formDataToDataObjectRecord, formDataToObject, formDataToProcedureParameters } from "./formDataToObject.js";
|
|
11
|
+
export { UserSession };
|
|
13
12
|
export * from "./settings.js";
|
|
14
|
-
export const version = "
|
|
13
|
+
export const version = "2.0.0";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Javascript libraries to utilize the Appframe framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"chalk": "^5.0.1"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "c415b5b6c68bb08712e38d9f91a01122c14e78a0"
|
|
52
52
|
}
|
package/src/UserSession.ts
CHANGED
|
@@ -2,11 +2,15 @@ import SessionHandler from "./SessionHandler.js";
|
|
|
2
2
|
|
|
3
3
|
export default class UserSession extends SessionHandler {
|
|
4
4
|
decimalSeparator: string = ".";
|
|
5
|
+
domain: string = "OB";
|
|
5
6
|
formats: any;
|
|
6
7
|
groupSeparator: string | null = null;
|
|
7
8
|
shortDateFormat: string = "dd.MM.yyyy";
|
|
8
|
-
login: string
|
|
9
|
+
login: string = "";
|
|
9
10
|
isDeveloper: boolean = false;
|
|
11
|
+
culture: string = "en-GB";
|
|
12
|
+
uiculture: string = "en-GB";
|
|
13
|
+
expired: (callback: () => void) => void = () => null;
|
|
10
14
|
|
|
11
15
|
constructor(userData: any) {
|
|
12
16
|
super();
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,49 @@
|
|
|
1
1
|
import "./errorHandler.js";
|
|
2
2
|
|
|
3
|
+
import UserSession from "./UserSession.js";
|
|
4
|
+
|
|
3
5
|
export { default as mitt } from "mitt";
|
|
4
6
|
export { downloadBlob } from "./downloadBlob.js";
|
|
5
7
|
export * from "./downloadRequest.js";
|
|
6
|
-
export * from "./exportDataObject.js";
|
|
7
8
|
export { default as expose } from "./expose.js";
|
|
8
9
|
export { getLocalizedString } from "./getLocalizedString.js";
|
|
9
10
|
export * from "./has.js";
|
|
10
11
|
export { default as localStorage } from "./localStorage.js";
|
|
11
12
|
export { default as SessionHandler } from "./SessionHandler.js";
|
|
12
|
-
export {
|
|
13
|
-
export { formDataToDataObjectRecord, formDataToObject, formDataToProcedureParameters } from "./formDataToObject.js";
|
|
13
|
+
export { UserSession };
|
|
14
14
|
export * from "./settings.js";
|
|
15
15
|
|
|
16
16
|
export const version = __VERSION__;
|
|
17
|
+
|
|
18
|
+
declare global {
|
|
19
|
+
var __VERSION__: string;
|
|
20
|
+
var __DEV__: number;
|
|
21
|
+
var af: AfCore;
|
|
22
|
+
|
|
23
|
+
interface Window {
|
|
24
|
+
af: AfCore;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface AfArticle {
|
|
29
|
+
hostName: string;
|
|
30
|
+
i18n: Record<string, string>;
|
|
31
|
+
id: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface AfCore {
|
|
35
|
+
article: AfArticle;
|
|
36
|
+
common?: {
|
|
37
|
+
getLocalizedString?: (string: string) => string;
|
|
38
|
+
};
|
|
39
|
+
controls?: {
|
|
40
|
+
alert?: (message: string, callback?: () => void) => void;
|
|
41
|
+
confirm?: (options: {
|
|
42
|
+
title: string;
|
|
43
|
+
message: string;
|
|
44
|
+
buttons: string[];
|
|
45
|
+
callback: (button: number) => void;
|
|
46
|
+
}) => void;
|
|
47
|
+
};
|
|
48
|
+
userSession: UserSession;
|
|
49
|
+
}
|
package/es/exportDataObject.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { DataObject, DataObjectOptions, FieldDefinition } 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>["parameters"] & {
|
|
46
|
-
columns: FieldDefinition[];
|
|
47
|
-
}>): {
|
|
48
|
-
distinctRows: boolean | undefined;
|
|
49
|
-
fields?: FieldDefinition[] | undefined;
|
|
50
|
-
filterObject: import("@olenbetong/appframe-data").Filter | undefined;
|
|
51
|
-
filterString: string | undefined;
|
|
52
|
-
masterChildCriteria?: Partial<any> | undefined;
|
|
53
|
-
maxRecords: number | undefined;
|
|
54
|
-
skip?: number | undefined;
|
|
55
|
-
sortOrder: Record<string | number | symbol, import("@olenbetong/appframe-data").SortOrder>[] | undefined;
|
|
56
|
-
uniqueName?: string | undefined;
|
|
57
|
-
returnTotal?: boolean | undefined;
|
|
58
|
-
whereClause: string | undefined;
|
|
59
|
-
whereObject: import("@olenbetong/appframe-data").Filter | undefined;
|
|
60
|
-
columns: {
|
|
61
|
-
name: string;
|
|
62
|
-
}[];
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Get a request object to download a report from a data object.
|
|
66
|
-
* @param params Parameters to use to create a report
|
|
67
|
-
* @returns Request object for the report
|
|
68
|
-
*/
|
|
69
|
-
export declare function getDataObjectReportRequest(params: DataObjectReportParams): {
|
|
70
|
-
controller: AbortController;
|
|
71
|
-
request: Request;
|
|
72
|
-
};
|
|
73
|
-
export declare function openDataObjectReport(params: DataObjectReportParams): Promise<void>;
|
package/es/exportDataObject.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
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/formDataToObject.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { DataObject, Procedure } from "@olenbetong/appframe-data";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an object from form data. Uses the type map passed to convert the form values to the correct type.
|
|
4
|
-
* @param form HTML form element to get form data from.
|
|
5
|
-
* @param typeMap A mapping from field name to field type
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
export declare function formDataToObject<T = any>(form: HTMLFormElement, typeMap?: Record<string, string>): Partial<T>;
|
|
9
|
-
/**
|
|
10
|
-
* Creates a partial data object record from form data. The name property is mapped
|
|
11
|
-
* to field name.
|
|
12
|
-
*
|
|
13
|
-
* @param form HTML form element to get FormData from
|
|
14
|
-
* @param dataObject Data object for which to create a record from the form data
|
|
15
|
-
* @returns {Partial<T>} Partial data object record
|
|
16
|
-
*/
|
|
17
|
-
export declare function formDataToDataObjectRecord<T>(form: HTMLFormElement, dataObject: DataObject<T>): Partial<T>;
|
|
18
|
-
/**
|
|
19
|
-
* Creates procedure parameters from form data. The name property is mapped
|
|
20
|
-
* to parameter names.
|
|
21
|
-
*
|
|
22
|
-
* @param form HTML Form element to get FormData from
|
|
23
|
-
* @param procedure Appframe Procedure to create parameters for
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
export declare function formDataToProcedureParameters<T>(form: HTMLFormElement, procedure: Procedure<T, any>): T;
|
package/es/formDataToObject.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
function getFormValue(value, type) {
|
|
2
|
-
if (value === "") {
|
|
3
|
-
return null;
|
|
4
|
-
}
|
|
5
|
-
else if (type === "number") {
|
|
6
|
-
let numValue = Number(value);
|
|
7
|
-
return isNaN(numValue) ? undefined : numValue;
|
|
8
|
-
}
|
|
9
|
-
else if (["date", "datetime", "time"].includes(type)) {
|
|
10
|
-
let dateValue = new Date(value);
|
|
11
|
-
return isNaN(dateValue.getTime()) ? undefined : dateValue;
|
|
12
|
-
}
|
|
13
|
-
else if (type === "boolean") {
|
|
14
|
-
return value.toLowerCase() === "true";
|
|
15
|
-
}
|
|
16
|
-
else if (type === "bigint") {
|
|
17
|
-
return BigInt(value);
|
|
18
|
-
}
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Creates an object from form data. Uses the type map passed to convert the form values to the correct type.
|
|
23
|
-
* @param form HTML form element to get form data from.
|
|
24
|
-
* @param typeMap A mapping from field name to field type
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
export function formDataToObject(form, typeMap = {}) {
|
|
28
|
-
let formData = new FormData(form);
|
|
29
|
-
let result = {};
|
|
30
|
-
for (let entry of formData.entries()) {
|
|
31
|
-
let field = entry[0];
|
|
32
|
-
let type = typeMap?.[field] ?? "string";
|
|
33
|
-
let value = getFormValue(entry[1], type);
|
|
34
|
-
if (result.hasOwnProperty(field)) {
|
|
35
|
-
if (Array.isArray(result[field])) {
|
|
36
|
-
result[field].push(value);
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
result[field] = [result[field], value];
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
result[field] = value;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return result;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Creates a partial data object record from form data. The name property is mapped
|
|
50
|
-
* to field name.
|
|
51
|
-
*
|
|
52
|
-
* @param form HTML form element to get FormData from
|
|
53
|
-
* @param dataObject Data object for which to create a record from the form data
|
|
54
|
-
* @returns {Partial<T>} Partial data object record
|
|
55
|
-
*/
|
|
56
|
-
export function formDataToDataObjectRecord(form, dataObject) {
|
|
57
|
-
let fields = dataObject.getFields();
|
|
58
|
-
let types = Object.fromEntries(fields.map((field) => [field.name, field.type]));
|
|
59
|
-
return formDataToObject(form, types);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Creates procedure parameters from form data. The name property is mapped
|
|
63
|
-
* to parameter names.
|
|
64
|
-
*
|
|
65
|
-
* @param form HTML Form element to get FormData from
|
|
66
|
-
* @param procedure Appframe Procedure to create parameters for
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
export function formDataToProcedureParameters(form, procedure) {
|
|
70
|
-
let parameters = procedure.getParameters();
|
|
71
|
-
let types = Object.fromEntries(parameters.map((param) => [param.name, param.type]));
|
|
72
|
-
return formDataToObject(form, types);
|
|
73
|
-
}
|
package/src/exportDataObject.ts
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { DataObject, DataObjectOptions, FieldDefinition } 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>["parameters"] & { columns: FieldDefinition[] }>
|
|
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/formDataToObject.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import type { DataObject, Procedure } from "@olenbetong/appframe-data";
|
|
2
|
-
|
|
3
|
-
function getFormValue(value: string, type: string): string | number | boolean | Date | BigInt | null | undefined {
|
|
4
|
-
if (value === "") {
|
|
5
|
-
return null;
|
|
6
|
-
} else if (type === "number") {
|
|
7
|
-
let numValue = Number(value);
|
|
8
|
-
|
|
9
|
-
return isNaN(numValue) ? undefined : numValue;
|
|
10
|
-
} else if (["date", "datetime", "time"].includes(type)) {
|
|
11
|
-
let dateValue = new Date(value);
|
|
12
|
-
|
|
13
|
-
return isNaN(dateValue.getTime()) ? undefined : dateValue;
|
|
14
|
-
} else if (type === "boolean") {
|
|
15
|
-
return value.toLowerCase() === "true";
|
|
16
|
-
} else if (type === "bigint") {
|
|
17
|
-
return BigInt(value);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return value;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Creates an object from form data. Uses the type map passed to convert the form values to the correct type.
|
|
25
|
-
* @param form HTML form element to get form data from.
|
|
26
|
-
* @param typeMap A mapping from field name to field type
|
|
27
|
-
* @returns
|
|
28
|
-
*/
|
|
29
|
-
export function formDataToObject<T = any>(form: HTMLFormElement, typeMap: Record<string, string> = {}): Partial<T> {
|
|
30
|
-
let formData = new FormData(form);
|
|
31
|
-
let result: any = {};
|
|
32
|
-
|
|
33
|
-
for (let entry of formData.entries()) {
|
|
34
|
-
let field = entry[0];
|
|
35
|
-
let type = typeMap?.[field] ?? "string";
|
|
36
|
-
let value = getFormValue(entry[1] as string, type);
|
|
37
|
-
|
|
38
|
-
if (result.hasOwnProperty(field)) {
|
|
39
|
-
if (Array.isArray(result[field])) {
|
|
40
|
-
result[field].push(value);
|
|
41
|
-
} else {
|
|
42
|
-
result[field] = [result[field], value];
|
|
43
|
-
}
|
|
44
|
-
} else {
|
|
45
|
-
result[field] = value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return result as T;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Creates a partial data object record from form data. The name property is mapped
|
|
54
|
-
* to field name.
|
|
55
|
-
*
|
|
56
|
-
* @param form HTML form element to get FormData from
|
|
57
|
-
* @param dataObject Data object for which to create a record from the form data
|
|
58
|
-
* @returns {Partial<T>} Partial data object record
|
|
59
|
-
*/
|
|
60
|
-
export function formDataToDataObjectRecord<T>(form: HTMLFormElement, dataObject: DataObject<T>): Partial<T> {
|
|
61
|
-
let fields = dataObject.getFields();
|
|
62
|
-
let types = Object.fromEntries(fields.map((field) => [field.name, field.type])) as Record<string, string>;
|
|
63
|
-
|
|
64
|
-
return formDataToObject<T>(form, types);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Creates procedure parameters from form data. The name property is mapped
|
|
69
|
-
* to parameter names.
|
|
70
|
-
*
|
|
71
|
-
* @param form HTML Form element to get FormData from
|
|
72
|
-
* @param procedure Appframe Procedure to create parameters for
|
|
73
|
-
* @returns
|
|
74
|
-
*/
|
|
75
|
-
export function formDataToProcedureParameters<T>(form: HTMLFormElement, procedure: Procedure<T, any>): T {
|
|
76
|
-
let parameters = procedure.getParameters();
|
|
77
|
-
let types = Object.fromEntries(parameters.map((param) => [param.name, param.type])) as Record<string, string>;
|
|
78
|
-
|
|
79
|
-
return formDataToObject(form, types) as T;
|
|
80
|
-
}
|
package/src/global.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AfDataObject,
|
|
3
|
-
DataHandler,
|
|
4
|
-
DataObject,
|
|
5
|
-
Procedure,
|
|
6
|
-
ProcedureAPI,
|
|
7
|
-
} from "@olenbetong/appframe-data";
|
|
8
|
-
import UserSession from "./UserSession.js";
|
|
9
|
-
|
|
10
|
-
export type Appframe = {
|
|
11
|
-
article: {
|
|
12
|
-
dataObjects?: Record<string, DataObject<any>>;
|
|
13
|
-
i18n: Record<string, string>;
|
|
14
|
-
id: string;
|
|
15
|
-
hostName: string;
|
|
16
|
-
};
|
|
17
|
-
common?: {
|
|
18
|
-
getLocalizedString?: (string: string) => string;
|
|
19
|
-
};
|
|
20
|
-
controls?: {
|
|
21
|
-
alert?: (message: string, callback?: () => void) => void;
|
|
22
|
-
confirm?: (options: {
|
|
23
|
-
title: string;
|
|
24
|
-
message: string;
|
|
25
|
-
buttons: string[];
|
|
26
|
-
callback: (button: number) => void;
|
|
27
|
-
}) => void;
|
|
28
|
-
};
|
|
29
|
-
data?: {
|
|
30
|
-
[index: string]: { new (options?: any): DataHandler<any> };
|
|
31
|
-
} & { version?: string };
|
|
32
|
-
DataObject?: {
|
|
33
|
-
new <T>(options: any): DataObject<T>;
|
|
34
|
-
getByID?: (name: string) => AfDataObject<unknown> | null;
|
|
35
|
-
};
|
|
36
|
-
Procedure?: { new <T, V>(options: any): Procedure<T, V> };
|
|
37
|
-
ProcedureAPI?: { new <T, V>(options: any): ProcedureAPI<T, V> };
|
|
38
|
-
userSession: UserSession;
|
|
39
|
-
template: {
|
|
40
|
-
loop: (template: string, data: any, custom?: any) => string;
|
|
41
|
-
run: (template: string, row: any, custom?: any) => string;
|
|
42
|
-
run2: (
|
|
43
|
-
template: string,
|
|
44
|
-
currentRow: any,
|
|
45
|
-
previousRow?: any,
|
|
46
|
-
state?: any,
|
|
47
|
-
custom?: any
|
|
48
|
-
) => string;
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
declare global {
|
|
53
|
-
var __VERSION__: string;
|
|
54
|
-
var __DEV__: number;
|
|
55
|
-
var af: Appframe;
|
|
56
|
-
}
|