@itrocks/core-transformers 0.0.3 → 0.0.4
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/collection-type.d.ts +2 -0
- package/cjs/collection-type.js +10 -6
- package/cjs/primitive.d.ts +2 -0
- package/cjs/primitive.js +19 -9
- package/cjs/store.d.ts +2 -0
- package/cjs/store.js +21 -16
- package/esm/collection-type.d.ts +2 -0
- package/esm/collection-type.js +10 -6
- package/esm/primitive.d.ts +2 -0
- package/esm/primitive.js +19 -9
- package/esm/store.d.ts +2 -0
- package/esm/store.js +21 -16
- package/package.json +1 -1
package/cjs/collection-type.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { AnyObject } from '@itrocks/class-type';
|
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
3
|
export type Dependencies = {
|
|
4
4
|
displayOf: (object: AnyObject, property: string) => string;
|
|
5
|
+
fieldNameOf: (property: string) => string;
|
|
6
|
+
fieldIdOf: (property: string) => string;
|
|
5
7
|
ignoreTransformedValue: any;
|
|
6
8
|
representativeValueOf: (object: object) => string;
|
|
7
9
|
routeOf: (type: Type) => string;
|
package/cjs/collection-type.js
CHANGED
|
@@ -15,6 +15,8 @@ const transformer_2 = require("@itrocks/transformer");
|
|
|
15
15
|
const transformer_3 = require("@itrocks/transformer");
|
|
16
16
|
const depends = {
|
|
17
17
|
displayOf: (_object, property) => property,
|
|
18
|
+
fieldNameOf: property => property,
|
|
19
|
+
fieldIdOf: property => property,
|
|
18
20
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
19
21
|
representativeValueOf: object => (0, class_type_1.baseType)((0, class_type_2.typeOf)(object)).name,
|
|
20
22
|
routeOf: type => '/' + (0, class_type_1.baseType)(type).name,
|
|
@@ -22,19 +24,21 @@ const depends = {
|
|
|
22
24
|
};
|
|
23
25
|
const areMayEntityEntries = (entries) => (typeof entries[0]?.[1])[0] === 'o';
|
|
24
26
|
function collectionEdit(values, object, property) {
|
|
27
|
+
const fieldId = depends.fieldIdOf(property);
|
|
28
|
+
const fieldName = depends.fieldNameOf(property);
|
|
25
29
|
const propertyType = new reflect_2.ReflectProperty(object, property).collectionType;
|
|
26
30
|
const fetch = depends.routeOf(propertyType?.elementType) + '/summary';
|
|
27
|
-
const label = `<label for="${
|
|
31
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(object, property))}</label>`;
|
|
28
32
|
const inputs = [];
|
|
29
33
|
for (const object of values) {
|
|
30
34
|
const attrValue = `value="${depends.representativeValueOf(object)}"`;
|
|
31
35
|
inputs.push('<li>' + ((0, storage_1.dataSource)().isObjectConnected(object)
|
|
32
|
-
? `<input id="${
|
|
33
|
-
: `<input id="${
|
|
36
|
+
? `<input id="${fieldId}.${object.id}" name="${fieldName}.${object.id}" ${attrValue}>`
|
|
37
|
+
: `<input id="${fieldId}." name="${fieldName}." ${attrValue}>`) + '</li>');
|
|
34
38
|
}
|
|
35
39
|
return label + `<ul data-multiple-contained-auto-width data-fetch="${fetch}" data-type="objects">`
|
|
36
40
|
+ inputs.join('')
|
|
37
|
-
+ `<li><input id="${
|
|
41
|
+
+ `<li><input id="${fieldId}" name="${fieldName}" placeholder="+"></li>`
|
|
38
42
|
+ '</ul>';
|
|
39
43
|
}
|
|
40
44
|
function collectionInput(values, object, property) {
|
|
@@ -44,7 +48,7 @@ function collectionInput(values, object, property) {
|
|
|
44
48
|
}
|
|
45
49
|
else {
|
|
46
50
|
delete object[property];
|
|
47
|
-
Object.assign(object, { [property + '
|
|
51
|
+
Object.assign(object, { [property + 'Ids']: Object.keys(values).map(id => +id) });
|
|
48
52
|
}
|
|
49
53
|
return depends.ignoreTransformedValue;
|
|
50
54
|
}
|
|
@@ -74,7 +78,7 @@ function collectionOutput(values, object, property, askFor) {
|
|
|
74
78
|
}
|
|
75
79
|
async function collectionSave(values, object, property) {
|
|
76
80
|
const dao = (0, storage_1.dataSource)();
|
|
77
|
-
const newIdsPromise = object[property + '
|
|
81
|
+
const newIdsPromise = object[property + 'Ids']
|
|
78
82
|
?? values?.map(async (value) => (dao.isObjectConnected(value) ? value : await dao.save(value)).id).sort()
|
|
79
83
|
?? [];
|
|
80
84
|
const previousIdsPromise = dao.isObjectConnected(object)
|
package/cjs/primitive.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AnyObject } from '@itrocks/class-type';
|
|
2
2
|
export type CoreDependencies = {
|
|
3
3
|
displayOf: (object: AnyObject, property: string) => string;
|
|
4
|
+
fieldIdOf: (property: string) => string;
|
|
5
|
+
fieldNameOf: (property: string) => string;
|
|
4
6
|
tr: (text: string) => string;
|
|
5
7
|
};
|
|
6
8
|
export type Dependencies = CoreDependencies & {
|
package/cjs/primitive.js
CHANGED
|
@@ -16,6 +16,8 @@ const lfTab = '\n\t\t\t\t';
|
|
|
16
16
|
const depends = {
|
|
17
17
|
displayOf: (_object, property) => property,
|
|
18
18
|
formatDate: date => date.toString(),
|
|
19
|
+
fieldIdOf: property => property,
|
|
20
|
+
fieldNameOf: property => property,
|
|
19
21
|
parseDate: date => new Date(date),
|
|
20
22
|
tr: text => text
|
|
21
23
|
};
|
|
@@ -27,9 +29,11 @@ function initBigintHtmlTransformers() {
|
|
|
27
29
|
}
|
|
28
30
|
// Boolean
|
|
29
31
|
function booleanEdit(value, type, property) {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
32
|
+
const fieldId = depends.fieldIdOf(property);
|
|
33
|
+
const fieldName = depends.fieldNameOf(property);
|
|
34
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
35
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
36
|
+
const hidden = `<input name="${fieldName}" type="hidden" value="0">`;
|
|
33
37
|
const checked = value ? 'checked ' : '';
|
|
34
38
|
const checkbox = `<input ${checked}${name} type="checkbox" value="1">`;
|
|
35
39
|
return label + lfTab + hidden + lfTab + checkbox;
|
|
@@ -50,8 +54,10 @@ function initBooleanSqlTransformers() {
|
|
|
50
54
|
}
|
|
51
55
|
// Date
|
|
52
56
|
function dateEdit(value, type, property) {
|
|
53
|
-
const
|
|
54
|
-
const
|
|
57
|
+
const fieldId = depends.fieldIdOf(property);
|
|
58
|
+
const fieldName = depends.fieldNameOf(property);
|
|
59
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
60
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
55
61
|
const inputValue = value ? ` value="${depends.formatDate(value)}"` : '';
|
|
56
62
|
const input = `<input data-type="date" ${name}${inputValue}>`;
|
|
57
63
|
return label + lfTab + input;
|
|
@@ -67,8 +73,10 @@ function initDateHtmlTransformers() {
|
|
|
67
73
|
}
|
|
68
74
|
// Number
|
|
69
75
|
function numberEdit(value, type, property) {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
76
|
+
const fieldId = depends.fieldIdOf(property);
|
|
77
|
+
const fieldName = depends.fieldNameOf(property);
|
|
78
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
79
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
72
80
|
const inputValue = (value !== undefined) ? ` value="${value}"` : '';
|
|
73
81
|
const input = `<input data-type="number" ${name}${inputValue}>`;
|
|
74
82
|
return label + lfTab + input;
|
|
@@ -81,8 +89,10 @@ function initNumberHtmlTransformers() {
|
|
|
81
89
|
}
|
|
82
90
|
// default
|
|
83
91
|
function defaultEdit(value, type, property) {
|
|
84
|
-
const
|
|
85
|
-
const
|
|
92
|
+
const fieldId = depends.fieldIdOf(property);
|
|
93
|
+
const fieldName = depends.fieldNameOf(property);
|
|
94
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
95
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
86
96
|
const inputValue = value ? ` value="${value}"` : '';
|
|
87
97
|
const input = `<input ${name}${inputValue}>`;
|
|
88
98
|
return label + lfTab + input;
|
package/cjs/store.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type SqlDependencies = {
|
|
|
5
5
|
};
|
|
6
6
|
export type Dependencies = SqlDependencies & {
|
|
7
7
|
displayOf: (object: AnyObject, property: string) => string;
|
|
8
|
+
fieldOf: (property: string) => string;
|
|
9
|
+
idOf: (property: string) => string;
|
|
8
10
|
representativeValueOf: (object: object) => string;
|
|
9
11
|
routeOf: (type: Type) => string;
|
|
10
12
|
tr: (text: string) => string;
|
package/cjs/store.js
CHANGED
|
@@ -14,6 +14,8 @@ const transformer_3 = require("@itrocks/transformer");
|
|
|
14
14
|
const lfTab = '\n\t\t\t\t';
|
|
15
15
|
const depends = {
|
|
16
16
|
displayOf: (_object, property) => property,
|
|
17
|
+
fieldOf: property => property,
|
|
18
|
+
idOf: property => property,
|
|
17
19
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
18
20
|
representativeValueOf: object => (0, class_type_1.baseType)((0, class_type_1.typeOf)(object)).name,
|
|
19
21
|
routeOf: type => '/' + (0, class_type_1.baseType)(type).name,
|
|
@@ -37,38 +39,41 @@ function setStoreDependencies(dependencies) {
|
|
|
37
39
|
exports.setStoreHtmlDependencies = setStoreDependencies;
|
|
38
40
|
exports.setStoreSqlDependencies = setStoreDependencies;
|
|
39
41
|
function storeEdit(value, object, property) {
|
|
42
|
+
const fieldName = depends.fieldOf(property);
|
|
43
|
+
const fieldId = depends.idOf(property);
|
|
40
44
|
const propertyType = new reflect_1.ReflectProperty(object, property).type;
|
|
41
|
-
const
|
|
45
|
+
const textValue = value ? depends.representativeValueOf(value) : '';
|
|
42
46
|
const fetch = depends.routeOf(propertyType) + '/summary';
|
|
43
|
-
const label = `<label for="${
|
|
44
|
-
const name = `id="${
|
|
45
|
-
const inputValue =
|
|
47
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(object, property))}</label>`;
|
|
48
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
49
|
+
const inputValue = (textValue === '') ? '' : ` value="${textValue}"`;
|
|
46
50
|
const input = `<input data-fetch="${fetch}" data-type="object" ${name}${inputValue}>`;
|
|
47
|
-
const
|
|
48
|
-
return label + lfTab + input +
|
|
51
|
+
const inputId = `<input id="${fieldId}-id" name="${fieldName}_id" type="hidden" value="${value?.id}">`;
|
|
52
|
+
return label + lfTab + input + inputId;
|
|
49
53
|
}
|
|
50
54
|
function storeInput(value, object, property, data) {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const propertyId = property + 'Id';
|
|
56
|
+
const fieldId = depends.fieldOf(propertyId);
|
|
57
|
+
if ((fieldId in data)
|
|
58
|
+
&& ((propertyId in object)
|
|
59
|
+
? (data[fieldId] !== object[propertyId] + '')
|
|
60
|
+
: (data[fieldId] !== value?.id + ''))) {
|
|
56
61
|
delete object[property];
|
|
57
|
-
Object.assign(object, { [
|
|
62
|
+
Object.assign(object, { [propertyId]: +data[fieldId] });
|
|
58
63
|
}
|
|
59
64
|
return depends.ignoreTransformedValue;
|
|
60
65
|
}
|
|
61
66
|
function storeOutput(value) {
|
|
62
67
|
return value ? depends.representativeValueOf(value) : '';
|
|
63
68
|
}
|
|
64
|
-
async function storeSave(value, _object, property,
|
|
69
|
+
async function storeSave(value, _object, property, record) {
|
|
65
70
|
const dao = (0, storage_1.dataSource)();
|
|
66
71
|
if (value && !dao.isObjectConnected(value)) {
|
|
67
72
|
await dao.save(value);
|
|
68
73
|
}
|
|
69
|
-
const
|
|
70
|
-
const id = (value && dao.isObjectConnected(value)) ? value.id :
|
|
71
|
-
|
|
74
|
+
const columnId = property + '_id';
|
|
75
|
+
const id = (value && dao.isObjectConnected(value)) ? value.id : record[columnId];
|
|
76
|
+
record[columnId] = id ?? null;
|
|
72
77
|
return depends.ignoreTransformedValue;
|
|
73
78
|
}
|
|
74
79
|
//# sourceMappingURL=store.js.map
|
package/esm/collection-type.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { AnyObject } from '@itrocks/class-type';
|
|
|
2
2
|
import { Type } from '@itrocks/class-type';
|
|
3
3
|
export type Dependencies = {
|
|
4
4
|
displayOf: (object: AnyObject, property: string) => string;
|
|
5
|
+
fieldNameOf: (property: string) => string;
|
|
6
|
+
fieldIdOf: (property: string) => string;
|
|
5
7
|
ignoreTransformedValue: any;
|
|
6
8
|
representativeValueOf: (object: object) => string;
|
|
7
9
|
routeOf: (type: Type) => string;
|
package/esm/collection-type.js
CHANGED
|
@@ -10,6 +10,8 @@ import { INPUT, OUTPUT, SAVE, SQL } from '@itrocks/transformer';
|
|
|
10
10
|
import { setPropertyTypeTransformer } from '@itrocks/transformer';
|
|
11
11
|
const depends = {
|
|
12
12
|
displayOf: (_object, property) => property,
|
|
13
|
+
fieldNameOf: property => property,
|
|
14
|
+
fieldIdOf: property => property,
|
|
13
15
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
14
16
|
representativeValueOf: object => baseType(typeOf(object)).name,
|
|
15
17
|
routeOf: type => '/' + baseType(type).name,
|
|
@@ -17,19 +19,21 @@ const depends = {
|
|
|
17
19
|
};
|
|
18
20
|
const areMayEntityEntries = (entries) => (typeof entries[0]?.[1])[0] === 'o';
|
|
19
21
|
function collectionEdit(values, object, property) {
|
|
22
|
+
const fieldId = depends.fieldIdOf(property);
|
|
23
|
+
const fieldName = depends.fieldNameOf(property);
|
|
20
24
|
const propertyType = new ReflectProperty(object, property).collectionType;
|
|
21
25
|
const fetch = depends.routeOf(propertyType?.elementType) + '/summary';
|
|
22
|
-
const label = `<label for="${
|
|
26
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(object, property))}</label>`;
|
|
23
27
|
const inputs = [];
|
|
24
28
|
for (const object of values) {
|
|
25
29
|
const attrValue = `value="${depends.representativeValueOf(object)}"`;
|
|
26
30
|
inputs.push('<li>' + (dataSource().isObjectConnected(object)
|
|
27
|
-
? `<input id="${
|
|
28
|
-
: `<input id="${
|
|
31
|
+
? `<input id="${fieldId}.${object.id}" name="${fieldName}.${object.id}" ${attrValue}>`
|
|
32
|
+
: `<input id="${fieldId}." name="${fieldName}." ${attrValue}>`) + '</li>');
|
|
29
33
|
}
|
|
30
34
|
return label + `<ul data-multiple-contained-auto-width data-fetch="${fetch}" data-type="objects">`
|
|
31
35
|
+ inputs.join('')
|
|
32
|
-
+ `<li><input id="${
|
|
36
|
+
+ `<li><input id="${fieldId}" name="${fieldName}" placeholder="+"></li>`
|
|
33
37
|
+ '</ul>';
|
|
34
38
|
}
|
|
35
39
|
function collectionInput(values, object, property) {
|
|
@@ -39,7 +43,7 @@ function collectionInput(values, object, property) {
|
|
|
39
43
|
}
|
|
40
44
|
else {
|
|
41
45
|
delete object[property];
|
|
42
|
-
Object.assign(object, { [property + '
|
|
46
|
+
Object.assign(object, { [property + 'Ids']: Object.keys(values).map(id => +id) });
|
|
43
47
|
}
|
|
44
48
|
return depends.ignoreTransformedValue;
|
|
45
49
|
}
|
|
@@ -69,7 +73,7 @@ function collectionOutput(values, object, property, askFor) {
|
|
|
69
73
|
}
|
|
70
74
|
async function collectionSave(values, object, property) {
|
|
71
75
|
const dao = dataSource();
|
|
72
|
-
const newIdsPromise = object[property + '
|
|
76
|
+
const newIdsPromise = object[property + 'Ids']
|
|
73
77
|
?? values?.map(async (value) => (dao.isObjectConnected(value) ? value : await dao.save(value)).id).sort()
|
|
74
78
|
?? [];
|
|
75
79
|
const previousIdsPromise = dao.isObjectConnected(object)
|
package/esm/primitive.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AnyObject } from '@itrocks/class-type';
|
|
2
2
|
export type CoreDependencies = {
|
|
3
3
|
displayOf: (object: AnyObject, property: string) => string;
|
|
4
|
+
fieldIdOf: (property: string) => string;
|
|
5
|
+
fieldNameOf: (property: string) => string;
|
|
4
6
|
tr: (text: string) => string;
|
|
5
7
|
};
|
|
6
8
|
export type Dependencies = CoreDependencies & {
|
package/esm/primitive.js
CHANGED
|
@@ -5,6 +5,8 @@ const lfTab = '\n\t\t\t\t';
|
|
|
5
5
|
const depends = {
|
|
6
6
|
displayOf: (_object, property) => property,
|
|
7
7
|
formatDate: date => date.toString(),
|
|
8
|
+
fieldIdOf: property => property,
|
|
9
|
+
fieldNameOf: property => property,
|
|
8
10
|
parseDate: date => new Date(date),
|
|
9
11
|
tr: text => text
|
|
10
12
|
};
|
|
@@ -16,9 +18,11 @@ export function initBigintHtmlTransformers() {
|
|
|
16
18
|
}
|
|
17
19
|
// Boolean
|
|
18
20
|
function booleanEdit(value, type, property) {
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
21
|
+
const fieldId = depends.fieldIdOf(property);
|
|
22
|
+
const fieldName = depends.fieldNameOf(property);
|
|
23
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
24
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
25
|
+
const hidden = `<input name="${fieldName}" type="hidden" value="0">`;
|
|
22
26
|
const checked = value ? 'checked ' : '';
|
|
23
27
|
const checkbox = `<input ${checked}${name} type="checkbox" value="1">`;
|
|
24
28
|
return label + lfTab + hidden + lfTab + checkbox;
|
|
@@ -39,8 +43,10 @@ export function initBooleanSqlTransformers() {
|
|
|
39
43
|
}
|
|
40
44
|
// Date
|
|
41
45
|
function dateEdit(value, type, property) {
|
|
42
|
-
const
|
|
43
|
-
const
|
|
46
|
+
const fieldId = depends.fieldIdOf(property);
|
|
47
|
+
const fieldName = depends.fieldNameOf(property);
|
|
48
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
49
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
44
50
|
const inputValue = value ? ` value="${depends.formatDate(value)}"` : '';
|
|
45
51
|
const input = `<input data-type="date" ${name}${inputValue}>`;
|
|
46
52
|
return label + lfTab + input;
|
|
@@ -56,8 +62,10 @@ export function initDateHtmlTransformers() {
|
|
|
56
62
|
}
|
|
57
63
|
// Number
|
|
58
64
|
function numberEdit(value, type, property) {
|
|
59
|
-
const
|
|
60
|
-
const
|
|
65
|
+
const fieldId = depends.fieldIdOf(property);
|
|
66
|
+
const fieldName = depends.fieldNameOf(property);
|
|
67
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
68
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
61
69
|
const inputValue = (value !== undefined) ? ` value="${value}"` : '';
|
|
62
70
|
const input = `<input data-type="number" ${name}${inputValue}>`;
|
|
63
71
|
return label + lfTab + input;
|
|
@@ -70,8 +78,10 @@ export function initNumberHtmlTransformers() {
|
|
|
70
78
|
}
|
|
71
79
|
// default
|
|
72
80
|
function defaultEdit(value, type, property) {
|
|
73
|
-
const
|
|
74
|
-
const
|
|
81
|
+
const fieldId = depends.fieldIdOf(property);
|
|
82
|
+
const fieldName = depends.fieldNameOf(property);
|
|
83
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(type, property))}</label>`;
|
|
84
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
75
85
|
const inputValue = value ? ` value="${value}"` : '';
|
|
76
86
|
const input = `<input ${name}${inputValue}>`;
|
|
77
87
|
return label + lfTab + input;
|
package/esm/store.d.ts
CHANGED
|
@@ -5,6 +5,8 @@ export type SqlDependencies = {
|
|
|
5
5
|
};
|
|
6
6
|
export type Dependencies = SqlDependencies & {
|
|
7
7
|
displayOf: (object: AnyObject, property: string) => string;
|
|
8
|
+
fieldOf: (property: string) => string;
|
|
9
|
+
idOf: (property: string) => string;
|
|
8
10
|
representativeValueOf: (object: object) => string;
|
|
9
11
|
routeOf: (type: Type) => string;
|
|
10
12
|
tr: (text: string) => string;
|
package/esm/store.js
CHANGED
|
@@ -7,6 +7,8 @@ import { INPUT, OUTPUT, SAVE, SQL } from '@itrocks/transformer';
|
|
|
7
7
|
const lfTab = '\n\t\t\t\t';
|
|
8
8
|
const depends = {
|
|
9
9
|
displayOf: (_object, property) => property,
|
|
10
|
+
fieldOf: property => property,
|
|
11
|
+
idOf: property => property,
|
|
10
12
|
ignoreTransformedValue: Symbol('ignoreTransformedValue'),
|
|
11
13
|
representativeValueOf: object => baseType(typeOf(object)).name,
|
|
12
14
|
routeOf: type => '/' + baseType(type).name,
|
|
@@ -30,38 +32,41 @@ export function setStoreDependencies(dependencies) {
|
|
|
30
32
|
export const setStoreHtmlDependencies = setStoreDependencies;
|
|
31
33
|
export const setStoreSqlDependencies = setStoreDependencies;
|
|
32
34
|
function storeEdit(value, object, property) {
|
|
35
|
+
const fieldName = depends.fieldOf(property);
|
|
36
|
+
const fieldId = depends.idOf(property);
|
|
33
37
|
const propertyType = new ReflectProperty(object, property).type;
|
|
34
|
-
const
|
|
38
|
+
const textValue = value ? depends.representativeValueOf(value) : '';
|
|
35
39
|
const fetch = depends.routeOf(propertyType) + '/summary';
|
|
36
|
-
const label = `<label for="${
|
|
37
|
-
const name = `id="${
|
|
38
|
-
const inputValue =
|
|
40
|
+
const label = `<label for="${fieldId}">${depends.tr(depends.displayOf(object, property))}</label>`;
|
|
41
|
+
const name = `id="${fieldId}" name="${fieldName}"`;
|
|
42
|
+
const inputValue = (textValue === '') ? '' : ` value="${textValue}"`;
|
|
39
43
|
const input = `<input data-fetch="${fetch}" data-type="object" ${name}${inputValue}>`;
|
|
40
|
-
const
|
|
41
|
-
return label + lfTab + input +
|
|
44
|
+
const inputId = `<input id="${fieldId}-id" name="${fieldName}_id" type="hidden" value="${value?.id}">`;
|
|
45
|
+
return label + lfTab + input + inputId;
|
|
42
46
|
}
|
|
43
47
|
function storeInput(value, object, property, data) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const propertyId = property + 'Id';
|
|
49
|
+
const fieldId = depends.fieldOf(propertyId);
|
|
50
|
+
if ((fieldId in data)
|
|
51
|
+
&& ((propertyId in object)
|
|
52
|
+
? (data[fieldId] !== object[propertyId] + '')
|
|
53
|
+
: (data[fieldId] !== value?.id + ''))) {
|
|
49
54
|
delete object[property];
|
|
50
|
-
Object.assign(object, { [
|
|
55
|
+
Object.assign(object, { [propertyId]: +data[fieldId] });
|
|
51
56
|
}
|
|
52
57
|
return depends.ignoreTransformedValue;
|
|
53
58
|
}
|
|
54
59
|
function storeOutput(value) {
|
|
55
60
|
return value ? depends.representativeValueOf(value) : '';
|
|
56
61
|
}
|
|
57
|
-
async function storeSave(value, _object, property,
|
|
62
|
+
async function storeSave(value, _object, property, record) {
|
|
58
63
|
const dao = dataSource();
|
|
59
64
|
if (value && !dao.isObjectConnected(value)) {
|
|
60
65
|
await dao.save(value);
|
|
61
66
|
}
|
|
62
|
-
const
|
|
63
|
-
const id = (value && dao.isObjectConnected(value)) ? value.id :
|
|
64
|
-
|
|
67
|
+
const columnId = property + '_id';
|
|
68
|
+
const id = (value && dao.isObjectConnected(value)) ? value.id : record[columnId];
|
|
69
|
+
record[columnId] = id ?? null;
|
|
65
70
|
return depends.ignoreTransformedValue;
|
|
66
71
|
}
|
|
67
72
|
//# sourceMappingURL=store.js.map
|
package/package.json
CHANGED