@mediusinc/mng-commons 5.5.0 → 6.0.0-rc.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/core/action/action-parameters.model.d.ts +4 -4
- package/core/data-providers/base.data-provider.d.ts +4 -7
- package/core/data-providers/lookup.data-provider.d.ts +2 -2
- package/core/descriptors/model.descriptor.d.ts +1 -7
- package/core/descriptors/tableview.descriptor.d.ts +5 -5
- package/core/helpers/route.d.ts +0 -1
- package/core/helpers/type-helpers.d.ts +8 -0
- package/core/index.d.ts +0 -3
- package/core/models/menu.model.d.ts +0 -4
- package/core/services/commons.service.d.ts +0 -32
- package/core/services/tokens/module-config.token.d.ts +0 -28
- package/esm2022/core/action/action-parameters.model.mjs +1 -1
- package/esm2022/core/data-providers/base.data-provider.mjs +2 -4
- package/esm2022/core/data-providers/lookup.data-provider.mjs +1 -1
- package/esm2022/core/descriptors/model.descriptor.mjs +1 -1
- package/esm2022/core/descriptors/tableview.descriptor.mjs +1 -1
- package/esm2022/core/helpers/type-helpers.mjs +1 -1
- package/esm2022/core/index.mjs +1 -4
- package/esm2022/core/models/menu.model.mjs +1 -1
- package/esm2022/core/services/commons.service.mjs +1 -34
- package/esm2022/core/services/tokens/module-config.token.mjs +1 -1
- package/esm2022/filter/descriptors/filter-lookup.descriptor.mjs +5 -86
- package/esm2022/filter/descriptors/filter.descriptor.mjs +7 -29
- package/esm2022/form/api/data-providers/lookup-data-provider.factory.mjs +14 -41
- package/esm2022/form/api/data-providers/lookup.data-provider.mjs +3 -3
- package/esm2022/model/class/data-providers/base-from-class-data-provider.factory.mjs +5 -0
- package/esm2022/model/class/descriptors/model-class.descriptor.mjs +28 -0
- package/esm2022/model/class/descriptors/type-class.descriptor.mjs +6 -0
- package/esm2022/model/class/helpers/model.mjs +53 -0
- package/esm2022/model/class/index.mjs +8 -0
- package/esm2022/model/class/mediusinc-mng-commons-model-class.mjs +5 -0
- package/esm2022/model/data-providers/base-from-type-data-provider.factory.mjs +11 -6
- package/esm2022/model/descriptors/model.descriptor.mjs +11 -54
- package/esm2022/model/descriptors/type.descriptor.mjs +2 -10
- package/esm2022/model/index.mjs +1 -2
- package/esm2022/table/api/class/class-table-attribute-converter.mjs +80 -0
- package/esm2022/table/api/class/class-table-attribute.model.mjs +2 -0
- package/esm2022/table/api/class/class-table-data-provider.factory.mjs +5 -0
- package/esm2022/table/api/class/class-table-descriptor-helpers.mjs +99 -0
- package/esm2022/table/api/class/class-table-descriptor.factory.mjs +21 -0
- package/esm2022/table/api/class/index.mjs +6 -0
- package/esm2022/table/api/class/mediusinc-mng-commons-table-api-class.mjs +5 -0
- package/esm2022/table/api/data-providers/table-data-provider.factory.mjs +14 -41
- package/esm2022/table/api/data-providers/table.data-provider.mjs +3 -9
- package/esm2022/table/api/descriptors/column.descriptor.mjs +8 -3
- package/esm2022/table/api/descriptors/table-descriptor.factory.mjs +10 -77
- package/esm2022/table/api/descriptors/table.descriptor.mjs +3 -3
- package/esm2022/table/api/helpers/column-converter.mjs +25 -0
- package/esm2022/table/api/helpers/table-data-provider-descriptor-convert.mjs +4 -4
- package/esm2022/table/api/index.mjs +2 -4
- package/esm2022/table/api/models/table-columns.model.mjs +1 -1
- package/esm2022/table/components/column-value/column-value.component.mjs +4 -3
- package/esm2022/table/components/filter/filter-active-tag/filter-active-tag.component.mjs +3 -3
- package/esm2022/table/components/filter/filter-form/filter-form.component.mjs +5 -5
- package/esm2022/table/components/table/table.component.mjs +6 -8
- package/esm2022/tableview/action/components/action/action.component.mjs +1 -1
- package/esm2022/tableview/action/components/editor/injector-context/action-editor-injector-context.component.mjs +10 -6
- package/esm2022/tableview/action/helpers/action-execution.mjs +1 -1
- package/esm2022/tableview/action/models/execution/action-context.model.mjs +1 -1
- package/esm2022/tableview/action/models/execution/action-instance.model.mjs +1 -1
- package/esm2022/tableview/action/services/action-executor.service.mjs +11 -11
- package/esm2022/tableview/action/services/data-provider-executor.service.mjs +18 -3
- package/esm2022/tableview/api/action/descriptors/action-confirmation.descriptor.mjs +1 -1
- package/esm2022/tableview/api/action/descriptors/action-descriptor.factory.mjs +13 -104
- package/esm2022/tableview/api/action/descriptors/action-editor-descriptor.factory.mjs +15 -62
- package/esm2022/tableview/api/action/descriptors/action-editor.descriptor.mjs +3 -63
- package/esm2022/tableview/api/action/descriptors/action-link-descriptor.factory.mjs +17 -30
- package/esm2022/tableview/api/action/descriptors/action-link.descriptor.mjs +1 -1
- package/esm2022/tableview/api/action/descriptors/action.descriptor.mjs +6 -29
- package/esm2022/tableview/api/action/descriptors/editor-action-descriptor.factory.mjs +21 -0
- package/esm2022/tableview/api/action/descriptors/editor-action-editor-descriptor.factory.mjs +21 -0
- package/esm2022/tableview/api/action/descriptors/table-action-descriptor.factory.mjs +37 -0
- package/esm2022/tableview/api/action/descriptors/table-action-editor-descriptor.factory.mjs +40 -0
- package/esm2022/tableview/api/action/helpers/data-provider-executors.mjs +25 -5
- package/esm2022/tableview/api/action/models/action-descriptor.types.mjs +1 -1
- package/esm2022/tableview/api/action/models/action-error.model.mjs +1 -1
- package/esm2022/tableview/api/action/models/execution/action-context-validation.model.mjs +1 -1
- package/esm2022/tableview/api/action/models/execution/action-context.model.mjs +1 -1
- package/esm2022/tableview/api/action/models/execution/action-instance.model.mjs +1 -1
- package/esm2022/tableview/api/action/models/tableview-action-default-categories.model.mjs +6 -6
- package/esm2022/tableview/api/action/services/data-provider-executor.service.mjs +3 -3
- package/esm2022/tableview/api/class/editor/class-editor-attribute-converter.mjs +85 -0
- package/esm2022/tableview/api/class/editor/class-editor-attribute.model.mjs +2 -0
- package/esm2022/tableview/api/class/editor/class-editor-data-provider.factory.mjs +5 -0
- package/esm2022/tableview/api/class/editor/class-editor-descriptor-helpers.mjs +95 -0
- package/esm2022/tableview/api/class/editor/class-editor-descriptor.factory.mjs +21 -0
- package/esm2022/tableview/api/class/index.mjs +13 -0
- package/esm2022/tableview/api/class/mediusinc-mng-commons-tableview-api-class.mjs +5 -0
- package/esm2022/tableview/api/class/tableview/class-tableview-attribute-converter.mjs +35 -0
- package/esm2022/tableview/api/class/tableview/class-tableview-attribute.model.mjs +2 -0
- package/esm2022/tableview/api/class/tableview/class-tableview-data-provider.factory.mjs +5 -0
- package/esm2022/tableview/api/class/tableview/class-tableview-descriptor-helpers.mjs +111 -0
- package/esm2022/tableview/api/class/tableview/class-tableview-descriptor.factory.mjs +26 -0
- package/esm2022/tableview/api/editor/data-providers/editor-data-provider.factory.mjs +14 -32
- package/esm2022/tableview/api/editor/data-providers/editor.data-provider.mjs +40 -7
- package/esm2022/tableview/api/editor/descriptors/editor-descriptor.factory.mjs +7 -73
- package/esm2022/tableview/api/editor/descriptors/editor.descriptor.mjs +49 -134
- package/esm2022/tableview/api/editor/descriptors/field-base.descriptor.mjs +11 -2
- package/esm2022/tableview/api/editor/descriptors/field-lookup.descriptor.mjs +3 -5
- package/esm2022/tableview/api/editor/descriptors/field-many.descriptor.mjs +2 -18
- package/esm2022/tableview/api/editor/descriptors/wrappers/editor-descriptor-nested-object-wrapper.mjs +51 -0
- package/esm2022/tableview/api/editor/models/editor-fields.model.mjs +1 -1
- package/esm2022/tableview/api/editor/models/form-editor.event.mjs +1 -1
- package/esm2022/tableview/api/index.mjs +8 -8
- package/esm2022/tableview/api/tableview/data-providers/tableview-data-provider.factory.mjs +13 -51
- package/esm2022/tableview/api/tableview/data-providers/tableview.data-provider.mjs +19 -11
- package/esm2022/tableview/api/tableview/descriptors/tableview-descriptor.factory.mjs +19 -96
- package/esm2022/tableview/api/tableview/descriptors/tableview.descriptor.mjs +29 -182
- package/esm2022/tableview/api/tableview/helpers/tableview-create.mjs +8 -6
- package/esm2022/tableview/api/tableview/helpers/tableview-data-provider-descriptor-convert.mjs +4 -4
- package/esm2022/tableview/api/tableview/helpers/tableview-default-actions.mjs +117 -99
- package/esm2022/tableview/api/tableview/helpers/tableview-input-builder.mjs +164 -7
- package/esm2022/tableview/api/tableview/models/tableview-descriptor-fields-manage-helper.type.mjs +2 -0
- package/esm2022/tableview/api/tableview/models/tableview-descriptor-helper.type.mjs +2 -0
- package/esm2022/tableview/api/tableview/models/tableview-input.model.mjs +1 -1
- package/esm2022/tableview/api/tableview/models/tableview-route.model.mjs +1 -1
- package/esm2022/tableview/editor/components/formly/fields/formly-field-table-dialog-form/formly-field-table-dialog-form.component.mjs +6 -6
- package/esm2022/tableview/editor/helpers/editor-field.mjs +3 -3
- package/esm2022/tableview/editor/helpers/editor-formly.mjs +4 -4
- package/esm2022/tableview/editor/helpers/field-create.mjs +21 -0
- package/esm2022/tableview/index.mjs +3 -2
- package/esm2022/tableview/tableview/components/route/tableview-route.component.mjs +1 -1
- package/esm2022/tableview/tableview/components/tableview/tableview.component.mjs +3 -1
- package/fesm2022/mediusinc-mng-commons-core.mjs +687 -781
- package/fesm2022/mediusinc-mng-commons-core.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-filter.mjs +10 -113
- package/fesm2022/mediusinc-mng-commons-filter.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-form-api.mjs +15 -42
- package/fesm2022/mediusinc-mng-commons-form-api.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-model-class.mjs +97 -0
- package/fesm2022/mediusinc-mng-commons-model-class.mjs.map +1 -0
- package/fesm2022/mediusinc-mng-commons-model.mjs +23 -137
- package/fesm2022/mediusinc-mng-commons-model.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-table-api-class.mjs +204 -0
- package/fesm2022/mediusinc-mng-commons-table-api-class.mjs.map +1 -0
- package/fesm2022/mediusinc-mng-commons-table-api.mjs +55 -319
- package/fesm2022/mediusinc-mng-commons-table-api.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-table.mjs +14 -15
- package/fesm2022/mediusinc-mng-commons-table.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-tableview-api-class.mjs +367 -0
- package/fesm2022/mediusinc-mng-commons-tableview-api-class.mjs.map +1 -0
- package/fesm2022/mediusinc-mng-commons-tableview-api.mjs +715 -1298
- package/fesm2022/mediusinc-mng-commons-tableview-api.mjs.map +1 -1
- package/fesm2022/mediusinc-mng-commons-tableview.mjs +67 -27
- package/fesm2022/mediusinc-mng-commons-tableview.mjs.map +1 -1
- package/filter/descriptors/filter-lookup.descriptor.d.ts +1 -26
- package/filter/descriptors/filter.descriptor.d.ts +5 -12
- package/form/api/data-providers/lookup-data-provider.factory.d.ts +17 -20
- package/form/api/data-providers/lookup.data-provider.d.ts +3 -3
- package/model/class/README.md +8 -0
- package/model/class/data-providers/base-from-class-data-provider.factory.d.ts +3 -0
- package/model/class/descriptors/model-class.descriptor.d.ts +12 -0
- package/model/class/descriptors/type-class.descriptor.d.ts +3 -0
- package/model/{helpers → class/helpers}/model.d.ts +1 -2
- package/model/class/index.d.ts +4 -0
- package/model/data-providers/base-from-type-data-provider.factory.d.ts +13 -6
- package/model/descriptors/model.descriptor.d.ts +12 -27
- package/model/descriptors/type.descriptor.d.ts +0 -5
- package/model/index.d.ts +0 -1
- package/package.json +19 -1
- package/table/api/class/README.md +10 -0
- package/table/api/{helpers/class-attribute-converter.d.ts → class/class-table-attribute-converter.d.ts} +2 -9
- package/table/api/{models → class}/class-table-attribute.model.d.ts +1 -1
- package/table/api/class/class-table-data-provider.factory.d.ts +4 -0
- package/table/api/{helpers/table-descriptor-helpers.d.ts → class/class-table-descriptor-helpers.d.ts} +2 -4
- package/table/api/class/class-table-descriptor.factory.d.ts +11 -0
- package/table/api/class/index.d.ts +5 -0
- package/table/api/data-providers/table-data-provider.factory.d.ts +17 -20
- package/table/api/data-providers/table.data-provider.d.ts +4 -12
- package/table/api/descriptors/column.descriptor.d.ts +5 -2
- package/table/api/descriptors/table-descriptor.factory.d.ts +3 -39
- package/table/api/descriptors/table.descriptor.d.ts +3 -3
- package/table/api/helpers/column-converter.d.ts +7 -0
- package/table/api/helpers/table-data-provider-descriptor-convert.d.ts +3 -3
- package/table/api/index.d.ts +1 -3
- package/table/api/models/table-columns.model.d.ts +2 -2
- package/table/components/column-value/column-value.component.d.ts +1 -0
- package/table/components/filter/filter-active-tag/filter-active-tag.component.d.ts +1 -1
- package/table/components/filter/filter-form/filter-form.component.d.ts +1 -1
- package/table/components/filter/filter-overlay-with-tag/filter-overlay-with-tag.component.d.ts +1 -1
- package/table/components/table/table.component.d.ts +0 -9
- package/tableview/action/components/action/action.component.d.ts +2 -2
- package/tableview/action/components/editor/action-editor.component.d.ts +1 -1
- package/tableview/action/components/editor/injector-context/action-editor-injector-context.component.d.ts +6 -5
- package/tableview/action/components/localization/data-language-dropdown.component.d.ts +3 -3
- package/tableview/action/components/table/action-table.component.d.ts +3 -3
- package/tableview/action/helpers/action-execution.d.ts +1 -1
- package/tableview/action/models/execution/action-context.model.d.ts +3 -3
- package/tableview/action/models/execution/action-instance.model.d.ts +5 -5
- package/tableview/action/services/action-executor.service.d.ts +7 -7
- package/tableview/action/services/data-provider-executor.service.d.ts +16 -16
- package/tableview/action/services/view-container.service.d.ts +1 -1
- package/tableview/api/action/descriptors/action-confirmation.descriptor.d.ts +1 -1
- package/tableview/api/action/descriptors/action-descriptor.factory.d.ts +20 -31
- package/tableview/api/action/descriptors/action-editor-descriptor.factory.d.ts +18 -25
- package/tableview/api/action/descriptors/action-editor.descriptor.d.ts +22 -40
- package/tableview/api/action/descriptors/action-link-descriptor.factory.d.ts +21 -13
- package/tableview/api/action/descriptors/action-link.descriptor.d.ts +3 -3
- package/tableview/api/action/descriptors/action.descriptor.d.ts +31 -33
- package/tableview/api/action/descriptors/editor-action-descriptor.factory.d.ts +21 -0
- package/tableview/api/action/descriptors/editor-action-editor-descriptor.factory.d.ts +21 -0
- package/tableview/api/action/descriptors/table-action-descriptor.factory.d.ts +36 -0
- package/tableview/api/action/descriptors/table-action-editor-descriptor.factory.d.ts +40 -0
- package/tableview/api/action/helpers/data-provider-executors.d.ts +13 -8
- package/tableview/api/action/models/action-descriptor.types.d.ts +2 -2
- package/tableview/api/action/models/action-error.model.d.ts +1 -1
- package/tableview/api/action/models/execution/action-context-validation.model.d.ts +2 -2
- package/tableview/api/action/models/execution/action-context.model.d.ts +2 -2
- package/tableview/api/action/models/execution/action-instance.model.d.ts +1 -1
- package/tableview/api/action/models/tableview-action-default-categories.model.d.ts +5 -5
- package/tableview/api/action/services/data-provider-executor.service.d.ts +26 -25
- package/tableview/api/class/README.md +13 -0
- package/tableview/api/{editor/helpers/class-attribute-converter.d.ts → class/editor/class-editor-attribute-converter.d.ts} +2 -2
- package/tableview/api/{editor/models/class-tableview-attribute.model.d.ts → class/editor/class-editor-attribute.model.d.ts} +1 -1
- package/tableview/api/class/editor/class-editor-data-provider.factory.d.ts +4 -0
- package/tableview/api/{editor/helpers/editor-descriptor-helpers.d.ts → class/editor/class-editor-descriptor-helpers.d.ts} +2 -5
- package/tableview/api/class/editor/class-editor-descriptor.factory.d.ts +11 -0
- package/tableview/api/class/index.d.ts +10 -0
- package/tableview/api/{tableview/helpers/class-attribute-converter.d.ts → class/tableview/class-tableview-attribute-converter.d.ts} +1 -1
- package/tableview/api/{tableview/models → class/tableview}/class-tableview-attribute.model.d.ts +2 -2
- package/tableview/api/class/tableview/class-tableview-data-provider.factory.d.ts +4 -0
- package/tableview/api/{tableview/helpers/tableview-descriptor-helpers.d.ts → class/tableview/class-tableview-descriptor-helpers.d.ts} +1 -2
- package/tableview/api/class/tableview/class-tableview-descriptor.factory.d.ts +12 -0
- package/tableview/api/editor/data-providers/editor-data-provider.factory.d.ts +17 -16
- package/tableview/api/editor/data-providers/editor.data-provider.d.ts +64 -29
- package/tableview/api/editor/descriptors/editor-descriptor.factory.d.ts +5 -38
- package/tableview/api/editor/descriptors/editor.descriptor.d.ts +48 -112
- package/tableview/api/editor/descriptors/field-base.descriptor.d.ts +8 -1
- package/tableview/api/editor/descriptors/field-lookup.descriptor.d.ts +2 -3
- package/tableview/api/editor/descriptors/field-many.descriptor.d.ts +3 -11
- package/tableview/api/editor/descriptors/wrappers/editor-descriptor-nested-object-wrapper.d.ts +25 -0
- package/tableview/api/editor/models/editor-fields.model.d.ts +25 -21
- package/tableview/api/editor/models/form-editor.event.d.ts +0 -4
- package/tableview/api/index.d.ts +7 -6
- package/tableview/api/tableview/data-providers/tableview-data-provider.factory.d.ts +20 -25
- package/tableview/api/tableview/data-providers/tableview.data-provider.d.ts +22 -22
- package/tableview/api/tableview/descriptors/tableview-descriptor.factory.d.ts +20 -50
- package/tableview/api/tableview/descriptors/tableview.descriptor.d.ts +69 -163
- package/tableview/api/tableview/helpers/tableview-create.d.ts +18 -5
- package/tableview/api/tableview/helpers/tableview-data-provider-descriptor-convert.d.ts +2 -2
- package/tableview/api/tableview/helpers/tableview-default-actions.d.ts +73 -20
- package/tableview/api/tableview/helpers/tableview-input-builder.d.ts +87 -9
- package/tableview/api/tableview/models/tableview-descriptor-fields-manage-helper.type.d.ts +9 -0
- package/tableview/api/tableview/models/tableview-descriptor-helper.type.d.ts +2 -0
- package/tableview/api/tableview/models/tableview-input.model.d.ts +1 -1
- package/tableview/api/tableview/models/tableview-route.model.d.ts +1 -1
- package/tableview/editor/helpers/field-create.d.ts +9 -0
- package/tableview/index.d.ts +2 -1
- package/tableview/tableview/components/route/tableview-route.component.d.ts +1 -1
- package/tableview/tableview/components/tableview/tableview.component.d.ts +6 -6
- package/version-info.json +6 -6
- package/core/components/pages/error/error.page.component.d.ts +0 -11
- package/core/components/pages/not-found/not-found.page.component.d.ts +0 -11
- package/core/data-providers/base-data-provider.factory.d.ts +0 -13
- package/esm2022/core/components/pages/error/error.page.component.mjs +0 -24
- package/esm2022/core/components/pages/not-found/not-found.page.component.mjs +0 -24
- package/esm2022/core/data-providers/base-data-provider.factory.mjs +0 -28
- package/esm2022/model/helpers/model.mjs +0 -71
- package/esm2022/table/api/helpers/class-attribute-converter.mjs +0 -104
- package/esm2022/table/api/helpers/table-descriptor-helpers.mjs +0 -98
- package/esm2022/table/api/models/class-table-attribute.model.mjs +0 -2
- package/esm2022/tableview/api/editor/helpers/class-attribute-converter.mjs +0 -85
- package/esm2022/tableview/api/editor/helpers/editor-descriptor-helpers.mjs +0 -95
- package/esm2022/tableview/api/editor/models/class-tableview-attribute.model.mjs +0 -2
- package/esm2022/tableview/api/tableview/helpers/class-attribute-converter.mjs +0 -34
- package/esm2022/tableview/api/tableview/helpers/tableview-descriptor-helpers.mjs +0 -110
- package/esm2022/tableview/api/tableview/models/class-tableview-attribute.model.mjs +0 -2
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { DataProviderInst, TypeRegistry, findReflectTypeName } from '@mediusinc/mng-commons/core';
|
|
2
|
+
import { ModelDescriptor, TypeDescriptor } from '@mediusinc/mng-commons/model';
|
|
3
|
+
|
|
4
|
+
function dataProviderFromClass(type, serviceType) {
|
|
5
|
+
return new DataProviderInst(serviceType);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function findClassIdAttribute(classType) {
|
|
9
|
+
if (!classType)
|
|
10
|
+
return null;
|
|
11
|
+
const attrDef = getClassAttributeDef(classType);
|
|
12
|
+
if (!attrDef) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
let idAttribute = findAttributeByTypeAndName(attrDef, ['string', 'number'], 'id', 'uuid', 'code', 'sifra');
|
|
16
|
+
if (!idAttribute) {
|
|
17
|
+
// if no id or code, take the first attribute
|
|
18
|
+
idAttribute = attrDef[0];
|
|
19
|
+
}
|
|
20
|
+
return idAttribute?.name ?? null;
|
|
21
|
+
}
|
|
22
|
+
function findClassTitleAttribute(classType) {
|
|
23
|
+
if (!classType)
|
|
24
|
+
return null;
|
|
25
|
+
const attrDef = getClassAttributeDef(classType);
|
|
26
|
+
if (!attrDef) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
let titleAttribute = findAttributeByTypeAndName(attrDef, ['string'], 'name', 'ime', 'title', 'naziv');
|
|
30
|
+
if (!titleAttribute) {
|
|
31
|
+
// if no name or title, take the first attribute
|
|
32
|
+
titleAttribute = attrDef[0];
|
|
33
|
+
}
|
|
34
|
+
return titleAttribute?.name ?? null;
|
|
35
|
+
}
|
|
36
|
+
function getClassAttributeDef(classType) {
|
|
37
|
+
if (!classType)
|
|
38
|
+
return null;
|
|
39
|
+
const attrDefByFn = classType.getAttributeTypeMap?.();
|
|
40
|
+
if (attrDefByFn)
|
|
41
|
+
return attrDefByFn;
|
|
42
|
+
const attrDefByProp = classType.attributeTypeMap;
|
|
43
|
+
if (attrDefByProp)
|
|
44
|
+
return attrDefByProp;
|
|
45
|
+
const attrByObjSer = TypeRegistry.get().findAttributesDefinitionByClassType(classType);
|
|
46
|
+
if (attrByObjSer)
|
|
47
|
+
return attrByObjSer;
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function findAttributeByTypeAndName(attributes, types, ...names) {
|
|
51
|
+
for (const name of names) {
|
|
52
|
+
const attribute = attributes.find(a => types.some(t => t === a.type) && a.name === name);
|
|
53
|
+
if (attribute) {
|
|
54
|
+
return attribute;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class ModelClassDescriptor extends ModelDescriptor {
|
|
61
|
+
constructor(_type, idProperty, titleProperty, i18nBaseKey) {
|
|
62
|
+
super(idProperty, titleProperty, i18nBaseKey);
|
|
63
|
+
this._classType = _type;
|
|
64
|
+
}
|
|
65
|
+
get classType() {
|
|
66
|
+
return this._classType;
|
|
67
|
+
}
|
|
68
|
+
copy() {
|
|
69
|
+
return new ModelClassDescriptor(this._classType, this._idProperty, this._titleProperty, this._i18nBaseKey);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function modelClass(type, opts) {
|
|
73
|
+
let idProperty = opts?.id;
|
|
74
|
+
if (!idProperty && type) {
|
|
75
|
+
idProperty = findClassIdAttribute(type) ?? undefined;
|
|
76
|
+
}
|
|
77
|
+
let titleProp = opts?.title;
|
|
78
|
+
if (!titleProp && type) {
|
|
79
|
+
titleProp = findClassTitleAttribute(type) ?? undefined;
|
|
80
|
+
}
|
|
81
|
+
const i18nBaseKey = opts?.i18nBase != null ? (typeof opts?.i18nBase === 'string' ? opts.i18nBase : findReflectTypeName(opts.i18nBase)) : findReflectTypeName(type);
|
|
82
|
+
return new ModelClassDescriptor(type, idProperty, titleProp, i18nBaseKey ?? undefined);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
86
|
+
function typeFromClass(type) {
|
|
87
|
+
return new TypeDescriptor();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// data providers
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Generated bundle index. Do not edit.
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export { ModelClassDescriptor, dataProviderFromClass, findClassIdAttribute, findClassTitleAttribute, getClassAttributeDef, modelClass, typeFromClass };
|
|
97
|
+
//# sourceMappingURL=mediusinc-mng-commons-model-class.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mediusinc-mng-commons-model-class.mjs","sources":["../../model/class/src/data-providers/base-from-class-data-provider.factory.ts","../../model/class/src/helpers/model.ts","../../model/class/src/descriptors/model-class.descriptor.ts","../../model/class/src/descriptors/type-class.descriptor.ts","../../model/class/src/index.ts","../../model/class/src/mediusinc-mng-commons-model-class.ts"],"sourcesContent":["import {ClassType, DataProviderInst, ServiceClassType} from '@mediusinc/mng-commons/core';\n\nexport function dataProviderFromClass<Model>(type: ClassType<Model>): DataProviderInst<Model, undefined, undefined>;\nexport function dataProviderFromClass<Model, Service = any>(\n type: ClassType<Model>,\n ServiceClass: ServiceClassType<Service>\n): DataProviderInst<Model, Service, ServiceClassType<Service>>;\nexport function dataProviderFromClass<Model, Service = any, ServiceClass = ServiceClassType<Service>>(type: ClassType<Model>, serviceType?: ServiceClass) {\n return new DataProviderInst<Model, Service, ServiceClass>(serviceType as ServiceClass);\n}\n","import {ClassAttributeDef, ClassType, TypeRegistry} from '@mediusinc/mng-commons/core';\n\nexport function findClassIdAttribute<T>(classType?: ClassType<T>): string | null {\n if (!classType) return null;\n\n const attrDef = getClassAttributeDef(classType);\n if (!attrDef) {\n return null;\n }\n\n let idAttribute = findAttributeByTypeAndName(attrDef, ['string', 'number'], 'id', 'uuid', 'code', 'sifra');\n if (!idAttribute) {\n // if no id or code, take the first attribute\n idAttribute = attrDef[0];\n }\n\n return idAttribute?.name ?? null;\n}\n\nexport function findClassTitleAttribute<T>(classType?: ClassType<T>): string | null {\n if (!classType) return null;\n\n const attrDef = getClassAttributeDef(classType);\n if (!attrDef) {\n return null;\n }\n\n let titleAttribute = findAttributeByTypeAndName(attrDef, ['string'], 'name', 'ime', 'title', 'naziv');\n if (!titleAttribute) {\n // if no name or title, take the first attribute\n titleAttribute = attrDef[0];\n }\n\n return titleAttribute?.name ?? null;\n}\n\nexport function getClassAttributeDef<T>(classType?: ClassType<T>) {\n if (!classType) return null;\n const attrDefByFn = (classType as any).getAttributeTypeMap?.() as Array<ClassAttributeDef> | undefined;\n if (attrDefByFn) return attrDefByFn;\n const attrDefByProp = (classType as any).attributeTypeMap as Array<ClassAttributeDef> | undefined;\n if (attrDefByProp) return attrDefByProp;\n const attrByObjSer = TypeRegistry.get().findAttributesDefinitionByClassType(classType);\n if (attrByObjSer) return attrByObjSer;\n return null;\n}\n\nfunction findAttributeByTypeAndName(attributes: ClassAttributeDef[], types: string[], ...names: string[]): ClassAttributeDef | null {\n for (const name of names) {\n const attribute = attributes.find(a => types.some(t => t === a.type) && a.name === name);\n if (attribute) {\n return attribute;\n }\n }\n return null;\n}\n","import {ClassType, IModelDescriptor, findReflectTypeName} from '@mediusinc/mng-commons/core';\nimport {ModelDescriptor, ModelDescriptorCreateOpts} from '@mediusinc/mng-commons/model';\n\nimport {findClassIdAttribute, findClassTitleAttribute} from '../helpers/model';\n\nexport class ModelClassDescriptor<Model> extends ModelDescriptor<Model> implements IModelDescriptor<Model> {\n private readonly _classType: ClassType<Model>;\n\n public constructor(_type: ClassType<Model>, idProperty?: string, titleProperty?: string | ((item: Model) => string), i18nBaseKey?: string) {\n super(idProperty, titleProperty, i18nBaseKey);\n this._classType = _type;\n }\n\n public get classType() {\n return this._classType;\n }\n\n public override copy(): ModelClassDescriptor<Model> {\n return new ModelClassDescriptor<Model>(this._classType, this._idProperty, this._titleProperty, this._i18nBaseKey);\n }\n}\n\nexport type ModelClassDescriptorCreateOpts<Model> = Omit<ModelDescriptorCreateOpts<Model>, 'i18nBase'> & {\n i18nBase?: string | ClassType<unknown>;\n};\n\nexport function modelClass<Model>(type: ClassType<Model>, opts?: ModelClassDescriptorCreateOpts<Model>): ModelClassDescriptor<Model> {\n let idProperty = opts?.id as string | undefined;\n if (!idProperty && type) {\n idProperty = findClassIdAttribute(type as unknown as ClassType<Model>) ?? undefined;\n }\n let titleProp = opts?.title as string | ((item: Model) => string) | undefined;\n if (!titleProp && type) {\n titleProp = findClassTitleAttribute(type as unknown as ClassType<Model>) ?? undefined;\n }\n const i18nBaseKey =\n opts?.i18nBase != null ? (typeof opts?.i18nBase === 'string' ? opts.i18nBase : findReflectTypeName(opts.i18nBase)) : findReflectTypeName(type as ClassType<Model>);\n return new ModelClassDescriptor<Model>(type, idProperty, titleProp, i18nBaseKey ?? undefined);\n}\n","import {ClassType} from '@mediusinc/mng-commons/core';\nimport {TypeDescriptor} from '@mediusinc/mng-commons/model';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function typeFromClass<Type>(type: ClassType<Type>): TypeDescriptor<Type> {\n return new TypeDescriptor<Type>();\n}\n","// data providers\nexport * from './data-providers/base-from-class-data-provider.factory';\n\n// descriptors\nexport * from './descriptors/model-class.descriptor';\nexport * from './descriptors/type-class.descriptor';\n\n// helpers\nexport * from './helpers/model';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAOgB,SAAA,qBAAqB,CAAiE,IAAsB,EAAE,WAA0B,EAAA;AACpJ,IAAA,OAAO,IAAI,gBAAgB,CAA+B,WAA2B,CAA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,SAAS;;AAEvF,IAAA,IAAI,SAAS,GAAG,IAAI,EAAE,KAAuD;AAC7E,IAAA,IAAI,CAAC,SAAS,IAAI,IAAI,EAAE;AACpB,QAAA,SAAS,GAAG,uBAAuB,CAAC,IAAmC,CAAC,IAAI,SAAS;;AAEzF,IAAA,MAAM,WAAW,GACb,IAAI,EAAE,QAAQ,IAAI,IAAI,IAAI,OAAO,IAAI,EAAE,QAAQ,KAAK,QAAQ,GAAG,IAAI,CAAC,QAAQ,GAAG,mBAAmB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,mBAAmB,CAAC,IAAwB,CAAC;AACtK,IAAA,OAAO,IAAI,oBAAoB,CAAQ,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,IAAI,SAAS,CAAC;AACjG;;ACnCA;AACM,SAAU,aAAa,CAAO,IAAqB,EAAA;IACrD,OAAO,IAAI,cAAc,EAAQ;AACrC;;ACNA;;ACAA;;AAEG;;;;"}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { DataProviderInst, findReflectEnumName,
|
|
1
|
+
import { DataProviderInst, findReflectEnumName, getI18n, getI18nTypeParams, getI18nTypeParamsAsync, getI18nTypeKeyBasePath } from '@mediusinc/mng-commons/core';
|
|
2
2
|
import { map } from 'rxjs/operators';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Creates and returns an instance of `DataProviderInst` with the specified options for managing editor data.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} [opts] - The options object to configure the data provider.
|
|
8
|
+
* @param {TypeDescriptor<Model> | ModelDescriptor<Model>} [opts.type] - The descriptor defining the type of model.
|
|
9
|
+
* @param {ServiceClassType<Service>} [opts.service] - The service class type associated with the data provider.
|
|
10
|
+
* @return {DataProviderInst<Model, Service, ServiceClass>} An instance of `EditorDataProviderInst` configured according to the provided options.
|
|
11
|
+
*/
|
|
12
|
+
function dataProvider(opts) {
|
|
13
|
+
return new DataProviderInst(opts?.service);
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
class EnumDescriptor {
|
|
@@ -35,127 +40,18 @@ function enumModelGeneric(type, i18nBaseKey = null, nameAsValue = false) {
|
|
|
35
40
|
return new EnumDescriptor(undefined, type, i18nBaseKey, nameAsValue);
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
if (!classType)
|
|
40
|
-
return null;
|
|
41
|
-
const attrDef = getClassAttributeDef(classType);
|
|
42
|
-
if (!attrDef) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
let idAttribute = findAttributeByTypeAndName(attrDef, ['string', 'number'], 'id', 'uuid', 'code', 'sifra');
|
|
46
|
-
if (!idAttribute) {
|
|
47
|
-
// if no id or code, take the first attribute
|
|
48
|
-
idAttribute = attrDef[0];
|
|
49
|
-
}
|
|
50
|
-
return idAttribute?.name ?? null;
|
|
51
|
-
}
|
|
52
|
-
function findClassTitleAttribute(classType) {
|
|
53
|
-
if (!classType)
|
|
54
|
-
return null;
|
|
55
|
-
const attrDef = getClassAttributeDef(classType);
|
|
56
|
-
if (!attrDef) {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
let titleAttribute = findAttributeByTypeAndName(attrDef, ['string'], 'name', 'ime', 'title', 'naziv');
|
|
60
|
-
if (!titleAttribute) {
|
|
61
|
-
// if no name or title, take the first attribute
|
|
62
|
-
titleAttribute = attrDef[0];
|
|
63
|
-
}
|
|
64
|
-
return titleAttribute?.name ?? null;
|
|
65
|
-
}
|
|
66
|
-
function getClassAttributeDef(classType) {
|
|
67
|
-
if (!classType)
|
|
68
|
-
return null;
|
|
69
|
-
const attrDefByFn = classType.getAttributeTypeMap?.();
|
|
70
|
-
if (attrDefByFn)
|
|
71
|
-
return attrDefByFn;
|
|
72
|
-
const attrDefByProp = classType.attributeTypeMap;
|
|
73
|
-
if (attrDefByProp)
|
|
74
|
-
return attrDefByProp;
|
|
75
|
-
const attrByObjSer = TypeRegistry.get().findAttributesDefinitionByClassType(classType);
|
|
76
|
-
if (attrByObjSer)
|
|
77
|
-
return attrByObjSer;
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
function findAttributeByTypeAndName(attributes, types, ...names) {
|
|
81
|
-
for (const name of names) {
|
|
82
|
-
const attribute = attributes.find(a => types.some(t => t === a.type) && a.name === name);
|
|
83
|
-
if (attribute) {
|
|
84
|
-
return attribute;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
function trySetLookupItemsProperties(lookup, idAsTrack = true) {
|
|
90
|
-
if (lookup.dataProvider.classType) {
|
|
91
|
-
if (!lookup.optionsValueProperty && !lookup.optionsTrackProperty) {
|
|
92
|
-
const idProperty = findClassIdAttribute(lookup.dataProvider.classType) ?? undefined;
|
|
93
|
-
if (idProperty && !lookup.optionsValueProperty && !lookup.optionsTrackProperty) {
|
|
94
|
-
if (idAsTrack) {
|
|
95
|
-
lookup.withOptionsTrackPropertyUnsafe(idProperty);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (!lookup.optionsLabelProperty) {
|
|
100
|
-
const labelProperty = findClassTitleAttribute(lookup.dataProvider.classType);
|
|
101
|
-
if (labelProperty) {
|
|
102
|
-
lookup.withOptionsLabelPropertyUnsafe(labelProperty);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
108
44
|
class TypeDescriptor {
|
|
109
|
-
constructor(classType) {
|
|
110
|
-
this._classType = classType;
|
|
111
|
-
}
|
|
112
|
-
get classType() {
|
|
113
|
-
return this._classType;
|
|
114
|
-
}
|
|
115
45
|
}
|
|
116
46
|
function type() {
|
|
117
47
|
return new TypeDescriptor();
|
|
118
48
|
}
|
|
119
|
-
function typeClass(type) {
|
|
120
|
-
return new TypeDescriptor(type);
|
|
121
|
-
}
|
|
122
49
|
|
|
123
50
|
class ModelDescriptor {
|
|
124
|
-
constructor(
|
|
125
|
-
this._type = type;
|
|
51
|
+
constructor(idProperty, titleProperty, i18nBaseKey) {
|
|
126
52
|
this._idProperty = idProperty;
|
|
127
53
|
this._titleProperty = titleProperty;
|
|
128
|
-
|
|
129
|
-
this._idProperty = findClassIdAttribute(type) ?? undefined;
|
|
130
|
-
}
|
|
131
|
-
if (!this._titleProperty && type) {
|
|
132
|
-
this._titleProperty = findClassTitleAttribute(type) ?? undefined;
|
|
133
|
-
}
|
|
134
|
-
this._i18nBaseKey =
|
|
135
|
-
(typeof i18nBaseKey === 'string' || typeof i18nBaseKey === 'undefined' ? i18nBaseKey : findReflectTypeName(i18nBaseKey)) ??
|
|
136
|
-
findReflectTypeName(type) ??
|
|
137
|
-
'';
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* @deprecated Use standalone {model()} instead.
|
|
141
|
-
*/
|
|
142
|
-
static create(idProperty, titleProperty, i18nBaseKey) {
|
|
143
|
-
return new ModelDescriptor(undefined, idProperty, titleProperty, i18nBaseKey);
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* @deprecated Use standalone {model()} instead.
|
|
147
|
-
*/
|
|
148
|
-
static fromClass(type, idProperty, titleProperty, i18nBaseKey) {
|
|
149
|
-
return new ModelDescriptor(type, idProperty, titleProperty, i18nBaseKey);
|
|
150
|
-
}
|
|
151
|
-
get type() {
|
|
152
|
-
return this._type;
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* @deprecated Use `i18nBaseKey` instead.
|
|
156
|
-
*/
|
|
157
|
-
get typeName() {
|
|
158
|
-
return this.i18nBaseKey;
|
|
54
|
+
this._i18nBaseKey = i18nBaseKey ?? '';
|
|
159
55
|
}
|
|
160
56
|
get i18nBaseKey() {
|
|
161
57
|
return this._i18nBaseKey;
|
|
@@ -183,33 +79,23 @@ class ModelDescriptor {
|
|
|
183
79
|
return this;
|
|
184
80
|
}
|
|
185
81
|
withI18nBase(base) {
|
|
186
|
-
if (typeof base !== 'string') {
|
|
187
|
-
const typeName = findReflectTypeName(base);
|
|
188
|
-
if (!typeName) {
|
|
189
|
-
throw new CommonsInternalError(`Could not find define i18nBaseKey for ${base} on model ${this.i18nBaseKey}`);
|
|
190
|
-
}
|
|
191
|
-
base = typeName;
|
|
192
|
-
}
|
|
193
82
|
this._i18nBaseKey = base;
|
|
194
83
|
return this;
|
|
195
84
|
}
|
|
196
85
|
copy() {
|
|
197
|
-
return new ModelDescriptor(this.
|
|
86
|
+
return new ModelDescriptor(this._idProperty, this._titleProperty, this._i18nBaseKey);
|
|
198
87
|
}
|
|
199
88
|
}
|
|
200
|
-
function model(
|
|
201
|
-
if (
|
|
202
|
-
return new ModelDescriptor(
|
|
203
|
-
}
|
|
204
|
-
else if (typeOrClassOrOpts instanceof TypeDescriptor) {
|
|
205
|
-
return new ModelDescriptor(undefined, opts?.id, opts?.title, opts?.i18nBase);
|
|
89
|
+
function model(typeOrOpts, opts) {
|
|
90
|
+
if (typeOrOpts == null) {
|
|
91
|
+
return new ModelDescriptor();
|
|
206
92
|
}
|
|
207
|
-
else if (
|
|
208
|
-
return new ModelDescriptor(
|
|
93
|
+
else if (typeOrOpts instanceof TypeDescriptor) {
|
|
94
|
+
return new ModelDescriptor(opts?.id, opts?.title, opts?.i18nBase);
|
|
209
95
|
}
|
|
210
96
|
else {
|
|
211
|
-
const
|
|
212
|
-
return new ModelDescriptor(
|
|
97
|
+
const modelOpts = typeOrOpts;
|
|
98
|
+
return new ModelDescriptor(modelOpts?.id, modelOpts?.title, modelOpts?.i18nBase);
|
|
213
99
|
}
|
|
214
100
|
}
|
|
215
101
|
|
|
@@ -259,5 +145,5 @@ function getKeysByPriority(model, keyPath, customKey, fallbackKey) {
|
|
|
259
145
|
* Generated bundle index. Do not edit.
|
|
260
146
|
*/
|
|
261
147
|
|
|
262
|
-
export { EnumDescriptor, ModelDescriptor, TypeDescriptor, dataProvider,
|
|
148
|
+
export { EnumDescriptor, ModelDescriptor, TypeDescriptor, dataProvider, enumModel, enumModelGeneric, getI18nForModel, getI18nModelParams, getI18nModelParamsAsync, model, populateI18nModelParams, type };
|
|
263
149
|
//# sourceMappingURL=mediusinc-mng-commons-model.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mediusinc-mng-commons-model.mjs","sources":["../../model/src/data-providers/base-from-type-data-provider.factory.ts","../../model/src/descriptors/enum.descriptor.ts","../../model/src/helpers/model.ts","../../model/src/descriptors/type.descriptor.ts","../../model/src/descriptors/model.descriptor.ts","../../model/src/helpers/i18n.ts","../../model/src/index.ts","../../model/src/mediusinc-mng-commons-model.ts"],"sourcesContent":["import {ClassType, DataProviderInst, ServiceClassType} from '@mediusinc/mng-commons/core';\n\nimport {ModelDescriptor} from '../descriptors/model.descriptor';\nimport {TypeDescriptor} from '../descriptors/type.descriptor';\n\nexport function dataProvider<Model>(): DataProviderInst<Model, undefined, undefined, undefined>;\nexport function dataProvider<Model>(type: TypeDescriptor<Model>): DataProviderInst<Model, undefined, undefined, undefined>;\nexport function dataProvider<Model, Service = any>(\n type: TypeDescriptor<Model>,\n serviceType: ServiceClassType<Service>\n): DataProviderInst<Model, Service, undefined, ServiceClassType<Service>>;\nexport function dataProvider<Model, Service = any, ServiceClass = ServiceClassType<Service>>(type?: TypeDescriptor<Model>, serviceType?: ServiceClass) {\n return new DataProviderInst<Model, Service, undefined, ServiceClass>(undefined, serviceType as ServiceClass);\n}\n\nexport function dataProviderFromModel<Model, ModelClass = ClassType<Model>>(model: ModelDescriptor<Model, ModelClass>): DataProviderInst<Model, undefined, ModelClass, undefined>;\nexport function dataProviderFromModel<Model, Service = any, ModelClass = ClassType<Model>>(\n model: ModelDescriptor<Model, ModelClass>,\n ServiceClass: ServiceClassType<Service>\n): DataProviderInst<Model, Service, ModelClass, ServiceClassType<Service>>;\nexport function dataProviderFromModel<Model, Service = any, ModelClass = ClassType<Model>, ServiceClass = ServiceClassType<Service>>(\n model: ModelDescriptor<Model, ModelClass>,\n serviceType?: ServiceClass\n) {\n return new DataProviderInst<Model, Service, ClassType<Model>, ServiceClass>(model.type as ClassType<Model>, serviceType as ServiceClass);\n}\n","import {EnumType, findReflectEnumName} from '@mediusinc/mng-commons/core';\n\nexport class EnumDescriptor<Enum> {\n private readonly _value: Enum;\n private readonly _type: EnumType;\n private readonly _nameAsValue;\n private readonly _i18nBaseKey: string | null;\n\n public constructor(value: Enum, type: EnumType, i18nBaseKey?: string | null, nameAsValue = false) {\n this._value = value;\n this._type = type;\n this._nameAsValue = nameAsValue;\n\n if (typeof i18nBaseKey === 'undefined') {\n i18nBaseKey = findReflectEnumName(type);\n }\n this._i18nBaseKey = i18nBaseKey;\n }\n\n public get type() {\n return this._type;\n }\n\n public get i18nBaseKey() {\n return this._i18nBaseKey;\n }\n\n public get nameAsValue() {\n return this._nameAsValue;\n }\n}\n\nexport function enumModel<Enum>(value: Enum, type: EnumType, i18nBaseKey: string | undefined | null = null, nameAsValue = false) {\n return new EnumDescriptor<Enum>(value, type, i18nBaseKey, nameAsValue);\n}\n\nexport function enumModelGeneric<Enum = any>(type: EnumType, i18nBaseKey: string | undefined | null = null, nameAsValue = false) {\n return new EnumDescriptor<Enum>(undefined as Enum, type, i18nBaseKey, nameAsValue);\n}\n","import {ClassAttributeDef, ClassType, ILookupDescriptor, TypeRegistry} from '@mediusinc/mng-commons/core';\n\nexport function findClassIdAttribute<T>(classType?: ClassType<T>): string | null {\n if (!classType) return null;\n\n const attrDef = getClassAttributeDef(classType);\n if (!attrDef) {\n return null;\n }\n\n let idAttribute = findAttributeByTypeAndName(attrDef, ['string', 'number'], 'id', 'uuid', 'code', 'sifra');\n if (!idAttribute) {\n // if no id or code, take the first attribute\n idAttribute = attrDef[0];\n }\n\n return idAttribute?.name ?? null;\n}\n\nexport function findClassTitleAttribute<T>(classType?: ClassType<T>): string | null {\n if (!classType) return null;\n\n const attrDef = getClassAttributeDef(classType);\n if (!attrDef) {\n return null;\n }\n\n let titleAttribute = findAttributeByTypeAndName(attrDef, ['string'], 'name', 'ime', 'title', 'naziv');\n if (!titleAttribute) {\n // if no name or title, take the first attribute\n titleAttribute = attrDef[0];\n }\n\n return titleAttribute?.name ?? null;\n}\n\nexport function getClassAttributeDef<T>(classType?: ClassType<T>) {\n if (!classType) return null;\n const attrDefByFn = (classType as any).getAttributeTypeMap?.() as Array<ClassAttributeDef> | undefined;\n if (attrDefByFn) return attrDefByFn;\n const attrDefByProp = (classType as any).attributeTypeMap as Array<ClassAttributeDef> | undefined;\n if (attrDefByProp) return attrDefByProp;\n const attrByObjSer = TypeRegistry.get().findAttributesDefinitionByClassType(classType);\n if (attrByObjSer) return attrByObjSer;\n return null;\n}\n\nfunction findAttributeByTypeAndName(attributes: ClassAttributeDef[], types: string[], ...names: string[]): ClassAttributeDef | null {\n for (const name of names) {\n const attribute = attributes.find(a => types.some(t => t === a.type) && a.name === name);\n if (attribute) {\n return attribute;\n }\n }\n return null;\n}\n\nexport function trySetLookupItemsProperties<Model>(lookup: ILookupDescriptor<Model, any, any, any>, idAsTrack = true) {\n if (lookup.dataProvider.classType) {\n if (!lookup.optionsValueProperty && !lookup.optionsTrackProperty) {\n const idProperty = findClassIdAttribute(lookup.dataProvider.classType) ?? undefined;\n if (idProperty && !lookup.optionsValueProperty && !lookup.optionsTrackProperty) {\n if (idAsTrack) {\n lookup.withOptionsTrackPropertyUnsafe(idProperty);\n }\n }\n }\n if (!lookup.optionsLabelProperty) {\n const labelProperty = findClassTitleAttribute(lookup.dataProvider.classType);\n if (labelProperty) {\n lookup.withOptionsLabelPropertyUnsafe(labelProperty);\n }\n }\n }\n}\n","import {ClassType} from '@mediusinc/mng-commons/core';\n\nexport class TypeDescriptor<Type> {\n private readonly _classType?: ClassType<Type>;\n\n public constructor(classType?: ClassType<Type>) {\n this._classType = classType;\n }\n\n public get classType() {\n return this._classType;\n }\n}\n\nexport function type<Type>(): TypeDescriptor<Type> {\n return new TypeDescriptor<Type>();\n}\n\nexport function typeClass<Type>(type: ClassType<Type>): TypeDescriptor<Type> {\n return new TypeDescriptor<Type>(type);\n}\n","import {ClassOptType, ClassType, CommonsInternalError, IModelDescriptor, findReflectTypeName} from '@mediusinc/mng-commons/core';\n\nimport {findClassIdAttribute, findClassTitleAttribute} from '../helpers/model';\nimport {TypeDescriptor} from './type.descriptor';\n\nexport class ModelDescriptor<Model, ModelClass = ClassOptType<Model>> implements IModelDescriptor<Model, ModelClass> {\n private readonly _type: ModelClass;\n private _i18nBaseKey: string;\n private _idProperty?: string;\n private _titleProperty?: string | ((item: Model) => string);\n\n public constructor(type: ModelClass, idProperty?: string, titleProperty?: string | ((item: Model) => string), i18nBaseKey?: string | ClassType<any>) {\n this._type = type;\n this._idProperty = idProperty;\n this._titleProperty = titleProperty;\n if (!this._idProperty && type) {\n this._idProperty = findClassIdAttribute(type as unknown as ClassType<Model>) ?? undefined;\n }\n if (!this._titleProperty && type) {\n this._titleProperty = findClassTitleAttribute(type as unknown as ClassType<Model>) ?? undefined;\n }\n this._i18nBaseKey =\n (typeof i18nBaseKey === 'string' || typeof i18nBaseKey === 'undefined' ? i18nBaseKey : findReflectTypeName(i18nBaseKey)) ??\n findReflectTypeName(type as ClassType<Model>) ??\n '';\n }\n\n /**\n * @deprecated Use standalone {model()} instead.\n */\n public static create<Model>(idProperty?: keyof Model, titleProperty?: keyof Model, i18nBaseKey?: string | ClassType<unknown>): ModelDescriptor<Model, undefined> {\n return new ModelDescriptor(undefined, idProperty as string, titleProperty as string, i18nBaseKey);\n }\n\n /**\n * @deprecated Use standalone {model()} instead.\n */\n public static fromClass<Model>(\n type: ClassType<Model>,\n idProperty?: keyof Model,\n titleProperty?: keyof Model,\n i18nBaseKey?: string | ClassType<unknown>\n ): ModelDescriptor<Model, ClassType<Model>> {\n return new ModelDescriptor(type, idProperty as string, titleProperty as string, i18nBaseKey);\n }\n\n public get type() {\n return this._type;\n }\n\n /**\n * @deprecated Use `i18nBaseKey` instead.\n */\n public get typeName() {\n return this.i18nBaseKey;\n }\n\n public get i18nBaseKey() {\n return this._i18nBaseKey;\n }\n\n public get idProperty() {\n return this._idProperty;\n }\n\n public get titleProperty() {\n return this._titleProperty;\n }\n\n public withIdProperty(property: keyof Model): this {\n this._idProperty = property as string;\n return this;\n }\n\n public withIdPropertyUnsafe(property: string): this {\n this._idProperty = property;\n return this;\n }\n\n public withTitleProperty(property: keyof Model): this {\n this._titleProperty = property as string;\n return this;\n }\n\n public withTitlePropertyUnsafe(property: string): this {\n this._titleProperty = property;\n return this;\n }\n\n public withI18nBase(base: ClassType<any> | string): this {\n if (typeof base !== 'string') {\n const typeName = findReflectTypeName(base);\n if (!typeName) {\n throw new CommonsInternalError(`Could not find define i18nBaseKey for ${base} on model ${this.i18nBaseKey}`);\n }\n base = typeName;\n }\n this._i18nBaseKey = base;\n return this;\n }\n\n public copy(): ModelDescriptor<Model, ModelClass> {\n return new ModelDescriptor<Model, ModelClass>(this._type, this._idProperty, this._titleProperty, this._i18nBaseKey);\n }\n}\n\nexport type ModelDescriptorCreateOpts<Model> = {\n id?: keyof Model;\n title?: keyof Model | ((item: Model) => string);\n i18nBase?: string | ClassType<any>;\n};\n\nexport function model<Model>(): ModelDescriptor<Model, undefined>;\nexport function model<Model>(opts: ModelDescriptorCreateOpts<Model>): ModelDescriptor<Model, undefined>;\nexport function model<Model>(type: TypeDescriptor<Model>, opts?: ModelDescriptorCreateOpts<Model>): ModelDescriptor<Model, undefined>;\nexport function model<Model>(clazz: ClassType<Model>, opts?: ModelDescriptorCreateOpts<Model>): ModelDescriptor<Model, ClassType<Model>>;\nexport function model<Model>(typeOrClassOrOpts?: ClassType<Model> | TypeDescriptor<Model> | ModelDescriptorCreateOpts<Model>, opts?: ModelDescriptorCreateOpts<Model>) {\n if (typeOrClassOrOpts == null) {\n return new ModelDescriptor<Model, undefined>(undefined);\n } else if (typeOrClassOrOpts instanceof TypeDescriptor) {\n return new ModelDescriptor<Model, undefined>(undefined, opts?.id as string, opts?.title as string, opts?.i18nBase);\n } else if (typeof typeOrClassOrOpts === 'function') {\n return new ModelDescriptor<Model, ClassType<Model>>(typeOrClassOrOpts as ClassType<Model>, opts?.id as string, opts?.title as string, opts?.i18nBase);\n } else {\n const typeOrClassAsOpts = typeOrClassOrOpts as ModelDescriptorCreateOpts<Model>;\n return new ModelDescriptor<Model, undefined>(undefined, typeOrClassAsOpts?.id as string, typeOrClassAsOpts?.title as string, typeOrClassAsOpts?.i18nBase);\n }\n}\n","import {TranslateService} from '@ngx-translate/core';\nimport {Observable} from 'rxjs';\nimport {map} from 'rxjs/operators';\n\nimport {KeyOfType, getI18n, getI18nTypeKeyBasePath, getI18nTypeParams, getI18nTypeParamsAsync} from '@mediusinc/mng-commons/core';\n\nimport {ModelDescriptor} from '../descriptors/model.descriptor';\n\nexport function getI18nForModel(\n translate: TranslateService,\n model: ModelDescriptor<any>,\n keyPath: string,\n customKey?: string,\n item?: any,\n fallbackKey?: string,\n params?: any\n): string | null {\n const keys = getKeysByPriority(model, keyPath, customKey, fallbackKey);\n const i18nParams = getI18nModelParams(translate, model, item, params);\n return getI18n(translate, i18nParams, ...keys);\n}\n\nexport function getI18nModelParams(translate: TranslateService, model?: ModelDescriptor<any>, item?: any, params: any = {}): any {\n const i18nParams = getI18nTypeParams(translate, model?.i18nBaseKey, item, params);\n return populateI18nModelParams(model?.idProperty, model?.titleProperty, item, i18nParams);\n}\n\nexport function getI18nModelParamsAsync(translate: TranslateService, model?: ModelDescriptor<any>, item?: any, params: any = {}): Observable<any> {\n return getI18nTypeParamsAsync(translate, model?.i18nBaseKey, item, params).pipe(\n map(i18nParams => populateI18nModelParams(model?.idProperty, model?.titleProperty, item, i18nParams))\n );\n}\n\nexport function populateI18nModelParams(idProperty?: KeyOfType, titleProperty?: KeyOfType | ((item: any) => string), item?: any, params: any = {}): any {\n const paramsRes = {...params, itemId: '', itemTitle: ''};\n if (item) {\n if (idProperty && item[idProperty]) {\n paramsRes.itemId = item[idProperty];\n }\n if (typeof titleProperty === 'function') {\n paramsRes.itemTitle = titleProperty(item);\n } else if (titleProperty && item[titleProperty]) {\n paramsRes.itemTitle = item[titleProperty];\n }\n }\n return paramsRes;\n}\n\nfunction getKeysByPriority(model: ModelDescriptor<any>, keyPath: string, customKey?: string, fallbackKey?: string) {\n const keys = [];\n if (customKey) {\n keys.push(customKey);\n }\n const modelActionKey = getI18nTypeKeyBasePath(model.i18nBaseKey, ...keyPath);\n keys.push(modelActionKey);\n if (fallbackKey) {\n keys.push(fallbackKey);\n }\n return keys;\n}\n","// data providers\nexport * from './data-providers/base-from-type-data-provider.factory';\n\n// descriptors\nexport * from './descriptors/enum.descriptor';\nexport * from './descriptors/model.descriptor';\nexport * from './descriptors/type.descriptor';\n\n// helpers\nexport * from './helpers/i18n';\nexport * from './helpers/model';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAWgB,SAAA,YAAY,CAAiE,IAA4B,EAAE,WAA0B,EAAA;AACjJ,IAAA,OAAO,IAAI,gBAAgB,CAA0C,SAAS,EAAE,WAA2B,CAAC;AAChH;AAOgB,SAAA,qBAAqB,CACjC,KAAyC,EACzC,WAA0B,EAAA;IAE1B,OAAO,IAAI,gBAAgB,CAAiD,KAAK,CAAC,IAAwB,EAAE,WAA2B,CAAC;AAC5I;;MCvBa,cAAc,CAAA;IAMvB,WAAmB,CAAA,KAAW,EAAE,IAAc,EAAE,WAA2B,EAAE,WAAW,GAAG,KAAK,EAAA;AAC5F,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;AACnB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI;AACjB,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;AAE/B,QAAA,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE;AACpC,YAAA,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC;;AAE3C,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;;A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AC,UAAsB,EAAE,aAAmD,EAAE,IAAU,EAAE,MAAA,GAAc,EAAE,EAAA;AAC7I,IAAA,MAAM,SAAS,GAAG,EAAC,GAAG,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE,EAAC;IACxD,IAAI,IAAI,EAAE;AACN,QAAA,IAAI,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC,EAAE;AAChC,YAAA,SAAS,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;;AAEvC,QAAA,IAAI,OAAO,aAAa,KAAK,UAAU,EAAE;AACrC,YAAA,SAAS,CAAC,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC;;AACtC,aAAA,IAAI,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,EAAE;AAC7C,YAAA,SAAS,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC;;;AAGjD,IAAA,OAAO,SAAS;AACpB;AAEA,SAAS,iBAAiB,CAAC,KAA2B,EAAE,OAAe,EAAE,SAAkB,EAAE,WAAoB,EAAA;IAC7G,MAAM,IAAI,GAAG,EAAE;IACf,IAAI,SAAS,EAAE;AACX,QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;;IAExB,MAAM,cAAc,GAAG,sBAAsB,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC;AAC5E,IAAA,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;IACzB,IAAI,WAAW,EAAE;AACb,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;;AAE1B,IAAA,OAAO,IAAI;AACf;;AC3DA;;ACAA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"mediusinc-mng-commons-model.mjs","sources":["../../model/src/data-providers/base-from-type-data-provider.factory.ts","../../model/src/descriptors/enum.descriptor.ts","../../model/src/descriptors/type.descriptor.ts","../../model/src/descriptors/model.descriptor.ts","../../model/src/helpers/i18n.ts","../../model/src/index.ts","../../model/src/mediusinc-mng-commons-model.ts"],"sourcesContent":["import {DataProviderInst, ServiceClassType} from '@mediusinc/mng-commons/core';\n\nimport {ModelDescriptor} from '../descriptors/model.descriptor';\nimport {TypeDescriptor} from '../descriptors/type.descriptor';\n\n/**\n * Creates and returns an instance of `DataProviderInst` with the specified options for managing editor data.\n *\n * @param {Object} [opts] - The options object to configure the data provider.\n * @param {TypeDescriptor<Model> | ModelDescriptor<Model>} [opts.type] - The descriptor defining the type of model.\n * @param {ServiceClassType<Service>} [opts.service] - The service class type associated with the data provider.\n * @return {DataProviderInst<Model, Service, ServiceClass>} An instance of `EditorDataProviderInst` configured according to the provided options.\n */\nexport function dataProvider<Model, Service = undefined, ServiceClass = Service extends undefined ? undefined : ServiceClassType<Service>>(opts?: {\n type?: TypeDescriptor<Model> | ModelDescriptor<Model>;\n service?: ServiceClassType<Service>;\n}): DataProviderInst<Model, Service, ServiceClass> {\n return new DataProviderInst<Model, Service, ServiceClass>(opts?.service as ServiceClass);\n}\n","import {EnumType, findReflectEnumName} from '@mediusinc/mng-commons/core';\n\nexport class EnumDescriptor<Enum> {\n private readonly _value: Enum;\n private readonly _type: EnumType;\n private readonly _nameAsValue;\n private readonly _i18nBaseKey: string | null;\n\n public constructor(value: Enum, type: EnumType, i18nBaseKey?: string | null, nameAsValue = false) {\n this._value = value;\n this._type = type;\n this._nameAsValue = nameAsValue;\n\n if (typeof i18nBaseKey === 'undefined') {\n i18nBaseKey = findReflectEnumName(type);\n }\n this._i18nBaseKey = i18nBaseKey;\n }\n\n public get type() {\n return this._type;\n }\n\n public get i18nBaseKey() {\n return this._i18nBaseKey;\n }\n\n public get nameAsValue() {\n return this._nameAsValue;\n }\n}\n\nexport function enumModel<Enum>(value: Enum, type: EnumType, i18nBaseKey: string | undefined | null = null, nameAsValue = false) {\n return new EnumDescriptor<Enum>(value, type, i18nBaseKey, nameAsValue);\n}\n\nexport function enumModelGeneric<Enum = any>(type: EnumType, i18nBaseKey: string | undefined | null = null, nameAsValue = false) {\n return new EnumDescriptor<Enum>(undefined as Enum, type, i18nBaseKey, nameAsValue);\n}\n","// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport class TypeDescriptor<Type> {}\n\nexport function type<Type>(): TypeDescriptor<Type> {\n return new TypeDescriptor<Type>();\n}\n","import {IModelDescriptor} from '@mediusinc/mng-commons/core';\n\nimport {TypeDescriptor} from './type.descriptor';\n\nexport class ModelDescriptor<Model> implements IModelDescriptor<Model> {\n protected _i18nBaseKey: string;\n protected _idProperty?: string;\n protected _titleProperty?: string | ((item: Model) => string);\n\n public constructor(idProperty?: string, titleProperty?: string | ((item: Model) => string), i18nBaseKey?: string) {\n this._idProperty = idProperty;\n this._titleProperty = titleProperty;\n this._i18nBaseKey = i18nBaseKey ?? '';\n }\n\n public get i18nBaseKey() {\n return this._i18nBaseKey;\n }\n\n public get idProperty() {\n return this._idProperty;\n }\n\n public get titleProperty() {\n return this._titleProperty;\n }\n\n public withIdProperty(property: keyof Model): this {\n this._idProperty = property as string;\n return this;\n }\n\n public withIdPropertyUnsafe(property: string): this {\n this._idProperty = property;\n return this;\n }\n\n public withTitleProperty(property: keyof Model): this {\n this._titleProperty = property as string;\n return this;\n }\n\n public withTitlePropertyUnsafe(property: string): this {\n this._titleProperty = property;\n return this;\n }\n\n public withI18nBase(base: string): this {\n this._i18nBaseKey = base;\n return this;\n }\n\n public copy(): ModelDescriptor<Model> {\n return new ModelDescriptor<Model>(this._idProperty, this._titleProperty, this._i18nBaseKey);\n }\n}\n\nexport type ModelDescriptorCreateOpts<Model> = {\n id?: keyof Model;\n title?: keyof Model | ((item: Model) => string);\n i18nBase?: string;\n};\n\nexport function model<Model>(): ModelDescriptor<Model>;\nexport function model<Model>(opts: ModelDescriptorCreateOpts<Model>): ModelDescriptor<Model>;\nexport function model<Model>(type: TypeDescriptor<Model>, opts?: ModelDescriptorCreateOpts<Model>): ModelDescriptor<Model>;\nexport function model<Model>(typeOrOpts?: TypeDescriptor<Model> | ModelDescriptorCreateOpts<Model>, opts?: ModelDescriptorCreateOpts<Model>) {\n if (typeOrOpts == null) {\n return new ModelDescriptor<Model>();\n } else if (typeOrOpts instanceof TypeDescriptor) {\n return new ModelDescriptor<Model>(opts?.id as string, opts?.title as string, opts?.i18nBase);\n } else {\n const modelOpts = typeOrOpts as ModelDescriptorCreateOpts<Model>;\n return new ModelDescriptor<Model>(modelOpts?.id as string, modelOpts?.title as string, modelOpts?.i18nBase);\n }\n}\n","import {TranslateService} from '@ngx-translate/core';\nimport {Observable} from 'rxjs';\nimport {map} from 'rxjs/operators';\n\nimport {KeyOfType, getI18n, getI18nTypeKeyBasePath, getI18nTypeParams, getI18nTypeParamsAsync} from '@mediusinc/mng-commons/core';\n\nimport {ModelDescriptor} from '../descriptors/model.descriptor';\n\nexport function getI18nForModel(\n translate: TranslateService,\n model: ModelDescriptor<any>,\n keyPath: string,\n customKey?: string,\n item?: any,\n fallbackKey?: string,\n params?: any\n): string | null {\n const keys = getKeysByPriority(model, keyPath, customKey, fallbackKey);\n const i18nParams = getI18nModelParams(translate, model, item, params);\n return getI18n(translate, i18nParams, ...keys);\n}\n\nexport function getI18nModelParams(translate: TranslateService, model?: ModelDescriptor<any>, item?: any, params: any = {}): any {\n const i18nParams = getI18nTypeParams(translate, model?.i18nBaseKey, item, params);\n return populateI18nModelParams(model?.idProperty, model?.titleProperty, item, i18nParams);\n}\n\nexport function getI18nModelParamsAsync(translate: TranslateService, model?: ModelDescriptor<any>, item?: any, params: any = {}): Observable<any> {\n return getI18nTypeParamsAsync(translate, model?.i18nBaseKey, item, params).pipe(\n map(i18nParams => populateI18nModelParams(model?.idProperty, model?.titleProperty, item, i18nParams))\n );\n}\n\nexport function populateI18nModelParams(idProperty?: KeyOfType, titleProperty?: KeyOfType | ((item: any) => string), item?: any, params: any = {}): any {\n const paramsRes = {...params, itemId: '', itemTitle: ''};\n if (item) {\n if (idProperty && item[idProperty]) {\n paramsRes.itemId = item[idProperty];\n }\n if (typeof titleProperty === 'function') {\n paramsRes.itemTitle = titleProperty(item);\n } else if (titleProperty && item[titleProperty]) {\n paramsRes.itemTitle = item[titleProperty];\n }\n }\n return paramsRes;\n}\n\nfunction getKeysByPriority(model: ModelDescriptor<any>, keyPath: string, customKey?: string, fallbackKey?: string) {\n const keys = [];\n if (customKey) {\n keys.push(customKey);\n }\n const modelActionKey = getI18nTypeKeyBasePath(model.i18nBaseKey, ...keyPath);\n keys.push(modelActionKey);\n if (fallbackKey) {\n keys.push(fallbackKey);\n }\n return keys;\n}\n","// data providers\nexport * from './data-providers/base-from-type-data-provider.factory';\n\n// descriptors\nexport * from './descriptors/enum.descriptor';\nexport * from './descriptors/model.descriptor';\nexport * from './descriptors/type.descriptor';\n\n// helpers\nexport * from './helpers/i18n';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;AAKA;;;;;;;AAOG;AACG,SAAU,YAAY,CAA+G,IAG1I,EAAA;AACG,IAAA,OAAO,IAAI,gBAAgB,CAA+B,IAAI,EAAE,OAAuB,CAAC;AAC5F;;MChBa,cAAc,CAAA;IAMvB,WAAmB,CAAA,KAAW,EAAE,IAAc,EAAE,WAA2B,EAAE,WAAW,GAAG,KAAK,EAAA;AAC5F,QAAA,IAAI,CAAC,MAAM,GAAG,KAAK;AACnB,QAAA,IAAI,CAAC,KAAK,GAAG,IAAI;AACjB,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;AAE/B,QAAA,IAAI,OAAO,WAAW,KAAK,WAAW,EAAE;AACpC,YAAA,WAAW,GAAG,mBAAmB,CAAC,IAAI,CAAC;;AAE3C,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;;AAGnC,IAAA,IAAW,IAAI,GAAA;QACX,OAAO,IAAI,CAAC,KAAK;;AAGrB,IAAA,IAAW,WAAW,GAAA;QAClB,OAAO,IAAI,CAAC,YAAY;;AAG5B,IAAA,IAAW,WAAW,GAAA;QAClB,OAAO,IAAI,CAAC,YAAY;;AAE/B;AAEe,SAAA,SAAS,CAA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QAAA,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;;IAExB,MAAM,cAAc,GAAG,sBAAsB,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,OAAO,CAAC;AAC5E,IAAA,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC;IACzB,IAAI,WAAW,EAAE;AACb,QAAA,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;;AAE1B,IAAA,OAAO,IAAI;AACf;;AC3DA;;ACAA;;AAEG;;;;"}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import { TypeRegistry, CommonsInternalError } from '@mediusinc/mng-commons/core';
|
|
2
|
+
import { ColumnTypeEnum, ColumnDisplayTypeEnum, TableDataProviderInst, TableDescriptorInst } from '@mediusinc/mng-commons/table/api';
|
|
3
|
+
import { findClassTitleAttribute, ModelClassDescriptor, modelClass } from '@mediusinc/mng-commons/model/class';
|
|
4
|
+
import { enumModelGeneric } from '@mediusinc/mng-commons/model';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* converts string type to column type enum, default is string
|
|
8
|
+
* @param attributeType
|
|
9
|
+
*/
|
|
10
|
+
function getColumnTypeFromClassAttributeDefType(attributeType) {
|
|
11
|
+
const typeRegistry = TypeRegistry.get();
|
|
12
|
+
if (typeRegistry.findEnum(attributeType)) {
|
|
13
|
+
attributeType = 'enum';
|
|
14
|
+
}
|
|
15
|
+
else if (typeRegistry.findType(attributeType)) {
|
|
16
|
+
attributeType = 'class';
|
|
17
|
+
}
|
|
18
|
+
switch (attributeType.toLowerCase()) {
|
|
19
|
+
case 'number':
|
|
20
|
+
case 'currency':
|
|
21
|
+
return ColumnTypeEnum.Number;
|
|
22
|
+
case 'boolean':
|
|
23
|
+
return ColumnTypeEnum.Boolean;
|
|
24
|
+
case 'date':
|
|
25
|
+
return ColumnTypeEnum.Date;
|
|
26
|
+
case 'enum':
|
|
27
|
+
return ColumnTypeEnum.Enum;
|
|
28
|
+
case 'custom':
|
|
29
|
+
return ColumnTypeEnum.Custom;
|
|
30
|
+
case 'class':
|
|
31
|
+
return ColumnTypeEnum.String;
|
|
32
|
+
case 'string':
|
|
33
|
+
default:
|
|
34
|
+
return ColumnTypeEnum.String;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function getColumnDisplayTypeFromColumnType(columnType, attributeType) {
|
|
38
|
+
switch (columnType) {
|
|
39
|
+
case ColumnTypeEnum.Number:
|
|
40
|
+
return attributeType === 'currency' ? ColumnDisplayTypeEnum.Currency : ColumnDisplayTypeEnum.Number;
|
|
41
|
+
case ColumnTypeEnum.Boolean:
|
|
42
|
+
return ColumnDisplayTypeEnum.Boolean;
|
|
43
|
+
case ColumnTypeEnum.Date:
|
|
44
|
+
return ColumnDisplayTypeEnum.Date;
|
|
45
|
+
case ColumnTypeEnum.Enum:
|
|
46
|
+
return ColumnDisplayTypeEnum.Enum;
|
|
47
|
+
case ColumnTypeEnum.Custom:
|
|
48
|
+
return ColumnDisplayTypeEnum.Component;
|
|
49
|
+
case ColumnTypeEnum.String:
|
|
50
|
+
default:
|
|
51
|
+
return ColumnDisplayTypeEnum.String;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function expandClassAttributeDefWithTableDef(attributes) {
|
|
55
|
+
if (!attributes) {
|
|
56
|
+
throw new CommonsInternalError('Class attribute definition is null, problem with TypeRegistry::findAttributesDefinitionByClassType?', { name: 'TableviewUtilsError' });
|
|
57
|
+
}
|
|
58
|
+
const typeRegistry = TypeRegistry.get();
|
|
59
|
+
const tableClassAttributeDef = [];
|
|
60
|
+
for (const attribute of attributes) {
|
|
61
|
+
const enumType = typeRegistry.findEnum(attribute.type);
|
|
62
|
+
const columnType = enumType ? ColumnTypeEnum.Enum : getColumnTypeFromClassAttributeDefType(attribute.type);
|
|
63
|
+
tableClassAttributeDef.push({
|
|
64
|
+
name: attribute.name,
|
|
65
|
+
baseName: attribute.baseName,
|
|
66
|
+
type: attribute.type,
|
|
67
|
+
subtype: attribute.subtype,
|
|
68
|
+
columnType: enumType ? ColumnTypeEnum.Enum : getColumnTypeFromClassAttributeDefType(attribute.type),
|
|
69
|
+
columnDisplayType: getColumnDisplayTypeFromColumnType(columnType, attribute.type),
|
|
70
|
+
enumType: typeRegistry.findEnum(attribute.type),
|
|
71
|
+
classType: typeRegistry.findType(attribute.type)
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return tableClassAttributeDef;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* returns attributes from class type and extends to typed def with column and field enum type
|
|
78
|
+
* @param type class type
|
|
79
|
+
*/
|
|
80
|
+
function getTableClassAttributeDef(type) {
|
|
81
|
+
return expandClassAttributeDefWithTableDef(TypeRegistry.get().findAttributesDefinitionByClassType(type));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function tableDataProviderFromClass(type, serviceType) {
|
|
85
|
+
return new TableDataProviderInst(serviceType);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* generates column based on attributes
|
|
90
|
+
* @param desc Table descriptor
|
|
91
|
+
* @param attribute attribute map
|
|
92
|
+
* @param column if provided, replaced by new, otherwise new is created
|
|
93
|
+
* @param args additional parameters
|
|
94
|
+
*/
|
|
95
|
+
function upsertTableColumnFromAttributeDef(desc, attribute, column, ...args) {
|
|
96
|
+
if (column == null) {
|
|
97
|
+
column = desc.addColumnUnsafe(attribute.name);
|
|
98
|
+
}
|
|
99
|
+
if (attribute.columnType === ColumnTypeEnum.Enum && args.length === 0 && attribute.enumType) {
|
|
100
|
+
args = [enumModelGeneric(attribute.enumType)];
|
|
101
|
+
}
|
|
102
|
+
column = column.asType(attribute.columnType, attribute.columnDisplayType, ...args);
|
|
103
|
+
if (attribute.classType) {
|
|
104
|
+
const titleProperty = findClassTitleAttribute(attribute.classType) ?? undefined;
|
|
105
|
+
if (titleProperty) {
|
|
106
|
+
column.withGetter(value => value?.[titleProperty]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
desc.addFilterFromColumnDescriptorUnsafe(column, false);
|
|
111
|
+
desc.withSortUnsafe(column.property);
|
|
112
|
+
}
|
|
113
|
+
return column;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* defines modified type of column
|
|
117
|
+
* DO NOT USE with enum (use withCustomEnumType)
|
|
118
|
+
* @param descriptor table descriptor
|
|
119
|
+
* @param property column name
|
|
120
|
+
* @param columnType modified type
|
|
121
|
+
* @param args additional attributes
|
|
122
|
+
* @param columnDisplayType
|
|
123
|
+
*/
|
|
124
|
+
function modifyTableClassAttributeColumnType(descriptor, property, columnType, columnDisplayType, ...args) {
|
|
125
|
+
return modifyTableClassAttributeColumnTypeUnsafe(descriptor, property, columnType, columnDisplayType, ...args);
|
|
126
|
+
}
|
|
127
|
+
function modifyTableClassAttributeColumnTypeUnsafe(descriptor, property, columnType, columnDisplayType, ...args) {
|
|
128
|
+
if (!(descriptor.model instanceof ModelClassDescriptor)) {
|
|
129
|
+
throw new CommonsInternalError(`withColumnModifiedType cannot be executed for property ${property}: Model descriptor is not of type 'ModelClassDescriptor' is not defined.`);
|
|
130
|
+
}
|
|
131
|
+
const attributeDef = getTableClassAttributeDef(descriptor.model.classType).find(attr => attr.name === property);
|
|
132
|
+
if (attributeDef != null) {
|
|
133
|
+
attributeDef.columnType = columnType ?? attributeDef.columnType;
|
|
134
|
+
attributeDef.columnDisplayType = columnDisplayType ?? attributeDef.columnDisplayType;
|
|
135
|
+
return upsertTableColumnFromAttributeDef(descriptor, attributeDef, descriptor.columns.find(col => col.property === attributeDef.name), ...args);
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* defines custom enum type for column
|
|
141
|
+
* @param descriptor table descriptor
|
|
142
|
+
* @param property column name
|
|
143
|
+
* @param enumDesc Enum descriptor.
|
|
144
|
+
*/
|
|
145
|
+
function modifyTableClassAttributeColumnEnum(descriptor, property, enumDesc) {
|
|
146
|
+
return tableDescriptorModifyEnumColumnUnsafe(descriptor, property, enumDesc);
|
|
147
|
+
}
|
|
148
|
+
function tableDescriptorModifyEnumColumnUnsafe(descriptor, property, enumDesc) {
|
|
149
|
+
if (!(descriptor.model instanceof ModelClassDescriptor)) {
|
|
150
|
+
throw new CommonsInternalError(`withColumnModifiedEnum cannot be executed for property ${property}: Model descriptor is not of type 'ModelClassDescriptor' is not defined.`);
|
|
151
|
+
}
|
|
152
|
+
const attributeDef = getTableClassAttributeDef(descriptor.model.classType).find(attr => attr.name === property);
|
|
153
|
+
if (attributeDef != null) {
|
|
154
|
+
attributeDef.columnType = ColumnTypeEnum.Enum;
|
|
155
|
+
upsertTableColumnFromAttributeDef(descriptor, attributeDef, descriptor.columns.find(col => col.property === property), enumDesc ?? enumModelGeneric(TypeRegistry.get().findEnum(attributeDef.type)));
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* modifies column with class and lookup provider
|
|
161
|
+
* @param descriptor table descriptor
|
|
162
|
+
* @param property column name
|
|
163
|
+
* @param lookupProvider lookupProvider for class
|
|
164
|
+
* @param optionsLabelProperty
|
|
165
|
+
* @param filterProperty
|
|
166
|
+
*/
|
|
167
|
+
function modifyTableColumnFilterLookup(descriptor, property, lookupProvider, optionsLabelProperty, filterProperty) {
|
|
168
|
+
return modifyTableColumnFilterLookupUnsafe(descriptor, property, lookupProvider, optionsLabelProperty, filterProperty);
|
|
169
|
+
}
|
|
170
|
+
function modifyTableColumnFilterLookupUnsafe(descriptor, property, lookupProvider, optionsLabelProperty, filterProperty) {
|
|
171
|
+
const column = descriptor.columns.find(col => col.property === property);
|
|
172
|
+
if (column) {
|
|
173
|
+
const filter = descriptor.addFilterLookupUnsafe(column.property, lookupProvider, filterProperty);
|
|
174
|
+
if (optionsLabelProperty) {
|
|
175
|
+
filter.withOptionsLabelPropertyUnsafe(optionsLabelProperty);
|
|
176
|
+
}
|
|
177
|
+
return filter;
|
|
178
|
+
}
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function tableDescriptorFromClass(type, opts) {
|
|
183
|
+
return new TableDescriptorInst(modelClass(type, opts));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* generates descriptor based on type attribute definition
|
|
187
|
+
* @param type class type
|
|
188
|
+
* @param attributes
|
|
189
|
+
* @param opts
|
|
190
|
+
*/
|
|
191
|
+
function tableDescriptorFromClassAttrsDef(type, attributes, opts) {
|
|
192
|
+
const descriptor = new TableDescriptorInst(modelClass(type, opts), true);
|
|
193
|
+
(attributes ?? getTableClassAttributeDef(type))
|
|
194
|
+
.filter(attr => !attr.type.includes('Set') && !attr.type.includes('Array'))
|
|
195
|
+
.forEach(attr => upsertTableColumnFromAttributeDef(descriptor, attr));
|
|
196
|
+
return descriptor;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Generated bundle index. Do not edit.
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
export { expandClassAttributeDefWithTableDef, getColumnDisplayTypeFromColumnType, getColumnTypeFromClassAttributeDefType, getTableClassAttributeDef, modifyTableClassAttributeColumnEnum, modifyTableClassAttributeColumnType, modifyTableClassAttributeColumnTypeUnsafe, modifyTableColumnFilterLookup, modifyTableColumnFilterLookupUnsafe, tableDataProviderFromClass, tableDescriptorFromClass, tableDescriptorFromClassAttrsDef, tableDescriptorModifyEnumColumnUnsafe, upsertTableColumnFromAttributeDef };
|
|
204
|
+
//# sourceMappingURL=mediusinc-mng-commons-table-api-class.mjs.map
|