From 2744554341702788ccfba7f80a8b39b0453c28d4 Mon Sep 17 00:00:00 2001 From: Henrikas Elsbergas Date: Thu, 23 Feb 2017 23:27:49 +0200 Subject: [PATCH 1/2] Implementing HTTP API for performance runner --- src/webui/backend/entry.js | 286 ++++++++++++---------- src/webui/backend/lib/ros.js | 116 +++++++-- src/webui/backend/routers/index.js | 2 + src/webui/backend/routers/performances.js | 129 ++++++++++ src/webui/package.json | 1 + 5 files changed, 373 insertions(+), 161 deletions(-) create mode 100644 src/webui/backend/routers/index.js create mode 100644 src/webui/backend/routers/performances.js diff --git a/src/webui/backend/entry.js b/src/webui/backend/entry.js index 691c19dfa..f0978794a 100644 --- a/src/webui/backend/entry.js +++ b/src/webui/backend/entry.js @@ -34,206 +34,222 @@ let express = require('express'), describe: 'Enable ssl', type: 'boolean' } - }).usage('Usage: $0 [options]').help('h').alias('h', 'help').argv; + }).usage('Usage: $0 [options]').help('h').alias('h', 'help').argv -app.use(bodyParser.urlencoded({extended: false})); -app.use(bodyParser.json()); -app.use('/public', express.static(path.join(__dirname, '../public'))); +app.use(bodyParser.urlencoded({extended: false})) +app.use(bodyParser.json()) +app.use('/public', express.static(path.join(__dirname, '../public'))) -app.get('/', function (req, res) { - res.sendFile(path.resolve(path.join(__dirname, '../public/index.html'))); -}); +app.get('/', function(req, res) { + res.sendFile(path.resolve(path.join(__dirname, '../public/index.html'))) +}) -app.get('/robot_config.js', function (req, res) { - let filename = path.resolve(argv.config, argv.robot, 'webstart.js'); +app.get('/robot_config.js', function(req, res) { + let filename = path.resolve(argv.config, argv.robot, 'webstart.js') if (monitoring.robot_started(argv.robot) === 1) { - res.send("define(function (){return {mode:'normal'}});"); + res.send("define(function (){return {mode:'normal'}});") } else { - res.sendFile(filename); + res.sendFile(filename) } -}); +}) -app.get('/robot_config_schema', function (req, res) { - res.json(yamlIO.readFile(path.join(argv.config, 'config_schema.yaml')) || {}); -}); +app.get('/robot_config_schema', function(req, res) { + res.json(yamlIO.readFile(path.join(argv.config, 'config_schema.yaml')) || {}) +}) -app.get('/robot_config/:name', function (req, res) { - res.json(yamlIO.readFile(path.join(argv.config, req.params['name'], 'config.yaml')) || {}); -}); +app.get('/robot_config/:name', function(req, res) { + res.json(yamlIO.readFile(path.join(argv.config, req.params['name'], 'config.yaml')) || {}) +}) -app.post('/robot_config/:name', function (req, res) { +app.post('/robot_config/:name', function(req, res) { // Do not overwrite config - res.json(req.body); + res.json(req.body) // if (yamlIO.writeFile(path.join(argv.config, req.params['name'], 'config.yaml'), req.body)) // res.json(req.body); // else // res.sendStatus(500); -}); +}) -app.get('/monitor/status', function (req, res) { - res.json(monitoring.system_status(argv.config, argv.robot)); -}); +app.get('/monitor/status', function(req, res) { + res.json(monitoring.system_status(argv.config, argv.robot)) +}) -app.get('/motors/get/:name', function (req, res) { - res.json({motors: yamlIO.readFile(path.join(argv.config, req.params['name'], 'motors_settings.yaml')) || []}); -}); +app.get('/motors/get/:name', function(req, res) { + res.json({motors: yamlIO.readFile(path.join(argv.config, req.params['name'], 'motors_settings.yaml')) || []}) +}) -app.post('/motors/update/:name', function (req, res) { - let robot_name = req.params['name']; - yamlIO.writeFile(path.join(argv.config, robot_name, 'motors_settings.yaml'), req.body); - ros.updateMotors(robot_name, req.body); - res.json({error: false}); -}); +app.post('/motors/update/:name', function(req, res) { + let robot_name = req.params['name'] + yamlIO.writeFile(path.join(argv.config, robot_name, 'motors_settings.yaml'), req.body) + ros.updateMotors(robot_name, req.body) + res.json({error: false}) +}) -app.get('/expressions/:name', function (req, res) { - res.json(yamlIO.readFile(path.join(argv.config, req.params['name'], 'expressions.yaml')) || {}); -}); +app.get('/expressions/:name', function(req, res) { + res.json(yamlIO.readFile(path.join(argv.config, req.params['name'], 'expressions.yaml')) || {}) +}) -app.post('/expressions/update/:name', function (req, res) { - let robot_name = req.params['name']; +app.post('/expressions/update/:name', function(req, res) { + let robot_name = req.params['name'] let save = {error: !yamlIO.writeFile(path.join(argv.config, req.params['name'], 'expressions.yaml'), req.body)} - ros.updateExpressions(robot_name); - res.json(save); -}); + ros.updateExpressions(robot_name) + res.json(save) +}) -app.get('/attention_regions/:name', function (req, res) { - let regions = yamlIO.readFile(path.join(argv.config, req.params['name'], 'attention_regions.yaml') || []); +app.get('/attention_regions/:name', function(req, res) { + let regions = yamlIO.readFile(path.join(argv.config, req.params['name'], 'attention_regions.yaml') || []) // TODO: remove when configs are updated - if ('attention_regions' in regions) regions = regions['attention_regions']; - res.json(regions); -}); + if ('attention_regions' in regions) regions = regions['attention_regions'] + res.json(regions) +}) -app.post('/attention_regions/:name', function (req, res) { - res.json({error: !yamlIO.writeFile(path.join(argv.config, req.params['name'], 'attention_regions.yaml'), req.body)}); -}); +app.post('/attention_regions/:name', function(req, res) { + res.json({error: !yamlIO.writeFile(path.join(argv.config, req.params['name'], 'attention_regions.yaml'), req.body)}) +}) -app.post('/animations/update/:name', function (req, res) { - let robot_name = req.params['name']; +app.post('/animations/update/:name', function(req, res) { + let robot_name = req.params['name'] let save = {error: !yamlIO.writeFile(path.join(argv.config, req.params['name'], 'animations.yaml'), req.body)} ros.updateExpressions(robot_name) - res.json(save); -}); + res.json(save) +}) -app.get('/performances/:name', function (req, res) { +app.get('/performances/:name', function(req, res) { res.json(performances.all([path.join(argv.config, req.params['name'], 'performances'), - path.join(argv.config, 'common', 'performances')], {skip_nodes: true})); -}); + path.join(argv.config, 'common', 'performances')], {skip_nodes: true})) +}) -let updatePerformance = function (req, res) { +let updatePerformance = function(req, res) { let name = req.params['id'].indexOf(shared_performances_folder) === 0 ? 'common' : req.params['name'], - root = path.join(argv.config, name, 'performances'); + root = path.join(argv.config, name, 'performances') if (performances.update(root, req.params['id'], _.cloneDeep(req.body))) - res.json(req.body); + res.json(req.body) else - res.sendStatus(500); -}; + res.sendStatus(500) +} app.route('/performances/:name/:id*').post(updatePerformance).put(updatePerformance) - .get(function (req, res) { + .get(function(req, res) { let name = req.params['id'].indexOf(shared_performances_folder) === 0 ? 'common' : req.params['name'], - dir = path.join(argv.config, name, 'performances'); + dir = path.join(argv.config, name, 'performances') - res.json(performances.get(dir, req.params['id'])); - }); + res.json(performances.get(dir, req.params['id'])) + }) -app.delete('/performances/:name/:id*', function (req, res) { +app.delete('/performances/:name/:id*', function(req, res) { let id = path.join(req.param('id') || '', req.params['0'] || ''), - name = req.params['id'].indexOf(shared_performances_folder) === 0 ? 'common' : req.params['name']; + name = req.params['id'].indexOf(shared_performances_folder) === 0 ? 'common' : req.params['name'] - res.json(performances.remove(path.join(argv.config, name, 'performances'), req.params['id'])); -}); + res.json(performances.remove(path.join(argv.config, name, 'performances'), req.params['id'])) +}) -app.post('/run_performance', function (req, res) { - res.json(performances.run('idf/' + req.body['key'])); -}); +app.post('/run_performance', function(req, res) { + res.json(performances.run('idf/' + req.body['key'])) +}) -app.get('/slide_performance/:show/:performance', function (req, res) { - res.json({result: performances.run(req.params['show'] + "/" + req.params['performance'])}); -}); +app.get('/slide_performance/:show/:performance', function(req, res) { + res.json({result: performances.run(req.params['show'] + "/" + req.params['performance'])}) +}) -app.post('/lookat', function (req, res) { +app.post('/lookat', function(req, res) { ros.lookAt({ x: req.body['x'], y: -1 * req.body['y'], z: req.body['z'] - }); + }) - res.json({result: true}); -}); + res.json({result: true}) +}) -app.post('/monitor/logs/:level', function (req, res) { +app.post('/monitor/logs/:level', function(req, res) { PythonShell.run('scripts/logs.py', { args: [req.params['level'], JSON.stringify(req.body)] - }, function (err, data) { + }, function(err, data) { if (err) - res.json([]); + res.json([]) else - res.json(JSON.parse(data)); - }); -}); - -let readPerformanceProperties = function (dir) { - dir = dir || '.'; - let name = dir.indexOf(shared_performances_folder) === 0 ? 'common' : argv.robot; - return yamlIO.readFile(path.join(argv.config, name, 'performances', dir, '.properties')) || {}; + res.json(JSON.parse(data)) + }) +}) + +let readPerformanceProperties = function(dir) { + dir = dir || '.' + let name = dir.indexOf(shared_performances_folder) === 0 ? 'common' : argv.robot + return yamlIO.readFile(path.join(argv.config, name, 'performances', dir, '.properties')) || {} }, - writePerformanceProperties = function (dir, data) { - dir = dir || '.'; + writePerformanceProperties = function(dir, data) { + dir = dir || '.' let name = dir.indexOf(shared_performances_folder) === 0 ? 'common' : argv.robot, filename = path.join(argv.config, name, 'performances', dir, '.properties'), properties = yamlIO.readFile(filename), - success = yamlIO.writeFile(filename, _.extend(properties, data)); - - ros.performances.reloadProperties(); - return success; - }; - -app.get('/performance/settings/:path(*)?', function (req, res) { - res.json(readPerformanceProperties(req.params['path']) || {}); -}); - -app.post('/performance/settings/:path(*)?', function (req, res) { - let success = writePerformanceProperties(req.params['path'], req.body || {}); - res.json(success ? req.body : {}); -}); - -app.get('/keywords/:path(*)?', function (req, res) { - res.json({keywords: readPerformanceProperties(req.params['path'])['keywords'] || []}); -}); + success = yamlIO.writeFile(filename, _.extend(properties, data)) -app.post('/keywords/:path(*)?', function (req, res) { - let keywords = _.map(req.body['keywords'] || [], function (k) { - return k.trim(); - }); - - res.json(writePerformanceProperties(req.params['path'], {keywords: keywords})); -}); - -app.get('/performance/attention/:path(*)?', function (req, res) { - res.json(readPerformanceProperties(req.params['path'])['regions'] || []); -}); - -app.post('/performance/attention/:path(*)?', function (req, res) { - res.json(writePerformanceProperties(req.params['path'], {regions: req.body})); -}); - -app.get('/performance/variables/:path(*)?', function (req, res) { - res.json(readPerformanceProperties(req.params['path'])['variables'] || {}); -}); + ros.performances.reloadProperties() + return success + } -app.post('/performance/variables/:path(*)?', function (req, res) { - res.json(writePerformanceProperties(req.params['path'], {variables: req.body})); -}); +app.get('/performance/settings/:path(*)?', function(req, res) { + res.json(readPerformanceProperties(req.params['path']) || {}) +}) + +app.post('/performance/settings/:path(*)?', function(req, res) { + let success = writePerformanceProperties(req.params['path'], req.body || {}) + res.json(success ? req.body : {}) +}) + +app.get('/keywords/:path(*)?', function(req, res) { + res.json({keywords: readPerformanceProperties(req.params['path'])['keywords'] || []}) +}) + +app.post('/keywords/:path(*)?', function(req, res) { + let keywords = _.map(req.body['keywords'] || [], function(k) { + return k.trim() + }) + + res.json(writePerformanceProperties(req.params['path'], {keywords: keywords})) +}) + +app.get('/performance/attention/:path(*)?', function(req, res) { + res.json(readPerformanceProperties(req.params['path'])['regions'] || []) +}) + +app.post('/performance/attention/:path(*)?', function(req, res) { + res.json(writePerformanceProperties(req.params['path'], {regions: req.body})) +}) + +app.get('/performance/variables/:path(*)?', function(req, res) { + res.json(readPerformanceProperties(req.params['path'])['variables'] || {}) +}) + +app.post('/performance/variables/:path(*)?', function(req, res) { + res.json(writePerformanceProperties(req.params['path'], {variables: req.body})) +}) + +// recursively require and use all routers +let routers = require('./routers'), + requireRouters = function(routers) { + _.forIn(routers, function(val) { + switch (typeof val) { + case 'function': + app.use('/api', val) + break + case 'object': + requireRouters(val) + break + } + }) + } +requireRouters(routers) if (argv.ssl) { let privateKey = fs.readFileSync(path.join(__dirname, 'ssl', 'key.pem')), - certificate = fs.readFileSync(path.join(__dirname, 'ssl', 'cert.crt')); + certificate = fs.readFileSync(path.join(__dirname, 'ssl', 'cert.crt')) https.createServer({ key: privateKey, cert: certificate - }, app).listen(argv.port); + }, app).listen(argv.port) } else { - app.listen(argv.port); + app.listen(argv.port) } diff --git a/src/webui/backend/lib/ros.js b/src/webui/backend/lib/ros.js index 0fa950b7f..8fc2626cc 100644 --- a/src/webui/backend/lib/ros.js +++ b/src/webui/backend/lib/ros.js @@ -2,23 +2,23 @@ var ROSLIB = require('roslib'), url = 'ws://localhost:9090', ros = new ROSLIB.Ros({ url: url - }); + }) -ros.on('connection', function () { - console.log('Connected to websocket server.'); -}); +ros.on('connection', function() { + console.log('Connected to websocket server.') +}) -ros.on('error', function (error) { - console.log('Error connecting to websocket server: \n', error); +ros.on('error', function(error) { + console.log('Error connecting to websocket server: \n', error) console.log('Retrying in 2 seconds') - setTimeout(function () { - ros.connect(url); - }, 2000); -}); + setTimeout(function() { + ros.connect(url) + }, 2000) +}) -ros.on('close', function () { - console.log('Connection to websocket server closed.'); -}); +ros.on('close', function() { + console.log('Connection to websocket server closed.') +}) var self = module.exports = { instance: ros, @@ -33,6 +33,61 @@ var self = module.exports = { ros: ros, name: '/performances/reload_properties', serviceType: 'std_srvs/Trigger' + }), + set_properties: new ROSLIB.Service({ + ros: ros, + name: '/performances/set_properties', + serviceType: 'performances/SetProperties' + }), + load: new ROSLIB.Service({ + ros: ros, + name: '/performances/load', + messageType: 'performances/Load' + }), + load_sequence: new ROSLIB.Service({ + ros: ros, + name: '/performances/load_sequence', + messageType: 'performances/LoadSequence' + }), + load_performance: new ROSLIB.Service({ + ros: ros, + name: '/performances/load_performance', + messageType: 'performances/LoadPerformance' + }), + current: new ROSLIB.Service({ + ros: ros, + name: '/performances/current', + messageType: 'performances/Current' + }), + run: new ROSLIB.Service({ + ros: ros, + name: '/performances/run', + messageType: 'performances/Run' + }), + run_by_name: new ROSLIB.Service({ + ros: ros, + name: '/performances/run_by_name', + messageType: 'performances/RunByName' + }), + run_full_performance: new ROSLIB.Service({ + ros: ros, + name: '/performances/run_full_performance', + messageType: 'performances/RunByName' + }), + stop: new ROSLIB.Service({ + ros: ros, + name: '/performances/stop', + messageType: 'performances/Stop' + }), + pause: new ROSLIB.Service({ + ros: ros, + name: '/performances/pause', + messageType: 'performances/Pause' + }), + resume: new ROSLIB.Service({ + ros: ros, + name: '/performances/resume', + messageType: 'performances/Resume' }) }, updateExpressions: new ROSLIB.Service({ @@ -48,33 +103,42 @@ var self = module.exports = { messageType: 'pi_face_tracker/Faces' }) }, - updateMotors: function (robot_name, motors) { + updateMotors: function(robot_name, motors) { this.services.updateMotors.callService({ robot_name: robot_name, motors: JSON.stringify(motors) - }, function (res) { - console.log(res); - }); + }, function(res) { + console.log(res) + }) }, - lookAt: function (point) { + lookAt: function(point) { this.topics.lookAt.publish(new ROSLIB.Message({ faces: [{ id: 1, point: point, attention: 0.99 }] - })); + })) }, performances: { - reloadProperties: function () { - self.services.performances.reload_properties.callService(); + reloadProperties: function() { + self.services.performances.reload_properties.callService() + }, + setProperties: function(id, properties) { + self.services.performances.set_properties.callService({ + id: id, + properties: properties + }, function(response) { + console.log(response) + + }) } }, - updateExpressions: function (robot_name) { + updateExpressions: function(robot_name) { this.services.updateExpressions.callService({ robot_name: robot_name, - }, function (res) { - console.log(res); - }); + }, function(res) { + console.log(res) + }) }, -}; +} diff --git a/src/webui/backend/routers/index.js b/src/webui/backend/routers/index.js new file mode 100644 index 000000000..d4d65b0a3 --- /dev/null +++ b/src/webui/backend/routers/index.js @@ -0,0 +1,2 @@ +requireDirectory = require('require-directory') +module.exports = requireDirectory(module) diff --git a/src/webui/backend/routers/performances.js b/src/webui/backend/routers/performances.js new file mode 100644 index 000000000..65e3b1c19 --- /dev/null +++ b/src/webui/backend/routers/performances.js @@ -0,0 +1,129 @@ +let express = require('express'), + router = express.Router(), + ros = require('../lib/ros') + +router.post('/set_properties', function(req, res) { + ros.services.performances.load.callService({ + id: req.body['id'], + properties: req.body['properties'] + }, function(response) { + res.json({success: response.success}) + }, function() { + res.json({success: false}) + }) +}) + +router.post('/load', function(req, res) { + ros.services.performances.load.callService({ + id: req.body['id'] + }, function(response) { + let success = response.success + res.json({success: success, performance: success ? JSON.parse(response.performance) : null}) + }, function() { + res.json({success: false, performance: null}) + }) +}) + +router.post('/load_sequence', function(req, res) { + let ids = req.body['ids'] + ids = ids.constructor === Array ? ids : (ids ? [ids] : []) + ros.services.performances.load_sequence.callService({ + ids: ids + }, function(response) { + let success = response.success + res.json({success: success, performances: success ? JSON.parse(response.performances) : null}) + }, function() { + res.json({success: false, performances: null}) + }) +}) + +router.post('/load_performance', function(req, res) { + ros.services.performances.load_performance.callService({ + performance: JSON.stringify(req.body['performance']) + }, function(response) { + res.json({success: response.success}) + }, function() { + res.json({success: false}) + }) +}) + +router.post('/run_by_name', function(req, res) { + ros.services.performances.run_by_name.callService({ + id: req.body['id'] + }, function(response) { + res.json({success: response.success}) + }, function() { + res.json({success: false}) + }) +}) + +router.post('/run_full_performance', function(req, res) { + ros.services.performances.run_full_performance.callService({ + id: req.body['id'] + }, function(response) { + res.json({success: response.success}) + }, function() { + res.json({success: false}) + }) +}) + +router.get('/current', function(req, res) { + ros.services.performances.current.callService({}, function(response) { + res.json({ + running: response.running, + current_time: response.current_time, + performances: JSON.parse(response.performances) + }) + }, function() { + res.json({ + running: false, + current_time: 0, + performances: [] + }) + }) +}) + +router.post('/run', function(req, res) { + ros.services.performances.run.callService({ + startTime: parseFloat(req.body['start_time']) || 0 + }, function(response) { + res.json({success: response.success}) + }, function() { + res.json({success: false}) + }) +}) + +router.post('/resume', function(req, res) { + ros.services.performances.resume.callService({}, function(response) { + res.json({success: response.success, time: response.time}) + }, function() { + res.json({success: false, time: null}) + }) +}) + +router.post('/pause', function(req, res) { + ros.services.performances.pause.callService({}, function(response) { + res.json({success: response.success, time: response.time}) + }, function() { + res.json({success: false, time: null}) + }) +}) + +router.post('/pause', function(req, res) { + ros.services.performances.pause.callService({}, function(response) { + res.json({success: response.success, time: response.time}) + }, function() { + res.json({success: false, time: null}) + }) +}) + +router.post('/stop', function(req, res) { + ros.services.performances.stop.callService({}, function(response) { + res.json({success: response.success, time: response.time}) + }, function() { + res.json({success: false, time: null}) + }) +}) + + +module.exports = router diff --git a/src/webui/package.json b/src/webui/package.json index 57b2df480..f55b723d9 100644 --- a/src/webui/package.json +++ b/src/webui/package.json @@ -40,6 +40,7 @@ "nouislider": "^9.0.0", "perfect-scrollbar": "^0.6.12", "python-shell": "^0.4.0", + "require-directory": "^2.1.1", "roslib": "^0.18.0", "select2": "^4.0.3", "supermodel": "github:pathable/supermodel", From 3981ac78cfecb67d2fadaf20d6ba2658a6a70def Mon Sep 17 00:00:00 2001 From: Henrikas Elsbergas Date: Tue, 25 Apr 2017 22:38:14 +0300 Subject: [PATCH 2/2] Finsihing performance HTTP API --- src/webui/backend/entry.js | 4 +- src/webui/backend/lib/ros.js | 37 +++++++----- src/webui/backend/routers/performances.js | 57 +++++++++---------- .../views/templates/interaction.tpl | 2 +- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/src/webui/backend/entry.js b/src/webui/backend/entry.js index 0d0200328..97a691ed0 100644 --- a/src/webui/backend/entry.js +++ b/src/webui/backend/entry.js @@ -230,10 +230,10 @@ app.post('/performance/variables/:path(*)?', function(req, res) { // recursively require and use all routers let routers = require('./routers'), requireRouters = function(routers) { - _.forIn(routers, function(val) { + _.forIn(routers, function(val, key) { switch (typeof val) { case 'function': - app.use('/api', val) + app.use(path.join('/api', key), val) break case 'object': requireRouters(val) diff --git a/src/webui/backend/lib/ros.js b/src/webui/backend/lib/ros.js index 5ac17e3e3..96b449de6 100644 --- a/src/webui/backend/lib/ros.js +++ b/src/webui/backend/lib/ros.js @@ -1,4 +1,4 @@ -var ROSLIB = require('roslib'), +let ROSLIB = require('roslib'), url = 'ws://localhost:9090', ros = new ROSLIB.Ros({ url: url @@ -20,7 +20,7 @@ ros.on('close', function() { console.log('Connection to websocket server closed.') }) -var self = module.exports = { +let self = module.exports = { instance: ros, services: { updateMotors: new ROSLIB.Service({ @@ -44,16 +44,16 @@ var self = module.exports = { name: '/performances/load', messageType: 'performances/Load' }), - load_sequence: new ROSLIB.Service({ - ros: ros, - name: '/performances/load_sequence', - messageType: 'performances/LoadSequence' - }), load_performance: new ROSLIB.Service({ ros: ros, name: '/performances/load_performance', messageType: 'performances/LoadPerformance' }), + unload: new ROSLIB.Service({ + ros: ros, + name: '/performances/unload', + messageType: 'std_srvs/Trigger' + }), current: new ROSLIB.Service({ ros: ros, name: '/performances/current', @@ -107,8 +107,6 @@ var self = module.exports = { this.services.updateMotors.callService({ robot_name: robot_name, motors: JSON.stringify(motors) - }, function(res) { - console.log(res) }) }, lookAt: function(point) { @@ -121,16 +119,25 @@ var self = module.exports = { })) }, performances: { - reloadProperties: function () { - self.services.performances.reload_properties.callService(); + reloadProperties: function(options) { + options = options || {} + self.services.performances.reload_properties.callService({}, + function() { + if (options.success) options.success() + }, function() { + if (options.error) options.error() + }) }, - setProperties: function (id, properties, options) { + setProperties: function(id, properties, options) { + options = options || {} self.services.performances.set_properties.callService({ id: id, properties: JSON.stringify(properties) - }, function (response) { - if (options.success) options.success(response); - }); + }, function(response) { + if (options.success) options.success(response) + }, function() { + if (options.error) options.error() + }) } }, updateExpressions: function(robot_name) { diff --git a/src/webui/backend/routers/performances.js b/src/webui/backend/routers/performances.js index 65e3b1c19..7432b855a 100644 --- a/src/webui/backend/routers/performances.js +++ b/src/webui/backend/routers/performances.js @@ -2,14 +2,25 @@ let express = require('express'), router = express.Router(), ros = require('../lib/ros') +router.post('/reload_properties', function(req, res) { + ros.performances.reloadProperties({ + success: function() { + res.json({success: true}) + }, + error: function() { + res.json({success: false}) + } + }) +}) + router.post('/set_properties', function(req, res) { - ros.services.performances.load.callService({ - id: req.body['id'], - properties: req.body['properties'] - }, function(response) { - res.json({success: response.success}) - }, function() { - res.json({success: false}) + ros.performances.setProperties(req.body['id'], req.body['properties'], { + success: function(response) { + res.json({success: response.success}) + }, + error: function() { + res.json({success: false}) + } }) }) @@ -24,19 +35,6 @@ router.post('/load', function(req, res) { }) }) -router.post('/load_sequence', function(req, res) { - let ids = req.body['ids'] - ids = ids.constructor === Array ? ids : (ids ? [ids] : []) - ros.services.performances.load_sequence.callService({ - ids: ids - }, function(response) { - let success = response.success - res.json({success: success, performances: success ? JSON.parse(response.performances) : null}) - }, function() { - res.json({success: false, performances: null}) - }) -}) - router.post('/load_performance', function(req, res) { ros.services.performances.load_performance.callService({ performance: JSON.stringify(req.body['performance']) @@ -47,6 +45,15 @@ router.post('/load_performance', function(req, res) { }) }) +router.post('/unload', function(req, res) { + ros.services.performances.unload.callService({}, + function() { + res.json({success: true}) + }, function() { + res.json({success: false}) + }) +}) + router.post('/run_by_name', function(req, res) { ros.services.performances.run_by_name.callService({ id: req.body['id'] @@ -72,7 +79,7 @@ router.get('/current', function(req, res) { res.json({ running: response.running, current_time: response.current_time, - performances: JSON.parse(response.performances) + performance: JSON.parse(response.performance) }) }, function() { res.json({ @@ -109,13 +116,6 @@ router.post('/pause', function(req, res) { }) }) -router.post('/pause', function(req, res) { - ros.services.performances.pause.callService({}, function(response) { - res.json({success: response.success, time: response.time}) - }, function() { - res.json({success: false, time: null}) - }) -}) router.post('/stop', function(req, res) { ros.services.performances.stop.callService({}, function(response) { @@ -125,5 +125,4 @@ router.post('/stop', function(req, res) { }) }) - module.exports = router diff --git a/src/webui/client/modules/interaction/views/templates/interaction.tpl b/src/webui/client/modules/interaction/views/templates/interaction.tpl index bf902bd8d..e555ae179 100644 --- a/src/webui/client/modules/interaction/views/templates/interaction.tpl +++ b/src/webui/client/modules/interaction/views/templates/interaction.tpl @@ -38,7 +38,7 @@ - +