Files
qt-migration-legatus/qt6-after/qt6-migrated-legatus/Lts/Tools/ArAssetsV3/src/Functions.ts
T
torsten d5c13033e2 Session 022: Migrate Lts/Tools (72 submodules) to Qt6
- Copied complete Lts/Tools directory from qt5-before to qt6-after
- Updated 32 CMakeLists.txt files (Qt5:: → Qt6::)
- Tools subdirectory already included in parent Lts/CMakeLists.txt
- All 72 tool submodules now present in qt6-migrated-legatus
- Includes: Adler, ArAssets, ConfigX, DBAdministration, DBUpdate,
  DdsView, InfrastructureManagement, and 67 more tools
- C++17 standard (RTI 7.7.0 compatibility maintained)
- Tests deferred until final validation phase

Migration progress:
✅ Lts/Application (68 files)
✅ Lts/DDS (verified Qt6-ready)
✅ Lts/Plugins (60 submodules, verified)
✅ Lts/Projects (5 submodules, verified)
✅ Lts/Proxies (13 submodules, verified)
✅ Lts/Services (47 submodules, verified)
✅ Lts/Tools (72 submodules, copied + CMake updated)
✅ Lts/Viewer (LtsFileDialog, LtsReportDisplay, SituationMap)
🟡 TetraIF (partial)
🟡 Z (partial: nglwidgets, QtSingleApplication, qsql_informix, WMS_Interface)
2026-08-25 14:07:20 +02:00

243 lines
6.0 KiB
TypeScript
Executable File

import { Helpers, _, MOBILE } from "./Helpers";
export module Functions {
//#region private
async function checkForPort(ip: string): Promise<number> {
return new Promise<number>(async (resolve, reject) => {
new Helpers.WebSocketRequest(
ip,
JSON.stringify({
type: "servicePortsInformationRequest",
uuid: Helpers.GenUuid()
})
)
.GetResponseAsync()
.then(response => {
for (let p of JSON.parse(response).data[0].services) {
if (p.nameAbbrevation === "ism") {
return resolve(p.ports[0].number);
}
}
return reject();
})
.catch(() => {
return reject();
});
});
}
async function retrieveDataIp(): Promise<string> {
return new Promise<string>((resolve, reject) => {
const defaultIp: string = "ws://192.168.133.140";
const portToCheck: number = 2080;
checkForPort(`${defaultIp}:${portToCheck}`)
.then(port => resolve(`${defaultIp}:${port}`))
.catch(() => {
return reject();
})
});
}
async function loadData(ip: string): Promise<any> {
return new Promise<any>((resolve, reject) => {
new Helpers.WebSocketRequest(
ip,
JSON.stringify({
type: "getEssentials",
uuid: Helpers.GenUuid()
})
)
.GetResponseAsync()
.then(data => resolve(JSON.parse(data).data))
.catch(() => {
return reject();
});
});
}
export async function manualLoad(): Promise<any> {
return new Promise<any>(async (resolve, reject) => {
let data: any;
let serverIp: string = "ws://exctds01:2080";
serverIp = prompt(
"Please enter ip to load data manually:",
serverIp
) as string;
try {
data = await loadData(serverIp);
} catch {
console.error("Unable to load data from " + serverIp);
}
WebSocketIp = serverIp;
return resolve(data);
});
}
function storeInCache(key: string, value: any): void {
window.localStorage.setItem(key, escape(JSON.stringify(value)));
}
function retrieveFromCache(key: string): any | never {
let value = window.localStorage.getItem(key);
if (!_(value)) return JSON.parse(unescape(value as string));
else throw new Error();
}
//#endregion
/**
* Tries to load the data automatically from the websocket,
* then from cache, then from the user. Always caches the
* response.
*/
export async function GetData(): Promise<any> {
return new Promise<any>(async (resolve, reject) => {
var lastIp: string;
try {
lastIp = retrieveFromCache("lastIp");
} catch {
lastIp = "ws://exctds01:2080";
}
var errorState = false;
var lastTry: string | null = "";
while (_(WebSocketIp)) {
try {
WebSocketIp = prompt(`${(errorState ? "Failed to connect." : "")}\nEnter IP to load data (usually ws://exctds01:2080)`, (_(lastTry) ? lastIp : lastTry) as string);
lastTry = WebSocketIp;
if (!WebSocketIp?.includes("ws://") && !WebSocketIp?.includes("WS://")) WebSocketIp = "ws://" + WebSocketIp as string;
let data = await loadData(WebSocketIp);
if (!_(WebSocketIp)) storeInCache("lastIp", WebSocketIp);
return resolve(data);
}
catch {
WebSocketIp = null;
errorState = true;
}
}
// var data: any;
// try {
// let serverIp = await retrieveDataIp();
// data = await loadData(serverIp);
// webSocketIp = serverIp;
// } catch {
// try {
// data = retrieveFromCache("data");
// } catch {
// data = await manualLoad();
// }
// } finally {
// console.log(data.type);
// //if (data.type == "essentials"){
// storeInCache("data", data);
// return resolve(data);
// /*} else {
// GetData();
// } */
// }
});
}
export var WebSocketIp: string | null = null;
export async function GetMountedAssetIp(Id: number): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
if (_(WebSocketIp)) return reject();
try {
let ip: string = JSON.parse(
await new Helpers.WebSocketRequest(
WebSocketIp as string,
JSON.stringify({
type: "getAssetState",
uuid: Helpers.GenUuid(),
data: {
assetId: Id
}
})
).GetResponseAsync()
).data.ipAddr;
if (!_(ip)) return resolve(`http://${ip}/`);
else return reject();
} catch {
return reject();
}
});
}
export async function MountAsset(AssetId: string, MountingPointId: number): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
if (_(WebSocketIp)) return reject();
try {
let response: string = JSON.parse(
await new Helpers.WebSocketRequest(
WebSocketIp as string,
JSON.stringify({
type: "mount",
uuid: Helpers.GenUuid(),
data: {
mountingPointId: MountingPointId,
assetId: +AssetId
}
})
).GetResponseAsync()
);
console.log(response);
if (response) return resolve();
else return reject();
} catch {
return reject();
}
});
}
export async function UnmountAsset(MountingPointId: number): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
if (_(WebSocketIp)) return reject();
try {
let response: string = JSON.parse(
await new Helpers.WebSocketRequest(
WebSocketIp as string,
JSON.stringify({
type: "unmountMountingPoint",
uuid: Helpers.GenUuid(),
data: {
mountingPointId: MountingPointId,
}
})
).GetResponseAsync()
);
if (response) return resolve();
else return reject();
} catch {
return reject();
}
});
}
export async function GetMountableAssets(AssetTypeIds: number[]): Promise<any[]> {
return new Promise<any[]>(async (resolve, reject) => {
if (_(WebSocketIp)) return reject();
try {
let response: any = JSON.parse(
await new Helpers.WebSocketRequest(
WebSocketIp as string,
JSON.stringify({
type: "getAssets",
uuid: Helpers.GenUuid(),
data: {
assetTypeId: AssetTypeIds,
}
})
).GetResponseAsync()
);
if (response) return resolve(response.data);
else return reject();
} catch {
return reject();
}
});
}
}