mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add ability to delete context values from sidebar
This commit is contained in:
@@ -20,7 +20,6 @@
|
||||
|
||||
var runtime;
|
||||
|
||||
// TODO: move runtime/util to util/index
|
||||
var util = require("@node-red/util").util;
|
||||
|
||||
function exportContextStore(scope,ctx, store, result, callback) {
|
||||
@@ -152,5 +151,104 @@ var api = module.exports = {
|
||||
resolve({});
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
/**
|
||||
* Gets the info of an individual node set
|
||||
* @param {Object} opts
|
||||
* @param {User} opts.user - the user calling the api
|
||||
* @param {String} opts.scope - the scope of the context
|
||||
* @param {String} opts.id - the id of the context
|
||||
* @param {String} opts.store - the context store
|
||||
* @param {String} opts.key - the context key
|
||||
|
||||
* @return {Promise} - the node information
|
||||
* @memberof RED.nodes
|
||||
*/
|
||||
delete: function(opts) {
|
||||
return new Promise(function(resolve,reject) {
|
||||
var scope = opts.scope;
|
||||
var id = opts.id;
|
||||
var store = opts.store;
|
||||
var key = opts.key;
|
||||
|
||||
var availableStores = runtime.nodes.listContextStores();
|
||||
//{ default: 'default', stores: [ 'default', 'file' ] }
|
||||
if (store && availableStores.stores.indexOf(store) === -1) {
|
||||
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"});
|
||||
var err = new Error();
|
||||
err.code = "not_found";
|
||||
err.status = 404;
|
||||
return reject(err);
|
||||
}
|
||||
var ctx;
|
||||
if (scope === 'global') {
|
||||
ctx = runtime.nodes.getContext('global');
|
||||
} else if (scope === 'flow') {
|
||||
ctx = runtime.nodes.getContext(id);
|
||||
} else if (scope === 'node') {
|
||||
var node = runtime.nodes.getNode(id);
|
||||
if (node) {
|
||||
ctx = node.context();
|
||||
}
|
||||
}
|
||||
if (ctx) {
|
||||
if (key) {
|
||||
store = store || availableStores.default;
|
||||
ctx.set(key,undefined,store,function(err) {
|
||||
runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key});
|
||||
resolve();
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
// TODO: support deleting whole context
|
||||
runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key,error:"not_found"});
|
||||
var err = new Error();
|
||||
err.code = "not_found";
|
||||
err.status = 404;
|
||||
return reject(err);
|
||||
// var stores;
|
||||
// if (!store) {
|
||||
// stores = availableStores.stores;
|
||||
// } else {
|
||||
// stores = [store];
|
||||
// }
|
||||
//
|
||||
// var result = {};
|
||||
// var c = stores.length;
|
||||
// var errorReported = false;
|
||||
// stores.forEach(function(store) {
|
||||
// exportContextStore(scope,ctx,store,result,function(err) {
|
||||
// if (err) {
|
||||
// // TODO: proper error reporting
|
||||
// if (!errorReported) {
|
||||
// errorReported = true;
|
||||
// runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key,error:"unexpected_error"});
|
||||
// var err = new Error();
|
||||
// err.code = "unexpected_error";
|
||||
// err.status = 400;
|
||||
// return reject(err);
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
// c--;
|
||||
// if (c === 0) {
|
||||
// if (!errorReported) {
|
||||
// runtime.log.audit({event: "context.get",scope:scope,id:id,store:store,key:key});
|
||||
// resolve(result);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// })
|
||||
}
|
||||
} else {
|
||||
runtime.log.audit({event: "context.delete",scope:scope,id:id,store:store,key:key});
|
||||
resolve();
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user