mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-04-18 13:51:02 +00:00
again a dirty commit for laptop syncing
This commit is contained in:
parent
8011a36915
commit
4b6de256aa
16 changed files with 315 additions and 188 deletions
|
|
@ -82,18 +82,19 @@ commandFunctions =
|
|||
cm = dynmod.compileString src, obj.id, {}, obj.lang
|
||||
answ = cm.answ
|
||||
if answ.code is 200
|
||||
events = []
|
||||
events.push name for name, id of cm.module
|
||||
@log.info "CM | Storing new eventpoller with events #{ events }"
|
||||
answ.message =
|
||||
"Event Poller module successfully stored! Found following event(s): #{ events }"
|
||||
db.eventPollers.storeModule obj.id, user.username,
|
||||
code: obj.data
|
||||
lang: obj.lang
|
||||
params: obj.params
|
||||
events: events
|
||||
if obj.public is 'true'
|
||||
db.eventPollers.publish obj.id
|
||||
if not obj.id or not obj.params
|
||||
answ.code = 400
|
||||
answ.message = "Your request didn't contain all necessary fields! id and params required"
|
||||
else
|
||||
events = []
|
||||
events.push name for name, id of cm.module
|
||||
@log.info "CM | Storing new eventpoller with events #{ events }"
|
||||
answ.message =
|
||||
"Event Poller module successfully stored! Found following event(s): #{ events }"
|
||||
obj.events = JSON.stringify events
|
||||
db.eventPollers.storeModule obj.id, user.username, obj
|
||||
if obj.public is 'true'
|
||||
db.eventPollers.publish obj.id
|
||||
cb answ
|
||||
|
||||
get_event_pollers: ( user, obj, cb ) ->
|
||||
|
|
@ -148,50 +149,61 @@ commandFunctions =
|
|||
cm = dynmod.compileString src, obj.id, {}, obj.lang
|
||||
answ = cm.answ
|
||||
if answ.code is 200
|
||||
actions = []
|
||||
actions.push name for name, id of cm.module
|
||||
@log.info "CM | Storing new eventpoller with actions #{ actions }"
|
||||
answ.message =
|
||||
"Action Invoker module successfully stored! Found following action(s): #{ actions }"
|
||||
db.actionInvokers.storeModule obj.id, user.username,
|
||||
code: obj.data
|
||||
lang: obj.lang
|
||||
params: obj.params
|
||||
actions: actions
|
||||
if obj.public is 'true'
|
||||
db.actionInvokers.publish obj.id
|
||||
if not obj.id or not obj.params
|
||||
answ.code = 400
|
||||
answ.message = "Your request didn't contain all necessary fields! id and params required"
|
||||
else
|
||||
actions = []
|
||||
actions.push name for name, id of cm.module
|
||||
@log.info "CM | Storing new eventpoller with actions #{ actions }"
|
||||
answ.message =
|
||||
"Action Invoker module successfully stored! Found following action(s): #{ actions }"
|
||||
obj.actions = JSON.stringify actions
|
||||
db.actionInvokers.storeModule obj.id, user.username, obj
|
||||
if obj.public is 'true'
|
||||
db.actionInvokers.publish obj.id
|
||||
cb answ
|
||||
|
||||
get_rules: ( user, obj, cb ) ->
|
||||
console.log 'CM | Implement get_rules'
|
||||
|
||||
# A rule needs to be in following format:
|
||||
#
|
||||
# - id
|
||||
# - event
|
||||
# - conditions
|
||||
# - actions
|
||||
forge_rule: ( user, obj, cb ) =>
|
||||
console.log obj
|
||||
db.getRule obj.id, ( err, objRule ) =>
|
||||
db.getRule obj.id, ( err, oExisting ) =>
|
||||
try
|
||||
if objRule isnt null
|
||||
if oExisting isnt null
|
||||
answ =
|
||||
code: 409
|
||||
message: 'Rule name already existing!'
|
||||
else
|
||||
rule =
|
||||
id: obj.id
|
||||
# users: [ user.username ] # This should be fetched from the db in each listener
|
||||
event: "#{ obj.event.module } -> #{ obj.event.function }"
|
||||
conditions: obj.conditions
|
||||
actions: obj.actions
|
||||
modules = JSON.parse obj.action_params
|
||||
db.storeRule rule.id, JSON.stringify rule
|
||||
db.linkRule rule.id, user.username
|
||||
db.activateRule rule.id, user.username
|
||||
db.eventPollers.storeUserParams obj.event.module, user.username, obj.event_params
|
||||
db.actionInvokers.storeUserParams id, user.username, JSON.stringify params for id, params of modules
|
||||
@ee.emit 'newRule', JSON.stringify rule
|
||||
answ =
|
||||
code: 400
|
||||
message: 'Rule stored and activated!'
|
||||
if not obj.id or not obj.event or
|
||||
not obj.conditions or not obj.actions
|
||||
answ =
|
||||
code: 400
|
||||
message: 'Missing properties in rule!'
|
||||
else
|
||||
ep = JSON.parse obj.event
|
||||
rule =
|
||||
id: obj.id
|
||||
event: ep
|
||||
conditions: JSON.parse obj.conditions
|
||||
actions: JSON.parse obj.actions
|
||||
strRule = JSON.stringify rule
|
||||
db.storeRule rule.id, strRule
|
||||
db.linkRule rule.id, user.username
|
||||
db.activateRule rule.id, user.username
|
||||
if obj.event_params
|
||||
db.eventPollers.storeUserParams ep.module, user.username, obj.event_params
|
||||
arrParams = JSON.parse obj.action_params
|
||||
db.actionInvokers.storeUserParams id, user.username, JSON.stringify params for id, params of arrParams
|
||||
@ee.emit 'newRule', strRule
|
||||
answ =
|
||||
code: 200
|
||||
message: 'Rule stored and activated!'
|
||||
catch err
|
||||
answ =
|
||||
code: 400
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ exports.compileString = ( src, id, params, lang ) =>
|
|||
try
|
||||
vm.runInNewContext src, sandbox, id + '.vm'
|
||||
catch err
|
||||
console.log err
|
||||
answ.code = 400
|
||||
answ.message = 'Loading Module failed: ' + err.message
|
||||
ret =
|
||||
|
|
|
|||
|
|
@ -244,14 +244,19 @@ class IndexedModules
|
|||
setDB: ( @db ) ->
|
||||
@log.info "DB | (IdxedMods) Registered new DB connection for '#{ @setname }'"
|
||||
|
||||
|
||||
###
|
||||
@private storeModule( *mId, userId, data* )
|
||||
@param {String} mId
|
||||
@param {String} userId
|
||||
@param {object} data
|
||||
###
|
||||
storeModule: ( mId, userId, data ) =>
|
||||
@log.info "DB | (IdxedMods) #{ @setname }.storeModule( #{ mId }, #{ userId }, data )"
|
||||
@db.sadd "#{ @setname }s", mId,
|
||||
replyHandler "sadd '#{ mId }' to '#{ @setname }'"
|
||||
@db.hmset "#{ @setname }:#{ mId }", 'code', data['code'],
|
||||
replyHandler "hmset 'code' in hash '#{ @setname }:#{ mId }'"
|
||||
@db.hmset "#{ @setname }:#{ mId }", 'reqparams', data['reqparams'],
|
||||
replyHandler "hmset 'reqparams' in hash '#{ @setname }:#{ mId }'"
|
||||
@db.hmset "#{ @setname }:#{ mId }", data,
|
||||
replyHandler "hmset properties in hash '#{ @setname }:#{ mId }'"
|
||||
@linkModule mId, userId
|
||||
|
||||
#TODO add testing
|
||||
|
|
@ -293,7 +298,7 @@ class IndexedModules
|
|||
|
||||
#TODO add testing
|
||||
getAvailableModuleIds: ( userId, cb ) =>
|
||||
@log.info "DB | (IdxedMods) #{ @setname }.getPublicModuleIds( #{ @suserId } )"
|
||||
@log.info "DB | (IdxedMods) #{ @setname }.getPublicModuleIds( #{ userId } )"
|
||||
@db.sunion "public-#{ @setname }s", "user:#{ userId }:#{ @setname }s", cb
|
||||
|
||||
getModuleIds: ( cb ) =>
|
||||
|
|
|
|||
|
|
@ -70,9 +70,13 @@ exports.handleEvent = ( req, resp ) ->
|
|||
body += data
|
||||
req.on 'end', ->
|
||||
if req.session and req.session.user
|
||||
obj = qs.parse body
|
||||
try
|
||||
obj = JSON.parse body
|
||||
catch err
|
||||
resp.send 400, 'Badly formed event!'
|
||||
|
||||
# If required event properties are present we process the event #
|
||||
if obj and obj.event
|
||||
if obj and obj.event and not err
|
||||
timestamp = ( new Date ).toISOString()
|
||||
rand = ( Math.floor Math.random() * 10e9 ).toString( 16 ).toUpperCase()
|
||||
obj.eventid = "#{ obj.event }_#{ timestamp }_#{ rand }"
|
||||
|
|
|
|||
|
|
@ -169,11 +169,11 @@ init = =>
|
|||
cm.addListener 'init', ( evt ) ->
|
||||
poller.send
|
||||
event: 'init'
|
||||
data:evt
|
||||
data: evt
|
||||
cm.addListener 'newRule', ( evt ) ->
|
||||
poller.send
|
||||
event: 'newRule'
|
||||
data:evt
|
||||
data: evt
|
||||
cm.addListener 'init', ( evt ) ->
|
||||
engine.internalEvent 'init', evt
|
||||
cm.addListener 'newRule', ( evt ) ->
|
||||
|
|
|
|||
|
|
@ -104,22 +104,23 @@ Components Manager
|
|||
cm = dynmod.compileString(src, obj.id, {}, obj.lang);
|
||||
answ = cm.answ;
|
||||
if (answ.code === 200) {
|
||||
events = [];
|
||||
_ref = cm.module;
|
||||
for (name in _ref) {
|
||||
id = _ref[name];
|
||||
events.push(name);
|
||||
}
|
||||
_this.log.info("CM | Storing new eventpoller with events " + events);
|
||||
answ.message = "Event Poller module successfully stored! Found following event(s): " + events;
|
||||
db.eventPollers.storeModule(obj.id, user.username, {
|
||||
code: obj.data,
|
||||
lang: obj.lang,
|
||||
params: obj.params,
|
||||
events: events
|
||||
});
|
||||
if (obj["public"] === 'true') {
|
||||
db.eventPollers.publish(obj.id);
|
||||
if (!obj.id || !obj.params) {
|
||||
answ.code = 400;
|
||||
answ.message = "Your request didn't contain all necessary fields! id and params required";
|
||||
} else {
|
||||
events = [];
|
||||
_ref = cm.module;
|
||||
for (name in _ref) {
|
||||
id = _ref[name];
|
||||
events.push(name);
|
||||
}
|
||||
_this.log.info("CM | Storing new eventpoller with events " + events);
|
||||
answ.message = "Event Poller module successfully stored! Found following event(s): " + events;
|
||||
obj.events = JSON.stringify(events);
|
||||
db.eventPollers.storeModule(obj.id, user.username, obj);
|
||||
if (obj["public"] === 'true') {
|
||||
db.eventPollers.publish(obj.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -207,22 +208,23 @@ Components Manager
|
|||
cm = dynmod.compileString(src, obj.id, {}, obj.lang);
|
||||
answ = cm.answ;
|
||||
if (answ.code === 200) {
|
||||
actions = [];
|
||||
_ref = cm.module;
|
||||
for (name in _ref) {
|
||||
id = _ref[name];
|
||||
actions.push(name);
|
||||
}
|
||||
_this.log.info("CM | Storing new eventpoller with actions " + actions);
|
||||
answ.message = "Action Invoker module successfully stored! Found following action(s): " + actions;
|
||||
db.actionInvokers.storeModule(obj.id, user.username, {
|
||||
code: obj.data,
|
||||
lang: obj.lang,
|
||||
params: obj.params,
|
||||
actions: actions
|
||||
});
|
||||
if (obj["public"] === 'true') {
|
||||
db.actionInvokers.publish(obj.id);
|
||||
if (!obj.id || !obj.params) {
|
||||
answ.code = 400;
|
||||
answ.message = "Your request didn't contain all necessary fields! id and params required";
|
||||
} else {
|
||||
actions = [];
|
||||
_ref = cm.module;
|
||||
for (name in _ref) {
|
||||
id = _ref[name];
|
||||
actions.push(name);
|
||||
}
|
||||
_this.log.info("CM | Storing new eventpoller with actions " + actions);
|
||||
answ.message = "Action Invoker module successfully stored! Found following action(s): " + actions;
|
||||
obj.actions = JSON.stringify(actions);
|
||||
db.actionInvokers.storeModule(obj.id, user.username, obj);
|
||||
if (obj["public"] === 'true') {
|
||||
db.actionInvokers.publish(obj.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -235,36 +237,46 @@ Components Manager
|
|||
},
|
||||
forge_rule: (function(_this) {
|
||||
return function(user, obj, cb) {
|
||||
console.log(obj);
|
||||
return db.getRule(obj.id, function(err, objRule) {
|
||||
var answ, id, modules, params, rule;
|
||||
return db.getRule(obj.id, function(err, oExisting) {
|
||||
var answ, arrParams, ep, id, params, rule, strRule;
|
||||
try {
|
||||
if (objRule !== null) {
|
||||
if (oExisting !== null) {
|
||||
answ = {
|
||||
code: 409,
|
||||
message: 'Rule name already existing!'
|
||||
};
|
||||
} else {
|
||||
rule = {
|
||||
id: obj.id,
|
||||
event: "" + obj.event.module + " -> " + obj.event["function"],
|
||||
conditions: obj.conditions,
|
||||
actions: obj.actions
|
||||
};
|
||||
modules = JSON.parse(obj.action_params);
|
||||
db.storeRule(rule.id, JSON.stringify(rule));
|
||||
db.linkRule(rule.id, user.username);
|
||||
db.activateRule(rule.id, user.username);
|
||||
db.eventPollers.storeUserParams(obj.event.module, user.username, obj.event_params);
|
||||
for (id in modules) {
|
||||
params = modules[id];
|
||||
db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params));
|
||||
if (!obj.id || !obj.event || !obj.conditions || !obj.actions) {
|
||||
answ = {
|
||||
code: 400,
|
||||
message: 'Missing properties in rule!'
|
||||
};
|
||||
} else {
|
||||
ep = JSON.parse(obj.event);
|
||||
rule = {
|
||||
id: obj.id,
|
||||
event: ep,
|
||||
conditions: JSON.parse(obj.conditions),
|
||||
actions: JSON.parse(obj.actions)
|
||||
};
|
||||
strRule = JSON.stringify(rule);
|
||||
db.storeRule(rule.id, strRule);
|
||||
db.linkRule(rule.id, user.username);
|
||||
db.activateRule(rule.id, user.username);
|
||||
if (obj.event_params) {
|
||||
db.eventPollers.storeUserParams(ep.module, user.username, obj.event_params);
|
||||
}
|
||||
arrParams = JSON.parse(obj.action_params);
|
||||
for (id in arrParams) {
|
||||
params = arrParams[id];
|
||||
db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params));
|
||||
}
|
||||
_this.ee.emit('newRule', strRule);
|
||||
answ = {
|
||||
code: 200,
|
||||
message: 'Rule stored and activated!'
|
||||
};
|
||||
}
|
||||
_this.ee.emit('newRule', JSON.stringify(rule));
|
||||
answ = {
|
||||
code: 400,
|
||||
message: 'Rule stored and activated!'
|
||||
};
|
||||
}
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ Dynamic Modules
|
|||
vm.runInNewContext(src, sandbox, id + '.vm');
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
console.log(err);
|
||||
answ.code = 400;
|
||||
answ.message = 'Loading Module failed: ' + err.message;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ var updateActionModules = function() {
|
|||
if(!listActionModules[user]) listActionModules[user] = {};
|
||||
for ( var rule in listRules[user] ) {
|
||||
var actions = listRules[user][rule].actions;
|
||||
for ( var i = 0; i < actions.length; i++ ){
|
||||
var arrMod = actions[i].split(' -> ');
|
||||
if ( !listActionModules[user][arrMod[0]] ){
|
||||
db.actionInvokers.getModule(arrMod[0], function( err, objAM ){
|
||||
db.actionInvokers.getUserParams(arrMod[0], user, function( err, objParams ) {
|
||||
console.log(actions);
|
||||
for ( var module in actions ){
|
||||
for ( var i = 0; i < actions[module]['functions'].length; i++ ){
|
||||
db.actionInvokers.getModule(module, function( err, objAM ){
|
||||
db.actionInvokers.getUserParams(module, user, function( err, objParams ) {
|
||||
console.log (objAM);
|
||||
|
||||
//FIXME am name is called 'actions'???
|
||||
|
|
@ -33,8 +33,8 @@ var updateActionModules = function() {
|
|||
var answ = dynmod.compileString(objAM.code, objAM.actions + "_" + user, objParams, objAM.lang);
|
||||
console.log('answ');
|
||||
console.log(answ);
|
||||
listActionModules[user][arrMod[0]] = answ.module;
|
||||
console.log('loaded ' + user + ': ' + arrMod[0]);
|
||||
listActionModules[user][module] = answ.module;
|
||||
console.log('loaded ' + user + ': ' + module);
|
||||
console.log(listActionModules);
|
||||
// }
|
||||
});
|
||||
|
|
@ -46,9 +46,13 @@ var updateActionModules = function() {
|
|||
};
|
||||
|
||||
exports.internalEvent = function( evt, data ) {
|
||||
try{
|
||||
try {
|
||||
// TODO do we need to determine init from newRule?
|
||||
console.log (evt);
|
||||
console.log (data);
|
||||
var obj = JSON.parse( data );
|
||||
db.getRuleActivatedUsers(obj.id, function ( err, arrUsers ) {
|
||||
console.log (arrUsers);
|
||||
for(var i = 0; i < arrUsers.length; i++) {
|
||||
if( !listRules[arrUsers[i]]) listRules[arrUsers[i]] = {};
|
||||
listRules[arrUsers[i]][obj.id] = obj;
|
||||
|
|
@ -79,31 +83,51 @@ function pollQueue() {
|
|||
function processEvent(evt) {
|
||||
log.info('EN', 'processing event: ' + evt.event + '(' + evt.eventid + ')');
|
||||
var actions = checkEvent(evt);
|
||||
console.log('found actions to invoke:');
|
||||
console.log(actions);
|
||||
for(var user in actions) {
|
||||
for(var i = 0; i < actions[user].length; i++) {
|
||||
invokeAction(evt, user, actions[user][i]);
|
||||
for(var module in actions[user]) {
|
||||
for(var i = 0; i < actions[user][module]['functions'].length; i++) {
|
||||
var act = {
|
||||
module: module,
|
||||
function: actions[user][module]['functions'][i]
|
||||
}
|
||||
invokeAction(evt, user, act);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
FIXME merge with processEvent
|
||||
|
||||
* Check an event against the rules repository and return the actions
|
||||
* if the conditons are met.
|
||||
* @param {Object} evt the event to check
|
||||
*/
|
||||
function checkEvent(evt) {
|
||||
var actions = {};
|
||||
var actions = {}, tEvt;
|
||||
for(var user in listRules) {
|
||||
actions[user] = [];
|
||||
actions[user] = {};
|
||||
for(var rule in listRules[user]) {
|
||||
//TODO this needs to get depth safe, not only data but eventually also
|
||||
// on one level above (eventid and other meta)
|
||||
|
||||
if(listRules[user][rule].event === evt.event && validConditions(evt.payload, listRules[user][rule])) {
|
||||
tEvt = listRules[user][rule].event;
|
||||
if(tEvt.module + ' -> ' + tEvt.function === evt.event && validConditions(evt.payload, listRules[user][rule])) {
|
||||
log.info('EN', 'Rule "' + rule + '" fired');
|
||||
var arrAct = listRules[user][rule].actions;
|
||||
for(var i = 0; i < arrAct.length; i++) {
|
||||
if(actions[user].indexOf(arrAct[i]) === -1) actions[user].push(arrAct[i]);
|
||||
var oAct = listRules[user][rule].actions;
|
||||
console.log (oAct);
|
||||
for(var module in oAct) {
|
||||
if(!actions[user][module]) {
|
||||
actions[user][module] = {
|
||||
functions: []
|
||||
};
|
||||
}
|
||||
for(var i = 0; i < oAct[module]['functions'].length; i++ ){
|
||||
console.log ('processing action ' + i + ', ' + oAct[module]['functions'][i]);
|
||||
actions[user][module]['functions'].push(oAct[module]['functions'][i]);
|
||||
// if(actions[user].indexOf(arrAct[i]) === -1) actions[user].push(arrAct[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -147,26 +171,21 @@ function validConditions(evt, rule) {
|
|||
* @param {Object} action The action to be invoked
|
||||
*/
|
||||
function invokeAction( evt, user, action ) {
|
||||
var actionargs = {},
|
||||
arrModule = action.split(' -> ');
|
||||
console.log('invoking action');
|
||||
var actionargs = {};
|
||||
//FIXME internal events, such as loopback ha sno arrow
|
||||
//TODO this requires change. the module property will be the identifier
|
||||
// in the actions object (or shall we allow several times the same action?)
|
||||
if(arrModule.length < 2) {
|
||||
log.error('EN', 'Invalid rule detected!');
|
||||
return;
|
||||
}
|
||||
console.log('invoking action');
|
||||
console.log(arrModule[0]);
|
||||
console.log(action.module);
|
||||
console.log(listActionModules);
|
||||
var srvc = listActionModules[user][arrModule[0]];
|
||||
var srvc = listActionModules[user][action.module];
|
||||
console.log(srvc);
|
||||
if(srvc && srvc[arrModule[1]]) {
|
||||
if(srvc && srvc[action.function]) {
|
||||
//FIXME preprocessing not only on data
|
||||
//FIXME no preprocessing at all, why don't we just pass the whole event to the action?'
|
||||
// preprocessActionArguments(evt.payload, action.arguments, actionargs);
|
||||
try {
|
||||
if(srvc[arrModule[1]]) srvc[arrModule[1]](evt.payload);
|
||||
if(srvc[action.function]) srvc[action.function](evt.payload);
|
||||
} catch(err) {
|
||||
log.error('EN', 'during action execution: ' + err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,8 +114,7 @@ function initMessageActions() {
|
|||
};
|
||||
|
||||
process.on('message', function( msg ) {
|
||||
console.log( 'message: ');
|
||||
console.log (msg);
|
||||
|
||||
console.log (JSON.parse(msg.data));
|
||||
// var arrProps = obj .split('|');
|
||||
// if(arrProps.length < 2) log.error('EP', 'too few parameter in message!');
|
||||
|
|
|
|||
|
|
@ -344,11 +344,18 @@ Persistence
|
|||
return this.log.info("DB | (IdxedMods) Registered new DB connection for '" + this.setname + "'");
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
@private storeModule( *mId, userId, data* )
|
||||
@param {String} mId
|
||||
@param {String} userId
|
||||
@param {object} data
|
||||
*/
|
||||
|
||||
IndexedModules.prototype.storeModule = function(mId, userId, data) {
|
||||
this.log.info("DB | (IdxedMods) " + this.setname + ".storeModule( " + mId + ", " + userId + ", data )");
|
||||
this.db.sadd("" + this.setname + "s", mId, replyHandler("sadd '" + mId + "' to '" + this.setname + "'"));
|
||||
this.db.hmset("" + this.setname + ":" + mId, 'code', data['code'], replyHandler("hmset 'code' in hash '" + this.setname + ":" + mId + "'"));
|
||||
this.db.hmset("" + this.setname + ":" + mId, 'reqparams', data['reqparams'], replyHandler("hmset 'reqparams' in hash '" + this.setname + ":" + mId + "'"));
|
||||
this.db.hmset("" + this.setname + ":" + mId, data, replyHandler("hmset properties in hash '" + this.setname + ":" + mId + "'"));
|
||||
return this.linkModule(mId, userId);
|
||||
};
|
||||
|
||||
|
|
@ -385,7 +392,7 @@ Persistence
|
|||
};
|
||||
|
||||
IndexedModules.prototype.getAvailableModuleIds = function(userId, cb) {
|
||||
this.log.info("DB | (IdxedMods) " + this.setname + ".getPublicModuleIds( " + this.suserId + " )");
|
||||
this.log.info("DB | (IdxedMods) " + this.setname + ".getPublicModuleIds( " + userId + " )");
|
||||
return this.db.sunion("public-" + this.setname + "s", "user:" + userId + ":" + this.setname + "s", cb);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -76,10 +76,15 @@ Request Handler
|
|||
return body += data;
|
||||
});
|
||||
return req.on('end', function() {
|
||||
var answ, obj, rand, timestamp;
|
||||
var answ, err, obj, rand, timestamp;
|
||||
if (req.session && req.session.user) {
|
||||
obj = qs.parse(body);
|
||||
if (obj && obj.event) {
|
||||
try {
|
||||
obj = JSON.parse(body);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
resp.send(400, 'Badly formed event!');
|
||||
}
|
||||
if (obj && obj.event && !err) {
|
||||
timestamp = (new Date).toISOString();
|
||||
rand = (Math.floor(Math.random() * 10e9)).toString(16).toUpperCase();
|
||||
obj.eventid = "" + obj.event + "_" + timestamp + "_" + rand;
|
||||
|
|
|
|||
|
|
@ -22,19 +22,19 @@ db = require path.join '..', 'js-coffee', 'persistence'
|
|||
db opts
|
||||
|
||||
|
||||
exports.testListener = ( test ) ->
|
||||
test.expect 2
|
||||
# exports.testListener = ( test ) ->
|
||||
# test.expect 2
|
||||
|
||||
oRuleOne = objects.rules.ruleOne
|
||||
oRuleTwo = objects.rules.ruleOne
|
||||
db.storeRule 'test-cm-rule', JSON.stringify oRuleOne
|
||||
cm.addListener 'init', ( evt ) =>
|
||||
test.deepEqual evt, oRuleOne, 'Event is not the same!'
|
||||
console.log 'got and checked init'
|
||||
# oRuleOne = objects.rules.ruleOne
|
||||
# oRuleTwo = objects.rules.ruleOne
|
||||
# db.storeRule 'test-cm-rule', JSON.stringify oRuleOne
|
||||
# cm.addListener 'init', ( evt ) =>
|
||||
# test.deepEqual evt, oRuleOne, 'Event is not the same!'
|
||||
# console.log 'got and checked init'
|
||||
|
||||
cm.addListener 'newRule', ( evt ) =>
|
||||
console.log 'new rule listener added'
|
||||
test.deepEqual evt, oRuleTwo, 'Event is not the same!'
|
||||
test.done()
|
||||
cm.processRequest oUser, oRuleTwo, ( answ ) =>
|
||||
console.log answ
|
||||
# cm.addListener 'newRule', ( evt ) =>
|
||||
# console.log 'new rule listener added'
|
||||
# test.deepEqual evt, oRuleTwo, 'Event is not the same!'
|
||||
# test.done()
|
||||
# cm.processRequest oUser, oRuleTwo, ( answ ) =>
|
||||
# console.log answ
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ exports.events =
|
|||
test.done()
|
||||
|
||||
@rh.handleEvent req, resp # set the handler to listening
|
||||
postRequestData req, qs.stringify oEvt # emit the data post event
|
||||
postRequestData req, JSON.stringify oEvt # emit the data post event
|
||||
setTimeout fPopEvent, 200 # try to fetch the db entry
|
||||
|
||||
testIncorrectEvent: ( test ) =>
|
||||
|
|
@ -295,4 +295,3 @@ exports.testUserCommands = ( test ) =>
|
|||
@rh.handleUserCommand req, resp # set the handler to listening
|
||||
postRequestData req, qs.stringify oReqData # emit the data post event
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -78,3 +78,24 @@ fOnLoad = () ->
|
|||
window.location.href = 'forge?page=forge_action_invoker'
|
||||
|
||||
window.addEventListener 'load', fOnLoad, true
|
||||
|
||||
# "ais": {
|
||||
# "ai1": {
|
||||
# "code": "
|
||||
# url = 'https://api.emailyak.com/v1/' + params.apikey + '/json/send/email/'
|
||||
|
||||
# exports.sendMail = ( args ) ->
|
||||
# data:
|
||||
# FromAddress: "no-reply@mscliveweb.simpleyak.com"
|
||||
# ToAddress: "test@mscliveweb.simpleyak.com"
|
||||
# log 'set data, posting now'
|
||||
# needle.post url, data, ( err, resp, body ) ->
|
||||
# log 'post returned'
|
||||
# if not err and resp.statusCode is 200
|
||||
# log 'Sent mail...'
|
||||
# else
|
||||
# log 'Error in EmailYak EM sendMail: ' + err.message
|
||||
# "
|
||||
|
||||
# }
|
||||
# },
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
|
||||
|
||||
fOnLoad = () ->
|
||||
|
||||
document.title = 'Rule Forge!'
|
||||
$( '#pagetitle' ).text '{{{user.username}}}, forge your custom rule!'
|
||||
$( '#pagetitle' ).text '{{{user.username}}}, forge your rule!'
|
||||
|
||||
# Fetch Event Poller user-specific parameters
|
||||
fFetchEventParams = ( name ) ->
|
||||
|
|
@ -35,6 +36,7 @@ fOnLoad = () ->
|
|||
|
||||
#FIXME Add possibility for custom event via text input
|
||||
#FIXME Add conditions
|
||||
#FIXME Only send user parameters encrypted! RSA required! Crypto-js doesn't provide it
|
||||
|
||||
|
||||
# Init Event Pollers
|
||||
|
|
@ -42,9 +44,13 @@ fOnLoad = () ->
|
|||
command: 'get_event_pollers'
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
fAppendEvent = ( id, name ) ->
|
||||
$( '#select_event' ).append $( '<option>' ).text id + ' -> ' + name
|
||||
fAppendEvent id, name for id, name of data.message
|
||||
fAppendEvents = ( id, events ) ->
|
||||
try
|
||||
arrNames = JSON.parse events
|
||||
$( '#select_event' ).append $( '<option>' ).text id + ' -> ' + name for name in arrNames
|
||||
catch err
|
||||
console.error 'ERROR: non-array received from server: ' + events
|
||||
fAppendEvents id, events for id, events of data.message
|
||||
fFetchEventParams $( '#select_event option:selected' ).text()
|
||||
.fail ( err ) ->
|
||||
console.log err
|
||||
|
|
@ -61,10 +67,15 @@ fOnLoad = () ->
|
|||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
i = 0
|
||||
fAppendAction = ( id, name ) ->
|
||||
$( '#select_actions' ).append $( '<option>' ).attr( 'id', i++ ).text id + ' -> ' + name
|
||||
arrActionInvoker.push id + ' -> ' + name
|
||||
fAppendAction id, name for id, name of data.message
|
||||
fAppendActions = ( id, actions ) ->
|
||||
try
|
||||
arrNames = JSON.parse actions
|
||||
for name in arrNames
|
||||
$( '#select_actions' ).append $( '<option>' ).attr( 'id', i++ ).text id + ' -> ' + name
|
||||
arrActionInvoker.push id + ' -> ' + name
|
||||
catch err
|
||||
console.error 'ERROR: non-array received from server: ' + actions
|
||||
fAppendActions id, actions for id, actions of data.message
|
||||
.fail ( err ) ->
|
||||
console.log err
|
||||
$( '#info' ).text 'Error fetching event poller'
|
||||
|
|
@ -131,7 +142,6 @@ fOnLoad = () ->
|
|||
if $( '#select_event option:selected' ).length is 0
|
||||
throw new Error 'Please create an Event Poller first!'
|
||||
|
||||
arrEP = $( '#select_event option:selected' ).val().split ' -> '
|
||||
if $( '#input_id' ).val() is ''
|
||||
throw new Error 'Please enter a rule name!'
|
||||
|
||||
|
|
@ -146,6 +156,7 @@ fOnLoad = () ->
|
|||
if $( '#selected_actions tr' ).length is 0
|
||||
throw new Error 'Please select at least one action or create one!'
|
||||
|
||||
# Store all selected action invokers
|
||||
ap = {}
|
||||
$( '#action_params div' ).each () ->
|
||||
id = $( this ).attr( 'id' ).substring 3
|
||||
|
|
@ -157,9 +168,15 @@ fOnLoad = () ->
|
|||
throw new Error "'#{ key }' missing for '#{ id }'"
|
||||
params[key] = val
|
||||
ap[id] = params
|
||||
acts = []
|
||||
acts = {}
|
||||
$( '#selected_actions .title' ).each () ->
|
||||
acts.push $( this ).text()
|
||||
arrAct = $( this ).text().split ' -> '
|
||||
if not acts[arrAct[0]]
|
||||
acts[arrAct[0]] =
|
||||
functions: []
|
||||
acts[arrAct[0]].functions.push arrAct[1]
|
||||
|
||||
arrEP = $( '#select_event option:selected' ).val().split ' -> '
|
||||
obj =
|
||||
command: 'forge_rule'
|
||||
id: $( '#input_id' ).val()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
fOnLoad = function() {
|
||||
var arrActionInvoker, fFetchActionParams, fFetchEventParams, obj;
|
||||
document.title = 'Rule Forge!';
|
||||
$('#pagetitle').text('{{{user.username}}}, forge your custom rule!');
|
||||
$('#pagetitle').text('{{{user.username}}}, forge your rule!');
|
||||
fFetchEventParams = function(name) {
|
||||
var arr, obj;
|
||||
arr = name.split(' -> ');
|
||||
|
|
@ -49,14 +49,26 @@
|
|||
command: 'get_event_pollers'
|
||||
};
|
||||
$.post('/usercommand', obj).done(function(data) {
|
||||
var fAppendEvent, id, name, _ref;
|
||||
fAppendEvent = function(id, name) {
|
||||
return $('#select_event').append($('<option>').text(id + ' -> ' + name));
|
||||
var events, fAppendEvents, id, _ref;
|
||||
fAppendEvents = function(id, events) {
|
||||
var arrNames, err, name, _i, _len, _results;
|
||||
try {
|
||||
arrNames = JSON.parse(events);
|
||||
_results = [];
|
||||
for (_i = 0, _len = arrNames.length; _i < _len; _i++) {
|
||||
name = arrNames[_i];
|
||||
_results.push($('#select_event').append($('<option>').text(id + ' -> ' + name)));
|
||||
}
|
||||
return _results;
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
return console.error('ERROR: non-array received from server: ' + events);
|
||||
}
|
||||
};
|
||||
_ref = data.message;
|
||||
for (id in _ref) {
|
||||
name = _ref[id];
|
||||
fAppendEvent(id, name);
|
||||
events = _ref[id];
|
||||
fAppendEvents(id, events);
|
||||
}
|
||||
return fFetchEventParams($('#select_event option:selected').text());
|
||||
}).fail(function(err) {
|
||||
|
|
@ -72,17 +84,27 @@
|
|||
command: 'get_action_invokers'
|
||||
};
|
||||
$.post('/usercommand', obj).done(function(data) {
|
||||
var fAppendAction, i, id, name, _ref, _results;
|
||||
var actions, fAppendActions, i, id, _ref, _results;
|
||||
i = 0;
|
||||
fAppendAction = function(id, name) {
|
||||
$('#select_actions').append($('<option>').attr('id', i++).text(id + ' -> ' + name));
|
||||
return arrActionInvoker.push(id + ' -> ' + name);
|
||||
fAppendActions = function(id, actions) {
|
||||
var arrNames, err, name, _i, _len;
|
||||
try {
|
||||
arrNames = JSON.parse(actions);
|
||||
for (_i = 0, _len = arrNames.length; _i < _len; _i++) {
|
||||
name = arrNames[_i];
|
||||
$('#select_actions').append($('<option>').attr('id', i++).text(id + ' -> ' + name));
|
||||
}
|
||||
return arrActionInvoker.push(id + ' -> ' + name);
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
return console.error('ERROR: non-array received from server: ' + actions);
|
||||
}
|
||||
};
|
||||
_ref = data.message;
|
||||
_results = [];
|
||||
for (id in _ref) {
|
||||
name = _ref[id];
|
||||
_results.push(fAppendAction(id, name));
|
||||
actions = _ref[id];
|
||||
_results.push(fAppendActions(id, actions));
|
||||
}
|
||||
return _results;
|
||||
}).fail(function(err) {
|
||||
|
|
@ -166,7 +188,6 @@
|
|||
if ($('#select_event option:selected').length === 0) {
|
||||
throw new Error('Please create an Event Poller first!');
|
||||
}
|
||||
arrEP = $('#select_event option:selected').val().split(' -> ');
|
||||
if ($('#input_id').val() === '') {
|
||||
throw new Error('Please enter a rule name!');
|
||||
}
|
||||
|
|
@ -199,10 +220,18 @@
|
|||
});
|
||||
return ap[id] = params;
|
||||
});
|
||||
acts = [];
|
||||
acts = {};
|
||||
$('#selected_actions .title').each(function() {
|
||||
return acts.push($(this).text());
|
||||
var arrAct;
|
||||
arrAct = $(this).text().split(' -> ');
|
||||
if (!acts[arrAct[0]]) {
|
||||
acts[arrAct[0]] = {
|
||||
functions: []
|
||||
};
|
||||
}
|
||||
return acts[arrAct[0]].functions.push(arrAct[1]);
|
||||
});
|
||||
arrEP = $('#select_event option:selected').val().split(' -> ');
|
||||
obj = {
|
||||
command: 'forge_rule',
|
||||
id: $('#input_id').val(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue