mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-16 22:10:31 +00:00
Updates in ECA rules management
This commit is contained in:
parent
234be71402
commit
a2e9e970c8
24 changed files with 752 additions and 484 deletions
|
|
@ -181,6 +181,7 @@ forgeModule = ( user, oPayload, dbMod, callback ) =>
|
|||
answ.message =
|
||||
" Module #{ oPayload.id } successfully stored! Found following function(s): #{ funcs }"
|
||||
oPayload.functions = JSON.stringify funcs
|
||||
oPayload.functionParameters = JSON.stringify cm.funcParams
|
||||
dbMod.storeModule user.username, oPayload
|
||||
if oPayload.public is 'true'
|
||||
dbMod.publish oPayload.id
|
||||
|
|
@ -225,13 +226,27 @@ commandFunctions =
|
|||
getModules user, oPayload, db.actionInvokers, callback
|
||||
|
||||
get_full_action_invoker: ( user, oPayload, callback ) ->
|
||||
db.actionInvokers.getModule oPayload.id, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: JSON.stringify obj
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.actionInvokers.getModule oPayload.id, ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: JSON.stringify obj
|
||||
|
||||
get_action_invoker_params: ( user, oPayload, callback ) ->
|
||||
getModuleParams user, oPayload, db.actionInvokers, callback
|
||||
|
||||
get_action_invoker_function_params: ( user, oPayload, callback ) ->
|
||||
answ = hasRequiredParams [ 'id' ], oPayload
|
||||
if answ.code isnt 200
|
||||
callback answ
|
||||
else
|
||||
db.actionInvokers.getModuleField oPayload.id, 'functionParameters', ( err, obj ) ->
|
||||
callback
|
||||
code: 200
|
||||
message: obj
|
||||
|
||||
forge_action_invoker: ( user, oPayload, callback ) ->
|
||||
forgeModule user, oPayload, db.actionInvokers, callback
|
||||
|
|
@ -281,20 +296,28 @@ commandFunctions =
|
|||
code: 409
|
||||
message: 'Rule name already existing!'
|
||||
else
|
||||
console.log 'new ruke'
|
||||
rule =
|
||||
id: oPayload.id
|
||||
event: oPayload.event
|
||||
conditions: oPayload.conditions
|
||||
actions: oPayload.actions
|
||||
strRule = JSON.stringify rule
|
||||
console.log 'stringified'
|
||||
db.storeRule rule.id, strRule
|
||||
console.log 'stored'
|
||||
db.linkRule rule.id, user.username
|
||||
console.log 'linked'
|
||||
db.activateRule rule.id, user.username
|
||||
console.log 'activated'
|
||||
if oPayload.event_params
|
||||
epModId = rule.event.split( ' -> ' )[0]
|
||||
db.eventPollers.storeUserParams epModId, user.username, oPayload.event_params
|
||||
console.log 'event params loaded'
|
||||
arrParams = oPayload.action_params
|
||||
console.log 'arractionparams'
|
||||
db.actionInvokers.storeUserParams id, user.username, JSON.stringify params for id, params of arrParams
|
||||
console.log 'action aprams stored'
|
||||
db.resetLog user.username, rule.id
|
||||
db.appendLog user.username, rule.id, "INIT", "Rule '#{ rule.id }' initialized"
|
||||
eventEmitter.emit 'rule',
|
||||
|
|
@ -304,6 +327,7 @@ commandFunctions =
|
|||
answ =
|
||||
code: 200
|
||||
message: "Rule '#{ rule.id }' stored and activated!"
|
||||
console.log 'done'
|
||||
callback answ
|
||||
|
||||
delete_rule: ( user, oPayload, callback ) ->
|
||||
|
|
|
|||
|
|
@ -80,6 +80,15 @@ logFunction = ( uId, rId, mId ) ->
|
|||
( msg ) ->
|
||||
db.appendLog uId, rId, mId, msg
|
||||
|
||||
regexpComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
getFunctionParamNames = ( fName, func, oFuncs ) ->
|
||||
fnStr = func.toString().replace regexpComments, ''
|
||||
result = fnStr.slice( fnStr.indexOf( '(' ) + 1, fnStr.indexOf( ')' ) ).match /([^\s,]+)/g
|
||||
if not result
|
||||
result = []
|
||||
oFuncs[fName] = result
|
||||
|
||||
|
||||
###
|
||||
Try to run a JS module from a string, together with the
|
||||
given parameters. If it is written in CoffeeScript we
|
||||
|
|
@ -142,9 +151,13 @@ exports.compileString = ( src, userId, ruleId, modId, lang, dbMod, cb ) =>
|
|||
if not msg
|
||||
msg = 'Try to run the script locally to track the error! Sadly we cannot provide the line number'
|
||||
answ.message = 'Loading Module failed: ' + msg
|
||||
oFuncParams = {}
|
||||
for fName, func of sandbox.exports
|
||||
getFunctionParamNames fName, func, oFuncParams
|
||||
cb
|
||||
answ: answ
|
||||
module: sandbox.exports
|
||||
funcParams: oFuncParams
|
||||
logger: sandbox.log
|
||||
|
||||
if dbMod
|
||||
|
|
|
|||
|
|
@ -252,6 +252,10 @@ class IndexedModules
|
|||
@log.info "DB | (IdxedMods) #{ @setname }.getModule( #{ mId } )"
|
||||
@db.hgetall "#{ @setname }:#{ mId }", cb
|
||||
|
||||
getModuleField: ( mId, field, cb ) =>
|
||||
@log.info "DB | (IdxedMods) #{ @setname }.getModule( #{ mId } )"
|
||||
@db.hget "#{ @setname }:#{ mId }", field, cb
|
||||
|
||||
#TODO add testing
|
||||
getModuleParams: ( mId, cb ) =>
|
||||
@log.info "DB | (IdxedMods) #{ @setname }.getModuleParams( #{ mId } )"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
"mode": "development",
|
||||
"io-level": "info",
|
||||
"file-level": "info",
|
||||
"file-path": "server.log"
|
||||
"file-path": "logs/server.log"
|
||||
},
|
||||
"keygen-passphrase": "[TODO this has to come from prompt when server is started!]"
|
||||
}
|
||||
|
|
@ -4,9 +4,6 @@ EmailYak ACTION INVOKER
|
|||
#
|
||||
# Requires user params:
|
||||
# - apikey: The user's EmailYak API key
|
||||
# - sender: The email address belonging to your apikey
|
||||
# - receipient: The email address for the one that receives the mail
|
||||
# - subject: The subject of the mail
|
||||
###
|
||||
|
||||
url = 'https://api.emailyak.com/v1/' + params.apikey + '/json/send/email/'
|
||||
|
|
@ -29,13 +26,16 @@ standardCallback = ( funcName ) ->
|
|||
###
|
||||
Send a mail through Emailyak.
|
||||
|
||||
@param {Object} args.content the content to be posted in the mail body
|
||||
@param sender The email address belonging to your apikey
|
||||
@param receipient The email address for the one that receives the mail
|
||||
@param subject The subject of the mail
|
||||
@param content The content of the mail
|
||||
###
|
||||
exports.sendMail = ( args ) ->
|
||||
exports.sendMail = ( sender, receipient, subject, content ) ->
|
||||
data =
|
||||
FromAddress: params.sender
|
||||
ToAddress: params.receipient
|
||||
Subject: params.subject
|
||||
TextBody: args.content
|
||||
FromAddress: sender
|
||||
ToAddress: receipient
|
||||
Subject: subject
|
||||
TextBody: content
|
||||
needlereq 'post', url, data, json: true, standardCallback 'sendMail'
|
||||
|
||||
|
|
|
|||
|
|
@ -249,6 +249,7 @@ Components Manager
|
|||
_this.log.info("CM | Storing new module with functions " + (funcs.join(', ')));
|
||||
answ.message = " Module " + oPayload.id + " successfully stored! Found following function(s): " + funcs;
|
||||
oPayload.functions = JSON.stringify(funcs);
|
||||
oPayload.functionParameters = JSON.stringify(cm.funcParams);
|
||||
dbMod.storeModule(user.username, oPayload);
|
||||
if (oPayload["public"] === 'true') {
|
||||
dbMod.publish(oPayload.id);
|
||||
|
|
@ -303,16 +304,36 @@ Components Manager
|
|||
return getModules(user, oPayload, db.actionInvokers, callback);
|
||||
},
|
||||
get_full_action_invoker: function(user, oPayload, callback) {
|
||||
return db.actionInvokers.getModule(oPayload.id, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: JSON.stringify(obj)
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.actionInvokers.getModule(oPayload.id, function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: JSON.stringify(obj)
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
get_action_invoker_params: function(user, oPayload, callback) {
|
||||
return getModuleParams(user, oPayload, db.actionInvokers, callback);
|
||||
},
|
||||
get_action_invoker_function_params: function(user, oPayload, callback) {
|
||||
var answ;
|
||||
answ = hasRequiredParams(['id'], oPayload);
|
||||
if (answ.code !== 200) {
|
||||
return callback(answ);
|
||||
} else {
|
||||
return db.actionInvokers.getModuleField(oPayload.id, 'functionParameters', function(err, obj) {
|
||||
return callback({
|
||||
code: 200,
|
||||
message: obj
|
||||
});
|
||||
});
|
||||
}
|
||||
},
|
||||
forge_action_invoker: function(user, oPayload, callback) {
|
||||
return forgeModule(user, oPayload, db.actionInvokers, callback);
|
||||
},
|
||||
|
|
@ -365,6 +386,7 @@ Components Manager
|
|||
message: 'Rule name already existing!'
|
||||
};
|
||||
} else {
|
||||
console.log('new ruke');
|
||||
rule = {
|
||||
id: oPayload.id,
|
||||
event: oPayload.event,
|
||||
|
|
@ -372,18 +394,25 @@ Components Manager
|
|||
actions: oPayload.actions
|
||||
};
|
||||
strRule = JSON.stringify(rule);
|
||||
console.log('stringified');
|
||||
db.storeRule(rule.id, strRule);
|
||||
console.log('stored');
|
||||
db.linkRule(rule.id, user.username);
|
||||
console.log('linked');
|
||||
db.activateRule(rule.id, user.username);
|
||||
console.log('activated');
|
||||
if (oPayload.event_params) {
|
||||
epModId = rule.event.split(' -> ')[0];
|
||||
db.eventPollers.storeUserParams(epModId, user.username, oPayload.event_params);
|
||||
}
|
||||
console.log('event params loaded');
|
||||
arrParams = oPayload.action_params;
|
||||
console.log('arractionparams');
|
||||
for (id in arrParams) {
|
||||
params = arrParams[id];
|
||||
db.actionInvokers.storeUserParams(id, user.username, JSON.stringify(params));
|
||||
}
|
||||
console.log('action aprams stored');
|
||||
db.resetLog(user.username, rule.id);
|
||||
db.appendLog(user.username, rule.id, "INIT", "Rule '" + rule.id + "' initialized");
|
||||
eventEmitter.emit('rule', {
|
||||
|
|
@ -395,6 +424,7 @@ Components Manager
|
|||
code: 200,
|
||||
message: "Rule '" + rule.id + "' stored and activated!"
|
||||
};
|
||||
console.log('done');
|
||||
}
|
||||
return callback(answ);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ Dynamic Modules
|
|||
*/
|
||||
|
||||
(function() {
|
||||
var cryptico, cryptoJS, cs, db, exports, issueNeedleCall, issueRequest, logFunction, needle, request, vm;
|
||||
var cryptico, cryptoJS, cs, db, exports, getFunctionParamNames, issueNeedleCall, issueRequest, logFunction, needle, regexpComments, request, vm;
|
||||
|
||||
db = require('./persistence');
|
||||
|
||||
|
|
@ -104,6 +104,18 @@ Dynamic Modules
|
|||
};
|
||||
};
|
||||
|
||||
regexpComments = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
|
||||
getFunctionParamNames = function(fName, func, oFuncs) {
|
||||
var fnStr, result;
|
||||
fnStr = func.toString().replace(regexpComments, '');
|
||||
result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(/([^\s,]+)/g);
|
||||
if (!result) {
|
||||
result = [];
|
||||
}
|
||||
return oFuncs[fName] = result;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
Try to run a JS module from a string, together with the
|
||||
|
|
@ -134,7 +146,7 @@ Dynamic Modules
|
|||
}
|
||||
}
|
||||
fTryToLoad = function(params) {
|
||||
var logFunc, msg, oDecrypted, sandbox;
|
||||
var fName, func, logFunc, msg, oDecrypted, oFuncParams, sandbox, _ref;
|
||||
if (params) {
|
||||
try {
|
||||
oDecrypted = cryptico.decrypt(params, _this.oPrivateRSAkey);
|
||||
|
|
@ -170,9 +182,16 @@ Dynamic Modules
|
|||
}
|
||||
answ.message = 'Loading Module failed: ' + msg;
|
||||
}
|
||||
oFuncParams = {};
|
||||
_ref = sandbox.exports;
|
||||
for (fName in _ref) {
|
||||
func = _ref[fName];
|
||||
getFunctionParamNames(fName, func, oFuncParams);
|
||||
}
|
||||
return cb({
|
||||
answ: answ,
|
||||
module: sandbox.exports,
|
||||
funcParams: oFuncParams,
|
||||
logger: sandbox.log
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -262,6 +262,7 @@ Persistence
|
|||
this.getModuleIds = __bind(this.getModuleIds, this);
|
||||
this.getAvailableModuleIds = __bind(this.getAvailableModuleIds, this);
|
||||
this.getModuleParams = __bind(this.getModuleParams, this);
|
||||
this.getModuleField = __bind(this.getModuleField, this);
|
||||
this.getModule = __bind(this.getModule, this);
|
||||
this.unpublish = __bind(this.unpublish, this);
|
||||
this.publish = __bind(this.publish, this);
|
||||
|
|
@ -319,6 +320,11 @@ Persistence
|
|||
return this.db.hgetall("" + this.setname + ":" + mId, cb);
|
||||
};
|
||||
|
||||
IndexedModules.prototype.getModuleField = function(mId, field, cb) {
|
||||
this.log.info("DB | (IdxedMods) " + this.setname + ".getModule( " + mId + " )");
|
||||
return this.db.hget("" + this.setname + ":" + mId, field, cb);
|
||||
};
|
||||
|
||||
IndexedModules.prototype.getModuleParams = function(mId, cb) {
|
||||
this.log.info("DB | (IdxedMods) " + this.setname + ".getModuleParams( " + mId + " )");
|
||||
return this.db.hget("" + this.setname + ":" + mId, "params", cb);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@
|
|||
"dependencies": {
|
||||
"bunyan": "0.22.1",
|
||||
"coffee-script": "1.6.3",
|
||||
"connect-redis": "1.4.6",
|
||||
"crypto-js": "3.1.2",
|
||||
"express": "3.4.8",
|
||||
"groc": "0.6.1",
|
||||
|
|
|
|||
|
|
@ -47,11 +47,13 @@ fOnLoad = () ->
|
|||
oMods = JSON.parse data.message
|
||||
for modName of oMods
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr( 'class', 'del' ).attr 'src', 'red_cross_small.png'
|
||||
imgTwo = $( '<img>' ).attr( 'class', 'log' ).attr 'src', 'logicon.png'
|
||||
inp = $( '<div>' ).text modName
|
||||
img = $( '<img>' ).attr( 'class', 'del' )
|
||||
.attr( 'title', 'Delete Module' ).attr 'src', 'red_cross_small.png'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
img = $( '<img>' ).attr( 'class', 'log' )
|
||||
.attr( 'title', 'Edit Module' ).attr 'src', 'edit.png'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
tr.append( $( '<td>' ).append imgTwo )
|
||||
tr.append( $( '<td>' ).append inp )
|
||||
$( '#tableModules' ).append tr
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,15 @@
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# encodeURIComponent(url); -> Rule Name to be passed to forge_rule
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fOnLoad = () ->
|
||||
document.title = 'Edit Rules'
|
||||
|
|
@ -29,11 +41,16 @@ fOnLoad = () ->
|
|||
$( '#tableRules tr' ).remove()
|
||||
for ruleName in data.message
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr( 'class', 'del' ).attr 'src', 'red_cross_small.png'
|
||||
imgTwo = $( '<img>' ).attr( 'class', 'log' ).attr 'src', 'logicon.png'
|
||||
inp = $( '<div>' ).text ruleName
|
||||
img = $( '<img>' ).attr( 'class', 'del' )
|
||||
.attr( 'title', 'Delete Rule' ).attr 'src', 'red_cross_small.png'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
tr.append( $( '<td>' ).append imgTwo )
|
||||
img = $( '<img>' ).attr( 'class', 'edit' )
|
||||
.attr( 'title', 'Edit Rule' ).attr 'src', 'edit.png'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
img = $( '<img>' ).attr( 'class', 'log' )
|
||||
.attr( 'title', 'Show Rule Log' ).attr 'src', 'logicon.png'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
inp = $( '<div>' ).text ruleName
|
||||
tr.append( $( '<td>' ).append inp )
|
||||
$( '#tableRules' ).append tr
|
||||
|
||||
|
|
@ -52,6 +69,10 @@ fOnLoad = () ->
|
|||
.done fFetchRules
|
||||
.fail fErrHandler 'Could not delete rule! '
|
||||
|
||||
$( '#tableRules' ).on 'click', 'img.edit', () ->
|
||||
ruleName = $( 'div', $( this ).closest( 'tr' )).text()
|
||||
window.location.href = 'forge?page=forge_rule&id=' + encodeURIComponent ruleName
|
||||
|
||||
$( '#tableRules' ).on 'click', 'img.log', () ->
|
||||
ruleName = $( 'div', $( this ).closest( 'tr' )).text()
|
||||
data =
|
||||
|
|
@ -65,4 +86,38 @@ fOnLoad = () ->
|
|||
$( '#log_col' ).html "<h3>#{ ruleName } Log:</h3>#{ log }"
|
||||
.fail fErrHandler 'Could not get rule log! '
|
||||
|
||||
# Add parameter list functionality
|
||||
fChangeInputVisibility = () ->
|
||||
$( '#tableParams tr' ).each ( id ) ->
|
||||
if $( this ).is ':last-child' or $( this ).is ':only-child'
|
||||
$( 'img', this ).hide()
|
||||
$( 'input[type=checkbox]', this ).hide()
|
||||
else
|
||||
$( 'img', this ).show()
|
||||
$( 'input[type=checkbox]', this ).show()
|
||||
|
||||
$( '#tableParams' ).on 'click', 'img', () ->
|
||||
par = $( this ).closest 'tr'
|
||||
if not par.is ':last-child'
|
||||
par.remove()
|
||||
fChangeInputVisibility()
|
||||
|
||||
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
|
||||
code = e.keyCode or e.which
|
||||
if code isnt 9
|
||||
par = $( this ).closest 'tr'
|
||||
if par.is ':last-child'
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
|
||||
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
|
||||
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
|
||||
tr.append $( '<td>' ).append img
|
||||
tr.append $( '<td>' ).append cb
|
||||
tr.append $( '<td>' ).append inp
|
||||
par.parent().append tr
|
||||
fChangeInputVisibility()
|
||||
else if $( this ).val() is '' and not par.is ':only-child'
|
||||
par.remove()
|
||||
|
||||
fChangeInputVisibility()
|
||||
window.addEventListener 'load', fOnLoad, true
|
||||
|
|
|
|||
|
|
@ -17,44 +17,52 @@ fOnLoad = () ->
|
|||
editor.getSession().setMode "ace/mode/javascript"
|
||||
|
||||
# Add parameter list functionality
|
||||
fChangeCrosses = () ->
|
||||
$( '#tableParams img' ).each ( id ) ->
|
||||
par = $( this ).closest 'tr'
|
||||
if par.is ':last-child' or par.is ':only-child'
|
||||
$( this ).hide()
|
||||
fChangeInputVisibility = () ->
|
||||
$( '#tableParams tr' ).each ( id ) ->
|
||||
if $( this ).is ':last-child' or $( this ).is ':only-child'
|
||||
$( 'img', this ).hide()
|
||||
$( 'input[type=checkbox]', this ).hide()
|
||||
else
|
||||
$( this ).show()
|
||||
$( 'img', this ).show()
|
||||
$( 'input[type=checkbox]', this ).show()
|
||||
|
||||
$( '#tableParams' ).on 'click', 'img', () ->
|
||||
par = $( this ).closest 'tr'
|
||||
if not par.is ':last-child'
|
||||
par.remove()
|
||||
fChangeCrosses()
|
||||
fChangeInputVisibility()
|
||||
|
||||
$( '#tableParams' ).on 'keyup', 'input', () ->
|
||||
par = $( this ).closest( 'tr' )
|
||||
if par.is ':last-child'
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr 'src', 'red_cross_small.png'
|
||||
inp = $( '<input>' ).attr 'type', 'text'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
tr.append( $( '<td>' ).append inp )
|
||||
par.parent().append tr
|
||||
fChangeCrosses()
|
||||
else if $( this ).val() is '' and not par.is ':only-child'
|
||||
par.remove()
|
||||
fChangeCrosses()
|
||||
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
|
||||
code = e.keyCode or e.which
|
||||
if code isnt 9
|
||||
par = $( this ).closest( 'tr' )
|
||||
if par.is ':last-child'
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
|
||||
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
|
||||
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
tr.append( $( '<td>' ).append cb )
|
||||
tr.append( $( '<td>' ).append inp )
|
||||
par.parent().append tr
|
||||
fChangeInputVisibility()
|
||||
else if $( this ).val() is '' and not par.is ':only-child'
|
||||
par.remove()
|
||||
|
||||
fChangeInputVisibility()
|
||||
|
||||
# Add submit button logic
|
||||
$( '#but_submit' ).click () ->
|
||||
if $( '#input_id' ).val() is ''
|
||||
alert 'Please enter an action invoker name!'
|
||||
else
|
||||
listParams = []
|
||||
$( '#tableParams input' ).each () ->
|
||||
val = $( this ).val()
|
||||
listParams = {}
|
||||
$( '#tableParams tr' ).each () ->
|
||||
val = $( 'input.textinput', this ).val()
|
||||
shld = $( 'input[type=checkbox]', this ).is ':checked'
|
||||
if val isnt ""
|
||||
listParams.push val
|
||||
listParams[val] = shld
|
||||
true
|
||||
obj =
|
||||
command: 'forge_action_invoker'
|
||||
payload:
|
||||
|
|
|
|||
|
|
@ -16,44 +16,53 @@ fOnLoad = () ->
|
|||
editor.getSession().setMode "ace/mode/javascript"
|
||||
|
||||
# Add parameter list functionality
|
||||
fChangeCrosses = () ->
|
||||
$( '#tableParams img' ).each ( id ) ->
|
||||
par = $( this ).closest 'tr'
|
||||
if par.is ':last-child' or par.is ':only-child'
|
||||
$( this ).hide()
|
||||
fChangeInputVisibility = () ->
|
||||
$( '#tableParams tr' ).each ( id ) ->
|
||||
if $( this ).is ':last-child' or $( this ).is ':only-child'
|
||||
$( 'img', this ).hide()
|
||||
$( 'input[type=checkbox]', this ).hide()
|
||||
else
|
||||
$( this ).show()
|
||||
$( 'img', this ).show()
|
||||
$( 'input[type=checkbox]', this ).show()
|
||||
|
||||
$( '#tableParams' ).on 'click', 'img', () ->
|
||||
par = $( this ).closest 'tr'
|
||||
if not par.is ':last-child'
|
||||
par.remove()
|
||||
fChangeCrosses()
|
||||
fChangeInputVisibility()
|
||||
|
||||
$( '#tableParams' ).on 'keyup', 'input', () ->
|
||||
par = $( this ).closest( 'tr' )
|
||||
if par.is ':last-child'
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr 'src', 'red_cross_small.png'
|
||||
inp = $( '<input>' ).attr 'type', 'text'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
tr.append( $( '<td>' ).append inp )
|
||||
par.parent().append tr
|
||||
fChangeCrosses()
|
||||
else if $( this ).val() is '' and not par.is ':only-child'
|
||||
par.remove()
|
||||
fChangeCrosses()
|
||||
$( '#tableParams' ).on 'keyup', 'input', ( e ) ->
|
||||
code = e.keyCode or e.which
|
||||
if code isnt 9
|
||||
par = $( this ).closest( 'tr' )
|
||||
if par.is ':last-child'
|
||||
tr = $ '<tr>'
|
||||
img = $( '<img>' ).attr( 'title', 'Remove?').attr 'src', 'red_cross_small.png'
|
||||
cb = $( '<input>' ).attr( 'type', 'checkbox' ).attr 'title', 'Password shielded input?'
|
||||
inp = $( '<input>' ).attr( 'type', 'text' ).attr 'class', 'textinput'
|
||||
tr.append( $( '<td>' ).append img )
|
||||
tr.append( $( '<td>' ).append cb )
|
||||
tr.append( $( '<td>' ).append inp )
|
||||
tr.append $( '<td>' )
|
||||
par.parent().append tr
|
||||
fChangeInputVisibility()
|
||||
else if $( this ).val() is '' and not par.is ':only-child'
|
||||
par.remove()
|
||||
|
||||
fChangeInputVisibility()
|
||||
|
||||
# Add submit button logic
|
||||
$( '#but_submit' ).click () ->
|
||||
if $( '#input_id' ).val() is ''
|
||||
alert 'Please enter an event poller name!'
|
||||
else
|
||||
listParams = []
|
||||
$( '#tableParams input' ).each () ->
|
||||
val = $( this ).val()
|
||||
listParams = {}
|
||||
$( '#tableParams tr' ).each () ->
|
||||
val = $( 'input.textinput', this ).val()
|
||||
shld = $( 'input[type=checkbox]', this ).is ':checked'
|
||||
if val isnt ""
|
||||
listParams.push val
|
||||
listParams[val] = shld
|
||||
true
|
||||
obj =
|
||||
command: 'forge_event_poller'
|
||||
payload:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,13 @@
|
|||
strPublicKey = ''
|
||||
|
||||
fFailedRequest = ( msg ) ->
|
||||
( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
$( '#info' ).text msg
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
|
||||
$.post( '/usercommand', command: 'get_public_key' )
|
||||
.done ( data ) ->
|
||||
strPublicKey = data.message
|
||||
|
|
@ -6,11 +15,12 @@ $.post( '/usercommand', command: 'get_public_key' )
|
|||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
console.log err
|
||||
$( '#info' ).text 'Error fetching public key, unable to send user-specific parameters securely'
|
||||
$( '#info' ).text 'Error fetching public key, unable to send user specific parameters securely'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
|
||||
fOnLoad = () ->
|
||||
document.title = 'Rule Forge!'
|
||||
$( '#pagetitle' ).text '{{{user.username}}}, forge your ECA Rule!'
|
||||
|
||||
editor = ace.edit "editor_conditions"
|
||||
editor.setTheme "ace/theme/monokai"
|
||||
|
|
@ -18,9 +28,6 @@ fOnLoad = () ->
|
|||
editor.setShowPrintMargin false
|
||||
# editor.session.setUseSoftTabs false
|
||||
|
||||
document.title = 'Rule Forge!'
|
||||
$( '#pagetitle' ).text '{{{user.username}}}, forge your ECA Rule!'
|
||||
|
||||
# Fetch Event Poller user-specific parameters
|
||||
fFetchEventParams = ( name ) ->
|
||||
if name
|
||||
|
|
@ -33,39 +40,24 @@ fOnLoad = () ->
|
|||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
if data.message
|
||||
arrParams = JSON.parse data.message
|
||||
oParams = JSON.parse data.message
|
||||
$( '#event_poller_params table' ).remove()
|
||||
if arrParams.length > 0
|
||||
table = $ '<table>'
|
||||
$( '#event_poller_params' ).append table
|
||||
fAppendParam = ( name ) ->
|
||||
tr = $( '<tr>' )
|
||||
tr.append $( '<td>' ).css 'width', '20px'
|
||||
tr.append $( '<td>' ).attr( 'class', 'key' ).text name
|
||||
inp = $( '<input>' ).attr( 'type', 'password' ).attr 'id', "#{ name }"
|
||||
tr.append $( '<td>' ).text( ' :' ).append inp
|
||||
table.append tr
|
||||
fAppendParam name for name in arrParams
|
||||
.fail ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
fDelayed = () ->
|
||||
console.log err
|
||||
$( '#info' ).text 'Error fetching event poller params'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
setTimeout fDelayed, 500
|
||||
|
||||
|
||||
#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
|
||||
|
||||
table = $ '<table>'
|
||||
$( '#event_poller_params' ).append table
|
||||
fAppendParam = ( name, shielded ) ->
|
||||
tr = $( '<tr>' )
|
||||
tr.append $( '<td>' ).css 'width', '20px'
|
||||
tr.append $( '<td>' ).attr( 'class', 'key' ).text name
|
||||
inp = $( '<input>' ).attr 'id', "#{ name }"
|
||||
if shielded
|
||||
inp.attr( 'type', 'password' )
|
||||
tr.append $( '<td>' ).text( ' : ' ).append inp
|
||||
table.append tr
|
||||
fAppendParam name, shielded for name, shielded of oParams
|
||||
.fail fFailedRequest 'Error fetching event poller params'
|
||||
|
||||
# Init Event Pollers
|
||||
obj =
|
||||
command: 'get_event_pollers'
|
||||
$.post( '/usercommand', obj )
|
||||
$.post( '/usercommand', command: 'get_event_pollers' )
|
||||
.done ( data ) ->
|
||||
try
|
||||
oEps = JSON.parse data.message
|
||||
|
|
@ -79,110 +71,119 @@ fOnLoad = () ->
|
|||
fAppendEvent evt for evt in events
|
||||
fAppendEvents id, events for id, events of oEps
|
||||
fFetchEventParams $( '#select_event option:selected' ).text()
|
||||
.fail ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
fDelayed = () ->
|
||||
console.log err
|
||||
$( '#info' ).text 'Error fetching event poller'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
setTimeout fDelayed, 500
|
||||
.fail fFailedRequest 'Error fetching event poller'
|
||||
|
||||
$( '#select_event' ).change () ->
|
||||
fFetchEventParams $( this ).val()
|
||||
|
||||
# Init Action Invoker
|
||||
arrActionInvoker = []
|
||||
obj =
|
||||
command: 'get_action_invokers'
|
||||
$.post( '/usercommand', obj )
|
||||
|
||||
.done ( data ) ->
|
||||
try
|
||||
oAis = JSON.parse data.message
|
||||
catch err
|
||||
console.error 'ERROR: non-object received from server: ' + data.message
|
||||
return
|
||||
i = 0
|
||||
fAppendActions = ( id, actions ) ->
|
||||
fAppendAction = ( act ) ->
|
||||
$( '#select_actions' ).append $( '<option>' ).attr( 'id', i++ ).text id + ' -> ' + act
|
||||
arrActionInvoker.push id + ' -> ' + act
|
||||
fAppendAction act for act in actions
|
||||
fAppendActions id, actions for id, actions of oAis
|
||||
fAppendActions = ( module, actions ) ->
|
||||
for act in actions
|
||||
$( '#select_actions' ).append $( '<option>' ).text module + ' -> ' + act
|
||||
fAppendActions module, actions for module, actions of oAis
|
||||
.fail fFailedRequest 'Error fetching event poller'
|
||||
|
||||
.fail ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
console.log err
|
||||
fDelayed = () ->
|
||||
$( '#info' ).text 'Error fetching event poller'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
setTimeout fDelayed, 500
|
||||
|
||||
# Fetch Action Invoker user-specific parameters
|
||||
fFetchActionParams = ( div, name ) ->
|
||||
fFetchActionParams = ( div, modName ) ->
|
||||
obj =
|
||||
command: 'get_action_invoker_params'
|
||||
payload:
|
||||
id: name
|
||||
id: modName
|
||||
obj.payload = JSON.stringify( obj.payload );
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
if data.message
|
||||
arrParams = JSON.parse data.message
|
||||
if arrParams.length > 0
|
||||
table = $ '<table>'
|
||||
div.append table
|
||||
fAppendActionParam = ( name ) ->
|
||||
tr = $( '<tr>' )
|
||||
tr.append $( '<td>' ).css 'width', '20px'
|
||||
tr.append $( '<td>' ).attr( 'class', 'key').text name
|
||||
tr.append $( '<td>' ).text(' :').append $( '<input>' ).attr( 'type', 'password' )
|
||||
table.append tr
|
||||
fAppendActionParam name for name in arrParams
|
||||
.fail ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
else
|
||||
console.log err
|
||||
fDelayed = () ->
|
||||
$( '#info' ).text 'Error fetching action invoker params'
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
setTimeout fDelayed, 500
|
||||
oParams = JSON.parse data.message
|
||||
table = $ '<table>'
|
||||
div.append table
|
||||
fAppendActionParam = ( name, shielded ) ->
|
||||
tr = $( '<tr>' )
|
||||
tr.append $( '<td>' ).css 'width', '20px'
|
||||
tr.append $( '<td>' ).attr( 'class', 'key').text name
|
||||
inp = $( '<input>' ).attr 'id', "#{ name }"
|
||||
if shielded
|
||||
inp.attr( 'type', 'password' )
|
||||
else
|
||||
inp.attr( 'type', 'text' )
|
||||
tr.append $( '<td>' ).text(' : ').append inp
|
||||
table.append tr
|
||||
fAppendActionParam name, sh for name, sh of oParams
|
||||
.fail fFailedRequest 'Error fetching action invoker params'
|
||||
|
||||
fFetchActionFunctionParams = ( tag, arrName ) ->
|
||||
obj =
|
||||
command: 'get_action_invoker_function_params'
|
||||
payload:
|
||||
id: arrName[ 0 ]
|
||||
obj.payload = JSON.stringify( obj.payload );
|
||||
$.post( '/usercommand', obj )
|
||||
.done ( data ) ->
|
||||
if data.message
|
||||
oParams = JSON.parse data.message
|
||||
if oParams[ arrName[ 1 ] ]
|
||||
table = $( '<table>' ).appendTo tag
|
||||
for functionArgument in oParams[ arrName[ 1 ] ]
|
||||
tr = $( '<tr>' ).appendTo table
|
||||
td = $( '<td>' ).appendTo tr
|
||||
td.append $( '<div>' ).text functionArgument
|
||||
tr.append td
|
||||
td = $( '<td>' ).appendTo tr
|
||||
td.append $( '<input>' ).attr 'type', 'text'
|
||||
tr.append td
|
||||
tr.append td
|
||||
td = $( '<td>' ).appendTo tr
|
||||
td.append $( '<input>' ).attr( 'type', 'checkbox' )
|
||||
.attr 'title', 'js-select expression to be resolved on event?'
|
||||
.fail fFailedRequest 'Error fetching action invoker function params'
|
||||
|
||||
$( '#select_actions' ).on 'change', () ->
|
||||
opt = $ 'option:selected', this
|
||||
arrAI = opt.val().split ' -> '
|
||||
idAI = opt.attr 'id'
|
||||
|
||||
arrName = opt.text().split ' -> '
|
||||
|
||||
arrEls = $( "#action_params div.modName" ).map( () ->
|
||||
$( this ).text()
|
||||
).get()
|
||||
table = $( '#selected_actions' )
|
||||
tr = $( '<tr>' ).attr( 'id', 'title_' + idAI )
|
||||
tr = $( '<tr>' ).appendTo table
|
||||
img = $( '<img>' ).attr 'src', 'red_cross_small.png'
|
||||
tr.append $( '<td>' ).css( 'width', '20px' ).append img
|
||||
tr.append $( '<td>' ).attr( 'class', 'title').text( opt.val() )
|
||||
table.append tr
|
||||
if $( '#ap_' + idAI ).length is 0
|
||||
div = $( '<div>' )
|
||||
.attr( 'id', 'ap_' + idAI )
|
||||
td = $( '<div> ')
|
||||
td.append $( '<div>' )
|
||||
.attr( 'class', 'modName underlined' ).text arrAI[0]
|
||||
div.append td
|
||||
$( '#action_params' ).append div
|
||||
fFetchActionParams div, arrAI[0]
|
||||
tr.append $( '<td>' ).attr( 'class', 'title').text opt.val()
|
||||
td = $( '<td>' ).attr( 'class', 'funcMappings').appendTo tr
|
||||
fFetchActionFunctionParams td, arrName
|
||||
if arrName[ 0 ] not in arrEls
|
||||
div = $( '<div>' ).appendTo $( '#action_params' )
|
||||
subdiv = $( '<div> ').appendTo div
|
||||
subdiv.append $( '<div>' )
|
||||
.attr( 'class', 'modName underlined' ).text arrName[ 0 ]
|
||||
fFetchActionParams div, arrName[ 0 ]
|
||||
opt.remove()
|
||||
|
||||
$( '#selected_actions' ).on 'click', 'img', () ->
|
||||
id = $( this ).closest( 'tr' ).attr( 'id' ).substring 6
|
||||
name = arrActionInvoker[id]
|
||||
arrName = name.split ' -> '
|
||||
$( '#title_' + id ).remove()
|
||||
$( '#params_' + id ).remove()
|
||||
opt = $( '<option>' ).attr( 'id', id ).text name
|
||||
act = $( this ).closest( 'td' ).siblings( '.title' ).text()
|
||||
arrName = act.split ' -> '
|
||||
|
||||
nMods = 0
|
||||
# Check whether we're the only function left that was selected from this module
|
||||
$( "#selected_actions td.title" ).each () ->
|
||||
arrNm = $( this ).text().split ' -> '
|
||||
nMods++ if arrNm[0] is arrName[0]
|
||||
if nMods is 1
|
||||
$('#action_params > div').each () ->
|
||||
if $( this ).children( 'div.modName' ).text() is arrName[ 0 ]
|
||||
$( this ).remove()
|
||||
|
||||
opt = $( '<option>' ).text arrName[ 0 ]
|
||||
$( '#select_actions' ).append opt
|
||||
$( '#ap_' + id ).remove()
|
||||
$( this ).closest( 'tr' ).remove()
|
||||
|
||||
|
||||
$( '#but_submit' ).click () ->
|
||||
|
|
@ -208,20 +209,23 @@ fOnLoad = () ->
|
|||
ap = {}
|
||||
$( '> div', $( '#action_params' ) ).each () ->
|
||||
modName = $( '.modName', this ).text()
|
||||
id = $( this ).attr( 'id' ).substring 3
|
||||
params = {}
|
||||
$( 'tr', this ).each () ->
|
||||
key = $( '.key', this ).text()
|
||||
val = $( 'input', this ).val()
|
||||
if val is ''
|
||||
throw new Error "'#{ key }' missing for '#{ id }'"
|
||||
throw new Error "'#{ key }' missing for '#{ modName }'"
|
||||
params[key] = val
|
||||
encryptedParams = cryptico.encrypt JSON.stringify( params ), strPublicKey
|
||||
ap[modName] = encryptedParams.cipher
|
||||
acts = []
|
||||
$( '#selected_actions .title' ).each () ->
|
||||
acts.push $( this ).text()
|
||||
|
||||
actParams = {}
|
||||
$( '#selected_actions' ).each () ->
|
||||
acts.push $( '.title', this ).text()
|
||||
$( '.funcMappings tr' ).each () ->
|
||||
console.log $( 'input[type=text]', this ).val()
|
||||
console.log $( 'input[type=checkbox]', this ).is( ':checked' )
|
||||
|
||||
try
|
||||
conds = JSON.parse editor.getValue()
|
||||
catch err
|
||||
|
|
@ -240,6 +244,7 @@ fOnLoad = () ->
|
|||
conditions: conds
|
||||
actions: acts
|
||||
action_params: ap
|
||||
action_functions: actParams
|
||||
obj.payload = JSON.stringify obj.payload
|
||||
window.scrollTo 0, 0
|
||||
$.post( '/usercommand', obj )
|
||||
|
|
@ -247,21 +252,26 @@ fOnLoad = () ->
|
|||
$( '#info' ).text data.message
|
||||
$( '#info' ).attr 'class', 'success'
|
||||
.fail ( err ) ->
|
||||
if err.status is 401
|
||||
window.location.href = 'forge?page=forge_rule'
|
||||
if err.responseText is ''
|
||||
msg = 'No Response from Server!'
|
||||
else
|
||||
fDelayed = () ->
|
||||
if err.responseText is ''
|
||||
msg = 'No Response from Server!'
|
||||
else
|
||||
try
|
||||
oErr = JSON.parse err.responseText
|
||||
msg = oErr.message
|
||||
$( '#info' ).text 'Error in upload: ' + msg
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
setTimeout fDelayed, 500
|
||||
try
|
||||
msg = JSON.parse( err.responseText ).message
|
||||
fFailedRequest( 'Error in upload: ' + msg ) err
|
||||
catch err
|
||||
$( '#info' ).text 'Error in upload: ' + err.message
|
||||
$( '#info' ).attr 'class', 'error'
|
||||
alert err.message
|
||||
|
||||
arrParams = window.location.search.substring(1).split '&'
|
||||
id = ''
|
||||
for param in arrParams
|
||||
arrKV = param.split '='
|
||||
if arrKV[ 0 ] is 'id'
|
||||
id = decodeURIComponent arrKV[ 1 ]
|
||||
if id isnt ''
|
||||
console.log id
|
||||
|
||||
|
||||
|
||||
window.addEventListener 'load', fOnLoad, true
|
||||
|
|
|
|||
|
|
@ -54,17 +54,17 @@
|
|||
}).done(fUpdateModuleList).fail(fErrHandler('Did not retrieve rules! '));
|
||||
};
|
||||
fUpdateModuleList = function(data) {
|
||||
var img, imgTwo, inp, modName, oMods, tr, _results;
|
||||
var img, inp, modName, oMods, tr, _results;
|
||||
$('#tableModules tr').remove();
|
||||
oMods = JSON.parse(data.message);
|
||||
_results = [];
|
||||
for (modName in oMods) {
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('class', 'del').attr('src', 'red_cross_small.png');
|
||||
imgTwo = $('<img>').attr('class', 'log').attr('src', 'logicon.png');
|
||||
inp = $('<div>').text(modName);
|
||||
img = $('<img>').attr('class', 'del').attr('title', 'Delete Module').attr('src', 'red_cross_small.png');
|
||||
tr.append($('<td>').append(img));
|
||||
img = $('<img>').attr('class', 'log').attr('title', 'Edit Module').attr('src', 'edit.png');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(imgTwo));
|
||||
tr.append($('<td>').append(inp));
|
||||
_results.push($('#tableModules').append(tr));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
var fOnLoad;
|
||||
|
||||
fOnLoad = function() {
|
||||
var fErrHandler, fFetchRules, fUpdateRuleList;
|
||||
var fChangeInputVisibility, fErrHandler, fFetchRules, fUpdateRuleList;
|
||||
document.title = 'Edit Rules';
|
||||
$('#pagetitle').text("{{{user.username}}}, edit your Rules!");
|
||||
fErrHandler = function(errMsg) {
|
||||
|
|
@ -36,18 +36,20 @@
|
|||
}).done(fUpdateRuleList).fail(fErrHandler('Did not retrieve rules! '));
|
||||
};
|
||||
fUpdateRuleList = function(data) {
|
||||
var img, imgTwo, inp, ruleName, tr, _i, _len, _ref, _results;
|
||||
var img, inp, ruleName, tr, _i, _len, _ref, _results;
|
||||
$('#tableRules tr').remove();
|
||||
_ref = data.message;
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
ruleName = _ref[_i];
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('class', 'del').attr('src', 'red_cross_small.png');
|
||||
imgTwo = $('<img>').attr('class', 'log').attr('src', 'logicon.png');
|
||||
inp = $('<div>').text(ruleName);
|
||||
img = $('<img>').attr('class', 'del').attr('title', 'Delete Rule').attr('src', 'red_cross_small.png');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(imgTwo));
|
||||
img = $('<img>').attr('class', 'edit').attr('title', 'Edit Rule').attr('src', 'edit.png');
|
||||
tr.append($('<td>').append(img));
|
||||
img = $('<img>').attr('class', 'log').attr('title', 'Show Rule Log').attr('src', 'logicon.png');
|
||||
tr.append($('<td>').append(img));
|
||||
inp = $('<div>').text(ruleName);
|
||||
tr.append($('<td>').append(inp));
|
||||
_results.push($('#tableRules').append(tr));
|
||||
}
|
||||
|
|
@ -69,7 +71,12 @@
|
|||
return $.post('/usercommand', data).done(fFetchRules).fail(fErrHandler('Could not delete rule! '));
|
||||
}
|
||||
});
|
||||
return $('#tableRules').on('click', 'img.log', function() {
|
||||
$('#tableRules').on('click', 'img.edit', function() {
|
||||
var ruleName;
|
||||
ruleName = $('div', $(this).closest('tr')).text();
|
||||
return window.location.href = 'forge?page=forge_rule&id=' + encodeURIComponent(ruleName);
|
||||
});
|
||||
$('#tableRules').on('click', 'img.log', function() {
|
||||
var data, ruleName;
|
||||
ruleName = $('div', $(this).closest('tr')).text();
|
||||
data = {
|
||||
|
|
@ -85,6 +92,46 @@
|
|||
return $('#log_col').html("<h3>" + ruleName + " Log:</h3>" + log);
|
||||
}).fail(fErrHandler('Could not get rule log! '));
|
||||
});
|
||||
fChangeInputVisibility = function() {
|
||||
return $('#tableParams tr').each(function(id) {
|
||||
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
|
||||
$('img', this).hide();
|
||||
return $('input[type=checkbox]', this).hide();
|
||||
} else {
|
||||
$('img', this).show();
|
||||
return $('input[type=checkbox]', this).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
$('#tableParams').on('click', 'img', function() {
|
||||
var par;
|
||||
par = $(this).closest('tr');
|
||||
if (!par.is(':last-child')) {
|
||||
par.remove();
|
||||
}
|
||||
return fChangeInputVisibility();
|
||||
});
|
||||
$('#tableParams').on('keyup', 'input', function(e) {
|
||||
var cb, code, img, inp, par, tr;
|
||||
code = e.keyCode || e.which;
|
||||
if (code !== 9) {
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child')) {
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
|
||||
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
|
||||
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(cb));
|
||||
tr.append($('<td>').append(inp));
|
||||
par.parent().append(tr);
|
||||
return fChangeInputVisibility();
|
||||
} else if ($(this).val() === '' && !par.is(':only-child')) {
|
||||
return par.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
return fChangeInputVisibility();
|
||||
};
|
||||
|
||||
window.addEventListener('load', fOnLoad, true);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
var fOnLoad;
|
||||
|
||||
fOnLoad = function() {
|
||||
var editor, fChangeCrosses;
|
||||
var editor, fChangeInputVisibility;
|
||||
document.title = 'Forge Action Invoker';
|
||||
$('#pagetitle').text("{{{user.username}}}, forge your custom action invoker!");
|
||||
editor = ace.edit("editor");
|
||||
|
|
@ -18,14 +18,14 @@
|
|||
return editor.getSession().setMode("ace/mode/javascript");
|
||||
}
|
||||
});
|
||||
fChangeCrosses = function() {
|
||||
return $('#tableParams img').each(function(id) {
|
||||
var par;
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child' || par.is(':only-child'))) {
|
||||
return $(this).hide();
|
||||
fChangeInputVisibility = function() {
|
||||
return $('#tableParams tr').each(function(id) {
|
||||
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
|
||||
$('img', this).hide();
|
||||
return $('input[type=checkbox]', this).hide();
|
||||
} else {
|
||||
return $(this).show();
|
||||
$('img', this).show();
|
||||
return $('input[type=checkbox]', this).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -35,36 +35,43 @@
|
|||
if (!par.is(':last-child')) {
|
||||
par.remove();
|
||||
}
|
||||
return fChangeCrosses();
|
||||
return fChangeInputVisibility();
|
||||
});
|
||||
$('#tableParams').on('keyup', 'input', function() {
|
||||
var img, inp, par, tr;
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child')) {
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('src', 'red_cross_small.png');
|
||||
inp = $('<input>').attr('type', 'text');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(inp));
|
||||
par.parent().append(tr);
|
||||
return fChangeCrosses();
|
||||
} else if ($(this).val() === '' && !par.is(':only-child')) {
|
||||
return par.remove();
|
||||
$('#tableParams').on('keyup', 'input', function(e) {
|
||||
var cb, code, img, inp, par, tr;
|
||||
code = e.keyCode || e.which;
|
||||
if (code !== 9) {
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child')) {
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
|
||||
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
|
||||
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(cb));
|
||||
tr.append($('<td>').append(inp));
|
||||
par.parent().append(tr);
|
||||
return fChangeInputVisibility();
|
||||
} else if ($(this).val() === '' && !par.is(':only-child')) {
|
||||
return par.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
fChangeCrosses();
|
||||
fChangeInputVisibility();
|
||||
return $('#but_submit').click(function() {
|
||||
var listParams, obj;
|
||||
if ($('#input_id').val() === '') {
|
||||
return alert('Please enter an action invoker name!');
|
||||
} else {
|
||||
listParams = [];
|
||||
$('#tableParams input').each(function() {
|
||||
var val;
|
||||
val = $(this).val();
|
||||
listParams = {};
|
||||
$('#tableParams tr').each(function() {
|
||||
var shld, val;
|
||||
val = $('input.textinput', this).val();
|
||||
shld = $('input[type=checkbox]', this).is(':checked');
|
||||
if (val !== "") {
|
||||
return listParams.push(val);
|
||||
listParams[val] = shld;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
obj = {
|
||||
command: 'forge_action_invoker',
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
var fOnLoad;
|
||||
|
||||
fOnLoad = function() {
|
||||
var editor, fChangeCrosses;
|
||||
var editor, fChangeInputVisibility;
|
||||
document.title = 'Forge Event Poller';
|
||||
$('#pagetitle').text("{{{user.username}}}, forge your custom event poller!");
|
||||
editor = ace.edit("editor");
|
||||
|
|
@ -17,14 +17,14 @@
|
|||
return editor.getSession().setMode("ace/mode/javascript");
|
||||
}
|
||||
});
|
||||
fChangeCrosses = function() {
|
||||
return $('#tableParams img').each(function(id) {
|
||||
var par;
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child' || par.is(':only-child'))) {
|
||||
return $(this).hide();
|
||||
fChangeInputVisibility = function() {
|
||||
return $('#tableParams tr').each(function(id) {
|
||||
if ($(this).is(':last-child' || $(this).is(':only-child'))) {
|
||||
$('img', this).hide();
|
||||
return $('input[type=checkbox]', this).hide();
|
||||
} else {
|
||||
return $(this).show();
|
||||
$('img', this).show();
|
||||
return $('input[type=checkbox]', this).show();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
@ -34,36 +34,44 @@
|
|||
if (!par.is(':last-child')) {
|
||||
par.remove();
|
||||
}
|
||||
return fChangeCrosses();
|
||||
return fChangeInputVisibility();
|
||||
});
|
||||
$('#tableParams').on('keyup', 'input', function() {
|
||||
var img, inp, par, tr;
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child')) {
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('src', 'red_cross_small.png');
|
||||
inp = $('<input>').attr('type', 'text');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(inp));
|
||||
par.parent().append(tr);
|
||||
return fChangeCrosses();
|
||||
} else if ($(this).val() === '' && !par.is(':only-child')) {
|
||||
return par.remove();
|
||||
$('#tableParams').on('keyup', 'input', function(e) {
|
||||
var cb, code, img, inp, par, tr;
|
||||
code = e.keyCode || e.which;
|
||||
if (code !== 9) {
|
||||
par = $(this).closest('tr');
|
||||
if (par.is(':last-child')) {
|
||||
tr = $('<tr>');
|
||||
img = $('<img>').attr('title', 'Remove?').attr('src', 'red_cross_small.png');
|
||||
cb = $('<input>').attr('type', 'checkbox').attr('title', 'Password shielded input?');
|
||||
inp = $('<input>').attr('type', 'text').attr('class', 'textinput');
|
||||
tr.append($('<td>').append(img));
|
||||
tr.append($('<td>').append(cb));
|
||||
tr.append($('<td>').append(inp));
|
||||
tr.append($('<td>'));
|
||||
par.parent().append(tr);
|
||||
return fChangeInputVisibility();
|
||||
} else if ($(this).val() === '' && !par.is(':only-child')) {
|
||||
return par.remove();
|
||||
}
|
||||
}
|
||||
});
|
||||
fChangeCrosses();
|
||||
fChangeInputVisibility();
|
||||
return $('#but_submit').click(function() {
|
||||
var listParams, obj;
|
||||
if ($('#input_id').val() === '') {
|
||||
return alert('Please enter an event poller name!');
|
||||
} else {
|
||||
listParams = [];
|
||||
$('#tableParams input').each(function() {
|
||||
var val;
|
||||
val = $(this).val();
|
||||
listParams = {};
|
||||
$('#tableParams tr').each(function() {
|
||||
var shld, val;
|
||||
val = $('input.textinput', this).val();
|
||||
shld = $('input[type=checkbox]', this).is(':checked');
|
||||
if (val !== "") {
|
||||
return listParams.push(val);
|
||||
listParams[val] = shld;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
obj = {
|
||||
command: 'forge_event_poller',
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
// Generated by CoffeeScript 1.7.1
|
||||
(function() {
|
||||
var fOnLoad, strPublicKey;
|
||||
var fFailedRequest, fOnLoad, strPublicKey,
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
strPublicKey = '';
|
||||
|
||||
fFailedRequest = function(msg) {
|
||||
return function(err) {
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
$('#info').text(msg);
|
||||
return $('#info').attr('class', 'error');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
$.post('/usercommand', {
|
||||
command: 'get_public_key'
|
||||
}).done(function(data) {
|
||||
|
|
@ -12,20 +24,19 @@
|
|||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
console.log(err);
|
||||
$('#info').text('Error fetching public key, unable to send user-specific parameters securely');
|
||||
$('#info').text('Error fetching public key, unable to send user specific parameters securely');
|
||||
return $('#info').attr('class', 'error');
|
||||
}
|
||||
});
|
||||
|
||||
fOnLoad = function() {
|
||||
var arrActionInvoker, editor, fFetchActionParams, fFetchEventParams, obj;
|
||||
var arrKV, arrParams, editor, fFetchActionFunctionParams, fFetchActionParams, fFetchEventParams, id, obj, param, _i, _len;
|
||||
document.title = 'Rule Forge!';
|
||||
$('#pagetitle').text('{{{user.username}}}, forge your ECA Rule!');
|
||||
editor = ace.edit("editor_conditions");
|
||||
editor.setTheme("ace/theme/monokai");
|
||||
editor.getSession().setMode("ace/mode/json");
|
||||
editor.setShowPrintMargin(false);
|
||||
document.title = 'Rule Forge!';
|
||||
$('#pagetitle').text('{{{user.username}}}, forge your ECA Rule!');
|
||||
fFetchEventParams = function(name) {
|
||||
var arr, obj;
|
||||
if (name) {
|
||||
|
|
@ -38,49 +49,37 @@
|
|||
};
|
||||
obj.payload = JSON.stringify(obj.payload);
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
var arrParams, fAppendParam, table, _i, _len, _results;
|
||||
var fAppendParam, oParams, shielded, table, _results;
|
||||
if (data.message) {
|
||||
arrParams = JSON.parse(data.message);
|
||||
oParams = JSON.parse(data.message);
|
||||
$('#event_poller_params table').remove();
|
||||
if (arrParams.length > 0) {
|
||||
table = $('<table>');
|
||||
$('#event_poller_params').append(table);
|
||||
fAppendParam = function(name) {
|
||||
var inp, tr;
|
||||
tr = $('<tr>');
|
||||
tr.append($('<td>').css('width', '20px'));
|
||||
tr.append($('<td>').attr('class', 'key').text(name));
|
||||
inp = $('<input>').attr('type', 'password').attr('id', "" + name);
|
||||
tr.append($('<td>').text(' :').append(inp));
|
||||
return table.append(tr);
|
||||
};
|
||||
_results = [];
|
||||
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
|
||||
name = arrParams[_i];
|
||||
_results.push(fAppendParam(name));
|
||||
table = $('<table>');
|
||||
$('#event_poller_params').append(table);
|
||||
fAppendParam = function(name, shielded) {
|
||||
var inp, tr;
|
||||
tr = $('<tr>');
|
||||
tr.append($('<td>').css('width', '20px'));
|
||||
tr.append($('<td>').attr('class', 'key').text(name));
|
||||
inp = $('<input>').attr('id', "" + name);
|
||||
if (shielded) {
|
||||
inp.attr('type', 'password');
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
}
|
||||
}).fail(function(err) {
|
||||
var fDelayed;
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
fDelayed = function() {
|
||||
console.log(err);
|
||||
$('#info').text('Error fetching event poller params');
|
||||
return $('#info').attr('class', 'error');
|
||||
tr.append($('<td>').text(' : ').append(inp));
|
||||
return table.append(tr);
|
||||
};
|
||||
return setTimeout(fDelayed, 500);
|
||||
_results = [];
|
||||
for (name in oParams) {
|
||||
shielded = oParams[name];
|
||||
_results.push(fAppendParam(name, shielded));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
});
|
||||
}).fail(fFailedRequest('Error fetching event poller params'));
|
||||
}
|
||||
};
|
||||
obj = {
|
||||
$.post('/usercommand', {
|
||||
command: 'get_event_pollers'
|
||||
};
|
||||
$.post('/usercommand', obj).done(function(data) {
|
||||
}).done(function(data) {
|
||||
var err, events, fAppendEvents, id, oEps;
|
||||
try {
|
||||
oEps = JSON.parse(data.message);
|
||||
|
|
@ -106,28 +105,15 @@
|
|||
fAppendEvents(id, events);
|
||||
}
|
||||
return fFetchEventParams($('#select_event option:selected').text());
|
||||
}).fail(function(err) {
|
||||
var fDelayed;
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
fDelayed = function() {
|
||||
console.log(err);
|
||||
$('#info').text('Error fetching event poller');
|
||||
return $('#info').attr('class', 'error');
|
||||
};
|
||||
return setTimeout(fDelayed, 500);
|
||||
}
|
||||
});
|
||||
}).fail(fFailedRequest('Error fetching event poller'));
|
||||
$('#select_event').change(function() {
|
||||
return fFetchEventParams($(this).val());
|
||||
});
|
||||
arrActionInvoker = [];
|
||||
obj = {
|
||||
command: 'get_action_invokers'
|
||||
};
|
||||
$.post('/usercommand', obj).done(function(data) {
|
||||
var actions, err, fAppendActions, i, id, oAis, _results;
|
||||
var actions, err, fAppendActions, module, oAis, _results;
|
||||
try {
|
||||
oAis = JSON.parse(data.message);
|
||||
} catch (_error) {
|
||||
|
|
@ -135,118 +121,140 @@
|
|||
console.error('ERROR: non-object received from server: ' + data.message);
|
||||
return;
|
||||
}
|
||||
i = 0;
|
||||
fAppendActions = function(id, actions) {
|
||||
var act, fAppendAction, _i, _len, _results;
|
||||
fAppendAction = function(act) {
|
||||
$('#select_actions').append($('<option>').attr('id', i++).text(id + ' -> ' + act));
|
||||
return arrActionInvoker.push(id + ' -> ' + act);
|
||||
};
|
||||
fAppendActions = function(module, actions) {
|
||||
var act, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
||||
act = actions[_i];
|
||||
_results.push(fAppendAction(act));
|
||||
_results.push($('#select_actions').append($('<option>').text(module + ' -> ' + act)));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
_results = [];
|
||||
for (id in oAis) {
|
||||
actions = oAis[id];
|
||||
_results.push(fAppendActions(id, actions));
|
||||
for (module in oAis) {
|
||||
actions = oAis[module];
|
||||
_results.push(fAppendActions(module, actions));
|
||||
}
|
||||
return _results;
|
||||
}).fail(function(err) {
|
||||
var fDelayed;
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
console.log(err);
|
||||
fDelayed = function() {
|
||||
$('#info').text('Error fetching event poller');
|
||||
return $('#info').attr('class', 'error');
|
||||
};
|
||||
return setTimeout(fDelayed, 500);
|
||||
}
|
||||
});
|
||||
fFetchActionParams = function(div, name) {
|
||||
}).fail(fFailedRequest('Error fetching event poller'));
|
||||
fFetchActionParams = function(div, modName) {
|
||||
obj = {
|
||||
command: 'get_action_invoker_params',
|
||||
payload: {
|
||||
id: name
|
||||
id: modName
|
||||
}
|
||||
};
|
||||
obj.payload = JSON.stringify(obj.payload);
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
var arrParams, fAppendActionParam, table, _i, _len, _results;
|
||||
var fAppendActionParam, name, oParams, sh, table, _results;
|
||||
if (data.message) {
|
||||
arrParams = JSON.parse(data.message);
|
||||
if (arrParams.length > 0) {
|
||||
table = $('<table>');
|
||||
div.append(table);
|
||||
fAppendActionParam = function(name) {
|
||||
var tr;
|
||||
tr = $('<tr>');
|
||||
tr.append($('<td>').css('width', '20px'));
|
||||
tr.append($('<td>').attr('class', 'key').text(name));
|
||||
tr.append($('<td>').text(' :').append($('<input>').attr('type', 'password')));
|
||||
return table.append(tr);
|
||||
};
|
||||
oParams = JSON.parse(data.message);
|
||||
table = $('<table>');
|
||||
div.append(table);
|
||||
fAppendActionParam = function(name, shielded) {
|
||||
var inp, tr;
|
||||
tr = $('<tr>');
|
||||
tr.append($('<td>').css('width', '20px'));
|
||||
tr.append($('<td>').attr('class', 'key').text(name));
|
||||
inp = $('<input>').attr('id', "" + name);
|
||||
if (shielded) {
|
||||
inp.attr('type', 'password');
|
||||
} else {
|
||||
inp.attr('type', 'text');
|
||||
}
|
||||
tr.append($('<td>').text(' : ').append(inp));
|
||||
return table.append(tr);
|
||||
};
|
||||
_results = [];
|
||||
for (name in oParams) {
|
||||
sh = oParams[name];
|
||||
_results.push(fAppendActionParam(name, sh));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
}).fail(fFailedRequest('Error fetching action invoker params'));
|
||||
};
|
||||
fFetchActionFunctionParams = function(tag, arrName) {
|
||||
obj = {
|
||||
command: 'get_action_invoker_function_params',
|
||||
payload: {
|
||||
id: arrName[0]
|
||||
}
|
||||
};
|
||||
obj.payload = JSON.stringify(obj.payload);
|
||||
return $.post('/usercommand', obj).done(function(data) {
|
||||
var functionArgument, oParams, table, td, tr, _i, _len, _ref, _results;
|
||||
if (data.message) {
|
||||
oParams = JSON.parse(data.message);
|
||||
if (oParams[arrName[1]]) {
|
||||
table = $('<table>').appendTo(tag);
|
||||
_ref = oParams[arrName[1]];
|
||||
_results = [];
|
||||
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
|
||||
name = arrParams[_i];
|
||||
_results.push(fAppendActionParam(name));
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
functionArgument = _ref[_i];
|
||||
tr = $('<tr>').appendTo(table);
|
||||
td = $('<td>').appendTo(tr);
|
||||
td.append($('<div>').text(functionArgument));
|
||||
tr.append(td);
|
||||
td = $('<td>').appendTo(tr);
|
||||
td.append($('<input>').attr('type', 'text'));
|
||||
tr.append(td);
|
||||
tr.append(td);
|
||||
td = $('<td>').appendTo(tr);
|
||||
_results.push(td.append($('<input>').attr('type', 'checkbox')).attr('title', 'js-select expression to be resolved on event?'));
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
}
|
||||
}).fail(function(err) {
|
||||
var fDelayed;
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
} else {
|
||||
console.log(err);
|
||||
fDelayed = function() {
|
||||
$('#info').text('Error fetching action invoker params');
|
||||
return $('#info').attr('class', 'error');
|
||||
};
|
||||
return setTimeout(fDelayed, 500);
|
||||
}
|
||||
});
|
||||
}).fail(fFailedRequest('Error fetching action invoker function params'));
|
||||
};
|
||||
$('#select_actions').on('change', function() {
|
||||
var arrAI, div, idAI, img, opt, table, td, tr;
|
||||
var arrEls, arrName, div, img, opt, subdiv, table, td, tr, _ref;
|
||||
opt = $('option:selected', this);
|
||||
arrAI = opt.val().split(' -> ');
|
||||
idAI = opt.attr('id');
|
||||
arrName = opt.text().split(' -> ');
|
||||
arrEls = $("#action_params div.modName").map(function() {
|
||||
return $(this).text();
|
||||
}).get();
|
||||
table = $('#selected_actions');
|
||||
tr = $('<tr>').attr('id', 'title_' + idAI);
|
||||
tr = $('<tr>').appendTo(table);
|
||||
img = $('<img>').attr('src', 'red_cross_small.png');
|
||||
tr.append($('<td>').css('width', '20px').append(img));
|
||||
tr.append($('<td>').attr('class', 'title').text(opt.val()));
|
||||
table.append(tr);
|
||||
if ($('#ap_' + idAI).length === 0) {
|
||||
div = $('<div>').attr('id', 'ap_' + idAI);
|
||||
td = $('<div> ');
|
||||
td.append($('<div>')).attr('class', 'modName underlined').text(arrAI[0]);
|
||||
div.append(td);
|
||||
$('#action_params').append(div);
|
||||
fFetchActionParams(div, arrAI[0]);
|
||||
td = $('<td>').attr('class', 'funcMappings').appendTo(tr);
|
||||
fFetchActionFunctionParams(td, arrName);
|
||||
if (_ref = arrName[0], __indexOf.call(arrEls, _ref) < 0) {
|
||||
div = $('<div>').appendTo($('#action_params'));
|
||||
subdiv = $('<div> ').appendTo(div);
|
||||
subdiv.append($('<div>')).attr('class', 'modName underlined').text(arrName[0]);
|
||||
fFetchActionParams(div, arrName[0]);
|
||||
}
|
||||
return opt.remove();
|
||||
});
|
||||
$('#selected_actions').on('click', 'img', function() {
|
||||
var arrName, id, name, opt;
|
||||
id = $(this).closest('tr').attr('id').substring(6);
|
||||
name = arrActionInvoker[id];
|
||||
arrName = name.split(' -> ');
|
||||
$('#title_' + id).remove();
|
||||
$('#params_' + id).remove();
|
||||
opt = $('<option>').attr('id', id).text(name);
|
||||
var act, arrName, nMods, opt;
|
||||
act = $(this).closest('td').siblings('.title').text();
|
||||
arrName = act.split(' -> ');
|
||||
nMods = 0;
|
||||
$("#selected_actions td.title").each(function() {
|
||||
var arrNm;
|
||||
arrNm = $(this).text().split(' -> ');
|
||||
if (arrNm[0] === arrName[0]) {
|
||||
return nMods++;
|
||||
}
|
||||
});
|
||||
if (nMods === 1) {
|
||||
$('#action_params > div').each(function() {
|
||||
if ($(this).children('div.modName').text() === arrName[0]) {
|
||||
return $(this).remove();
|
||||
}
|
||||
});
|
||||
}
|
||||
opt = $('<option>').text(arrName[0]);
|
||||
$('#select_actions').append(opt);
|
||||
return $('#ap_' + id).remove();
|
||||
return $(this).closest('tr').remove();
|
||||
});
|
||||
return $('#but_submit').click(function() {
|
||||
var acts, ap, conds, encryptedParams, ep, err;
|
||||
$('#but_submit').click(function() {
|
||||
var actParams, acts, ap, conds, encryptedParams, ep, err;
|
||||
try {
|
||||
if ($('#select_event option:selected').length === 0) {
|
||||
throw new Error('Please create an Event Poller first!');
|
||||
|
|
@ -269,16 +277,15 @@
|
|||
}
|
||||
ap = {};
|
||||
$('> div', $('#action_params')).each(function() {
|
||||
var encryptedParams, id, modName, params;
|
||||
var encryptedParams, modName, params;
|
||||
modName = $('.modName', this).text();
|
||||
id = $(this).attr('id').substring(3);
|
||||
params = {};
|
||||
$('tr', this).each(function() {
|
||||
var key, val;
|
||||
key = $('.key', this).text();
|
||||
val = $('input', this).val();
|
||||
if (val === '') {
|
||||
throw new Error("'" + key + "' missing for '" + id + "'");
|
||||
throw new Error("'" + key + "' missing for '" + modName + "'");
|
||||
}
|
||||
return params[key] = val;
|
||||
});
|
||||
|
|
@ -286,8 +293,13 @@
|
|||
return ap[modName] = encryptedParams.cipher;
|
||||
});
|
||||
acts = [];
|
||||
$('#selected_actions .title').each(function() {
|
||||
return acts.push($(this).text());
|
||||
actParams = {};
|
||||
$('#selected_actions').each(function() {
|
||||
acts.push($('.title', this).text());
|
||||
return $('.funcMappings tr').each(function() {
|
||||
console.log($('input[type=text]', this).val());
|
||||
return console.log($('input[type=checkbox]', this).is(':checked'));
|
||||
});
|
||||
});
|
||||
try {
|
||||
conds = JSON.parse(editor.getValue());
|
||||
|
|
@ -307,7 +319,8 @@
|
|||
event_params: encryptedParams.cipher,
|
||||
conditions: conds,
|
||||
actions: acts,
|
||||
action_params: ap
|
||||
action_params: ap,
|
||||
action_functions: actParams
|
||||
}
|
||||
};
|
||||
obj.payload = JSON.stringify(obj.payload);
|
||||
|
|
@ -316,25 +329,15 @@
|
|||
$('#info').text(data.message);
|
||||
return $('#info').attr('class', 'success');
|
||||
}).fail(function(err) {
|
||||
var fDelayed;
|
||||
if (err.status === 401) {
|
||||
return window.location.href = 'forge?page=forge_rule';
|
||||
var msg;
|
||||
if (err.responseText === '') {
|
||||
msg = 'No Response from Server!';
|
||||
} else {
|
||||
fDelayed = function() {
|
||||
var msg, oErr;
|
||||
if (err.responseText === '') {
|
||||
msg = 'No Response from Server!';
|
||||
} else {
|
||||
try {
|
||||
oErr = JSON.parse(err.responseText);
|
||||
msg = oErr.message;
|
||||
} catch (_error) {}
|
||||
}
|
||||
$('#info').text('Error in upload: ' + msg);
|
||||
return $('#info').attr('class', 'error');
|
||||
};
|
||||
return setTimeout(fDelayed, 500);
|
||||
try {
|
||||
msg = JSON.parse(err.responseText).message;
|
||||
} catch (_error) {}
|
||||
}
|
||||
return fFailedRequest('Error in upload: ' + msg)(err);
|
||||
});
|
||||
} catch (_error) {
|
||||
err = _error;
|
||||
|
|
@ -343,6 +346,18 @@
|
|||
return alert(err.message);
|
||||
}
|
||||
});
|
||||
arrParams = window.location.search.substring(1).split('&');
|
||||
id = '';
|
||||
for (_i = 0, _len = arrParams.length; _i < _len; _i++) {
|
||||
param = arrParams[_i];
|
||||
arrKV = param.split('=');
|
||||
if (arrKV[0] === 'id') {
|
||||
id = decodeURIComponent(arrKV[1]);
|
||||
}
|
||||
}
|
||||
if (id !== '') {
|
||||
return console.log(id);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('load', fOnLoad, true);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,13 @@
|
|||
<td valign="top" width="700px">
|
||||
<div id="moduleName"><h2> </h2></div>
|
||||
<div id="moduleLanguage"><b> </b></div>
|
||||
<div id="editor"></div>
|
||||
<div id="editor"></div>
|
||||
<td id="params_col" valign="top">
|
||||
User-specific properties:
|
||||
<table id="tableParams">
|
||||
|
||||
</table>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
@ -7,6 +7,7 @@ Action Invoker Name: <input id="input_id" type="text" />
|
|||
<tr>
|
||||
<td id="editor_col" valign="top">
|
||||
<div id="editor">
|
||||
|
||||
###
|
||||
ProBinder ACTION INVOKER
|
||||
------------------------
|
||||
|
|
@ -15,8 +16,6 @@ Global variables
|
|||
This module requires user-specific parameters:
|
||||
- username
|
||||
- password
|
||||
- companyId: company where to post the binder entries
|
||||
- contextId: context where to post the binder entries
|
||||
###
|
||||
urlService = 'https://probinder.com/service/'
|
||||
credentials =
|
||||
|
|
@ -59,44 +58,39 @@ callService = ( args ) ->
|
|||
###
|
||||
Does everything to post something in a binder
|
||||
|
||||
@param {Object} args the object containing the content
|
||||
@param {String} args.content the content to be posted
|
||||
@param {String} companyId the comany associated to the binder
|
||||
@param {String} contextId the binder id
|
||||
@param {String} content the content to be posted
|
||||
###
|
||||
exports.newContent = ( args ) ->
|
||||
if not args.callback
|
||||
args.callback = standardCallback 'newContent'
|
||||
exports.newContent = ( companyId, contextId, content ) ->
|
||||
if arguments[ 4 ]
|
||||
callback = arguments[ 4 ]
|
||||
else
|
||||
callback = standardCallback 'newContent'
|
||||
callService
|
||||
service: '27'
|
||||
method: 'save'
|
||||
data:
|
||||
companyId: params.companyId
|
||||
context: params.contextId
|
||||
text: args.content
|
||||
callback: args.callback
|
||||
companyId: companyId
|
||||
context: contextId
|
||||
text: content
|
||||
callback: callback
|
||||
|
||||
###
|
||||
Does everything to post a file info in a binder tabe
|
||||
Does everything to post a file info in a binder tab
|
||||
|
||||
@param {Object} args the object containing the content
|
||||
@param {String} args.service the content service
|
||||
@param {String} args.id the content id
|
||||
@param {String} fromService the content service which grabs the content
|
||||
@param {String} fromId the content id from which the information is grabbed
|
||||
###
|
||||
exports.makeFileEntry = ( args ) ->
|
||||
if not args.callback
|
||||
args.callback = standardCallback 'makeFileEntry'
|
||||
exports.makeFileEntry = ( fromService, fromId, toCompany, toContext ) ->
|
||||
getContent
|
||||
serviceid: args.service
|
||||
contentid: args.id
|
||||
serviceid: fromService
|
||||
contentid: fromId
|
||||
callback: ( err, resp, body ) ->
|
||||
callService
|
||||
service: '27'
|
||||
method: 'save'
|
||||
data:
|
||||
companyId: params.companyId
|
||||
context: params.contextId
|
||||
text: "New file (#{ body.title }) in tab \"#{ body.context[0].name }\",
|
||||
find it <a href=\"https://probinder.com/file/#{ body.fileIds[0] }\">here</a>!'"
|
||||
callback: args.callback
|
||||
content = "New file (#{ body.title }) in tab \"#{ body.context[0].name }\",
|
||||
find it here!'"
|
||||
exports.newContent toCompanyId, toContextId, content, standardCallback 'makeFileEntry'
|
||||
|
||||
|
||||
###
|
||||
Calls the content get service with the content id and the service id provided.
|
||||
|
|
@ -121,18 +115,15 @@ getContent = ( args ) ->
|
|||
###
|
||||
Sets the content as read.
|
||||
|
||||
@param {Object} args the object containing the content
|
||||
@param {String} args.content the content to be posted
|
||||
@param {Object} id the content id to be set to read.
|
||||
###
|
||||
exports.setRead = ( args ) ->
|
||||
if not args.callback
|
||||
args.callback = standardCallback 'setRead'
|
||||
exports.setRead = ( id ) ->
|
||||
callService
|
||||
service: '2'
|
||||
method: 'setread'
|
||||
data:
|
||||
id: args.id
|
||||
callback: args.callback
|
||||
id: id
|
||||
callback: standardCallback 'setRead'
|
||||
</div>
|
||||
<button id="but_submit">save</button>
|
||||
</td>
|
||||
|
|
@ -141,23 +132,18 @@ This action invoker requires user-specific properties:
|
|||
<table id="tableParams">
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" value="username" /></td>
|
||||
<td><input type="checkbox" title="Password shielded input?" /></td>
|
||||
<td><input type="text" class="textinput" value="username" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" value="password" /></td>
|
||||
<td><input type="checkbox" title="Password shielded input?" checked="true" /></td>
|
||||
<td><input type="text" class="textinput" value="password" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" value="companyId" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" value="contextId" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" /></td>
|
||||
<td><input type="checkbox" title="Password shielded input?" /></td>
|
||||
<td><input type="text" class="textinput" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -40,14 +40,18 @@ exports.newMail = ( pushEvent ) ->
|
|||
This event poller requires user-specific properties:
|
||||
<table id="tableParams">
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" value="apikey" /></td>
|
||||
<td><img src="red_cross_small.png" title="Remove?"></td>
|
||||
<td><input type="checkbox" title="Password shielded input?" checked="true" /></td>
|
||||
<td><input type="text" class="textinput" value="apikey" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><img src="red_cross_small.png"></td>
|
||||
<td><input type="text" /></td>
|
||||
<td><img src="red_cross_small.png" title="Remove?"></td>
|
||||
<td><input type="checkbox" title="Password shielded input?" /></td>
|
||||
<td><input type="text" class="textinput" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</table><!--
|
||||
<td><input type="checkbox" title="Password shielded input?" /></td>
|
||||
<td></td> -->
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
BIN
webpages/public/edit.png
Normal file
BIN
webpages/public/edit.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 634 B |
|
|
@ -6,21 +6,23 @@ body {
|
|||
background-color: #EEF;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
input[type=text],
|
||||
input[type=password] {
|
||||
-webkit-transition: all 0.30s ease-in-out;
|
||||
-moz-transition: all 0.30s ease-in-out;
|
||||
-ms-transition: all 0.30s ease-in-out;
|
||||
-o-transition: all 0.30s ease-in-out;
|
||||
outline: none;
|
||||
padding: 3px 0px 3px 3px;
|
||||
margin: 5px 1px 3px 0px;
|
||||
padding: 2px 0px 2px 3px;
|
||||
margin: 2px 1px 2px 0px;
|
||||
border: 1px solid #DDDDDD;
|
||||
}
|
||||
|
||||
input[type=text]:focus {
|
||||
input[type=text]:focus,
|
||||
input[type=password]:focus {
|
||||
box-shadow: 0 0 5px rgba(81, 203, 238, 1);
|
||||
padding: 3px 0px 3px 3px;
|
||||
margin: 5px 1px 3px 0px;
|
||||
padding: 2px 0px 2px 3px;
|
||||
margin: 2px 1px 2px 0px;
|
||||
border: 1px solid rgba(81, 203, 238, 1);
|
||||
}
|
||||
|
||||
|
|
@ -119,11 +121,25 @@ input[type=text]:focus {
|
|||
width: 10px;
|
||||
}
|
||||
|
||||
#tableParams input {
|
||||
#tableParams input.textinput {
|
||||
width: 150px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
#selected_actions td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#selected_actions .title {
|
||||
font-size: 0.9em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.funcMappings {
|
||||
padding-left: 20px;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
#tableRules tr {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue