From fd2e47ed73ee6342f3d9988827a818f28e62a0e6 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sun, 6 Dec 2015 22:49:51 +0000 Subject: [PATCH] WIP: add flow api --- red/api/flow.js | 32 ++++++++ red/api/index.js | 4 + red/runtime/nodes/flows/index.js | 87 +++++++++++++++++++++- red/runtime/nodes/index.js | 16 +++- test/red/runtime/nodes/flows/index_spec.js | 70 +++++++++++++++++ 5 files changed, 203 insertions(+), 6 deletions(-) create mode 100644 red/api/flow.js diff --git a/red/api/flow.js b/red/api/flow.js new file mode 100644 index 000000000..d9e71964a --- /dev/null +++ b/red/api/flow.js @@ -0,0 +1,32 @@ +/** + * Copyright 2014, 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + **/ + +var log; +var redNodes; +var settings; + +module.exports = { + init: function(runtime) { + settings = runtime.settings; + redNodes = runtime.nodes; + log = runtime.log; + }, + get: function(req,res) { + var id = req.params.id; + log.audit({event: "flow.get"},req); + res.json(redNodes.getFlow(id)); + } +} diff --git a/red/api/index.js b/red/api/index.js index 9dd495801..d71f8ad9d 100644 --- a/red/api/index.js +++ b/red/api/index.js @@ -24,6 +24,7 @@ var when = require('when'); var ui = require("./ui"); var nodes = require("./nodes"); var flows = require("./flows"); +var flow = require("./flow"); var library = require("./library"); var info = require("./info"); var theme = require("./theme"); @@ -64,6 +65,7 @@ function init(_server,runtime) { auth.init(runtime); credentials.init(runtime); flows.init(runtime); + flow.init(runtime); info.init(runtime); library.init(adminApp,runtime); locales.init(runtime); @@ -103,6 +105,8 @@ function init(_server,runtime) { adminApp.get("/flows",needsPermission("flows.read"),flows.get); adminApp.post("/flows",needsPermission("flows.write"),flows.post); + adminApp.get("/flow/:id",needsPermission("flows.read"),flow.get); + // Nodes adminApp.get("/nodes",needsPermission("nodes.read"),nodes.getAll); adminApp.post("/nodes",needsPermission("nodes.write"),nodes.post); diff --git a/red/runtime/nodes/flows/index.js b/red/runtime/nodes/flows/index.js index 0c17b1500..c9d68c107 100644 --- a/red/runtime/nodes/flows/index.js +++ b/red/runtime/nodes/flows/index.js @@ -352,6 +352,81 @@ function checkTypeInUse(id) { } } +function addFlow(flow) { + /* + { + id:'', + label:'', + nodes:[] + } + + */ + + // flow.id should not exist - it will be assigned by the runtime + // all flow.{subflows|configs|nodes}.z will be set to flow.id + // all nodes will have new ids assigned if there is a clash + // check all known types - fail if otherwise? + // + // resolves with generated flow id + + return when.promise(function(resolve,reject) { + var i,id,node; + + flow.id = redUtil.generateId(); + + for (i=0;i