Skip to content

Commit

Permalink
Handle of additional parameters in command editor (buttons and UI pages)
Browse files Browse the repository at this point in the history
  • Loading branch information
albaintor committed Sep 23, 2024
1 parent e92f822 commit d4a4425
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 81 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ucr-tool",
"version": "1.3.2",
"version": "1.4.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
Expand Down
37 changes: 37 additions & 0 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`);
});


Expand Down
134 changes: 134 additions & 0 deletions server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "server",
"type": "module",
"version": "1.3.2",
"version": "1.4.0",
"main": "app.js",
"scripts": {
"start": "node app.js"
Expand All @@ -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": {
Expand Down
23 changes: 23 additions & 0 deletions server/remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/app/activity-editor/activity-editor.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ <h2>Create or clone activity : {{Helper.getEntityName(updatedActivity)}}</h2>
<p-messages severity="info">
<ng-template pTemplate>
<div class="ml-2">
<b>Features</b> (note that additional command parameters - delay, repeat...- are not covered yet) :
<ul>
<li>Clone, copy, paste an activity or import from a file</li>
<li>Replace an entity by another within the activity.</li>
Expand Down
Loading

0 comments on commit d4a4425

Please sign in to comment.