class-transformer#instanceToInstance TypeScript Examples
The following examples show how to use
class-transformer#instanceToInstance.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EntityService.ts From viewer-components-react with MIT License | 6 votes |
public getEntity$(entityType: EntityType, id: string): Observable<Node | Device | Sensor> {
if (this.entityCache[entityType][id]) {
return of(instanceToInstance(this.entityCache[entityType][id]));
} else {
return EntityTypeService.types$(entityType).pipe(
first(),
switchMap(() => {
return ApiService.sendRequest$(this.getEndpoint("getEntity", entityType) as string + id)
.pipe(
tap((data: any) => LoggerService.log(`Received ${entityType}:`, data)),
map((data: object) => {
const entity = plainToInstance<Node | Device | Sensor, object>(this.getEntityClass(entityType), data);
this.entityCache[entityType][id] = entity;
return entity;
})
);
})
);
}
}
Example #2
Source File: IModelSettingsService.ts From viewer-components-react with MIT License | 6 votes |
public deleteAllEntityAssociations(): void {
const iModelSettings = instanceToInstance(this.iModelSettings.getValue());
if (iModelSettings) {
const confirmMsg = "Are you sure you want to remove all sensors from this iModel?";
void IModelApp.notifications
.openMessageBox(MessageBoxType.OkCancel, confirmMsg, MessageBoxIconType.Critical)
.then((val: MessageBoxValue) => {
if (val === MessageBoxValue.Ok) {
iModelSettings.deleteAllAssociations();
this.setIModelSettings(iModelSettings);
}
});
} else {
LoggerService.warn("Unable to delete all associations: iModel settings not loaded");
}
}
Example #3
Source File: IModelSettingsService.ts From viewer-components-react with MIT License | 6 votes |
public setEntityObservationQuery(entityId: string, observationQueryIndex: number, observationQuery: ObservationQuery): void {
const iModelSettings = instanceToInstance(this.iModelSettings.getValue());
if (iModelSettings) {
const association = iModelSettings.getAssociation(entityId);
if (association) {
association.setObservationQuery(observationQueryIndex, observationQuery);
iModelSettings.setAssociation(association);
this.setIModelSettings(iModelSettings);
} else {
LoggerService.warn("Unable to set entity observation query: entity association not found");
}
} else {
LoggerService.warn("Unable to set entity observation query: iModel settings not loaded");
}
}
Example #4
Source File: IModelSettingsService.ts From viewer-components-react with MIT License | 6 votes |
public addEntityObservationQuery(entityId: string, observationQuery: ObservationQuery): void {
const iModelSettings = instanceToInstance(this.iModelSettings.getValue());
if (iModelSettings) {
const association = iModelSettings.getAssociation(entityId);
if (association) {
association.addObservationQuery(observationQuery);
iModelSettings.setAssociation(association);
this.setIModelSettings(iModelSettings);
} else {
LoggerService.warn("Unable to add entity observation query: entity association not found");
}
} else {
LoggerService.warn("Unable to add entity observation query: iModel settings not loaded");
}
}
Example #5
Source File: IModelSettingsService.ts From viewer-components-react with MIT License | 6 votes |
public deleteEntityObservationQuery(entityId: string, index: number): void {
const iModelSettings = instanceToInstance(this.iModelSettings.getValue());
if (iModelSettings) {
const association = iModelSettings.getAssociation(entityId);
if (association) {
association.deleteObservationQuery(index);
iModelSettings.setAssociation(association);
this.setIModelSettings(iModelSettings);
} else {
LoggerService.warn("Unable to delete entity observation query: entity association not found");
}
} else {
LoggerService.warn("Unable to delete entity observation query: iModel settings not loaded");
}
}
Example #6
Source File: IModelSettingsService.ts From viewer-components-react with MIT License | 5 votes |
public iModelSettings$(): Observable<IModelSettings> {
this.loadSettings();
return this.iModelSettings.pipe(
filter((iModelSettings: IModelSettings | undefined) => !!iModelSettings),
map((iModelSettings: IModelSettings | undefined) => instanceToInstance(iModelSettings))
) as Observable<IModelSettings>;
}
Example #7
Source File: IModelSettingsService.ts From viewer-components-react with MIT License | 5 votes |
public setEntityAssociation(entityId: string, removeAssociation = false): void {
const iModelSettings = instanceToInstance(this.iModelSettings.getValue());
if (iModelSettings) {
// Disable entity association mode, if it"s active (shouldn"t be)
this.disableEntityAssociationMode();
// Check if we"re setting or removing an association
if (!removeAssociation) {
// Get reference to current iModel
const iModelConnection = IModelApp.viewManager.selectedView?.iModel;
if (iModelConnection) {
// Add a listener for new selection events
this.enableEntityAssociationMode();
this.iModelSelectEventUnsubscribe = iModelConnection.selectionSet.onChanged.addListener(
(event: SelectionSetEvent) => {
if (event.set.elements.size === 1) {
const elementId = Array.from(event.set.elements).pop() as string;
let association = iModelSettings.getAssociation(entityId);
if (association) {
association.setElementId(elementId);
} else {
association = new IModelEntityAssociation(entityId, "element", elementId);
}
iModelSettings.setAssociation(association);
this.setIModelSettings(iModelSettings);
this.disableEntityAssociationMode(true);
LoggerService.log("Associated entity with element:", elementId);
}
}
);
} else {
LoggerService.warn("Unable to set entity association: iModel not available");
}
} else {
this.confirmDeleteAssociation(iModelSettings, entityId);
}
} else {
LoggerService.warn("Unable to set entity association: iModel settings not loaded");
}
}