Skip to content

Commit b5fd119

Browse files
authored
Automatically fetch changeset id if exists in the iModel for Cesium Sandcastle view (#80)
1 parent fd225e3 commit b5fd119

3 files changed

Lines changed: 41 additions & 24 deletions

File tree

docs/imodel/view/cesium-sandcastle.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ Setup iModel and get URL to view it in Cesium Sandcastle.
1919
## Examples
2020

2121
```bash
22-
# Example 1: Get a link to a specific changeset of an iModel in Cesium Sandcastle
23-
itp imodel view cesium-sandcastle --imodel-id "5e19bee0-3aea-4355-a9f0-c6df9989ee7d" --changeset-id "2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5"
22+
# Example 1: Get a link to an iModel in Cesium Sandcastle
23+
itp imodel view cesium-sandcastle --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d
2424

25-
# Example 2: Get a link to a specific changeset of an iModel in Cesium Sandcastle and open the URL in the browser
26-
itp imodel view cesium-sandcastle --imodel-id "5e19bee0-3aea-4355-a9f0-c6df9989ee7d" --changeset-id "2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5" --open
25+
# Example 2: Get a link to a specific changeset of an iModel in Cesium Sandcastle
26+
itp imodel view cesium-sandcastle --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5
27+
28+
# Example 3: Get a link to a specific changeset of an iModel in Cesium Sandcastle and open the URL in the browser
29+
itp imodel view cesium-sandcastle --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5 --open
2730
```
2831

2932
## API Reference

src/commands/imodel/changeset/list.ts

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import { Changeset, ChangesetOrderByProperty, OrderBy, OrderByOperator } from "@itwin/imodels-client-management";
6+
import { Changeset, ChangesetOrderByProperty, OrderBy, OrderByOperator, take, toArray } from "@itwin/imodels-client-management";
77
import { Flags } from "@oclif/core";
88

99
import BaseCommand from "../../../extensions/base-command.js";
@@ -70,23 +70,22 @@ export default class ListChangesets extends BaseCommand {
7070
property: ChangesetOrderByProperty.Index
7171
} : undefined;
7272

73+
const urlParams = {
74+
$orderBy: orderBy,
75+
$skip: flags.skip,
76+
$top: flags.top,
77+
afterIndex: flags["after-index"],
78+
lastIndex: flags["last-index"]
79+
};
80+
7381
const changesetList = client.changesets.getRepresentationList({
7482
authorization,
7583
iModelId: flags["imodel-id"],
76-
urlParams: {
77-
$orderBy: orderBy,
78-
$skip: flags.skip,
79-
$top: flags.top,
80-
afterIndex: flags["after-index"],
81-
lastIndex: flags["last-index"]
82-
},
84+
urlParams
8385
});
8486

85-
const result: Changeset[] = [];
86-
for await (const changeset of changesetList) {
87-
result.push(changeset);
88-
}
89-
87+
const result : Changeset[] = await (flags.top ? take(changesetList, flags.top) : toArray(changesetList));
88+
9089
return this.logAndReturnResult(result);
9190
}
9291
}

src/commands/imodel/view/cesium-sandcastle.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* See LICENSE.md in the project root for license terms and full copyright notice.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { Changeset } from "@itwin/imodels-client-management";
67
import { Flags } from "@oclif/core";
78
import open from 'open';
89
import { deflate } from "pako";
@@ -15,19 +16,23 @@ export default class CesiumSandcastle extends BaseCommand {
1516

1617
static examples = [
1718
{
18-
command: `<%= config.bin %> <%= command.id %> --imodel-id "5e19bee0-3aea-4355-a9f0-c6df9989ee7d" --changeset-id "2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5"`,
19-
description: 'Example 1: Get a link to a specific changeset of an iModel in Cesium Sandcastle'
19+
command: `<%= config.bin %> <%= command.id %> --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d`,
20+
description: 'Example 1: Get a link to an iModel in Cesium Sandcastle'
2021
},
2122
{
22-
command: `<%= config.bin %> <%= command.id %> --imodel-id "5e19bee0-3aea-4355-a9f0-c6df9989ee7d" --changeset-id "2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5" --open`,
23-
description: 'Example 2: Get a link to a specific changeset of an iModel in Cesium Sandcastle and open the URL in the browser'
23+
command: `<%= config.bin %> <%= command.id %> --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5`,
24+
description: 'Example 2: Get a link to a specific changeset of an iModel in Cesium Sandcastle'
25+
},
26+
{
27+
command: `<%= config.bin %> <%= command.id %> --imodel-id 5e19bee0-3aea-4355-a9f0-c6df9989ee7d --changeset-id 2f3b4a8c92d747d5c8a8b2f9cde6742e5d74b3b5 --open`,
28+
description: 'Example 3: Get a link to a specific changeset of an iModel in Cesium Sandcastle and open the URL in the browser'
2429
}
2530
];
2631

2732
static flags = {
2833
"changeset-id": Flags.string({
29-
description: "Changeset id to be viewed in Cesium Sandcastle.",
30-
required: true
34+
description: "Changeset id to be viewed in Cesium Sandcastle. If not provided, the latest changeset will be used.",
35+
required: false
3136
}),
3237
"imodel-id": Flags.string({
3338
char: "m",
@@ -96,7 +101,17 @@ export default class CesiumSandcastle extends BaseCommand {
96101
async run() {
97102
const { flags } = await this.parse(CesiumSandcastle);
98103

99-
const exportInfo : ExportInfo = await this.getOrCreateExport(flags["imodel-id"], flags["changeset-id"]);
104+
let changesetId = flags["changeset-id"];
105+
if (changesetId === undefined) {
106+
const existingChangesets = await this.runCommand<Changeset[]>("imodel:changeset:list", ["-m", flags["imodel-id"], "--top", "1", "--order-by", "desc"]);
107+
if (existingChangesets.length === 0) {
108+
this.error(`No changesets found for iModel: ${flags["imodel-id"]}`);
109+
}
110+
111+
changesetId = existingChangesets[0].id;
112+
}
113+
114+
const exportInfo : ExportInfo = await this.getOrCreateExport(flags["imodel-id"], changesetId);
100115

101116
this.log(`Extracting tileset URL from export info`);
102117
const tilesetUrl : string = extractTileSetUrl(exportInfo);

0 commit comments

Comments
 (0)