@itwin/presentation-testing 3.4.0-dev.44 → 3.4.0-dev.46
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/lib/cjs/presentation-testing/ContentBuilder.d.ts +87 -87
- package/lib/cjs/presentation-testing/ContentBuilder.js +147 -147
- package/lib/cjs/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing/Helpers.d.ts +38 -38
- package/lib/cjs/presentation-testing/Helpers.js +125 -125
- package/lib/cjs/presentation-testing/Helpers.js.map +1 -1
- package/lib/cjs/presentation-testing/HierarchyBuilder.d.ts +66 -66
- package/lib/cjs/presentation-testing/HierarchyBuilder.js +68 -68
- package/lib/cjs/presentation-testing/HierarchyBuilder.js.map +1 -1
- package/lib/cjs/presentation-testing.d.ts +21 -21
- package/lib/cjs/presentation-testing.js +37 -37
- package/lib/cjs/presentation-testing.js.map +1 -1
- package/lib/esm/presentation-testing/ContentBuilder.d.ts +87 -87
- package/lib/esm/presentation-testing/ContentBuilder.js +143 -143
- package/lib/esm/presentation-testing/ContentBuilder.js.map +1 -1
- package/lib/esm/presentation-testing/Helpers.d.ts +38 -38
- package/lib/esm/presentation-testing/Helpers.js +100 -100
- package/lib/esm/presentation-testing/Helpers.js.map +1 -1
- package/lib/esm/presentation-testing/HierarchyBuilder.d.ts +66 -66
- package/lib/esm/presentation-testing/HierarchyBuilder.js +63 -63
- package/lib/esm/presentation-testing/HierarchyBuilder.js.map +1 -1
- package/lib/esm/presentation-testing.d.ts +21 -21
- package/lib/esm/presentation-testing.js +25 -25
- package/lib/esm/presentation-testing.js.map +1 -1
- package/package.json +13 -13
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module Hierarchies
|
|
3
|
-
*
|
|
4
|
-
* @docs-group-description Hierarchies
|
|
5
|
-
* Types for testing hierarchies.
|
|
6
|
-
*/
|
|
7
|
-
export * from "./presentation-testing/HierarchyBuilder";
|
|
8
|
-
/**
|
|
9
|
-
* @module Content
|
|
10
|
-
*
|
|
11
|
-
* @docs-group-description Content
|
|
12
|
-
* Types for testing content.
|
|
13
|
-
*/
|
|
14
|
-
export * from "./presentation-testing/ContentBuilder";
|
|
15
|
-
/**
|
|
16
|
-
* @module Helpers
|
|
17
|
-
*
|
|
18
|
-
* @docs-group-description Helpers
|
|
19
|
-
* Various test helpers.
|
|
20
|
-
*/
|
|
21
|
-
export * from "./presentation-testing/Helpers";
|
|
1
|
+
/**
|
|
2
|
+
* @module Hierarchies
|
|
3
|
+
*
|
|
4
|
+
* @docs-group-description Hierarchies
|
|
5
|
+
* Types for testing hierarchies.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./presentation-testing/HierarchyBuilder";
|
|
8
|
+
/**
|
|
9
|
+
* @module Content
|
|
10
|
+
*
|
|
11
|
+
* @docs-group-description Content
|
|
12
|
+
* Types for testing content.
|
|
13
|
+
*/
|
|
14
|
+
export * from "./presentation-testing/ContentBuilder";
|
|
15
|
+
/**
|
|
16
|
+
* @module Helpers
|
|
17
|
+
*
|
|
18
|
+
* @docs-group-description Helpers
|
|
19
|
+
* Various test helpers.
|
|
20
|
+
*/
|
|
21
|
+
export * from "./presentation-testing/Helpers";
|
|
22
22
|
//# sourceMappingURL=presentation-testing.d.ts.map
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
/*---------------------------------------------------------------------------------------------
|
|
14
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
15
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
16
|
-
*--------------------------------------------------------------------------------------------*/
|
|
17
|
-
/**
|
|
18
|
-
* @module Hierarchies
|
|
19
|
-
*
|
|
20
|
-
* @docs-group-description Hierarchies
|
|
21
|
-
* Types for testing hierarchies.
|
|
22
|
-
*/
|
|
23
|
-
__exportStar(require("./presentation-testing/HierarchyBuilder"), exports);
|
|
24
|
-
/**
|
|
25
|
-
* @module Content
|
|
26
|
-
*
|
|
27
|
-
* @docs-group-description Content
|
|
28
|
-
* Types for testing content.
|
|
29
|
-
*/
|
|
30
|
-
__exportStar(require("./presentation-testing/ContentBuilder"), exports);
|
|
31
|
-
/**
|
|
32
|
-
* @module Helpers
|
|
33
|
-
*
|
|
34
|
-
* @docs-group-description Helpers
|
|
35
|
-
* Various test helpers.
|
|
36
|
-
*/
|
|
37
|
-
__exportStar(require("./presentation-testing/Helpers"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
/*---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
15
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
16
|
+
*--------------------------------------------------------------------------------------------*/
|
|
17
|
+
/**
|
|
18
|
+
* @module Hierarchies
|
|
19
|
+
*
|
|
20
|
+
* @docs-group-description Hierarchies
|
|
21
|
+
* Types for testing hierarchies.
|
|
22
|
+
*/
|
|
23
|
+
__exportStar(require("./presentation-testing/HierarchyBuilder"), exports);
|
|
24
|
+
/**
|
|
25
|
+
* @module Content
|
|
26
|
+
*
|
|
27
|
+
* @docs-group-description Content
|
|
28
|
+
* Types for testing content.
|
|
29
|
+
*/
|
|
30
|
+
__exportStar(require("./presentation-testing/ContentBuilder"), exports);
|
|
31
|
+
/**
|
|
32
|
+
* @module Helpers
|
|
33
|
+
*
|
|
34
|
+
* @docs-group-description Helpers
|
|
35
|
+
* Various test helpers.
|
|
36
|
+
*/
|
|
37
|
+
__exportStar(require("./presentation-testing/Helpers"), exports);
|
|
38
38
|
//# sourceMappingURL=presentation-testing.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/**\n * @module Hierarchies\n *\n * @docs-group-description Hierarchies\n * Types for testing hierarchies.\n */\nexport * from \"./presentation-testing/HierarchyBuilder\";\n\n/**\n * @module Content\n *\n * @docs-group-description Content\n * Types for testing content.\n */\nexport * from \"./presentation-testing/ContentBuilder\";\n\n/**\n * @module Helpers\n *\n * @docs-group-description Helpers\n * Various test helpers.\n */\nexport * from \"./presentation-testing/Helpers\";\n"]}
|
|
1
|
+
{"version":3,"file":"presentation-testing.js","sourceRoot":"","sources":["../../src/presentation-testing.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA;;;+FAG+F;AAC/F;;;;;GAKG;AACH,0EAAwD;AAExD;;;;;GAKG;AACH,wEAAsD;AAEtD;;;;;GAKG;AACH,iEAA+C","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/**\r\n * @module Hierarchies\r\n *\r\n * @docs-group-description Hierarchies\r\n * Types for testing hierarchies.\r\n */\r\nexport * from \"./presentation-testing/HierarchyBuilder\";\r\n\r\n/**\r\n * @module Content\r\n *\r\n * @docs-group-description Content\r\n * Types for testing content.\r\n */\r\nexport * from \"./presentation-testing/ContentBuilder\";\r\n\r\n/**\r\n * @module Helpers\r\n *\r\n * @docs-group-description Helpers\r\n * Various test helpers.\r\n */\r\nexport * from \"./presentation-testing/Helpers\";\r\n"]}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import { PropertyRecord } from "@itwin/appui-abstract";
|
|
2
|
-
import { IModelConnection } from "@itwin/core-frontend";
|
|
3
|
-
import { Content, InstanceKey, KeySet, PageOptions, Ruleset } from "@itwin/presentation-common";
|
|
4
|
-
/**
|
|
5
|
-
* Interface for a data provider, which is used by ContentBuilder.
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
|
-
export interface IContentBuilderDataProvider {
|
|
9
|
-
/** Keys the data provider is creating content for */
|
|
10
|
-
keys: Readonly<KeySet>;
|
|
11
|
-
/** Get the size of content result set */
|
|
12
|
-
getContentSetSize: () => Promise<number>;
|
|
13
|
-
/** Get the content */
|
|
14
|
-
getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Property records grouped under a single className
|
|
18
|
-
* @public
|
|
19
|
-
*/
|
|
20
|
-
export interface ContentBuilderResult {
|
|
21
|
-
/** Full name of ECClass whose records are contained in this data structure */
|
|
22
|
-
className: string;
|
|
23
|
-
/** Property records for the ECClass instance */
|
|
24
|
-
records: PropertyRecord[];
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Properties for creating a `ContentBuilder` instance.
|
|
28
|
-
* @public
|
|
29
|
-
*/
|
|
30
|
-
export interface ContentBuilderProps {
|
|
31
|
-
/** The iModel to pull data from */
|
|
32
|
-
imodel: IModelConnection;
|
|
33
|
-
/** Custom data provider that allows mocking data ContentBuilder receives */
|
|
34
|
-
dataProvider?: IContentBuilderDataProvider;
|
|
35
|
-
/**
|
|
36
|
-
* Decimal precision or numeric types.
|
|
37
|
-
*
|
|
38
|
-
* Raw numeric values with high precision may slightly differ from platform to platform due to
|
|
39
|
-
* rounding differences on different platforms. This may be a problem when used with snapshot testing,
|
|
40
|
-
* in which case this attribute may be set to supply the maximum precision of raw numeric values.
|
|
41
|
-
*
|
|
42
|
-
* By default no rounding is applied.
|
|
43
|
-
*/
|
|
44
|
-
decimalPrecision?: number;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* A class that constructs content from specified imodel and ruleset.
|
|
48
|
-
* @public
|
|
49
|
-
*/
|
|
50
|
-
export declare class ContentBuilder {
|
|
51
|
-
private readonly _iModel;
|
|
52
|
-
private _dataProvider;
|
|
53
|
-
private _decimalPrecision?;
|
|
54
|
-
/**
|
|
55
|
-
* Constructor
|
|
56
|
-
* @param iModel
|
|
57
|
-
* @param dataProvider
|
|
58
|
-
*/
|
|
59
|
-
constructor(props: ContentBuilderProps);
|
|
60
|
-
private doCreateContent;
|
|
61
|
-
/**
|
|
62
|
-
* Create a list of property records using the supplied presentation ruleset.
|
|
63
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
64
|
-
* @param instanceKeys Keys of instances that should be queried.
|
|
65
|
-
* @param displayType Type of content container display. For example:
|
|
66
|
-
* "PropertyPane", "Grid", "List" etc.
|
|
67
|
-
*/
|
|
68
|
-
createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType?: string): Promise<PropertyRecord[]>;
|
|
69
|
-
private getECClassNames;
|
|
70
|
-
private createContentForClasses;
|
|
71
|
-
/**
|
|
72
|
-
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
73
|
-
* Each group includes all of the class instances.
|
|
74
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
75
|
-
* @param displayType Type of content container display. For example:
|
|
76
|
-
* "PropertyPane", "Grid", "List" etc.
|
|
77
|
-
*/
|
|
78
|
-
createContentForAllInstances(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
|
|
79
|
-
/**
|
|
80
|
-
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
81
|
-
* Each group includes at most one class instance.
|
|
82
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
83
|
-
* @param displayType Type of content container display. For example:
|
|
84
|
-
* "PropertyPane", "Grid", "List" etc.
|
|
85
|
-
*/
|
|
86
|
-
createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
|
|
87
|
-
}
|
|
1
|
+
import { PropertyRecord } from "@itwin/appui-abstract";
|
|
2
|
+
import { IModelConnection } from "@itwin/core-frontend";
|
|
3
|
+
import { Content, InstanceKey, KeySet, PageOptions, Ruleset } from "@itwin/presentation-common";
|
|
4
|
+
/**
|
|
5
|
+
* Interface for a data provider, which is used by ContentBuilder.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export interface IContentBuilderDataProvider {
|
|
9
|
+
/** Keys the data provider is creating content for */
|
|
10
|
+
keys: Readonly<KeySet>;
|
|
11
|
+
/** Get the size of content result set */
|
|
12
|
+
getContentSetSize: () => Promise<number>;
|
|
13
|
+
/** Get the content */
|
|
14
|
+
getContent: (options?: PageOptions) => Promise<Readonly<Content> | undefined>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Property records grouped under a single className
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export interface ContentBuilderResult {
|
|
21
|
+
/** Full name of ECClass whose records are contained in this data structure */
|
|
22
|
+
className: string;
|
|
23
|
+
/** Property records for the ECClass instance */
|
|
24
|
+
records: PropertyRecord[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Properties for creating a `ContentBuilder` instance.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export interface ContentBuilderProps {
|
|
31
|
+
/** The iModel to pull data from */
|
|
32
|
+
imodel: IModelConnection;
|
|
33
|
+
/** Custom data provider that allows mocking data ContentBuilder receives */
|
|
34
|
+
dataProvider?: IContentBuilderDataProvider;
|
|
35
|
+
/**
|
|
36
|
+
* Decimal precision or numeric types.
|
|
37
|
+
*
|
|
38
|
+
* Raw numeric values with high precision may slightly differ from platform to platform due to
|
|
39
|
+
* rounding differences on different platforms. This may be a problem when used with snapshot testing,
|
|
40
|
+
* in which case this attribute may be set to supply the maximum precision of raw numeric values.
|
|
41
|
+
*
|
|
42
|
+
* By default no rounding is applied.
|
|
43
|
+
*/
|
|
44
|
+
decimalPrecision?: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A class that constructs content from specified imodel and ruleset.
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
export declare class ContentBuilder {
|
|
51
|
+
private readonly _iModel;
|
|
52
|
+
private _dataProvider;
|
|
53
|
+
private _decimalPrecision?;
|
|
54
|
+
/**
|
|
55
|
+
* Constructor
|
|
56
|
+
* @param iModel
|
|
57
|
+
* @param dataProvider
|
|
58
|
+
*/
|
|
59
|
+
constructor(props: ContentBuilderProps);
|
|
60
|
+
private doCreateContent;
|
|
61
|
+
/**
|
|
62
|
+
* Create a list of property records using the supplied presentation ruleset.
|
|
63
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
64
|
+
* @param instanceKeys Keys of instances that should be queried.
|
|
65
|
+
* @param displayType Type of content container display. For example:
|
|
66
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
67
|
+
*/
|
|
68
|
+
createContent(rulesetOrId: Ruleset | string, instanceKeys: InstanceKey[], displayType?: string): Promise<PropertyRecord[]>;
|
|
69
|
+
private getECClassNames;
|
|
70
|
+
private createContentForClasses;
|
|
71
|
+
/**
|
|
72
|
+
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
73
|
+
* Each group includes all of the class instances.
|
|
74
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
75
|
+
* @param displayType Type of content container display. For example:
|
|
76
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
77
|
+
*/
|
|
78
|
+
createContentForAllInstances(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
81
|
+
* Each group includes at most one class instance.
|
|
82
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
83
|
+
* @param displayType Type of content container display. For example:
|
|
84
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
85
|
+
*/
|
|
86
|
+
createContentForInstancePerClass(rulesetOrId: Ruleset | string, displayType?: string): Promise<ContentBuilderResult[]>;
|
|
87
|
+
}
|
|
88
88
|
//# sourceMappingURL=ContentBuilder.d.ts.map
|
|
@@ -1,144 +1,144 @@
|
|
|
1
|
-
/*---------------------------------------------------------------------------------------------
|
|
2
|
-
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
-
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
-
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
/** @packageDocumentation
|
|
6
|
-
* @module Content
|
|
7
|
-
*/
|
|
8
|
-
import { using } from "@itwin/core-bentley";
|
|
9
|
-
import { QueryRowFormat } from "@itwin/core-common";
|
|
10
|
-
import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
|
|
11
|
-
import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
|
|
12
|
-
import { Presentation } from "@itwin/presentation-frontend";
|
|
13
|
-
/**
|
|
14
|
-
* A class that constructs content from specified imodel and ruleset.
|
|
15
|
-
* @public
|
|
16
|
-
*/
|
|
17
|
-
export class ContentBuilder {
|
|
18
|
-
/**
|
|
19
|
-
* Constructor
|
|
20
|
-
* @param iModel
|
|
21
|
-
* @param dataProvider
|
|
22
|
-
*/
|
|
23
|
-
constructor(props) {
|
|
24
|
-
this._iModel = props.imodel;
|
|
25
|
-
this._dataProvider = props.dataProvider;
|
|
26
|
-
this._decimalPrecision = props.decimalPrecision;
|
|
27
|
-
}
|
|
28
|
-
async doCreateContent(rulesetId, instanceKeys, displayType) {
|
|
29
|
-
const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
|
|
30
|
-
dataProvider.keys = new KeySet(instanceKeys);
|
|
31
|
-
const content = await dataProvider.getContent();
|
|
32
|
-
if (!content)
|
|
33
|
-
return [];
|
|
34
|
-
const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
|
|
35
|
-
traverseContent(accumulator, content);
|
|
36
|
-
return accumulator.records;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Create a list of property records using the supplied presentation ruleset.
|
|
40
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
41
|
-
* @param instanceKeys Keys of instances that should be queried.
|
|
42
|
-
* @param displayType Type of content container display. For example:
|
|
43
|
-
* "PropertyPane", "Grid", "List" etc.
|
|
44
|
-
*/
|
|
45
|
-
async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
46
|
-
if (typeof rulesetOrId === "string")
|
|
47
|
-
return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
|
|
48
|
-
return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
|
|
49
|
-
return this.doCreateContent(ruleset.id, instanceKeys, displayType);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async getECClassNames() {
|
|
53
|
-
const rows = [];
|
|
54
|
-
for await (const row of this._iModel.query(`
|
|
55
|
-
SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
|
|
56
|
-
INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
|
|
57
|
-
WHERE c.Modifier <> 1 AND c.Type = 0
|
|
58
|
-
ORDER BY s.Name, c.Name
|
|
59
|
-
`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
|
|
60
|
-
rows.push(row);
|
|
61
|
-
}
|
|
62
|
-
return rows;
|
|
63
|
-
}
|
|
64
|
-
async createContentForClasses(rulesetOrId, limitInstances, displayType) {
|
|
65
|
-
const classNameEntries = await this.getECClassNames();
|
|
66
|
-
const contents = [];
|
|
67
|
-
for (const nameEntry of classNameEntries) {
|
|
68
|
-
// try {
|
|
69
|
-
const instanceIds = [];
|
|
70
|
-
for await (const row of this._iModel.query(`
|
|
71
|
-
SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
|
|
72
|
-
ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
|
|
73
|
-
instanceIds.push(row.id);
|
|
74
|
-
}
|
|
75
|
-
if (!instanceIds.length)
|
|
76
|
-
continue;
|
|
77
|
-
const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
|
|
78
|
-
contents.push({
|
|
79
|
-
className: `${nameEntry.schemaName}:${nameEntry.className}`,
|
|
80
|
-
records: await this.createContent(rulesetOrId, instanceKeys, displayType),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
return contents;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
87
|
-
* Each group includes all of the class instances.
|
|
88
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
89
|
-
* @param displayType Type of content container display. For example:
|
|
90
|
-
* "PropertyPane", "Grid", "List" etc.
|
|
91
|
-
*/
|
|
92
|
-
async createContentForAllInstances(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
93
|
-
return this.createContentForClasses(rulesetOrId, false, displayType);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
97
|
-
* Each group includes at most one class instance.
|
|
98
|
-
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
99
|
-
* @param displayType Type of content container display. For example:
|
|
100
|
-
* "PropertyPane", "Grid", "List" etc.
|
|
101
|
-
*/
|
|
102
|
-
async createContentForInstancePerClass(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
103
|
-
return this.createContentForClasses(rulesetOrId, true, displayType);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
class PropertyRecordsAccumulator extends PropertyRecordsBuilder {
|
|
107
|
-
constructor(decimalPrecision) {
|
|
108
|
-
super();
|
|
109
|
-
this._records = [];
|
|
110
|
-
this._decimalPrecision = decimalPrecision;
|
|
111
|
-
}
|
|
112
|
-
get records() {
|
|
113
|
-
return this._records;
|
|
114
|
-
}
|
|
115
|
-
createRootPropertiesAppender() {
|
|
116
|
-
return {
|
|
117
|
-
append: (record) => {
|
|
118
|
-
this._records.push(record.record);
|
|
119
|
-
},
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
processRawValue(value) {
|
|
123
|
-
if (this._decimalPrecision === undefined)
|
|
124
|
-
return value;
|
|
125
|
-
if (typeof value === "number") {
|
|
126
|
-
return +(Number(value)).toFixed(this._decimalPrecision);
|
|
127
|
-
}
|
|
128
|
-
if (Array.isArray(value)) {
|
|
129
|
-
return value.map((item) => this.processRawValue(item));
|
|
130
|
-
}
|
|
131
|
-
if (value instanceof Object) {
|
|
132
|
-
const res = {};
|
|
133
|
-
Object.entries(value).forEach(([key, memberValue]) => {
|
|
134
|
-
res[key] = this.processRawValue(memberValue);
|
|
135
|
-
});
|
|
136
|
-
return res;
|
|
137
|
-
}
|
|
138
|
-
return value;
|
|
139
|
-
}
|
|
140
|
-
processPrimitiveValue(props) {
|
|
141
|
-
super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
|
|
142
|
-
}
|
|
143
|
-
}
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
/** @packageDocumentation
|
|
6
|
+
* @module Content
|
|
7
|
+
*/
|
|
8
|
+
import { using } from "@itwin/core-bentley";
|
|
9
|
+
import { QueryRowFormat } from "@itwin/core-common";
|
|
10
|
+
import { DefaultContentDisplayTypes, KeySet, traverseContent, } from "@itwin/presentation-common";
|
|
11
|
+
import { ContentDataProvider, PropertyRecordsBuilder } from "@itwin/presentation-components";
|
|
12
|
+
import { Presentation } from "@itwin/presentation-frontend";
|
|
13
|
+
/**
|
|
14
|
+
* A class that constructs content from specified imodel and ruleset.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export class ContentBuilder {
|
|
18
|
+
/**
|
|
19
|
+
* Constructor
|
|
20
|
+
* @param iModel
|
|
21
|
+
* @param dataProvider
|
|
22
|
+
*/
|
|
23
|
+
constructor(props) {
|
|
24
|
+
this._iModel = props.imodel;
|
|
25
|
+
this._dataProvider = props.dataProvider;
|
|
26
|
+
this._decimalPrecision = props.decimalPrecision;
|
|
27
|
+
}
|
|
28
|
+
async doCreateContent(rulesetId, instanceKeys, displayType) {
|
|
29
|
+
const dataProvider = this._dataProvider ? this._dataProvider : new ContentDataProvider({ imodel: this._iModel, ruleset: rulesetId, displayType });
|
|
30
|
+
dataProvider.keys = new KeySet(instanceKeys);
|
|
31
|
+
const content = await dataProvider.getContent();
|
|
32
|
+
if (!content)
|
|
33
|
+
return [];
|
|
34
|
+
const accumulator = new PropertyRecordsAccumulator(this._decimalPrecision);
|
|
35
|
+
traverseContent(accumulator, content);
|
|
36
|
+
return accumulator.records;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Create a list of property records using the supplied presentation ruleset.
|
|
40
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
41
|
+
* @param instanceKeys Keys of instances that should be queried.
|
|
42
|
+
* @param displayType Type of content container display. For example:
|
|
43
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
44
|
+
*/
|
|
45
|
+
async createContent(rulesetOrId, instanceKeys, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
46
|
+
if (typeof rulesetOrId === "string")
|
|
47
|
+
return this.doCreateContent(rulesetOrId, instanceKeys, displayType);
|
|
48
|
+
return using(await Presentation.presentation.rulesets().add(rulesetOrId), async (ruleset) => {
|
|
49
|
+
return this.doCreateContent(ruleset.id, instanceKeys, displayType);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
async getECClassNames() {
|
|
53
|
+
const rows = [];
|
|
54
|
+
for await (const row of this._iModel.query(`
|
|
55
|
+
SELECT s.Name schemaName, c.Name className FROM meta.ECClassDef c
|
|
56
|
+
INNER JOIN meta.ECSchemaDef s ON c.Schema.id = s.ECInstanceId
|
|
57
|
+
WHERE c.Modifier <> 1 AND c.Type = 0
|
|
58
|
+
ORDER BY s.Name, c.Name
|
|
59
|
+
`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames })) {
|
|
60
|
+
rows.push(row);
|
|
61
|
+
}
|
|
62
|
+
return rows;
|
|
63
|
+
}
|
|
64
|
+
async createContentForClasses(rulesetOrId, limitInstances, displayType) {
|
|
65
|
+
const classNameEntries = await this.getECClassNames();
|
|
66
|
+
const contents = [];
|
|
67
|
+
for (const nameEntry of classNameEntries) {
|
|
68
|
+
// try {
|
|
69
|
+
const instanceIds = [];
|
|
70
|
+
for await (const row of this._iModel.query(`
|
|
71
|
+
SELECT ECInstanceId FROM ONLY "${nameEntry.schemaName}"."${nameEntry.className}"
|
|
72
|
+
ORDER BY ECInstanceId`, undefined, { rowFormat: QueryRowFormat.UseJsPropertyNames, limit: { count: limitInstances ? 1 : 4000 } })) {
|
|
73
|
+
instanceIds.push(row.id);
|
|
74
|
+
}
|
|
75
|
+
if (!instanceIds.length)
|
|
76
|
+
continue;
|
|
77
|
+
const instanceKeys = instanceIds.map((idEntry) => ({ className: `${nameEntry.schemaName}:${nameEntry.className}`, id: idEntry }));
|
|
78
|
+
contents.push({
|
|
79
|
+
className: `${nameEntry.schemaName}:${nameEntry.className}`,
|
|
80
|
+
records: await this.createContent(rulesetOrId, instanceKeys, displayType),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return contents;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
87
|
+
* Each group includes all of the class instances.
|
|
88
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
89
|
+
* @param displayType Type of content container display. For example:
|
|
90
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
91
|
+
*/
|
|
92
|
+
async createContentForAllInstances(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
93
|
+
return this.createContentForClasses(rulesetOrId, false, displayType);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Create a list of grouped property records using the supplied presentation ruleset.
|
|
97
|
+
* Each group includes at most one class instance.
|
|
98
|
+
* @param rulesetOrId Either a [[Ruleset]] object or a ruleset id.
|
|
99
|
+
* @param displayType Type of content container display. For example:
|
|
100
|
+
* "PropertyPane", "Grid", "List" etc.
|
|
101
|
+
*/
|
|
102
|
+
async createContentForInstancePerClass(rulesetOrId, displayType = DefaultContentDisplayTypes.PropertyPane) {
|
|
103
|
+
return this.createContentForClasses(rulesetOrId, true, displayType);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
class PropertyRecordsAccumulator extends PropertyRecordsBuilder {
|
|
107
|
+
constructor(decimalPrecision) {
|
|
108
|
+
super();
|
|
109
|
+
this._records = [];
|
|
110
|
+
this._decimalPrecision = decimalPrecision;
|
|
111
|
+
}
|
|
112
|
+
get records() {
|
|
113
|
+
return this._records;
|
|
114
|
+
}
|
|
115
|
+
createRootPropertiesAppender() {
|
|
116
|
+
return {
|
|
117
|
+
append: (record) => {
|
|
118
|
+
this._records.push(record.record);
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
processRawValue(value) {
|
|
123
|
+
if (this._decimalPrecision === undefined)
|
|
124
|
+
return value;
|
|
125
|
+
if (typeof value === "number") {
|
|
126
|
+
return +(Number(value)).toFixed(this._decimalPrecision);
|
|
127
|
+
}
|
|
128
|
+
if (Array.isArray(value)) {
|
|
129
|
+
return value.map((item) => this.processRawValue(item));
|
|
130
|
+
}
|
|
131
|
+
if (value instanceof Object) {
|
|
132
|
+
const res = {};
|
|
133
|
+
Object.entries(value).forEach(([key, memberValue]) => {
|
|
134
|
+
res[key] = this.processRawValue(memberValue);
|
|
135
|
+
});
|
|
136
|
+
return res;
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
processPrimitiveValue(props) {
|
|
141
|
+
super.processPrimitiveValue({ ...props, rawValue: this.processRawValue(props.rawValue) });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
144
|
//# sourceMappingURL=ContentBuilder.js.map
|