From d4a44256c48dffe9151f60c07bcd3892d7a4b1f2 Mon Sep 17 00:00:00 2001 From: albaintor <118518828+albaintor@users.noreply.github.com> Date: Mon, 23 Sep 2024 10:46:35 +0200 Subject: [PATCH] Handle of additional parameters in command editor (buttons and UI pages) --- package.json | 2 +- server/app.js | 37 +++++ server/package-lock.json | 134 ++++++++++++++++++ server/package.json | 4 +- server/remote.js | 23 +++ .../activity-editor.component.html | 1 - .../command-editor.component.html | 133 +++++++++++------ .../command-editor.component.ts | 79 ++++++++++- .../ui-command-editor.component.html | 4 +- src/app/helper.ts | 8 +- src/app/interfaces.ts | 44 +++--- .../remote-browser.component.ts | 2 +- src/app/server.service.ts | 9 +- 13 files changed, 399 insertions(+), 81 deletions(-) diff --git a/package.json b/package.json index d9959df..d544b38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucr-tool", - "version": "1.3.2", + "version": "1.4.0", "scripts": { "ng": "ng", "start": "ng serve", diff --git a/server/app.js b/server/app.js index 6b16a9b..fe20fa2 100644 --- a/server/app.js +++ b/server/app.js @@ -15,10 +15,23 @@ import {Remote} from "./remote.js"; import {getConfigFile, writeConfigFile} from "./config.js"; import {program} from 'commander'; import cors from 'cors'; +import process from 'process'; +import { fileURLToPath } from 'url'; +import open from 'open'; +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +try { + process.chdir(__dirname); +} +catch (err) { +} let LISTEN_PORT = "8000"; const UPLOAD_DIR = './uploads'; const RESOURCES_DIR = './resources'; + + + var app = express(); var storage = multer.diskStorage({ destination: function (req, file, callback) { @@ -468,6 +481,29 @@ app.delete('/api/remote/:address/activities/:activity_id/ui/pages/:page_id', asy } }) + +app.get('/api/remote/:address/entities/:entity_id', async (req, res, next) => { + const address = req.params.address; + const entity_id = req.params.entity_id; + let user = REMOTE_USER + if (req.body?.user) + user = req.body?.user; + const configFile = getConfigFile(); + const remoteEntry = configFile?.remotes?.find(remote => remote.address === address); + if (!remoteEntry) + { + res.status(404).json(address); + return; + } + const remote = new Remote(remoteEntry.address, remoteEntry.port, remoteEntry.user, remoteEntry.token, remoteEntry.api_key); + try { + res.status(200).json(await remote.getEntity(entity_id)); + } catch (error) + { + errorHandler(error, req, res, next); + } +}) + app.delete('/api/remote/:address/entities/:entity_id', async (req, res, next) => { const address = req.params.address; const entity_id = req.params.entity_id; @@ -1010,6 +1046,7 @@ if (fs.existsSync(WORKING_FOLDER)) // console.dir(rc2Model.entities_catalog, {depth: null, colors: true}); app.listen(LISTEN_PORT, function () { console.log(`Listening on port ${LISTEN_PORT}!`); + open(`http://localhost:${LISTEN_PORT}`); }); diff --git a/server/package-lock.json b/server/package-lock.json index e0e6cf9..173e8a3 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -20,6 +20,8 @@ "morgan": "~1.9.1", "multer": "^1.4.5-lts.1", "nodemon": "^3.1.4", + "open": "^10.1.0", + "process": "^0.11.10", "rimraf": "^6.0.1" }, "devDependencies": { @@ -614,6 +616,20 @@ "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" }, + "node_modules/bundle-name": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bundle-name/-/bundle-name-4.1.0.tgz", + "integrity": "sha512-tjwM5exMg6BGRI+kNmTntNsvdZS1X8BFYS6tnJ2hdH0kVxM6/eVZ2xy+FqStSWvYmtfFMDLIxurorHwDKfDz5Q==", + "dependencies": { + "run-applescript": "^7.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/busboy": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", @@ -828,6 +844,32 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/default-browser": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/default-browser/-/default-browser-5.2.1.tgz", + "integrity": "sha512-WY/3TUME0x3KPYdRRxEJJvXRHV4PyPoUsxtZa78lwItwRQRHhd2U9xOscaT/YTf8uCXIAjeJOFBVEh/7FtD8Xg==", + "dependencies": { + "bundle-name": "^4.1.0", + "default-browser-id": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/default-browser-id": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/default-browser-id/-/default-browser-id-5.0.0.tgz", + "integrity": "sha512-A6p/pu/6fyBcA1TRz/GqWYPViplrftcW2gZC9q79ngNCKAeR/X3gcEdXQHl4KNXV+3wgIJ1CPkJQ3IHM6lcsyA==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/defer-to-connect": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", @@ -836,6 +878,17 @@ "node": ">=10" } }, + "node_modules/define-lazy-prop": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/define-lazy-prop/-/define-lazy-prop-3.0.0.tgz", + "integrity": "sha512-N+MeXYoqr3pOgn8xfyRPREN7gHakLYjhsHhWGT3fWAiL4IkAt0iDw14QiiEm2bE30c5XX5q0FtAA3CK5f9/BUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/depd": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", @@ -1252,6 +1305,20 @@ "node": ">=8" } }, + "node_modules/is-docker": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-3.0.0.tgz", + "integrity": "sha512-eljcgEDlEns/7AXFosB5K/2nCM4P7FQPkGc/DWLy5rmFEWvZayGrik1d9/QIY5nJ4f9YsVvBkA6kJpHn9rISdQ==", + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-extglob": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", @@ -1279,6 +1346,23 @@ "node": ">=0.10.0" } }, + "node_modules/is-inside-container": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-inside-container/-/is-inside-container-1.0.0.tgz", + "integrity": "sha512-KIYLCCJghfHZxqjYBE7rEy0OBuTd5xCHS7tHVgvCLkx7StIoaxwNW3hCALgEUjFfeRk+MG/Qxmp/vtETEF3tRA==", + "dependencies": { + "is-docker": "^3.0.0" + }, + "bin": { + "is-inside-container": "cli.js" + }, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -1298,6 +1382,20 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-wsl": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-3.1.0.tgz", + "integrity": "sha512-UcVfVfaK4Sc4m7X3dUSoHoozQGBEFeDC+zVo06t98xe8CzHSZZBekNXH+tu0NalHolcJ/QAGqS46Hef7QXBIMw==", + "dependencies": { + "is-inside-container": "^1.0.0" + }, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", @@ -1617,6 +1715,23 @@ "node": ">= 0.8" } }, + "node_modules/open": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/open/-/open-10.1.0.tgz", + "integrity": "sha512-mnkeQ1qP5Ue2wd+aivTD3NHd/lZ96Lu0jgf0pwktLPtx6cTZiH7tyeGRRHs0zX0rbrahXPnXlUnbeXyaBBuIaw==", + "dependencies": { + "default-browser": "^5.2.1", + "define-lazy-prop": "^3.0.0", + "is-inside-container": "^1.0.0", + "is-wsl": "^3.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/p-cancelable": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-4.0.1.tgz", @@ -1682,6 +1797,14 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", @@ -1826,6 +1949,17 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/run-applescript": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/run-applescript/-/run-applescript-7.0.0.tgz", + "integrity": "sha512-9by4Ij99JUr/MCFBUkDKLWK3G9HVXmabKz9U5MlIAIuvuzkiOicRYs8XJLxX+xahD+mLiiCYDqF9dKAgtzKP1A==", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", diff --git a/server/package.json b/server/package.json index 671134f..eb44f71 100644 --- a/server/package.json +++ b/server/package.json @@ -1,7 +1,7 @@ { "name": "server", "type": "module", - "version": "1.3.2", + "version": "1.4.0", "main": "app.js", "scripts": { "start": "node app.js" @@ -19,6 +19,8 @@ "morgan": "~1.9.1", "multer": "^1.4.5-lts.1", "nodemon": "^3.1.4", + "open": "^10.1.0", + "process": "^0.11.10", "rimraf": "^6.0.1" }, "devDependencies": { diff --git a/server/remote.js b/server/remote.js index 84b756f..ad031a2 100644 --- a/server/remote.js +++ b/server/remote.js @@ -234,6 +234,29 @@ export class Remote } } + async getEntity(entityId) + { + let headers = this.getHeaders(); + const limit = 100; + const options = { + ...this.getOptions(), + searchParams: { + limit, + page: 1 + } + } + const url = this.getURL() + `/api/entities/${entityId}`; + const res = await got.get(url, options); + let resBody; + try { + if (res?.body) resBody = JSON.parse(res.body); + return resBody; + } catch (err) { + console.error('Error', err, res?.body); + throw(err); + } + } + async getEntities() { let headers = this.getHeaders(); diff --git a/src/app/activity-editor/activity-editor.component.html b/src/app/activity-editor/activity-editor.component.html index fb7c87a..3a31f46 100644 --- a/src/app/activity-editor/activity-editor.component.html +++ b/src/app/activity-editor/activity-editor.component.html @@ -88,7 +88,6 @@