Skip to content

Commit

Permalink
present all available facilities
Browse files Browse the repository at this point in the history
On load, it was trying to only get currentTeamsFacilities(), but that was flaky, so now I get ALL facilities from all teams that I'm on.  Also fixed a few things that had changed in Viewer API.
  • Loading branch information
JimAwe committed Apr 23, 2024
1 parent 0dc56a2 commit f0902bf
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
32 changes: 21 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,39 @@ import * as st_stubs from './src/st_stubs.js';
**********************/

async function getAllFacilities(app) {
const currentTeamFacilities = await app.getCurrentTeamsFacilities(); // Facilities we have access to based on the current team

// we will construct a readable table to dump out the info for the user
let printOutFacilities = [];
let tmp = null;
for (let i=0; i<currentTeamFacilities.length; i++) {
tmp = currentTeamFacilities[i];
printOutFacilities.push({ name: tmp.settings.props["Identity Data"]["Building Name"], shared: "via current team", twinID: tmp.twinId });
const printOutFacilities = [];
let teamFacilities = [];

// cycle through all the teams and get each's facilities
const teams = await app.getTeams();
let tmpTeamFacilities = null;
for (let i=0; i<teams.length; i++) {
tmpTeamFacilities = await teams[i].getFacilities();

teamFacilities = teamFacilities.concat(tmpTeamFacilities);
//console.log(`Facilities for team: ${teams[i].name}`, teamFacilities); // dump out raw return result

let tmpFacility = null;
for (let j=0; j<tmpTeamFacilities.length; j++) {
tmpFacility = tmpTeamFacilities[j];
printOutFacilities.push({ name: tmpFacility.settings.props["Identity Data"]["Building Name"], account: teams[i].name, twinID: tmpFacility.twinId });
}
}
console.log("getCurrentTeamsFacilities()", currentTeamFacilities); // dump out raw return result

const sharedWithMe = await app.getUsersFacilities(); // Facilities we have access to because they've been directly shared with us

let tmp = null;
for (let i=0; i<sharedWithMe.length; i++) {
tmp = sharedWithMe[i];
printOutFacilities.push({ name: tmp.settings.props["Identity Data"]["Building Name"], shared: "directly with me", twinID: tmp.twinId });
printOutFacilities.push({ name: tmp.settings.props["Identity Data"]["Building Name"], account: "shared directly with me", twinID: tmp.twinId });
}
console.log("getUsersFacilities()", sharedWithMe); // dump out raw return result
//console.log("getUsersFacilities()", sharedWithMe); // dump out raw return result

// now try to print out a readable table
console.table(printOutFacilities);

return [].concat(currentTeamFacilities, sharedWithMe); // return the full list for the popup selector
return [].concat(teamFacilities, sharedWithMe); // return the full list for the popup selector
}

/***************************************************
Expand Down
4 changes: 2 additions & 2 deletions src/fac_stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export async function dumpDtFacilityInfo() {
console.log("facility.getDefaultModelId()", facility.getDefaultModelId());
console.log("facility.getDefaultModel()", facility.getDefaultModel());
console.log("facility.getStreamManager()", facility.getStreamManager());
console.log("facility.getAllRoomsInfo()", facility.getAllRoomsInfo());
//console.log("facility.getAllRoomsInfo()", facility.getAllRoomsInfo()); (TBD: dissappeared??)
console.log("facility.getAllImportedSystemClasses()", facility.getAllImportedSystemClasses());
console.log("facility.getSavedViewsList()", await facility.getSavedViewsList());

Expand Down Expand Up @@ -105,7 +105,7 @@ export async function dumpDtFacilityInfo() {
**********************/

export async function dumpDtConstants() {
const dtConst = Autodesk.Viewing.Private.DtConstants;
const dtConst = Autodesk.Tandem.DtConstants;

console.group("STUB: dumpDtConstants()")

Expand Down
2 changes: 1 addition & 1 deletion src/model_stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async function dumpSingleModel(model) {
console.log("fileName()", model.fileName());
console.log("displayName()", model.displayName());
console.log("isLoaded()", model.isLoaded());
console.log("getSeedUrn()", model.getSeedUrn());
//console.log("getSeedUrn()", model.getSeedUrn());
console.log("getAttributes()", await model.getAttributes());
console.log("canEdit()", model.canEdit());
//console.log("hasPhysicalElements()", model.hasPhysicalElements());
Expand Down
26 changes: 25 additions & 1 deletion src/st_stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ export function prettyPrintStreamValues(streamIds, streamKeys, streamDataObj) {
// iterate over the map structure and make a nice, readable table
let timeseriesData = [];

for (let i=0; i<streamDataObj.length; i++) { // one entry for each parameter used to store timeseries data
if (streamDataObj[i] != undefined) { // undefined unless there are values for this index
for (const [propKey, propValues] of Object.entries(streamDataObj[i])) { // one entry for each parameter used to store timeseries data
const timestamp = parseInt(propValues.ts); // convert timestamp to human readable date
const date = new Date(timestamp);
timeseriesData.push( { streamId: streamIds[i], streamKey: streamKeys[i], propId: propKey, value: propValues.val, timestamp: timestamp, date: date.toString()} );
}
}
}
if (timeseriesData.length) {
console.table(timeseriesData);
}
}

/*export function prettyPrintStreamValues(streamIds, streamKeys, streamDataObj) {
console.log("Stream IDs", streamIds);
if (streamIds.length != streamDataObj.length) {
console.warning("WARNING: streamIds.length doesn't match streamDataObj.length");
}
// iterate over the map structure and make a nice, readable table
let timeseriesData = [];
for (let i=0; i<streamDataObj.length; i++) { // one entry for each parameter used to store timeseries data
if (streamDataObj[i] != undefined) { // undefined unless there are values for this index
for (const [propKey, propValues] of Object.entries(streamDataObj[i])) { // one entry for each parameter used to store timeseries data
Expand All @@ -81,7 +105,7 @@ export function prettyPrintStreamValues(streamIds, streamKeys, streamDataObj) {
if (timeseriesData.length) {
console.table(timeseriesData);
}
}
}*/

/***************************************************
** FUNC: getLastReadings()
Expand Down

0 comments on commit f0902bf

Please sign in to comment.